I'm having problems understanding what the JVM does at runtime and what the compiler does.
This code snippet is from K&B SCP&D for J2 book (p218):
This code won't compile because the case argument must be a compile time constant and apparently "b" is assigned "2" at runtime. In theory a more intelligent compiler would be able to substitute 2 for the final variable b into the bytecode.
Ok, fair enough, the compiler only does the minimum possible and leaves calculations and assignments for the runtime environment.
But then check this code (from same book, Self
Test question 4.2):
Based on the first example I would have thought that "x-1" would be evaluated at runtime and consequently this code would cause a compile error.
But no, all of a sudden the compiler isn't a complete doofus and can evaluate "x-1"
So my question is how do you work out what will be done at compile time and what is done at runtime, what rules of thumb are there?
Thanks for any insight.
(ps. I'm studying for the 310-035 exam, should I be posting questions like this here or in the Programmer Certification forum?)