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!!!
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
Joined: Aug 02, 2005
Originally posted by Stan James: tell us if your classes have package statements at the top. Thanks!!
yes it has a package "package firstname.lastname"
Joined: Jan 29, 2003
Let's say your source is here:
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.
Joined: Aug 02, 2005
i found a simple way without setting the class path add the jar to both C:\Program Files\Java\jre1.5.0_07\lib\ext and C:\Program Files\Java\jdk1.5.0_07\jre\lib\ext
OK, that works, but it's a bad idea. If you do that, your classes will be in the classpath for every single Java application that you run.
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.