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.

One language adds a checking stage between writing and running.
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 PythonIn Java
Code can stand alone in a fileEverything inside a class
A name with no typeA type declared before the name
Indentation settles structureBraces
An error at run timeA large share before running

Example 1 — why not one line runs

  1. The check reads the whole file.
  2. It finds a mismatch.
  3. And refuses to produce a runnable program.

Example 2 — why the file name matters

  1. All code belongs to a class.
  2. The file is named after the public class.
  3. Otherwise the check fails at once.
The check catches everything that can be known from reading the code; what depends on values created at run time still waits for the run.