Java Installation, PATH Setup & Command-Line Execution
Install JDK on Windows, Linux, and macOS, configure JAVA_HOME and PATH, set up IntelliJ IDEA / Eclipse / VS Code, and pass command-line arguments.
- Windows (PowerShell / System Environment Variables):
* Set
JAVA_HOME=C:\Program Files\Java\jdk-21 - Linux / macOS (`~/.bashrc` or `~/.zshrc`): ```bash
- IntelliJ IDEA: Industry-standard Java IDE with deep refactoring, Maven/Gradle integration, and visual debugger.
- VS Code: Lightweight editor with Microsoft's "Extension Pack for Java".
Introduction
A reliable Java development setup requires installing an LTS JDK (Java 17 or Java 21), configuring JAVA_HOME and PATH, and knowing how to compile, package, and run programs from both the terminal and an IDE.
Learning Objectives
- Install an OpenJDK / Oracle JDK on Windows, Linux, or macOS.
- Configure
JAVA_HOMEandPATHenvironment variables accurately. - Compile and run Java programs from the CLI, including passing
String[] args.
Setting Environment Variables
- Windows (PowerShell / System Environment Variables):
- Set
JAVA_HOME=C:\Program Files\Java\jdk-21 - Add
%JAVA_HOME%\bintoPath. - Linux / macOS (`~/.bashrc` or `~/.zshrc`):
Verify your setup by running java -version and javac -version.
Command-Line Execution & Arguments
Inside public static void main(String[] args), args[0] is the first CLI argument passed after the class name. Since Java 11, you can also run a single source file directly with java Main.java without a separate javac step.
Recommended IDEs
- IntelliJ IDEA: Industry-standard Java IDE with deep refactoring, Maven/Gradle integration, and visual debugger.
- VS Code: Lightweight editor with Microsoft's "Extension Pack for Java".
- Eclipse: Mature open-source IDE widely used in enterprise teams.
Common Mistakes
- Pointing
JAVA_HOMEto thebinfolder instead of the JDK root directory—build tools like Maven and Gradle expectJAVA_HOMEto be the parent ofbin. - Forgetting to restart your terminal after editing environment variables.
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)