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:
- Open the Start menu and search for “Command Prompt” or “cmd”
- In the Command Prompt window, type:
java -version
- 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:
- Open Terminal (Applications > Utilities > Terminal)
- Type the same command:
java -version
- The output will be similar to the Windows example if Java is installed.
For Linux Users:
- Open Terminal
- Type:
java -version
- 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:
- Visit oracle.com
- Select the version appropriate for your operating system
- Follow the installation instructions provided by the installer
- 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
andmain
are different
Step 2: Write Your Code
Enter the following code into your Main.java
file:
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 classpublic static void main(String[] args)
: This is the entry point method for Java applicationsSystem.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:
- Open Command Prompt/Terminal
- Navigate to the directory where you saved
Main.java
using thecd
command - Type:
javac Main.java
- 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:
- In the same Command Prompt/Terminal window, type:
java Main
- You should see the output:
Hello World
Congratulations! You’ve successfully written and executed your first Java program.