Platformeasy0-2 years

You get three different Java errors on three different days: `error: illegal start of type`, `Error: Could not find or load main class Foo`, and `Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5`. How do you tell, from the shape of the message alone, what kind of problem each one is — and why can the compiler never catch the third one?

Each error names the stage it happened at, and the stage tells you where to look. A compile error (illegal start of type) means the text you wrote isn't legal Java — nothing was produced, so look at the file and the line. A startup error (Could not find or load main class) means the source compiled fine but the runtime can't find what you're asking it to run — look at where things are (the classpath, the directory, the class name), not at your logic. A runtime error (a stack trace) means it compiled, it loaded, and it ran — and the values were wrong. The compiler can't catch that last kind because x[5] on a two-element array is perfectly legal Java; the array's actual size isn't known until the program runs.

The lesson behind it →
More on Platform