Choose the appropriate JDK version for your operating system (Windows, macOS, or Linux) and download the installer.
After installation,
set the JAVA_HOME environment variable to point to the JDK installation directory.
Set Environmental Variables in Java
Step 1: Add Java to System Variables
1. Open the Start menu and search for environment variables.
2. Select the Edit the system environment variables result.
3. In the System Properties window, under the Advanced tab, click Environment Variables…
4. Under the System variables category, select the Path variable and click Edit:
5. Click the New button and enter the path to the Java bin directory:
Note: The default path is usually C:\Program Files\Java\jdk-17.0.1\bin.
6. Click OK to save the changes and exit the variable editing window.
Step 2: Add JAVA_HOME Variable
Some applications require the JAVA_HOME variable. Follow the steps below to create the variable:
1. In the Environment Variables window, under the System variables category, click the New… button to create a new variable.
2. Name the variable as JAVA_HOME.
3. In the variable value field, paste the path to your Java jdk directory and click OK.
4. Confirm the changes by clicking OK in the Environment Variables and System properties windows.
Test the Java Installation
Run the java -version command in the command prompt to make sure Java installed correctly:
Verify the installation by opening a command prompt (or terminal) and running the command java -version. This should display the installed Java version.
If installed correctly, the command outputs the Java version. Make sure everything works by writing a simple program and compiling it. Follow the steps below:
Step 1: Write a Test Java Script
Hello World Program
Let's create a simple "Hello World" program in Java to get started:
publicclassHelloWorld{
publicstaticvoidmain(String[] args){
System.out.println("Hello, World!");
}
}
In this program:
public class HelloWorld defines a class named HelloWorld.
public static void main(String[] args) is the main method, which serves as the entry point for our program.
System.out.println("Hello, World!"); prints the text "Hello, World!" to the console.
To run this program, compile it using the javac command and then execute it using the java command.
Want to print your doc? This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (