0% found this document useful (0 votes)
2 views4 pages

To Run A Java Program Using Command

This document outlines the steps to run a Java program using Command Prompt, starting with creating a folder and writing a Java class. It details the process of compiling and executing the Java program, including setting the JDK path. Important notes on case sensitivity and path settings are also provided to ensure proper execution.

Uploaded by

shwetikesoe704
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

To Run A Java Program Using Command

This document outlines the steps to run a Java program using Command Prompt, starting with creating a folder and writing a Java class. It details the process of compiling and executing the Java program, including setting the JDK path. Important notes on case sensitivity and path settings are also provided to ensure proper execution.

Uploaded by

shwetikesoe704
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

To run a Java program using Command Prompt.

Steps to achieve our goal:


i. Create a folder
ii. Create a java class and write a java program
iii. Open command prompt
iv. Run the created Java program using command prompt

Step i: Create a folder

C:\Softw areTestingMaterial

1 C:\SoftwareTestingMaterial

Step ii: Create a java class and write a java program

Using Notepad or another text editor, create a Java file [Link] with the following
text:

1 public class HelloTesters{


2 public static void main(String[] args){
3 [Link]("This is SoftwareTestngMaterial website!");
4 }
5}

Save your file as [Link] in C:\SoftwareTestingMaterial.

Step iii: Open command prompt

Open Command Prompt (Open Run (Windows+R) and type cmd)

Step iv: Run the created Java program using command prompt

Follow the below steps:


C:\Users\Admin> cd\

1 C:\Users\Admin> cd\
C:\> cd Softw areTestingMateria

1 C:\> cd SoftwareTestingMaterial

This makes C:\SoftwareTestingMaterial the current directory.

C:\Softw areTestingMaterial> dir

1 C:\SoftwareTestingMaterial> dir

This displays the directory contents. You should see [Link] among the files.

C:\Softw areTestingMaterial> se

1 C:\SoftwareTestingMaterial> set path=%path%;C:\Program Files\Java\jdk1.8.0_101\bin

(use the JDK folder for the version installed on your system). This tells the system where to find
JDK programs.

C:\Softw areTestingMaterial> jav


1 C:\SoftwareTestingMaterial> javac [Link]

This runs [Link], the compiler. You should see nothing but the next system prompt.

C:\Softw areTestingMaterial> dir

1 C:\SoftwareTestingMaterial> dir

javac has created the [Link] file. You should see [Link] and
[Link] among the files.

C:\Softw areTestingMaterial> jav

1 C:\SoftwareTestingMaterial> java HelloTesters

This runs the Java interpreter. You should see the program output:

Output:This is SoftwareTestngMaterial website!

Note:
i. Java is case-sensitive! Check your Java text. Check the spelling and capitalization in the file
name and the class name and the java HelloTesters command.

ii. In “Step iv”, we set the jdk path. It is possible to make the path setting permanent but you
have to be very careful because your system might crash in case of any mistake. Proceed with
extreme caution!

To ensure that Windows can find the Java compiler and interpreter:

Select Start -> Computer -> System Properties -> Advanced System Settings -> Environment
Variables -> System Variables -> PATH

Click “Edit” and at the end append the jdk path after semicolon ( ; )
C:\Program Files\Java\jdk1.8.0_1

1 C:\Program Files\Java\jdk1.8.0_101\bin

Note: Add jdk path based on your system jdk path

Click on OK.

You might also like