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.

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.

Thank you John very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.