Sorry for posting a lot of questions lately but i still do not get it.
I have a java file, but when i compile it it creates a folder then a it places the class file in it, unlike the normal compilations where the class file and the java file are in the same place.
Another thing, when i compile using the comand promt, it only creates the class file but then when i type java nameoffile it says not class definition found but if i write using the heirarichy of folders that are present when i complie using Jcreator it works althought i do not see the folders..like when i write java nameoffolder.nameoffile
please tell me what is that cause it is quite confusing
note: that program is based on an API and it creats folder with the same names of the folders in the API
example: i wrote package firstname.lastname
then i should type java firstname.lastname.nameoffile to run!!!
Here's a short tutorial on the topic. See if it answers any of your questions, too.
So if you add "package firstname.lastname;" at the top of your source file, the source and class files must be in a directory named "...\firstname\lastname".
Suppose your base directory is C:\MyProject, then your source file must be in the directory C:\MyProject\firstname\lastname. You compile and run it from the base directory:
C:\MyProject> javac firstname\lastname\MyClass.java
C:\MyProject> java firstname.lastname.MyClass
See this page in The Java Tutorial: Managing Source and Class Files
Each directory listed in the class path is a top-level directory in which package directories appear. From the top-level directory, the compiler and the JVM can construct the rest of the path based on the package and the class name for the class. For example, the class path entry for the directory structure shown in the previous figure would include classes but not com or any of the directories below com. Both the compiler and the JVM construct the path name to a .class file with its full package name.
I do not understant it .
and yes the source has a package as it starts
The directory path you give the compiler must match the package:
That should create firstname\lastname\MyClass.class. When you run it, give the package name, which must match the directory path
See how that all works. BTW: That's all in the tutorial linked above.
You don't need to set the classpath. See my comments and the comments of others above. It's not difficult, you just have to be careful to make sure that you run the correct commands from the correct directory.