I've trying to start learning Java and already in stuck with the easiest possible program (http://introcs.cs.princeton.edu/java/11hello/)
So I created HelloWorld.java
with
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
Compiled it with D:\tmp\java>javac HelloWorld.java
(all passed fine, w开发者_JAVA百科ithout errors)
And tried to run compiled .class
:
D:\tmp\java>java HelloWorld.class
Error: Could not find or load main class HelloWorld.class
I have
D:\tmp\java>javac -version
javac 1.7.0
and cannot get why such trivial example doesn't work :-S
You should run it as java HelloWorld
(without .class
extension).
Remove the .class when running the program.
java HelloWorld
Good luck on your coding journey!
many instance we forgot to close and reopen the command prompt after editing the environement varriable . 1. In the environement varriable -create system variable called JAVA_HOME set the JAVA_HOME value upto bin folder of your JAVA directory 'C:\Program Files\Java\jdk1.7.0_04\bin'.3.Edit path in the system variable and add ';%JAVA_HOME%'. 4. close the control panel and close the command prompt and reopen and compile and run.donot bother about class path.
you can test the functioning by typing javac
For the first time create file helloworld.java the folder c:\users\documents\helloworld.java in note pad and type the following
class helloworld
{
public static void main(String [] args )
{
System.out.println("Welcome Helloworld");
}
}
after saving click command prompt and type
for compiling c:\users\documents\ javac helloworld.java
for running c:\users\documents\ java helloworld
精彩评论