Java Basics #1 — Introduction to Java & Setting Up
What Java actually is, how the JVM works, and getting your dev environment ready in under 10 minutes.
What Is Java, Really?
Java isn't just a language — it's a platform. When you write Java code, you're not compiling to machine code for one specific OS. You're compiling to bytecode that runs on the JVM (Java Virtual Machine). That's the "write once, run anywhere" promise.
Your .java file → javac → .class (bytecode) → JVM → runs on any OS
The three things you need to know up front:
- JDK — Java Development Kit. You write code with this.
- JRE — Java Runtime Environment. Included in the JDK. Runs code.
- JVM — The virtual machine that actually executes bytecode.
Installing Java (JDK 21 LTS)
JDK 21 is the current long-term support version. Don't install Java 8 just because a tutorial told you to.
macOS (Homebrew):
brew install openjdk@21
echo 'export PATH="/opt/homebrew/opt/openjdk@21/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Ubuntu/Debian:
sudo apt update
sudo apt install openjdk-21-jdk
Windows: Download from adoptium.net and run the installer. Make sure to check "Set JAVA_HOME variable".
Verify it worked:
java -version
javac -version
Your First Java Program
Create a file called Hello.java:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Compile and run it:
javac Hello.java
java Hello
You'll see Hello, Java! printed. Let's break down what each part means:
public class Hello— Every Java file has a class with the same name as the file.public static void main(String[] args)— The entry point. Java always starts here.System.out.println(...)— Print to the console with a newline.
In Java, the public class name must exactly match the filename (including case). Hello.java must contain public class Hello. This trips up beginners constantly.
IDE Setup — IntelliJ IDEA
Use IntelliJ IDEA Community Edition (free). It's what most professional Java devs use.
- Download from jetbrains.com/idea
- Create a new project → Java → SDK: 21
- Create
src/Hello.java - Click the green ▶ button
Eclipse was the standard in 2010. IntelliJ is what teams actually use in 2025. Learn the right tool from the start.
How the JVM Works (Simplified)
When you run java Hello, here's what happens:
Class Loading
The JVM's ClassLoader finds your .class file and loads it into memory.
Bytecode Verification
The JVM checks the bytecode is valid and won't corrupt memory. This is part of Java's security model.
JIT Compilation
The Just-In-Time compiler watches which code runs frequently ("hot paths") and compiles those to native machine code for speed.
Execution
Your code runs. The Garbage Collector manages memory automatically — no malloc/free like in C.
Java Versions — Which to Use?
| Version | Type | Use it? |
|---|---|---|
| Java 8 | LTS | Only for legacy projects |
| Java 11 | LTS | Still common in enterprise |
| Java 17 | LTS | Safe choice for new projects |
| Java 21 | LTS | ✅ Best choice right now |
JDK 21 installed, IntelliJ set up, and your first program compiled. In the next post we'll cover variables, data types, and operators — the actual building blocks of every Java program.
What's Next?
In Java Basics #2, we'll cover variables, primitive types, type casting, and operators — and why int and Integer are not the same thing.
✦ Enjoyed this post?
Get posts like this in your inbox
No spam, just real tutorials when they're ready.
Discussion
Powered by GitHubComments use GitHub Discussions — no separate account needed if you have GitHub.