Please help me out.
and please UseCodeTags henceforth
Do I need to type java -cp . <class_name> every time I run a prog? Wont the command java <classname> simply work??? Is the CLASSPATH setting correct???
Will you please clarify how to use compile a prog without going into the bin...I mean without typing the complete path address (C:\Java\jdk1.7.0\bin) again and again.
Two things i can think of not using the -cp option is
1. If your .class file is in the same directory then you don't have to specify the class path option
2. If your .class file is present in the subfolders say C:/MyClasses/com/mypackage/HelloWorld.class and com and mypackage are the packages in which the HelloWorld is present. Now say if you are in the location C:/MyClasses in the cmd prompt you can just give java com.mypackage.HelloWorld
I hope you knew about packages - the declaration you give at the start of a java program if needed - say in this case ->
You do not need to specify every time the path of the java.exe. To make the OS to locate the java exe it you have to specify the JAVA_HOME and path variables in the Environment variables.
This post should help you setting the environment variables - http://www.coderanch.com/t/551943/java/java/Wrong-version-appearing-java-command
and this to understand path & classpath -> http://download.oracle.com/javase/tutorial/essential/environment/paths.html
Also I think Java should be already installed in your OS by default. So just type the command java in your command prompt and see what the output is shown.
If the classpath was set by another application, edit it by adding the . at the beginning. It will read something like .;C:\something\folder;C:\Program Files\qt\lib;... Quicktime is one of the applications prone to setting a system classpath.
My knowledge is restricted to Java 1.5.... and it would be appropriate for other ranchers who knew 1.7 version to answer your query... hope so you will get that in a moment..
And please start new thread for new questions...
Saptaparna Dhar wrote:Thank you for your assistance.
I have set the path as suggested and now I compile the program by simply typing javac <classname>.java
Mr. John, the output which I got by typing java in the command prompt is--
I have a related issue. I am getting the above message and I have entered the command:
Why does this screen appear in the windows command prompt and what can I do to run my program. I created a simple hello world program and used:
I got the output Hello world, so it must have executed fineactually the same thing is happening to my hello world program too. I do also have a jar file that I needed for jsch-0.1.48.jar in the same folder as the java and .class files. I'd Also like to mention that I ran this in eclipse and it works just fine. I've never used the command prompt to execute java before. Thank you!
If you need to write -cp . you have a classpath problem. You ought not to set a system classpath; if you set your own, you ought to delete it. If it was there before you started, eg containing QuickTime entries, add a . for current directory at its beginning. In Windows® it looks like this .;blahblahblah and on other OSs like this .:somethingsomethingsomething. You probably have to reopen the command line to see any effect.
Your post was moved to a new topic.