Originally posted by swapnil paranjape:
...now in one file how many packages can be there?
in one package how many public classes can be there?whats the main difference between package and file?
In java "package" is a way of organizing java classes in order to identify each class uniquely. Having said that you can surely think that a "package" is an hierarchy of folders.
A java file named HelloWorld.java sitting in ...com/idreamz/research folder
should have the package declaration as . And the next thing is to compile and run.
For your questions, you can have only one package declaration. Now if you understand package you can have N (many) classes. Now it should be clear to understand the difference between "package" from a "class".
....now in one file how many packages can be there ?
Packages are nothing more than the way we organize files into different directories according to their functionality, usability as well as category they should belong to.
<b>PACKAGES DO NOT REPRESENT ANY SORT OF SOURCE CODE ORGANIZATION.</b>
There can be only a single package declaration in one java source file. This package can successively have more subpackages.
...in one package how many public classes can be there?
There can be any number of public classes in a package. But ur source file can contain only one public class definition. Import statements help us use the classes defined in that particular package.
...whats the main difference between package and file ?
A package is a way to organize ur source files and classes and interfaces. A file is the place where ur source code is implemented.
Hope this clears ur doubts !!