What does it exactly mean to have a package statement in the beginning of a java code.
Does it mean :
1> The class file generated after compiling the java file should be in a directory having same name as in the package statement?
Packages are a concept to manage huge projects. Using this related classes are grouped together.
Let us say this is the folder structure you have created for saving your .java files. Also lets say your program(YourProgram.java) has the statement
Now lets say at command prompt we are in the folder src. If you execute,
we are saying using the source file pack2/client/YourProgram.java(because of what is mentioned in the command being executed) store the class file to the location pack2/client(because of the package statement) under the current location(src) AND if the folder structure does not already exist(which is not the case here) create it and then store.So here the class files will be created in src/pack/client itself.
Lets say your source file is not at src/pack/client. It is in src itself and at command prompt we move to src location.
Now if we execute this.
we are saying that from current folder the class files have to be created in pack2/client(through the package statement). But this time pack and client folder will be automatically created and then class files will be stored there.
Now if you want the following structure:
i.e. source files at one place and class files at another place
Navigate to src location from command prompt and execute
javac -d ../classes pack2/client/YourProgram.java
Your source files are already in src/pack2/client and class files will be created in classes/pack2/client.
So according to me package declaration is a way of saying in which folder structure should the class files be stored irrespective of where your source file is.
Hope I have not confused you. I am still not that much into IDEs.