Java is one of the most widely used programming languages in the world. It runs banking systems, Android apps, big-data platforms and — closer to home for integration developers — the engines behind tools like Boomi, MuleSoft and countless enterprise APIs. Learning Java gives you a language that will keep paying off for decades.
This first lesson gets you from nothing to a running program. No previous programming experience is needed.
The three words you’ll keep hearing
- JVM (Java Virtual Machine) — the engine that runs Java programs. Your code is compiled into bytecode, and the JVM runs that bytecode on Windows, macOS or Linux. That’s Java’s famous promise: write once, run anywhere.
- JDK (Java Development Kit) — everything you need to write Java: the compiler (
javac), the launcher (java), JShell and the standard library. This is what you install. - JRE — the runtime only. Modern JDKs include it, so you rarely think about it separately.
Step 1: install a JDK
Install a long-term-support (LTS) version — Java 21 is a great choice. Free builds are available from Eclipse Temurin (adoptium.net), Oracle, Amazon Corretto and others; they all behave the same for learning.
Check it worked by opening a terminal (Command Prompt or PowerShell on Windows) and typing:
java -version
You should see something like openjdk version "21...". If you get “command not found”, the JDK’s bin folder isn’t on your PATH yet — the installer usually offers to set it up.
Step 2: experiment with JShell
JShell is Java’s interactive playground: type a line, see the result instantly. It’s the fastest way to learn.
jshell
Then try:
int quantity = 24;
double price = 8.50;
quantity * price
"po-4471".toUpperCase()
JShell prints each result ($3 ==> 204.0, $4 ==> "PO-4471"). Type /exit to leave.
Tip: Keep JShell open while you work through these tutorials. Whenever you wonder “what does this do?”, try it there.
Step 3: your first program
Create a file called HelloWorld.java with this content:
// HelloWorld.java — your first Java program.
// Run it with: java HelloWorld.java (Java 11+ runs a single file directly)
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
String name = args.length > 0 ? args[0] : "Java learner";
System.out.println("Welcome, " + name + "!");
}
}
What each line means
public class HelloWorld— every Java program lives inside a class. The file name must match the public class name:HelloWorld.java.public static void main(String[] args)— the main method, where the program starts.argsholds anything typed after the program name on the command line.System.out.println(...)— prints a line of text.String name = ... ? ... : ...;— creates a text variable. The? :part chooses a value: if arguments were given, use the first one, otherwise use “Java learner”.;— every statement ends with a semicolon. Forgetting one is the most common beginner error, and the compiler will point to it.
Step 4: run it
Since Java 11 you can run a single file directly:
java HelloWorld.java
java HelloWorld.java Chirag
Hello, World!
Welcome, Java learner!
Hello, World!
Welcome, Chirag!
For bigger projects you compile first and then run the compiled class — this is what build tools like Maven and Gradle do for you:
javac HelloWorld.java # creates HelloWorld.class (bytecode)
java HelloWorld # runs it on the JVM
Choosing an editor
Any text editor works, but an IDE makes Java much friendlier: IntelliJ IDEA Community (free), VS Code with the Java extension pack, or Eclipse. They highlight mistakes as you type, auto-complete methods and run programs with one click.
Common first-day errors
error: class HelloWorld is public, should be declared in a file named HelloWorld.java— rename the file to match the class.error: ';' expected— a missing semicolon on the line shown (or just before it).cannot find symbol— a typo, or wrong capitalisation. Java is case-sensitive:system.outis notSystem.out.
Try it yourself
Change the program so it prints a short receipt: your name, a product, a quantity and the total price (quantity × price).
Show a solution
public class Receipt {
public static void main(String[] args) {
String customer = "Acme Ltd";
String product = "AX-200";
int quantity = 24;
double price = 8.50;
System.out.println("Customer: " + customer);
System.out.println(quantity + " x " + product + " = " + (quantity * price));
}
}
Save it as Receipt.java and run java Receipt.java.
Key takeaways
- Install a JDK (Java 21 LTS is a good default) and check it with
java -version. - JShell lets you try any line of Java instantly.
- Every program needs a class and a
mainmethod; the file name matches the public class. java File.javaruns a single file;javac+javais the compile-then-run route.