Java Program Syntax Output

Run Java First Program on Windows 10

In the previous lesson, we learned how to set environment for Java. We successfully verified the installation of Java on command prompt (cmd). In this lesson, we will learn how to write and run Java first program on Windows.

Open a notepad and enter the following code:

Now, save the above notepad as Example1.java. Here, you can see the extension is java to run a java program.

The class above is a main class, since it is having the main() function in it. Also, a program having main should have the program name similar to class name. In this case, its Example1.

Now, we will reach the Command Prompt as we did in the previous lesson to verify JDK installation. Here, we will add a new project folder in D: drive i.e.

We will save all our Java examples in the above folder. You can add any folder.

But to tell the compiler that here you have saved our Java Programs, you need to set the path in Environment Variables i.e.

Go to Control Panel > System > Advanced System Settings > Advanced tab > Environment Variables.

Under System Variable, click Path, then New and add the following path and save it,

After adding the path above, now again go to Command Prompt and reach the above path as shown below,

Java program folder Command Prompt

Now, type the following command to compile the java program and press enter:

>javac Example1.java

Now, type the following command to run the java program, which we compiled successfully and press enter:

>java Example1

Now, if the program is correct,  without any bug, then it will be successful, and the following will be printed,

Java First Program Output

After successfully running the program, output will be visible as shown above.

Now, go to the same path and now you can see a class file generated for the same program.

Java program class file

In this lesson, we learned how to run our first Java program on Windows 10.

Install Java on Windows
Java Syntax
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading