Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Beginners How to run a Java program in CMD

 
 

Share on Google+Share on Google+

How to run a Java program in CMD

Advertisement
The article describes How to run a Java program in Command Prompt(CMD) using Notepad. Here you will also find tips to set the Java Class Path.

There are multiple ways to write and run Java programs. In this article we discussed how to write and run Java program in CMD.

Tips to run Java program in command prompt.

  •  Create a myproject folder in C folder
  • Open a notepad or any other editor and write a small program
    in Java as given below.
public class HelloWorld
{
public static void main(String[] args)
 {
System.out.println("Hello, World!");
	}
		}
  •  Save the program file as 'HelloWorld.java' in your C:\myproject folder and cross check the file name it must be
    saved as 'HelloWorld.java'.
  • In windows go to the Start Menu and open the command prompt.
  • Change the directory from c to C:\myproject. To change the directory type the given command in your command prompt.

Cd \myproject and press enter. It will change the folder.

  • Run the dir command to check if the 'HelloWorld.java' exist or not.
  • Make sure that your Java Path is set. If not then you can set it by running following command at your command prompt.

set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin

  • Now time to compile your program. Write the following command to your command prompt and press enter.

Cd \myproject> javac HelloWorld.java it should compile the file.

  •  Now time to execute the program. Run the given command.

C:\myproject> java HelloWorld

This will run the Java interpreter and You will see the program output as follows:

Hello, World!

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 21, 2013

Related Tutorials

Discuss: How to run a Java program in CMD  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com