Setting Up Java
Install the JDK, choose an IDE, and get your development environment ready to write and run Java programs.
Overview
Key Points
- β’JDK (Java Development Kit) includes the compiler (javac) and standard library - you need this to develop
- β’JRE (Java Runtime Environment) can only run Java programs; the JDK includes the JRE
- β’Online compilers (onecompiler.com/java, replit.com) let you start immediately with zero setup
- β’IntelliJ IDEA Community Edition is the most popular free Java IDE with excellent tooling
- β’VS Code + "Extension Pack for Java" is a lighter alternative to IntelliJ
- β’Java 21 is the current LTS release - use it for learning to get the latest stable features
Examples
Verify Java is installed (run in your terminal)
# Check your Java version
java -version
# Check the compiler version
javac -versionIf both commands print version numbers, your JDK is correctly installed.
Compile and run a Java file from the terminal
# 1. Save your code as HelloWorld.java
# 2. Compile it
javac HelloWorld.java
# 3. Run the compiled class (no .class extension)
java HelloWorldThe class name must exactly match the filename (including case). HelloWorld.java β public class HelloWorld.
A standard project file structure in IntelliJ IDEA
MyProject/
βββ src/
β βββ Main.java β your source files go here
βββ out/
β βββ Main.class β compiled bytecode (auto-generated)
βββ MyProject.iml β IntelliJ project fileIntelliJ handles compilation automatically when you click Run.
Common Mistakes
- Installing only the JRE instead of the JDK - the JRE cannot compile code, you need the full JDK
- File name does not match class name - HelloWorld.java must contain `public class HelloWorld`
- Running `java HelloWorld.class` instead of `java HelloWorld` - omit the .class extension when running
Note
If you just want to experiment quickly, skip the local setup for now. Go to onecompiler.com/java, type your code, and hit Run. You can install IntelliJ IDEA later when you are ready to build larger projects.
Exercises
Write Java code and click Run to execute it instantly. When your output looks correct, mark as done.
Completed: 0 / 4 exercises
Knowledge Check
Question 1 of 4