Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried to compile some code written in Java and I used the command:

javac Code.java
java Code.java

and I got following errors:

Exception in thread "main" java.lang.NoClassDefFoundError: Code/java
Caused by: java.lang.ClassNotFoundException: Code.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)
Could not find the main class: Code.java. Program will exit.

I would be thankful for your advice.

share|improve this question
2  
You should be running javac Code.java and then java Code. – i08in Apr 3 '14 at 15:34
up vote 2 down vote accepted

The correct way of compiling java code in your case is

javac Code.java

and then run using

java Code
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.