Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default Package

 
Jay Kay
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Packages are not garbage collected. Objects are garbage collected.
 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jay Kay
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome. Thanks guys.
-Jay
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic