Java
Java
›Short versionOpen if you only have a minute.
- You write the program as ordinary text. A compiler turns that text into bytecode.
- Bytecode is the same file on every computer. It is not yet the native instructions of one chip.
- A Java Virtual Machine on the other machine reads the bytecode and does the work.
- A class describes one kind of thing: the data it holds and the actions that belong with that data.
- The language was called Oak for a while. The idea that stayed is one program traveling to many machines.
You write a small program that reads a name and prints a greeting, then you save the file and run it. Later you copy that same file to a friend. Their computer is a different kind of machine, and the greeting still prints.
Java is built for that handoff. You write the program as ordinary text. A reads the text and writes , a compact list of instructions that stays the same from one computer to the next. A on the other machine reads those instructions and does the work, using whatever operating system and processor it finds there.
Source → another machine
Write
You save ordinary text in a .java file.
Compile
javac turns that text into bytecode.
Ship
The .class file is the same on every computer.
Run
A JVM on that machine carries the instructions out.
What you edit
- The .java file is for people. Names, braces, and comments stay readable.
- A class describes one kind of thing: the data it holds and the actions that belong with it.
What you ship
- The .class file is bytecode. It is not tied to Windows, macOS, or Linux.
- The receiving machine needs its own JVM. That runner knows the local OS and chip.
Two files, two jobs
| File | Who needs it | What it is for |
|---|---|---|
| .java | Anyone who will change the program | Source text the compiler reads |
| .class | Any machine that should run it | Bytecode a compatible JVM executes |
| JDK | The author | Compiler, launcher, and libraries |
| JRE / runtime | The machine that only runs | A JVM without javac |
Read the diagram definition
sequenceDiagram
participant You
participant javac
participant Class as Hello.class
participant FriendJVM as Friend JVM
You->>javac: Hello.java
javac-->>Class: bytecode
You->>FriendJVM: copy Hello.class
FriendJVM->>Class: load and run main
FriendJVM-->>You: prints the greetingWhat you are writing
The text on the page is for you as much as for the machine. Short statements, names you chose, and the braces that group them stay readable, so next week you can still tell what you meant. Java is a programming language in that ordinary sense: a set of rules for writing instructions a computer can follow.
Programs in this language are usually arranged as . A class describes one kind of thing, the data it holds and the actions that belong with that data. Building a program this way is called . The introduction begins with one file and one line of output. Classes settle into place after you have typed that line yourself.
You copy Hello.class to a laptop that has never had Java installed. The greeting does not print. What is missing?
The class file is already compiled. The laptop needs a Java Virtual Machine that knows its operating system and processor. A second handwritten version of the program is the wrong fix.
James Gosling led the early work at Sun in the 1990s. The group called the language Oak for a while, after an oak tree outside his office. The name was replaced. The picture of one program traveling to many machines remained.
Why the same file runs somewhere else
The compiler on your machine writes bytecode, a file that is not tied to Windows or macOS or Linux. That is the file you copy. The receiving computer needs its own Java Virtual Machine, because that program is the part that knows the local system and can carry the instructions out.
When both pieces are present, the behavior you wrote stays in the file and the other machine supplies the runner. If a copied file will not start, the usual missing piece is that runner, not a second version of your program rewritten by hand.
Where people actually use it
People keep reaching for Java in a few kinds of work you can picture before you write a line of it.
- Android. Many applications on Android phones are written in Java. You tap the app, and the phone runs it.
- Server applications. Banks, shops, and other organizations run Java programs that stay up on a server and answer requests through the day, such as account lookups and orders.
- Data tools. Software that stores records and works through large collections of them is often written in Java, so the same program can sit on the machines a team already runs.
Simple rule of thumb
Treat the class file as the thing that travels. Keep the source for the person who will change it. A machine with only a runtime can start the class file. It cannot compile a new one.
Good default: begin with a JDK on your machine, one public class in a file of the same name, and a single main that prints a line. The introduction page walks that first run.
Start with the introduction
If you have not written Java yet, begin there. The introduction assumes that, and it walks through a first program slowly enough that you can type along. Later notes use the words that page puts in your hands.