10.9 C
New York
Wednesday, February 28, 2024

Run Java Program from Command Prompt

In this tutorial, we are going to learn how to write a JAVA program from a command prompt by typing the commands.

We must have JDK installed in our computer system before running the JAVA program in Command Prompt.

Please follow the steps mentioned below to run JAVA program in Command Prompt:

1) First, write your Java program in notepad or any other text editor and save it

Note: Save the java program with name same as the class name and .java extension.

2) Now open the run command prompt Start Menu -> All Program -> Accessories. type your user directory click ok.

3) Now you will see your user directory displayed in the command prompt. Write command dir next to your user directory and press enter

5) Now all the content in the directory will be displayed. You will also see your .java file

6) Now as we know before running a java program we must need to compile the java codes and convert it into byte code. Therefore in order to compile the Java source code, we will use the compiler by using command C:Usert> javac classname.java

7) Now command javac has created a classname.class file. You will see classname.java and classname.class among the files. The file created by class extension contains the byte code

8) In order to execute the java program we have to call Java interpreter using command C:user> java classname, press enter to get output

Read Next Variable types and Data types in JAVA

Related Articles

Latest Articles