AnyCompiler

Introduction to Java

Java is a compiled, statically typed, garbage-collected language that doesn't compile straight to machine code — it compiles to bytecode, which runs on the Java Virtual Machine (JVM). That's the source of Java's signature promise, 'write once, run anywhere': the same compiled bytecode runs unmodified on any platform with a JVM installed.

Unlike C++, which hands you raw pointers and manual memory management, Java has no pointers you can manipulate directly and no manual delete — the garbage collector reclaims memory automatically once nothing references an object anymore. That tradeoff is central to understanding Java: it trades some of C++'s low-level control for memory safety and simplicity.

A quick preview

Here's a real Java program, executed for real on this page's own compiler — not a mockup:

public class Main {
    public static void main(String[] args) {
        String message = "Hello from Java!";
        System.out.println(message);
    }
}
Output
Hello from Java!

That's it — a String variable, printed with System.out.println. The next lesson runs your first full program and explains exactly what's happening.

Practice exercise

Declare a variable named version with type int set to 21, then print "Java version: " followed by version using System.out.println.