Running a Java Program from Command Prompt
Create a temporary folder C:\mywork. Using Notepad or another text editor, create a small Java file HelloWorld.java with the following text:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello, World!");
}
}
Save your file as HelloWorld.java in C:\mywork. To make sure your file name is HeloWorld.java, (not HelloWorld.java.txt), first choose "Save as file type:" All files, then type in the file name HelloWorld.java.
Run Command Prompt (found under All Programs/Accessories in the Start menu). Type
C:\> cd \mywork
This makes C:\mywork the current directory.
C:\mywork> dir
This displays the directory contents. You should see HelloWorld.java among the files.
C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin
This tells the system where to find JDK programs.
C:\mywork> javac HelloWorld.java
This runs javac.exe, the compiler. You should see nothing but the next system prompt...
C:\mywork> dir
javac has created the HelloWorld.class file. You should see HelloWorld.java and HelloWorld.class among the files.
C:\mywork> java HelloWorld
This runs the Java interpreter. You should see the program output:
Hello, World!
If the system cannot find javac, check the set path command. If javac runs but you get errors, check your Java text. If the program compiles but you get an exception, check the spelling and capitalization in the file name and the class name and the java HelloWorld command. Java is case-sensitive!
It is possible to make the path setting permanent but you have to be very careful because your system might crash if you make a mistake. Proceed with extreme caution!
In Windows XP, go to Control Panel, choose "System," click on the "Advanced" tab, click on the "Environment variables" button. In the lower list, "System variables," click on Path:
Click "Edit" and at the end append
;C:\Program Files\Java\jdk1.5.0_09\bin
(or the path to the appropriate folder where the latest version of JDK is installed). Do not put spaces before the appended path string.
Click OK on the path edit box and OK on the Ennvironment Variables box. The new setting will go into effect next time you run Command Prompt.
I'm using Windows7 i created classpath for java ....But when i try to execute java program it showing classnotfound exception........ When i remove classpath from computer then program runs fine........I tried all possible ways to keep classpath but i doesnt work for me......I cant do JDBC prog's without setting classpath so pls help me
Hi
I have window7 operating system.and i have installed
jdk-7u2-windows-x64.exe for java program.
But i have a problem to set path of java.
and also how to run java program.
I have set the path and classpath in environment variables.eventhough iam getting the error like
javac:file not found:Demo.java
usage java:<options> <source files>
please rectify my mistake if any
My problem is the recoruse file is available in one context (say aa), I'm trying to load the same using ResourceBundle from another context (say bb). But always I get MissingResourceException exception. But it works well when I put the properties file under bb context I think I can use the solution that you mentioned in this post for the time being. But I'm searching for a solution so that I can use ResourceBundle(since the property file is for i18n purposes). Any way thanks dude it is indeed a good post.
path for you can run java any where you feel hapythulasiram May 27, 2011 at 12:59 PM
Running a Java Program from Command Prompt Create a temporary folder C:\mywork. Using Notepad or another text editor, create a small Java file HelloWorld.java with the following text: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } Save your file as HelloWorld.java in C:\mywork. To make sure your file name is HeloWorld.java, (not HelloWorld.java.txt), first choose "Save as file type:" All files, then type in the file name HelloWorld.java. Run Command Prompt (found under All Programs/Accessories in the Start menu). Type C:\> cd \mywork This makes C:\mywork the current directory. C:\mywork> dir This displays the directory contents. You should see HelloWorld.java among the files. C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin This tells the system where to find JDK programs. C:\mywork> javac HelloWorld.java This runs javac.exe, the compiler. You should see nothing but the next system prompt... C:\mywork> dir javac has created the HelloWorld.class file. You should see HelloWorld.java and HelloWorld.class among the files. C:\mywork> java HelloWorld This runs the Java interpreter. You should see the program output: Hello, World! If the system cannot find javac, check the set path command. If javac runs but you get errors, check your Java text. If the program compiles but you get an exception, check the spelling and capitalization in the file name and the class name and the java HelloWorld command. Java is case-sensitive! It is possible to make the path setting permanent but you have to be very careful because your system might crash if you make a mistake. Proceed with extreme caution! In Windows XP, go to Control Panel, choose "System," click on the "Advanced" tab, click on the "Environment variables" button. In the lower list, "System variables," click on Path: Click "Edit" and at the end append ;C:\Program Files\Java\jdk1.5.0_09\bin (or the path to the appropriate folder where the latest version of JDK is installed). Do not put spaces before the appended path string. Click OK on the path edit box and OK on the Ennvironment Variables box. The new setting will go into effect next time you run Command Prompt.
CLASSPATHPAVAN May 31, 2011 at 7:38 AM
I'm using Windows7 i created classpath for java ....But when i try to execute java program it showing classnotfound exception........ When i remove classpath from computer then program runs fine........I tried all possible ways to keep classpath but i doesnt work for me......I cant do JDBC prog's without setting classpath so pls help me
Class path setting problemvipin June 21, 2011 at 7:29 PM
sir, i am unable to set my java class path please help me
GreatAdvernus July 2, 2011 at 8:40 AM
Very nice tutorial
jangaiahjangaiah July 4, 2011 at 10:38 PM
i want know about java
javasonu July 29, 2011 at 12:03 AM
sir whan 1 pakage in another folder and another pakage is cantain in another folder.then how we set the pat
how to copy bin directory?Deepika Ghose September 27, 2011 at 10:52 PM
nothing
difficulty in setting of path of java.prabhat ranjan December 25, 2011 at 2:43 AM
Hi I have window7 operating system.and i have installed jdk-7u2-windows-x64.exe for java program. But i have a problem to set path of java. and also how to run java program.
unable to execute jar command vinayaka D J January 9, 2012 at 11:19 PM
i am trying to execute jar command but its showing command not found what to do
How to set the class path.Sunil Sharma February 1, 2012 at 4:49 PM
Thanks to this services for java.
Facing problem to set the classpath in javaPradeep Patel February 18, 2012 at 1:30 PM
Hello Sir I'm Pradeep Patel facing problem to set path and classpath for java programs
hideepika March 3, 2012 at 6:34 PM
i am getting noclassfound error while runtime
javamadhavi June 29, 2012 at 7:22 PM
I have set the path and classpath in environment variables.eventhough iam getting the error like javac:file not found:Demo.java usage java:<options> <source files> please rectify my mistake if any
sYQaUsZUhBRjMzNejla September 28, 2012 at 5:59 AM
My problem is the recoruse file is available in one context (say aa), I'm trying to load the same using ResourceBundle from another context (say bb). But always I get MissingResourceException exception. But it works well when I put the properties file under bb context I think I can use the solution that you mentioned in this post for the time being. But I'm searching for a solution so that I can use ResourceBundle(since the property file is for i18n purposes). Any way thanks dude it is indeed a good post.
how to set classpath temporary in javaabhishek kumar November 2, 2012 at 7:09 PM
two different folder having same package and same class name
Post your Comment