start

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
}

Compile and run:

javac Hello.java
java Hello

Output:

Hello, world!

The JVM

Source compiles to bytecode Bytecode runs on a virtual machine The same bytecode runs on any platform with a compatible JVM That is the write once, run anywhere promise, and it is the reason the compilation step exists

What Java is not

Java is not C with objects It has no pointer arithmetic Memory is managed by a garbage collector You still have to close files, sockets, and connections yourself

main

public static void main(String[] args) is the entry point public means the runtime can call it static means no instance is needed void means it returns nothing

Java 25 note

Java 25 added compact source files and instance main methods for small programs That syntax ships with Java 25 The traditional form above remains the portable form

Next

Types in 02 types

Posted