Java is a general-purpose, object-oriented programming language that compiles to bytecode and runs on the Java Virtual Machine (JVM), so the same program runs on Windows, macOS, and Linux. A simple example is a class with a main method that prints text, but real Java code also uses classes, records, collections, and streams.
This article shows Java through working examples, from Hello World to a small program using modern features, and explains where Java is used today.
Java source files end in .java. The compiler javac turns them into .class bytecode, and the java launcher runs that bytecode on the JVM. This is the idea behind "write once, run anywhere".
Save it as HelloWorld.java, then compile and run:
You can also skip the separate compile step for single files with java HelloWorld.java. Recent releases (Java 25 and later) also finalised compact source files with instance main methods, so a beginner program can be shorter, but the classic form above works on every version.
Java is statically typed: every variable has a type known at compile time. Since Java 10 you can use var for local variables when the type is clear from the right side.
The primitive types (int, long, double, boolean, char, and others) hold plain values, while String and other classes are objects.
Java organises code in classes. For simple data carriers, use a record (Java 16 and later), which generates the constructor, accessors, equals, hashCode, and toString.
The sealed interface limits the allowed implementations, so the switch expression can check at compile time that every case is covered. Pattern matching for switch is final from Java 21.
The collections framework (List, Map, Set) and the Stream API handle data processing.
| Area | Typical tools |
|---|---|
| Backend and web services | Spring Boot, Quarkus, Micronaut, Jakarta EE |
| Android apps | Kotlin is preferred, but Java is still fully supported |
| Enterprise and finance | Large, long-lived systems that value stability |
| Big data and tooling | Apache Kafka, Spark, Elasticsearch, build tools like Maven and Gradle |
| Desktop | JavaFX, Swing |
java -version and javac -version.javac, and run it with java.No. They are unrelated languages that share part of a name. Java is compiled to bytecode and runs on the JVM, while JavaScript runs in browsers and in runtimes such as Node.js.
The JVM runs bytecode. The JDK includes the JVM plus tools such as javac. A separate JRE is no longer distributed for new versions, so install the JDK.
OpenJDK builds are free and open source. Check the license of any vendor build you choose.
Use the latest LTS release, or the version your team runs. The core language is stable, and newer versions add features such as records and virtual threads.
Java is a statically typed, object-oriented language that compiles to bytecode for the JVM. Start with a main method, learn types, classes, collections, and streams, and use modern features such as records, sealed types, and pattern matching. Install a current LTS JDK and build small programs to practise.