Java Setup (JDK & IDE)
java setup jdk ide intellij idea java home path javac java version install lts java 21 first project
Introduction
Before writing your first Java program, you need a proper development environment.
A professional Java setup consists of two main components:
- Java Development Kit (JDK) – Required to compile and run Java applications.
- Integrated Development Environment (IDE) – A powerful editor that helps you write, debug, and manage Java projects efficiently.
A correct setup ensures that your Java programs compile successfully, your IDE recognizes the installed JDK, and you can begin building applications without configuration issues.
In this lesson, you'll learn how to install the JDK, configure Java, set up IntelliJ IDEA, understand project structures, and verify that everything works correctly.
What is the Java Development Kit (JDK)?
The Java Development Kit (JDK) is a complete toolkit for Java developers.
It contains everything needed to create Java applications.
The JDK includes:
- Java Compiler (
javac) - Java Runtime
- Java Virtual Machine (JVM)
- Debugging tools
- Packaging tools
- Development utilities
Without the JDK, you can run Java applications only if a runtime is available, but you cannot compile your own Java source code.
JDK vs JRE vs JVM
Many beginners confuse these three components.
Here's an easy comparison.
| Component | Purpose |
|---|---|
| JDK | Develop, compile, debug, and run Java applications |
| JRE | Run Java applications |
| JVM | Execute Java bytecode |
Think of it like this:
- JDK = Complete toolbox
- JRE = Runtime environment
- JVM = Engine that executes bytecode
Choosing the Right Java Version
Java releases a new version every six months.
However, most companies prefer Long-Term Support (LTS) versions because they receive updates and fixes for an extended period.
Popular LTS releases include:
- Java 17
- Java 21
For this course, Java 21 LTS is recommended because it is modern, stable, and widely adopted.
Installing the JDK
Download the appropriate installer for your operating system.
After downloading:
- Launch the installer.
- Accept the license agreement.
- Select the installation directory.
- Complete the installation.
- Restart the terminal if necessary.
Most installers automatically configure the required settings.
Verifying the Installation
Open a terminal (or Command Prompt on Windows).
Run:
java -version
Example output:
openjdk version "21.0.2"
Next, verify the compiler.
javac -version
Example:
javac 21.0.2
If both commands display version information, your installation is successful.
Understanding JAVA_HOME
Many Java tools rely on an environment variable named JAVA_HOME.
It points to the JDK installation directory.
Example:
Windows:
C:\\Program Files\\Java\\jdk-21
Linux/macOS:
/usr/lib/jvm/jdk-21
Many build tools such as Maven, Gradle, and application servers use this variable to locate the JDK.
Updating the PATH Variable
The PATH environment variable allows you to execute Java commands from any terminal window.
Example:
Windows:
%JAVA_HOME%\\bin
Linux/macOS:
$JAVA_HOME/bin
If java or javac commands are not recognized, the PATH is often the first place to check.
Choosing an IDE
While you can write Java code in a simple text editor, a professional IDE makes development much easier.
Popular Java IDEs include:
| IDE | Best For |
|---|---|
| IntelliJ IDEA Community | Most developers and beginners |
| Eclipse | Large enterprise projects |
| Visual Studio Code | Lightweight development with Java extensions |
| Apache NetBeans | Desktop applications and education |
For this course, IntelliJ IDEA Community Edition is recommended because of its excellent code assistance and debugging features.
Installing IntelliJ IDEA
Installation steps:
- Download IntelliJ IDEA Community Edition.
- Run the installer.
- Accept the default options.
- Launch IntelliJ IDEA.
- Allow it to detect the installed JDK automatically.
If it doesn't detect the JDK, you can manually specify the installation path.
Creating Your First Java Project
In IntelliJ IDEA:
- Click New Project.
- Select Java.
- Choose the installed JDK.
- Enter the project name.
Example:
JavaMastery
- Select the project location.
- Click Create.
Your first project is now ready.
Understanding the Project Structure
A simple Java project looks like this:
JavaMastery│├── src│ └── Main.java│├── out│└── .idea
src
Contains your Java source code.
out
Contains compiled .class files generated by the compiler.
.idea
Stores IntelliJ IDEA project configuration.
Understanding this structure makes it easier to navigate and manage your projects.
Writing Your First Java Program
Open Main.java and type:
public class Main {public static void main(String[] args) {System.out.println("Welcome to TechLearningPro!");}}
Click Run.
Expected output:
Welcome to TechLearningPro!
Congratulations! You've successfully compiled and executed your first Java application.
Understanding the Code
public class Main
Defines a class named Main.
public static void main(String[] args)
The JVM begins execution from the main() method.
System.out.println()
Prints text to the console.
You'll explore each of these concepts in detail in upcoming lessons.
Compiling from the Command Line
Although IDEs automate compilation, every Java developer should understand the manual process.
Compile the program:
javac Main.java
This generates:
Main.class
Run it:
java Main
Output:
Welcome to TechLearningPro!
Knowing these commands helps when working on servers, build pipelines, or troubleshooting environment issues.
Real-World Example
Imagine you're joining a software company.
On your first day, you'll typically:
- Install the required JDK version.
- Install an IDE such as IntelliJ IDEA.
- Clone the project's Git repository.
- Configure the project SDK.
- Build and run the application locally.
A proper setup is the first step in becoming productive on any Java project.
Troubleshooting Common Problems
Problem: java Command Not Found
Possible causes:
- JDK isn't installed.
- PATH is not configured.
- Terminal needs to be restarted.
Problem: javac Command Not Found
Possible causes:
- Only a runtime is installed.
- PATH doesn't include the JDK's
bindirectory.
Problem: Wrong Java Version
Check:
java -versionjavac -version
Ensure your terminal and IDE are using the same JDK.
Problem: IDE Cannot Find the JDK
Open your IDE settings and configure the Project SDK to point to the installed JDK.
Best Practices
- Use an LTS Java version for learning and production.
- Verify the installation immediately after setup.
- Keep your IDE updated.
- Use a consistent project folder structure.
- Learn both IDE-based and command-line compilation.
- Use version control (Git) from the beginning.
Common Mistakes
Installing Only the Runtime
You need the full JDK to compile Java programs.
Ignoring Version Compatibility
Some projects require a specific Java version.
Always verify the required version before starting work.
Not Configuring the Project SDK
Even if Java is installed correctly, the IDE must know which JDK to use.
Depending Only on the IDE
Understanding javac and java commands helps when working with servers, containers, and build tools.
Hands-on Exercise
Complete the following tasks:
- Install Java 21 LTS.
- Verify the installation using:
java -versionjavac -version
- Install IntelliJ IDEA Community Edition.
- Create a project named JavaMastery.
- Write the "Welcome to TechLearningPro!" program.
- Compile and run it using IntelliJ IDEA.
- Compile and run the same program using the command line.
- Create a second class and print another custom message.
By completing these exercises, you'll gain confidence in setting up and using a professional Java development environment.
Summary
A properly configured Java development environment is the foundation of every Java project.
The JDK provides the tools to build applications, the JVM executes compiled bytecode, and a modern IDE such as IntelliJ IDEA improves productivity through intelligent coding assistance, debugging, and project management.
Learning both IDE workflows and command-line tools prepares you for real-world software development.
Key Takeaways
- Install the full JDK, not just the runtime.
- Prefer an LTS version such as Java 21 for learning and production.
- Verify your installation using
java -versionandjavac -version. - IntelliJ IDEA Community Edition is an excellent choice for Java development.
- Understand the difference between the JDK, JRE, and JVM.
- Learn to compile and run Java programs both manually and through an IDE.
Professional Interview Questions
1What is the difference between the JDK, JRE, and JVM?
Professional Answer
The JDK is a complete development toolkit that includes the compiler, runtime, debugging tools, and the JRE. The JRE provides the libraries and JVM required to run Java applications. The JVM is responsible for executing Java bytecode on a specific platform.
Follow-up Questions
- Does the JDK include the JRE?
- Why is the JVM platform-specific?
- What is bytecode?
Interview Tip: A simple way to remember is: JDK = Develop, JRE = Run, JVM = Execute.
Common Mistake: Saying that the JRE can compile Java programs. Compilation requires the JDK.
2Why is JAVA_HOME important?
Professional Answer
JAVA_HOME is an environment variable that points to the JDK installation directory. Many development tools, build systems, and application servers use it to locate the correct Java installation.
Follow-up Questions
- How is JAVA_HOME different from PATH?
- What happens if JAVA_HOME points to the wrong version?
Interview Tip: Explain that JAVA_HOME identifies the JDK location, while PATH allows Java commands to be executed from the terminal.
3Why should every Java developer learn command-line compilation?
Professional Answer
Understanding command-line compilation helps developers troubleshoot build issues, work on remote servers, understand how IDEs operate behind the scenes, and integrate Java applications into build tools and CI/CD pipelines.
Follow-up Questions
- Which command compiles Java code?
- Which command runs a compiled Java program?
Interview Tip: Mention javac for compilation and java for execution, and explain that IDEs internally use these same tools.