Java is a high-level, class-based, object-oriented programming language used across multiple platforms.
You can run Java on your computer by installing it and setting up the required environment. In this tutorial, you will learn how to install {Java} on your system and run your first {Java} program.
Install Java on Your Computer #
To start programming in {Java}, you need to install the Java Development Kit (JDK) on your computer. Below is a step-by-step guide to installing {Java} on Windows, macOS, and Linux.
Install Java on Windows
Follow these steps to install Java on a Windows computer:
- Download JDK (Java Development Kit)
- Visit the official Oracle website and download the latest version of the JDK for Windows.
- Choose the x64 MSI Installer and download the file.
- Run the Installer
- Open your downloads folder and run the installer.
- Follow the on-screen instructions and click Next to proceed.
- Configure Environment Variables
After installation, you need to configure environment variables to let your system locate {Java}.- Locate JDK Path: The JDK is usually installed in:
C:\Program Files\Java\jdk-22\bin
this path. - Access Environment Variables:
- Open the Start menu and search for Environment Variables.
- In the System Properties window, click Environment Variables.
- Update the Path Variable:
- Under System Variables, find the Path variable and click Edit.
- Click New and paste the copied JDK bin path (e.g.,
C:\Program Files\Java\jdk-22\bin
). - Click OK to save the changes.
- Set JAVA_HOME Variable:
- Under System Variables, click New to create a new variable.
- Set the Variable Name as
JAVA_HOME
and the Variable Value as the JDK installation path (e.g.,C:\Program Files\Java\jdk-22
). - Click OK to save.
- Locate JDK Path: The JDK is usually installed in:
- Verify Installation
Open the command prompt and type the following command to check if {Java} is installed correctly:java --version
If {Java} is installed successfully, it will display the installed {Java} version.
Run Your First Java Program #
Java is installed. Write and run a simple {Java} program.
Step 1: Write Java Code
Open Notepad (or any text editor) and enter the following code:
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Save this file as HelloWorld.java (choose All Files in “Save as type”).
Step 2: Compile and Run the Program
- Open the Command Prompt and navigate to the folder where you saved the {Java} file.
- Compile the {Java} program using:nginx
javac HelloWorld.java
- Run the program with:
java HelloWorld
You should see this output:
Hello, World!
Understanding the Java Program Structure #
Let’s break down the {Java} program:
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
- class HelloWorld → Declares a class named
HelloWorld
. - public static void main(String[] args) → The main method where execution starts.
- System.out.println(“Hello, World!”); → Prints “Hello, World!” to the screen.
Key points to remember: #
- Code inside parentheses
()
must be correctly formatted. - Strings are enclosed in double quotes
" "
. - Each statement must end with a semicolon
;
.
You have installed {Java} and written your first program. Now, explore more {Java} concepts! Stay tuned for the next tutorial.
Want to learn Java Programming with an instructor, either offline or online? Find experienced tutors near you and join Coaching Wallah.
Leave your comment