This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
master stewards:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
garden masters:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
gardeners:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Default Package

 
pioneer
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
 
pioneer
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.
 
master steward
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Packages are not garbage collected. Objects are garbage collected.
 
pioneer
Posts: 5390
1
Spring Java
  • 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
 
pioneer
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
pioneer
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome. Thanks guys.
-Jay
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!