package is a folder...
like we say windows\system32\drivers folder structure as windows.system32.drivers
Normally packages are made to make your java classes unique.. Suppose u and me created same file for eg: BugKiller.java
if both are in default package.. ie no package then it will be difficult for differentiate.. So I will put in a folder i.e. package called arpita and u will put inside package called varsha.. So both are unique.. u need to declare package varsha; in ur java class..
doesn't matter about folders in ur filesystem.. it is the base path.. Suppose if ur file is in C:\java\examples\sources\varsha\Bugkiller.java
If ur base path is C:\java\examples\sources then package of BugKiller.java will be varsha. When u going to run tht class u need to be in base path not inside varsha..
u can create long packages.. for eg.. varsha.game.tictactoe.ui
But u need to create folders according to that..
It gives an hierarchy and better understanding of what that class is intent to..
Suppose u want to use BugKiller in another java file.. If it is in same package then u can use it directly.. If it is in different package(even if that package inside BugKiller's package) then u need to import it inorder to use it.. Otherwise it cudn't find that file..
U can import by
import varsha.BugKiller;
or even important all the classed in one package by
import varsha.*;
Note that it only import classes inside varsha not the classes inside the sub packages..
suppose u want to use classes inside varsha.game package and if u have already imported varsha.* then u need to import for varsha.game package also
import varsha.game.*;