Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"The use of the default package is discouraged." Should I worry?

 
T Dahl
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have installed Eclipse to start my Java developement. My first impression is good.

Whenever I create a new class in Eclipse I get this message: "The use of the default package is discouraged.".

What does the message mean, and should I care? Am I doing something stupid?
 
Jeff Friesen
author
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi T,

The default package is the package where Java classes, interfaces, and other top-level types (such as enums) are stored when the source file in which the type is declared does not contain a package statement, such as package foo;.

Unlike small toy (and throwaway) programs, a large application's top-level types should be stored in packages to organize them and prevent name conflicts with another application's top-level types.

Eclipse is basically warning you that you have not specified a package in which to store your application's top-level types.

All the best.

Jeff
 
T Dahl
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

So, as long as I am toying around, learning and testing I could probably not do much harm if I ignore the warning.

When I develop my real application (which is hopefully not going to be very big) I could risk a name conflict, but only if there are other applications around. I guess these other applications has to import classes from my application before that becomes an issue?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also a class in a package can't access a class that is not in a package i.e. the default package.
 
T Dahl
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote:Also a class in a package can't access a class that is not in a package i.e. the default package.

That makes sense. I should set aside some time to learn how to work properly with packages. Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic