Reputation:
I am a beginner in Java but not in OOP I have some experience in C and C++ and PHP5 For short I have "hello world" program for test
package com.tutorial.helloworld;
public class helloWorld {
public static void main(String[] args) {
System.out.print("hello world!!!\n");
}
}
When I compile in console with javac compile with no error but when I run Java helloWorld says
Exception in thread "main" java.lang.NoClassDefFoundError: helloWorld (wrong name:
com/tutorial/helloworld/helloWorld) and much more code
In eclipse run ok. If I delete package statement and compile manually will run ok. but if I keep package statement throws that error. should I put the class file in a subdirectory com/tutorial/helloworld and is that ok how should I run from terminal and from what directory?
I am on mac os x and I am use to type code in edit and compile and run from console than run in a ice. I cannot make eclipse to work for c++ (c++ ide)and because of that I try to stick on the console with all languages I know or I learn.
Upvotes: 0
Views: 444
Reputation: 200168
In Java the class name consists of package name + the class's "first name". Therefore write
java com.tutorial.helloworld.helloWorld
You must also know where your .class
files are. You must be in the directory containing the com
directory for this to work, where the .class
file finds itself inside com/tutorial/helloworld
directory.
Upvotes: 2