Run Java Command Prompt

If you have written new java program and want to run it through command prompt please follow steps below:

  • Install JDK and set it’s class path using this tutorial
  • Create folder name: C:\JavaHonk\RunJava\com\javahonk
  • Create sample java class inside folder C:\JavaHonk\RunJava\com\javahonk which we will run through command prompt:
package com.javahonk;

public class HelloWorldTest {

	public static void main(String[] args) {
		System.out.println("Hello World!");

	}

}

Note: As you see this java class is inside package name: com.javahonk so to run this program we will have to give package name as well.

  • Open command prompt and go to directory where you have created java class (For this demo java class created in below folder)

Run Java Command Prompt

  • Compile java class using below command:

Run Java Command Prompt

  • To run compiled java class which is inside package com.javahonk you will have to move back to root folder and run as below:

Run Java Command Prompt

Leave a Reply

Your email address will not be published. Required fields are marked *