Java — Get Started
Install the JDK
Before writing Java code you need the JDK — the Java Development Kit. It contains the compiler, standard libraries, and the runtime.
- Go to adoptium.net
- Download the installer for your operating system
- Run it and accept the defaults
The installer sets up JAVA_HOME and adds java and javac to your PATH automatically.
Verify the installation
Open a terminal and type:
java -version
javac -version
You should see version numbers for both. If javac is not found, the installer didn't add it to your PATH — fix that before continuing.
Your first program
Create a file called Main.java:
public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Save it, open a terminal in the same folder, and run:
javac Main.java
java Main
Output:
Hello, world!
Two commands did two different things:
| Command | What it does |
|---|---|
javac Main.java | Compiles your source file into bytecode (Main.class) |
java Main | Runs the compiled bytecode on the Java Virtual Machine |
This two-step process is what "write once, run anywhere" means — the .class file works on any machine that has a JVM.
Every Java program needs a class
Unlike Python or JavaScript, Java forces you to wrap code inside a class. The class name must match the file name:
// File: Hello.java
public class Hello {
public static void main(String[] args) {
System.out.println("This works.");
}
}
If the class name doesn't match the file name, the compiler rejects it. This strictness feels heavy at first, but it catches typos and naming problems before your code ever runs.
The main method explained
public static void main(String[] args)
Each word has a purpose:
public— anyone can call this methodstatic— you don't need an object to run it; Java can start it directlyvoid— this method doesn't return a valuemain— the special name Java looks for as the entry pointString[] args— receives command-line arguments (you can ignore it for now)
You don't need to memorize every keyword today. Just know that public static void main(String[] args) is the standard launch pad, and every beginner program starts with it.
Packages and project structure
Real Java projects have many files. The folder structure matches package names — a dot-separated namespace:
com/
example/
app/
Main.java
At the top of Main.java you'd declare:
package com.example.app;
Packages keep code organized and prevent naming collisions. When your project grows beyond a single file, start organizing classes into packages.
IDE vs terminal
You can compile from the terminal, but most Java developers use an IDE (Integrated Development Environment):
- IntelliJ IDEA Community — free, the industry standard
- VS Code — lighter, install the "Extension Pack for Java"
- Eclipse —老牌 free option, still maintained
An IDE gives you autocomplete, error highlighting, debugging, and project management — tools that save hours once your code goes beyond one file.
For learning, either approach works. The terminal keeps you close to what's actually happening; the IDE keeps you productive.
Mini Practice
- Install the JDK and verify both
javaandjavacversions - Create
Main.javaand print your name - Add a second
printlnthat prints the current year - Break the code — remove
publicfrom the class line and read the error - Rename the file without renaming the class — see what the compiler says
Errors are documentation. Read them carefully — Java's compiler messages tell you exactly what's wrong and often where to fix it.
Next: syntax rules that govern every Java file →
Related Topics
Frequently Asked Questions about Get Started
What is Get Started in Java?
Get Started is a fundamental concept in Java. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Get Started?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Get Started.
Why is Get Started important in Java?
Get Started is essential for Java development. Understanding this concept will help you write better code and solve real-world problems more effectively.