Free Lesson

What Is Java?

Java is a general-purpose, object-oriented programming language first released in 1995. Its code compiles to bytecode that runs on any device with a Java Virtual Machine (JVM), which is why Java's motto is “write once, run anywhere.”

James Gosling and his team created Java at Sun Microsystems, and Oracle has owned it since buying Sun in 2010. It powers Android apps, Minecraft: Java Edition and many bank and airline back ends. Follow a program through the JVM below.

Interactive demo

Java demo

How Java runs your code: source to bytecode to JVM

Follow one Hello World program through its four stops. Pick a step, then choose a device for the last one.

You write source code

A .java file is plain text that people can read. The computer cannot run it yet.

Java Hello World, line by line

Step through the classic first program. Each line gets a plain-English note.

Hello.java

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

Line 1 of 5

Every Java program lives inside a class. The class name, Hello, must match the file name, Hello.java.

Since Java 25, beginners can also skip the class and write a shorter version in a single file:

void main() {
    IO.println("Hello, World!");
}

Quick Java quiz

Six questions on what Java is and how it runs.

  1. What is Java?
  2. What does the javac compiler produce?
  3. Why can one .class file run on Windows, Mac and Linux?
  4. Is Java the same as JavaScript?
  5. Which do you install to write and compile Java?
  6. What does System.out.println("Hi"); do?

Real world

What is Java used for?

Android apps

Android was built around Java. Many apps are still written in Java, and Kotlin, Google's preferred language, runs on the same tools.

Examples: Older Android apps, banking and shopping apps

Games

Minecraft: Java Edition is written in Java, and its huge modding scene writes mods in Java too.

Examples: Minecraft: Java Edition, mods

Business back ends

Banks, airlines and stores run large server systems in Java because it is fast, stable and well supported.

Examples: Payment, booking and inventory systems

Big data and tools

Popular data and developer tools run on the JVM and are written in Java.

Examples: Apache Kafka, Hadoop, IntelliJ IDEA

Common mix-up

Java vs JavaScript vs Python

Java and JavaScript are different languages. Netscape renamed its browser language to JavaScript in 1995 to ride Java's popularity, and the confusion stuck. Here is how the three most-taught languages compare.

Java vs JavaScript vs Python comparison
JavaJavaScriptPython
Main jobAndroid apps, big business back ends, games like MinecraftInteractive web pages, plus servers with Node.jsData, AI, automation and scripts
Runs onThe JVM, on almost any deviceEvery web browser, and Node.jsThe Python interpreter
TypesStatic: declare types like int and StringDynamic: a variable can hold anythingDynamic, with optional type hints
Compiled?Yes, to bytecode with javacNo, run as is (engines compile on the fly)No, run as is
SpeedFast once the JVM warms upFast in modern browsersSlower, but fast enough for most scripts
Hello World5 lines with a class and mainconsole.log("Hello, World!");print("Hello, World!")
Beginner feelMore rules up front, clear errors earlyEasy start in any browserEasiest to read and write

Jargon buster

JDK vs JRE vs JVM

They fit inside each other like nesting boxes: the JDK contains the JRE, and the JRE contains the JVM.

JVM (Java Virtual Machine)

Runs bytecode on one kind of device. It is the engine.

JRE (Java Runtime Environment)

The JVM plus the standard library a program needs to run. Enough to run Java apps, not to build them.

JDK (Java Development Kit)

The JRE plus tools for programmers, like the javac compiler. Install a JDK to learn Java.

Get started

Is Java hard to learn?

It takes a little longer to start, then it pays off. Java asks you to declare types and put code in classes, so Hello World is five lines instead of one. Those rules catch mistakes before your program runs, and the same ideas carry over to C#, Kotlin and C++. Many schools teach Java first, including AP Computer Science A.

A 4-week Java starter path

  1. Week 1: Install a JDK and say hello

    Install a free OpenJDK build such as Eclipse Temurin, write Hello.java and run it with java Hello.java.

  2. Week 2: Variables, types and decisions

    Learn int, double, String and boolean, then if and else. Build a grade calculator that prints a letter grade.

  3. Week 3: Loops, arrays and methods

    Use for and while loops, arrays and your own methods. Build a number guessing game.

  4. Week 4: Classes and objects

    Write a class with fields and methods, then make objects from it. Build a small to-do list or bank account program.

Learning Java with AI?

Code Card turns your Claude Code, Codex, and OpenClaw sessions into a public developer profile with activity graphs, streaks, badges, and a shareable card, so you can track your coding progress. Start with npx code-card.

Make your Code Card

FAQ

Java questions, answered

What is Java in simple terms?

Java is a programming language for building apps, games and servers. You write code once, a compiler turns it into bytecode, and the Java Virtual Machine runs that bytecode on Windows, Mac, Linux and more without changes.

What is Java used for?

Java is used for Android apps, large business and banking back ends, games like Minecraft: Java Edition, big data tools like Apache Kafka, and developer tools like IntelliJ IDEA.

Is Java the same as JavaScript?

No. Java and JavaScript are different languages with different rules and uses. JavaScript runs web pages in the browser, while Java runs on the JVM for apps and servers. They only share part of a name.

Is Java hard to learn?

Java has more rules than Python or JavaScript, such as declaring types and putting code in classes, so the first week is slower. Those rules catch mistakes early, and many schools teach Java first, including the AP Computer Science A course.

Is Java free?

Yes. The Java language is free to learn and use, and free open-source builds of the JDK, such as OpenJDK and Eclipse Temurin, run on Windows, Mac and Linux. Oracle's own JDK has its own license terms for business use.