hi, i have just written a simple hello world java program in my linux server, installed jdk ... and tried to compile and run it and it gave me some errors.
please details below:
[root@localhost javaFiles]# cat HelloWorld.java
import java.util.*;
import java.io.*;
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello world!");
}
}
#javac HelloWorld.java
#
[root@localhost javaFiles]# ls
HelloWorld.class HelloWorld.java
[root@localhost javaFiles]# java HelloWorld.java
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/java
Caused by: java.lang.ClassNotFoundException: HelloWorld.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
would someone please tell me what is wrong? thanks very much.
thanks, i think that is the problem. do you know which path i should set it to? i know i am supposed the one to know this answer.
i meant, what file (some kind of jar file? ) am i supposed to find in the path that i should set to my java CLASSPATH?
sorry, i am pretty green to the whole thing. i was trying to ask how do i find out which path i should set? i use "yum install jdk* " to download and install my jdk.
[root@localhost javaFiles]# cat HelloWorld.java
import java.util.*;
import java.io.*;
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello world!");
}
}
#javac HelloWorld.java
#
[root@localhost javaFiles]# ls
HelloWorld.class HelloWorld.java
[root@localhost javaFiles]# java HelloWorld.java
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/java
Caused by: java.lang.ClassNotFoundException: HelloWorld.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
Actually, the problem is having a wrong command, not classpath issue.
It should read
java HelloWorld
without the extension. The "dot" is considered a namespace separator so Java runtime will look for a file HelloWorld/java.class in the current directory and of course it does not exist.