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.

9 Years
Discussion Span
Last Post by k2k

Try java HelloWorld . The .class file is the actual bytecode which java executes, but the java program requires you give the filename without the extension.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.