Java Installation

Last Updated: May 6, 2025

Java is one of the world’s most popular programming languages, known for its flexibility, robustness, and “write once, run anywhere” functionality. This tutorial will guide you through the initial steps of setting up Java on your computer and creating your first Java program.

Checking for Java Installation

Before installing Java, you should check if it’s already installed on your system:

For Windows Users:

  1. Open the Start menu and search for “Command Prompt” or “cmd”
  2. In the Command Prompt window, type:
    java -version
  3. If Java is installed, you’ll see information about your Java version:
    java version "22.0.0" 2024-08-21 LTS
    Java(TM) SE Runtime Environment 22.9 (build 22.0.0+13-LTS)
    Java HotSpot(TM) 64-Bit Server VM 22.9 (build 22.0.0+13-LTS, mixed mode)

For macOS Users:

  1. Open Terminal (Applications > Utilities > Terminal)
  2. Type the same command:
    java -version
  3. The output will be similar to the Windows example if Java is installed.

For Linux Users:

  1. Open Terminal
  2. Type:
    java -version
  3. You’ll see version information if Java is installed.

Installing Java

If you don’t have Java installed on your computer, you can download it from Oracle’s official website:

  1. Visit oracle.com
  2. Select the version appropriate for your operating system
  3. Follow the installation instructions provided by the installer
  4. After installation, verify it worked by checking the version again using java -version

Development Environments

While this tutorial uses a simple text editor approach, there are several Integrated Development Environments (IDEs) that make Java development more efficient:

  • IntelliJ IDEA: A powerful IDE with excellent code completion and analysis
  • Eclipse: A popular open-source IDE with a large plugin ecosystem
  • NetBeans: A free, open-source IDE that’s particularly good for beginners
  • Visual Studio Code: A lightweight but powerful code editor with Java extensions

For beginners, starting with a text editor helps you understand the basic concepts before moving to an IDE.

Your First Java Program

Let’s create your first Java application – the classic “Hello World” program:

Step 1: Create a Java File

Open any text editor (like Notepad, TextEdit, or VS Code) and create a new file. Save it as Main.java. Note that in Java:

  • Every application begins with a class name
  • The class name must match the filename
  • Java is case-sensitive, so Main and main are different

Step 2: Write Your Code

Enter the following code into your Main.java file:

  • JAVA
public class Main { 
    public static void main(String[] args) { 
        System.out.println("Hello World"); 
    } 
}

Let’s break down what this code means:

  • public class Main: Declares a class named “Main” that’s accessible by any other class
  • public static void main(String[] args): This is the entry point method for Java applications
  • System.out.println("Hello World"): This command prints text to the console

Step 3: Compile Your Java Program

To run your Java program, you first need to compile it:

  1. Open Command Prompt/Terminal
  2. Navigate to the directory where you saved Main.java using the cd command
  3. Type:
    javac Main.java
  4. If there are no errors, this will create a file called Main.class

Step 4: Run Your Java Program

Now you can run your compiled program:

  1. In the same Command Prompt/Terminal window, type:
    java Main
  2. You should see the output:
    Hello World

Congratulations! You’ve successfully written and executed your first Java program.