aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Default Package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Default Package" Watch "Default Package" New topic
Author

Default Package

Jay Kay
Ranch Hand

Joined: May 17, 2001
Posts: 58
If a package name is not specified for the class, the class
will be placed in a "default" package.
Where does this default package reside and what does it contain?
Is it garbage collected?

Any help is greatly appreciated.
Thank you.
-Jay
Yin Ming
Ranch Hand

Joined: Oct 12, 2001
Posts: 41
no its just a package like the others. if u dont put a package definition in a code, the classes in this file will be thrown into the default package. this package contains all classes like this.so classes which are not specified with a package are treated as in same package, the default package.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9052
    
  12
Packages are not garbage collected. Objects are garbage collected.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
Originally posted by Jay Kay:
If a package name is not specified for the class, the class
will be placed in a "default" package.
Where does this default package reside and what does it contain?
Is it garbage collected?
Any help is greatly appreciated.
Thank you.
-Jay

Hi Jay
Great boss has given answer for garbage collection.. so no more words after that..
The default package is your directory where you are placing your class file.
So what is the need of package??
If I want to use your class then I have place my .java file in the same folder where is your class file else i won't be able to use that class. And also if i want to run your file then again i have to go to your directory where u have placed class file.
package is a way to arrange your classes, to make easier access and to avoid name collision, as directory structure is to arrange your files. (when i was novice then i used to think what is the use of CD, MKDIR (dos commands), why to make directory? now on my disk by the directory name i can tell which files willbe there. so it takes time... to understand proper use of some good things)
CMIW
------------------
Regards
Ravish


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
You could consider that there is default package in each directory in which a Java application is launched. This package contains all the Java classes that reside in this directory and their sources has no package sentence.
In each directory also a named package could exist.
Please use the default package only for litle programs that you are not going to distribute or testing litle programs.
Please never tries to mix both types of packages, though possible it is of no use at all.
Remember that Sun encourages us to use named packages for any real program.


SCJP2. Please Indent your code using UBB Code
Jay Kay
Ranch Hand

Joined: May 17, 2001
Posts: 58
Awesome. Thanks guys.
-Jay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Default Package