# running java program question

**URL:** <https://community.unix.com/t/running-java-program-question/237382>\
**Category:** Linux\
**Created:** [April 9, 2009, 4:18pm UTC](https://community.unix.com/t/running-java-program-question/237382 "2009-04-09T16:18:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![k2k](https://community.unix.com/letter_avatar/k2k/32/6_449c533f586939b6e5f246632a46421f.png) [@k2k](https://community.unix.com/u/k2k)\
**Post date:** [April 9, 2009, 4:18pm UTC](https://community.unix.com/t/running-java-program-question/237382/1 "2009-04-09T16:18:48Z")

</div>

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:

```nohighlight
[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.

Edit: Added code tags. Please use them.

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [April 9, 2009, 4:22pm UTC](https://community.unix.com/t/running-java-program-question/237382/2 "2009-04-09T16:22:57Z")

</div>

Looks like you need to set your Java environment variables correctly, for example Jave CLASSPATH.

See this reference:

[Classpath (Java) - Wikipedia, the free encyclopedia](http://en.wikipedia.org/wiki/Classpath_(Java))

---

<div class="post-metadata">

**Author:** ![k2k](https://community.unix.com/letter_avatar/k2k/32/6_449c533f586939b6e5f246632a46421f.png) [@k2k](https://community.unix.com/u/k2k)\
**Post date:** [April 9, 2009, 4:48pm UTC](https://community.unix.com/t/running-java-program-question/237382/3 "2009-04-09T16:48:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [April 9, 2009, 4:54pm UTC](https://community.unix.com/t/running-java-program-question/237382/4 "2009-04-09T16:54:39Z")

</div>

You have to set CLASSPATH to the home directory of your Java installation.

---

<div class="post-metadata">

**Author:** ![cbkihong](https://community.unix.com/letter_avatar/cbkihong/32/6_449c533f586939b6e5f246632a46421f.png) [@cbkihong](https://community.unix.com/u/cbkihong)\
**Post date:** [April 13, 2009, 10:41pm UTC](https://community.unix.com/t/running-java-program-question/237382/5 "2009-04-13T22:41:00Z")

</div>

```nohighlight
[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

```nohighlight
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.
