Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
1  
You should be running javac Code.java and then java Code. –  i08in Apr 3 at 15:34

1 Answer 1

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.