Search Bar

How to run Java Programs?


 Run your very first JAVA program.


Hello guys,
In this tutorial, we are going to run our very first JAVA program in windows operating system. There are many ways to run JAVA programs. You can run your Java programs in different platforms like Windows, Linux, etc. but there is another option also you can run your java program online also. Nowadays there are many online compilers available free. You can run this on your laptop, desktop, mobile phone (Smart Phones). In this tutorial, we gonna see two ways to run Java programs in Windows OS.



How to run Java Programs?
How to run Java Programs?

Using CMD:



Windows OS having CMD (Command Prompt) this is default available in this OS. When you set an environment variable in windows as shown in our last tutorial. If you want to check your environment variable set correctly or not then for checking just open your Terminal or CMD and type java  If there terminal shows commands then you're all set good, If not then you have to check once again or set the variable again.

let's start coding...

Step 1) Open Notepad or any Text Editor.



Write your JAVA code in Text Editor
Write your JAVA code in Text Editor




Step 2) Copy and Paste the given code in your Text Editor. 

public class MyFirstPrograms
{

public static void main(String[] args)
{

System.out.println("Hey... \nThis is you first JAVA programs.");

}
}

Step 3) Click on the file tab, Under that select Save As.

Save java programs as a .java
Save java programs as a .java




Step 4) Give the name as you want I am giving as similar to my Class Name. (Eg. MyFirstPrograms)

Save java programs as a .java extension
Save java programs as a .java extension


Step 5) Don't forget to add .java extension to the file name & click on SAVE. (Eg. MyFirstPrograms.java)



JAVA file is created
JAVA file is created


Now run your java program in CMD:

Step 1) Open you CMD or Terminal.
Step 2) Locate the path to your program file (Where your program file is store.)


OR

Step 2) There is another way to locate CMD. Just click on the address bar and cut all text and type cmd. This will open CMD in your desired location.

Type CMD in the address bar
Type CMD in the address bar

CMD Open with location
CMD Open with location



Step 3) Type javac then your file name.java hit enter. (Eg. javac MyFirstPrograms.java)
JAVAC is a java compiler, it is used for compiling the java program.

javac command to compile java code
javac command to compile java code




Note: If you don't gate any error means you are on the right path. (Good.)
Step 4) Type java and now write your class name without any extension. (Eg. java MyFirstPrograms).

java command to run java code
java command to run java code



Two file is created, One .class file and a second .java file
Two files are created, One .class file and a second .java file


There are other ways to run our java programs, Just search on Google JAVA compiler online. For running java programs we have IDE's like Eclipse, NetBeans, Visual Studio, etc... we can use this IDE's also for compiling and running you JAVA programs.

Great You run your very first java program successfully.



Post a Comment

0 Comments