Question:
Why wont my java commands work from command prompt?
J M0C
2009-09-26 08:55:52 UTC
I have an programs from my computer at home beore but now the simple programs wont even run like the welcome program. The files will complie in textpad but wont run anywhere. I dont think its a classpath error because they ran before. any ideas?
And another thingany java command i run in th prompt just gives me a list of the commands i am so lost
Three answers:
Mark aka jack573
2009-09-26 23:14:02 UTC
Answering this part,

"And another thingany java command i run in th prompt just gives me a list of the commands i am so lost"



I presume you are just typing

java

into the command prompt.



What you need to do is use the name of your file you have compiled. Let us say that you have made the welcome program with the name of the file as

welcome.java

Then when you compile it, a new file is produced that is

welcome.class



Now, to run this program you need to type

java welcome

and it should work.



Of course, if the name of your file(s) is not welcome, change the command that you type to whatever name you have. For instance, just say the file is named myclass.class, you would type

java myclass



Good luck with it.



[EDIT]

It sounds as if you have not compiled the Welcome class yet.

You need to type

javac Welcome.java

before you can do the

java Welcome



The javac command will compile the Welcome.java to Welcome.class that you can run with the java command.



If you have already compiled the Welcome.java file, you will need to find where Welcome.class is. If it is in the D:\Programs> folder, then you have a classpath issue and will need to set the classpath.



These pages will give you information about how to set the classpath.

http://faculty.ed.umuc.edu/~arnoldyl/NetBeansTutorials/Setting-Classpath.html

http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html
2016-03-03 07:41:23 UTC
You need to set your PATH variable to the location of your java bin directory. Start > Control Panel > System > Advanced tab > Environment Variables > Click Path under 'System Variables' > Add the location of your Java bin directory to the beginning and end it with a semi-colon. > Click OK 3 times and close the Control Panel My Java bin directory is at 'C:\Program Files\Java\jdk1.6.0_18\bin' Hope this helps.
2009-09-26 09:03:17 UTC
sounds like you need to run it from the directory containing the .class file


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...