In Java4k, we are using a highly optimized and compressed archives. Not an executable. Also Java provides many high-level methods Wich only need to be called. The unpacking is also handled externally. And as said, you can use a lot (not all) of your provided memory, and much higher Processorspeed than in the old days.
All this adds to the possibibily to make complex games in such a small size.
Nevertheless, 4k does not give you space to store any "normal" assets, images or sounds. So its heavily relying on procedural generation. Even a short text can often drive the game out of bounds.
The resulting sourcecode also looks very messi. And highly linear. (mostly using just one Class, with one main procedure, and 2 small Appletspecific procedures)
---
Even in gamestudio, Im shure its possible to write a decent game in like 64kB(zipped), if the enginefiles are not counted in. Last 256k contest already showed that some cool games can result out of that.