Q:

How do I run a java program in cmd?

I have created a program in Java, but it is not taking the inputs correctly in edit-plus(compiler) so now I want it to run in cmd. My JSK file is at : C:\Program Files\Java\jdk1.7.0_21\bin and my Java file is at: C:\TurboC4\TC\java new programs
Please tell me the steps to run it in cmd.

A:

On the command line use:
java -jar path/to/your/jar_file.jar

if you do not have a jar file, than you have to compile first your Java classes:
javac -g Foo.java

if you have just a single file (containing a static void main()) than you can simply run it with:
java path/to/your/compiled_class_file [<command line args>, ...] 

Note: Run the command above without .class extension. i.e.
java Foo

if you want to generate a jar file from your compiled .class files run:
jar cf jar-file input-file(s)

However, I would recommend you to use a IDE that compiles, packs and runs your code for you automatically with one click. i.e. IntelliJ or Eclipse

