Grade 11 Computer Science · The bridge to Java
Common mistakes in the move
The habits from Python that cost dearly in the new language.
Mistakes that return even after you understand
You can explain correctly exactly why indentation does not settle a block in Java, and still forget a brace in the very next program. The mistakes in this lesson do not come from not knowing, so their cure is not another explanation either.
All four mistakes below are not mistakes of ignorance but of habit. They come from the hand continuing to write as in the previous language, and so they recur even after the rule is understood.
- Expecting code to run with no class — In Java no line stands alone in a file. All code sits in a class, and the start is the agreed operation belonging to the class itself.
- Relying on indentation to settle a block — Indentation is not read at all; only the braces settle it. Indent so a person can read, and brace so the language understands. Both, always.
- Reading all forty errors — Most are noise dragged from one mistake at the top. Fix the first only and run again. Usually the forty drop to three.
- Touching an object field from a class operation — Such an operation runs with no object existing, so it has no one to refer to. If it touches an object’s data — it belongs to the object, not the class.