Grade 11 Computer Science · The bridge to Java
A stage added before running
Why the language changes, and what exactly the difference is.
A program that ran not a single line
Line one hundred and two holds a small mistake. In Python the hundred and one lines before it would run and print, and only then would the error come. In the language you will learn this year nothing is printed at all — and that is exactly what you should want.
For four years you wrote in Python, and now a second language enters. This is no caprice: the certification exam these two years prepare for is written in Java, and it is the only place in the whole programme where a language is explicitly fixed. But the change is not merely syntactic, and it is worth starting from what it really is.
public class Hello {
public static void main(String[] args) {
int count = 3;
System.out.println("lessons: " + count);
}
}The three new things
The first: everything sits inside a class. In Java there is no code floating in a file — every line belongs to some class, and the file’s name must be the class’s name. The second: every name has a declared type, written before the name. The third: a semicolon at the end of each statement and braces around each block — in place of the indentation that settled structure in Python. All three will look superfluous in the first week, and then stop registering.
| In Python | In Java |
|---|---|
| Code can stand alone in a file | Everything inside a class |
| A name with no type | A type declared before the name |
| Indentation settles structure | Braces |
| An error at run time | A large share before running |
Example 1 — why not one line runs
- The check reads the whole file.
- It finds a mismatch.
- And refuses to produce a runnable program.
Example 2 — why the file name matters
- All code belongs to a class.
- The file is named after the public class.
- Otherwise the check fails at once.