Learn Java

Learn How to Install Java

 Let’s Get Start

In Part 2, we will learn how to install Java, setup for Windows, and go through Java quick start. So here we go!

 

Learn How To Install Java

If you have Java already installed on your PC, you can skip this part. Students who want to learn Java installation can continue.

Search for Java in the start bar to know whether Java is installed on your PC. You can also type as given below in the Command Prompt or cmd.exe:

  • C: UsersYour Name>java –version

If Java is installed, you will see as given below:

java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

 

If you don’t find Java on your PC, you can download it from the website Oracle.com for free. Download Java 17 or Java 19 For Windows 10.

After Download please install it

Install Java Now

Follow the steps given below to install Java:

Step 1: Go to “System Properties.” You fill find it on – Control Panel > System and Security > System > Advanced System Settings.

Now click on the “Environment Variables” button under the “Advanced Tab.”

Now, in System variables and click on the “New” button.

Click new on environment variables

Now click on the “New Button” and add the path where Java is installed, followed by in.

By default, Java is installed in C:\Program Files\Java\jdk-17\

Variable Name : JAVA_HOME

Variable Value: C:\Program Files\Java\jdk-17\

Add Java home and add the location without bin

 

Now, select the “Path” variable in System variables and click on the “Edit” button.

Click path then edit on environment variables system variables

Then add this

C:\Program Files\Java\jdk-17\bin

New addition to environment variables to install java

It’s time to open Command Prompt or cmd.exe and type java -version to see if Java is running on your machine.

C:\Users\Priyanka\Documents\java>java --version
openjdk 17.0.6 2023-01-17
OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10)
OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode, sharing)

java version 17

 

 

Java Quick Start

Every application starts with a class name in Java. That class should match the file name.

It’s time to create our first Java file called First.java. You can write the codes in any text editor like notepad.

First.java

public class First {

  public static void First(String[] args) {

    System.out.println("Hello From H4C");

  }

}

The first file should return the message Hello From H4C.

Save this code with a name first.java then open cmd or terminal and run the comman

javac first.java

If no error comes means it’s successfully compiled. Then run this command

java first as shown in the image below

compiled first java program