The classic first program when introducing any new language is Hello World, or a program that prints Hello World to the console. In Java, Hello World can be written as such:
voidmain(){IO.println("Hello world!");}
Compare this with the Python equivalent:
print("hello world!")
Compared to the extreme simplicity of Python, we observe the following features of this simplest Java program:
The main function: all the code that runs must be inside of a function called main. We'll cover what the void means later.
Curly braces{} enclose sections of code (functions, classes, and other types of code that will be covered in future chapters).
All statements must end with a semi-colon.
Printing requires us to use dot notation, going to some library called IO and asking for its print function.