Java Installation and Setup
Before writing any Java program, the development environment must be set up on the computer. This involves installing the Java Development Kit (JDK) and optionally an IDE (Integrated Development Environment) to make coding easier.
What Needs to Be Installed?
- JDK (Java Development Kit): This is the essential package. It includes the Java compiler (
javac), the JVM, and core Java libraries needed to write and run Java programs. - IDE (Optional but Recommended): A software tool that provides a text editor, compiler integration, and debugging tools in one place. Popular choices include IntelliJ IDEA, Eclipse, and VS Code.
Step 1 – Download the JDK
The JDK is available for free from the official Oracle website or from OpenJDK.
- Open a web browser and go to: https://www.oracle.com/java/technologies/downloads/
- Select the latest LTS (Long-Term Support) version — such as Java 17 or Java 21.
- Choose the correct installer for the operating system:
- Windows: Download the
.exeinstaller. - macOS: Download the
.dmginstaller. - Linux: Download the
.tar.gzor.debpackage.
- Windows: Download the
- Click the download link and save the file.
Step 2 – Install the JDK
On Windows
- Run the downloaded
.exefile. - Follow the installation wizard and click Next until installation is complete.
- By default, Java is installed in:
C:\Program Files\Java\jdk-XX
On macOS
- Open the downloaded
.dmgfile. - Follow the installation steps.
- Java is installed automatically in the system path.
On Linux (Ubuntu/Debian)
- Open the terminal.
- Run the following command:
sudo apt update
sudo apt install openjdk-17-jdkStep 3 – Set the JAVA_HOME Environment Variable (Windows)
Setting the JAVA_HOME variable tells the system where Java is installed. This step is important for many tools and frameworks that depend on Java.
- Right-click on This PC → Click Properties.
- Click Advanced system settings → Environment Variables.
- Under System Variables, click New:
- Variable name:
JAVA_HOME - Variable value:
C:\Program Files\Java\jdk-17(adjust based on your version)
- Variable name:
- Find the Path variable in System Variables → Click Edit.
- Add a new entry:
%JAVA_HOME%\bin - Click OK to save all changes.
Step 4 – Verify the Installation
After installation, confirm that Java is correctly installed by opening a terminal or command prompt and running these commands:
java -versionExpected output (version may vary):
java version "17.0.9" 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 17.0.9+11-LTS)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.9+11-LTS, mixed mode)javac -versionExpected output:
javac 17.0.9If both commands return version information, Java is installed successfully.
Step 5 – Install an IDE (Recommended)
While it is possible to write Java in any text editor, an IDE makes development much faster and easier.
IntelliJ IDEA (Recommended for Beginners)
- Go to: https://www.jetbrains.com/idea/download/
- Download the Community Edition (free).
- Install it and open the IDE.
- Create a new Java project and start coding.
Eclipse
- Go to: https://www.eclipse.org/downloads/
- Download Eclipse IDE for Java Developers.
- Run the installer and complete the setup.
Visual Studio Code (VS Code)
- Go to: https://code.visualstudio.com/
- Install VS Code.
- Install the Extension Pack for Java from the Extensions panel inside VS Code.
Writing Java Without an IDE
Java programs can also be written using a plain text editor like Notepad (Windows) or gedit (Linux). The file must be saved with the .java extension and compiled using the command line.
javac HelloWorld.java
java HelloWorldThis approach is useful for understanding how Java works at a fundamental level before relying on IDE tools.
Summary
- The JDK must be installed to compile and run Java programs.
- Download the JDK from Oracle's official website or use OpenJDK.
- On Windows, the JAVA_HOME environment variable and PATH must be configured manually.
- Verify installation using
java -versionandjavac -versionin the terminal. - An IDE like IntelliJ IDEA, Eclipse, or VS Code makes Java development more efficient.
