Java Get Started
Install JDK + IntelliJ/VS Code, compile your first program, and understand `javac` vs `java`.
To start writing Java, you need exactly two things:
- A JDK (Java Development Kit) — gives you
javac(compiler) +java(runtime). - A text editor or IDE — IntelliJ IDEA, VS Code, Eclipse, or even Notepad.
| OS | Recommended JDK | Install |
|---|---|---|
| Windows | Eclipse Temurin 21 LTS | adoptium.net installer |
| macOS | Eclipse Temurin or OpenJDK | brew install --cask temurin |
| Linux | OpenJDK 21 | sudo apt install openjdk-21-jdk |
Verify your install:
bashjavac --version java --version
You should see something like:
javac 21.0.2
openjdk 21.0.2 2024-01-16
Step 1. Create a file HelloWorld.java:
javapublic class HelloWorld { public static void main(String[] args) { System.out.println("Hello, Codekilla!"); } }
Step 2. Compile (produces bytecode):
bashjavac HelloWorld.java
This creates HelloWorld.class in the same folder.
Step 3. Run (note: no .class extension):
bashjava HelloWorld
Hello, Codekilla!
javacreadHelloWorld.java.- It translated the source into platform-independent bytecode (
HelloWorld.class). javalaunched the JVM, loaded the class, and calledmain.- The JIT (Just-In-Time) compiler converted hot bytecode into native machine code on the fly.
| Tool | Job | Input | Output |
|---|---|---|---|
javac | Compiler | .java source | .class bytecode |
java | JVM launcher | class name (no .class) | runs the program |
Two tools, two jobs.
| Flag | Purpose |
|---|---|
javac -d out | Put .class files in out/ folder |
javac -Xlint:all | Show all warnings |
java -cp lib/* | Add JARs to classpath |
java -Xmx512m | Limit heap to 512 MB |
java -ea | Enable assert statements |
- Download IntelliJ IDEA Community (free) from jetbrains.com.
- Open it, click New Project → Java.
- Pick your JDK → name the project → finish.
- Right-click
src→ New → Java Class → typeHelloWorld. - Paste the snippet above → click the green ▶ button.
- Install VS Code.
- Add the Extension Pack for Java by Microsoft.
- Open your folder, create
HelloWorld.java, hit ▶.
Don't want to install? Use Codekilla's online Java compiler — write code in the browser, click Run, see output.
Real Java projects use Maven or Gradle — they fetch dependencies, compile, test, and package one-command:
bashmvn package # Maven gradle build # Gradle
You'll meet them later. For now, plain javac/java is fine.
- Running
java HelloWorld.class— drop the.class. Usejava HelloWorld. - Filename mismatch —
public class HelloWorldrequiresHelloWorld.java(case-sensitive). javac: command not found— JDK not onPATH. Restart terminal or add the JDK'sbin/to PATH.- Mixing JDK versions — multiple JDKs installed →
java --versionmay differ fromjavac --version. UseJAVA_HOMEto pin one. - Skipping
-Xlint:all— you'll miss warnings the compiler could catch for free.
- Install + compile — Set up JDK 21 on your machine and compile
HelloWorld.java. Confirmjava HelloWorldworks. Hint: checkjava --version. - Different folder — Compile with
javac -d out HelloWorld.java. Run withjava -cp out HelloWorld. Hint:out/HelloWorld.class. - Read input — Modify the program to read your name with
Scannerand greet you. Hint:import java.util.Scanner; new Scanner(System.in).nextLine();. - JAR it — Run
jar cfe app.jar HelloWorld HelloWorld.class, thenjava -jar app.jar. Hint:cfe= create-file-entry-point.
💡 Think Like a Programmer: Master your toolchain first. Spending 30 minutes on
javac,java, and IntelliJ saves you days of confusing build bugs later.
Quick recap quiz?
We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.
Program
public class Main {
public static void main(String[] args) {
System.out.println("Welcome to Java on Codekilla");
}
}