JavaBasics

Java Environment Setup

Learn how to install Java JDK, set up environment variables, verify Java installation, and run your first Java program step by step.

Java Environment SetupLink to this section

Before writing and running Java programs, you need to properly set up the Java development environment on your system. This includes installing the Java Development Kit (JDK), configuring environment variables, and verifying the installation.

What is JDK?Link to this section

The Java Development Kit (JDK) is a software package required to develop Java applications. It contains tools such as the Java compiler, debugger, and runtime libraries.

Without JDK, you cannot compile or execute Java programs.

note

JDK includes both JRE and JVM, so installing JDK is sufficient for development.

Steps to Install Java JDKLink to this section

Follow these general steps to install Java on your system:

  • Download the latest LTS version of Java JDK from the official Oracle or OpenJDK website
  • Run the installer and follow on-screen instructions
  • Choose the default installation path

tip

Always prefer an LTS (Long-Term Support) version for stability and long-term projects.

Setting Environment VariablesLink to this section

After installing Java, environment variables must be configured so the system can recognize Java commands.

  • JAVA_HOME: Points to the JDK installation directory
  • PATH: Allows running Java commands from any location

Once configured correctly, you can run Java commands directly from the command line or terminal.

warning

Incorrect environment variable paths may cause Java commands to not work.

Verifying Java InstallationLink to this section

Once Java is installed and environment variables are configured, verification is required.

note

If version details do not appear, recheck the PATH variable.

Creating and Running the First Java ProgramLink to this section

Running a simple program confirms that the Java environment is correctly set up.

Code Example: First Java Program

Steps to execute the program:

  • Save the file as FirstProgram.java
  • Compile using: javac FirstProgram.java
  • Run using: java FirstProgram

warning

The file name must exactly match the class name.

Common Problems During SetupLink to this section

Beginners may face the following issues:

  • Java command not recognized
  • Incorrect JDK installation
  • Environment variables not set properly

tip

Restart the system after setting environment variables to apply changes.

Importance of Proper Java SetupLink to this section

A correctly configured Java environment ensures:

  • Error-free compilation and execution
  • Compatibility with IDEs like Eclipse and IntelliJ IDEA
  • Smooth learning experience for beginners
Quiz – Java Environment Setup
Question 1 of 5

Which component is required to develop Java applications?