For a human, you have to "get familiar with Java".
For a machine ( or a program that is ) it has to follow the rules the language specifies.
For instance the given class:
class Main {
String s;
}
What would be the result of invoking:
Main m = new Main();
m.s.length();
A) doesn't compile?
B) throws exception at runtime?
To answer this specific question you have to know, how classes are defined in Java ( to know if the one I show is a valid class definition or not ) , also you have to know how attributes are defined and default values etc, so you have to get familiar with the language.
When you know all these concepts, you can easily answer with a quick view.
BTW, the famous Sun Certified Java Programmer certification, is all about know this kind of stuff, rather than knowing how to develop an application. It is about converting your self in a "human compiler"