Questions about Java4k Code

Hi there,

Recently I’ve been looking up some more Java4k sources for fun, and have noticed a common pattern that I don’t fully understand.

Namely, people seem to declare all their variables and constants within the run() method, rather than at the class level. Meaning this:


public class Classy
{
  public void run()
  {
      final int CONSTANT = 0;
      int VARIABLE = 1;

      // etc...
  }
}

Instead of this:


public class Classy
{
  private final int CONSTANT = 0;
  private int VARIABLE = 1;

  public void run()
  {
      // etc...
  }
}

I was wondering if there is an actual performance/memory reason for this, or if simply people develop their Java4k games within a single method and just paste it into a standard class skeleton.

A class member requires a constant pool entry, and larger bytecode to access.

That said, once obfuscated these two are equivalent:

static final int a = 0;
run() {
final int b = 0;
}

Thanks!