What is Java? A Beginner's Guide to the JVM, Syntax, and First Program

Learn what Java is in 2026, how the JVM compiles and runs your code, and how the syntax is structured. Then write, compile, and run your first real Java program step by step.

Javabeginner
12 min read

Java turned 30 last year and it still quietly powers your bank's mobile app, the order system at your favourite coffee chain, every Android phone in your pocket, and a huge slice of the world's enterprise backends. If you have ever wondered what the fuss around Java is about, why developers keep mentioning the JVM, or how a single .java file becomes a running program, this guide gives you the complete picture and ends with you running real code on your machine.

By the end you will know what Java is, how the JVM works at a high level, how Java syntax is structured, and how to install the JDK, compile a .java file, and run a program that does something more interesting than printing a greeting. Everything here reflects Java 25 LTS, the long-term support release everyone is moving to in 2026.

What Java Actually Is

Java is a statically typed, object-oriented programming language created by James Gosling at Sun Microsystems in 1995, now stewarded by Oracle and developed in the open through OpenJDK. The original promise was write once, run anywhere: you compile your source code one time and the resulting program runs identically on Windows, macOS, Linux, and Android, all without recompiling.

That portability comes from the fact that Java does not compile to native machine code. It compiles to bytecode, a compact platform-neutral instruction set that is then interpreted and JIT-compiled at runtime by the Java Virtual Machine (JVM).

Why Java Has Survived 30 Years

A few qualities keep Java in production for decades after most languages would have faded:

  • Backwards compatibility. Code written for Java 8 in 2014 still compiles and runs on Java 25 today. That matters when a bank has 12 million lines of Java touching real money.
  • The JVM is one of the best runtimes ever built. Decades of optimisation work mean modern Java often beats Go and matches C# on throughput.
  • A massive ecosystem. Spring Boot, Quarkus, Hibernate, Maven, Gradle, IntelliJ IDEA. The tooling story is among the best in any language.
  • Android. Even though Kotlin is now the official Android language, the underlying runtime is still the JVM and the libraries you call into are still Java.

How the JVM Works in One Paragraph

You write .java source files. The Java compiler (javac) turns them into .class files containing bytecode. When you run java MyApp, the JVM loads those classes, verifies the bytecode for safety, interprets it for the first few iterations of each method, then a Just-In-Time compiler converts hot methods to optimised native machine code. Memory is reclaimed by a garbage collector so you do not free objects yourself. This is why Java programs start a little slowly but reach excellent steady-state performance.

Java Syntax in One Glance

Every Java file looks roughly like this: a package line, some import lines, then one public class whose name matches the filename, with a main method that runs when you execute the program.

javajava
package com.example;
 
public class Greeter {
  public static void main(String[] args) {
    var name = args.length > 0 ? args[0] : "world";
    System.out.println("Hello, " + name);
  }
}

Curly braces group blocks, semicolons end statements, and types come before names. The var keyword (added in Java 10) lets the compiler infer the type from the initialiser. Modern Java also gives you record for value classes, switch expressions, pattern matching, text blocks ("""..."""), and virtual threads for cheap concurrency. We use a record in the next tutorial.

How to Install Java in 2026

Skip Oracle's commercial JDK and install a free OpenJDK build. The two most popular distributions are Eclipse Temurin and Amazon Corretto. On macOS the easiest path is brew install --cask temurin@25. On Windows download the .msi from Adoptium. On Linux use sdkman or your package manager (apt install openjdk-25-jdk).

Verify the install with java --version. You should see something like openjdk 25 2025-09-16 LTS. Pair it with VS Code and the Extension Pack for Java, or with IntelliJ IDEA Community, which is what most professional Java teams use.

Your First Real Java Program

Save the following as WordCount.java. It reads a file passed on the command line and prints how many lines, words, and characters it contains, the same job that the Unix wc tool does.

javajava
import java.nio.file.*;
import java.util.stream.Stream;
 
public class WordCount {
  public static void main(String[] args) throws Exception {
    if (args.length == 0) { System.err.println("usage: WordCount <file>"); return; }
    long lines = 0, words = 0, chars = 0;
    try (Stream<String> s = Files.lines(Paths.get(args[0]))) {
      for (var line : (Iterable<String>) s::iterator) {
        lines++;
        chars += line.length();
        words += line.isBlank() ? 0 : line.trim().split("\\s+").length;
      }
    }
    System.out.printf("lines=%d words=%d chars=%d%n", lines, words, chars);
  }
}

Compile and run it from the same folder:

bashbash
javac WordCount.java
java WordCount some_text_file.txt

You just used the modern file API, a try-with-resources block (which closes the stream automatically), var type inference, and printf. That is real Java, not a hello-world toy.

Where Java Goes from Here for You

Once your first program runs, the natural next step is understanding Java Classes and Objects with Practical Examples. After that, pick a small real project: a CLI tool, a Spring Boot REST service, or a tiny Android app. Build something you actually want, not another tutorial.

Common Mistakes Beginners Make

  • Naming the file differently from the public class. The compiler will reject it. public class Greeter must live in Greeter.java.
  • Forgetting that String comparison uses .equals(), not ==. The == operator compares object identity, not contents.
  • Using raw types (List instead of List<String>). Always use generics.
  • Believing Java is slow because it starts slowly. Throughput after JIT warm-up is excellent.
  • Picking Java 8 because old tutorials still use it. Start on Java 25 LTS; you get every modern feature and free security updates for years.

Quick Reference

  • Compile: javac File.java produces File.class
  • Run: java File (no .class suffix)
  • Modern Java: var for local types, record for value classes, text blocks """...""", switch expressions
  • Build tools: Maven or Gradle for anything bigger than a single file
  • Concurrency: virtual threads via Thread.ofVirtual().start(...) for cheap parallel I/O
  • Standard formatter: mvn formatter:format or run Reformat Code in IntelliJ
Rune AI

Rune AI

Key Insights

  • Java is a compiled, statically typed language that runs on the JVM as bytecode.
  • The JVM gives you portability, garbage collection, and excellent steady-state performance.
  • Use a free OpenJDK build (Temurin or Corretto). Java 25 LTS is the version to learn in 2026.
  • Modern Java is concise: var, record, switch expressions, text blocks, and virtual threads.
  • Compile with javac File.java, run with java File. Move to Maven or Gradle once your project has more than one file.
RunePowered by Rune AI

Frequently Asked Questions

Java vs JavaScript: are they related?

No. The names are a 1990s marketing accident. Java is a compiled, statically typed JVM language. JavaScript is an interpreted dynamic language for browsers and Node.

Do I have to pay Oracle to use Java?

No. Use [OpenJDK](https://openjdk.org/) builds from Adoptium, Amazon, or Microsoft. They are free for any purpose, including commercial.

Is Kotlin replacing Java?

On Android, mostly yes. On the server, no. Kotlin is excellent and fully interoperable with Java, but the vast majority of new server code is still Java, especially in Spring and Quarkus shops.

Which Java version should I learn?

Java 25 LTS (released September 2025). It includes everything modern Java offers and has long-term support through 2030.

Do I need an IDE?

For real work, yes. IntelliJ IDEA Community Edition is free and is the standard. VS Code with the Extension Pack for Java is a lighter alternative.

Conclusion

Java in 2026 is a calm, modern, deeply optimised language that runs more production code than almost anything else on Earth. Install Java 25, compile the program above, then move on to classes and objects. Once you understand how a class becomes an object and how the JVM manages memory, the entire ecosystem (Spring, Android, Hibernate) becomes easy to read.