Use of the default package in Eclipse

J

Josh Zenker

I'm relatively new to Java and have been using Eclipse as my IDE.
Would someone please explain why it discourages the use of the default
package? (This is the message that appears when creating a new class
without specifying a package.)

Best Regards,
Josh
 
V

VisionSet

Josh Zenker said:
I'm relatively new to Java and have been using Eclipse as my IDE.
Would someone please explain why it discourages the use of the default
package? (This is the message that appears when creating a new class
without specifying a package.)

Best Regards,
Josh

To make name clashes more unlikely.
To enforce explicit importing again to prevent name clash.
Because the Java spec now forbids it (?).
Because many container framework specs and implementations of, do not
recognise default package classes - eg Tomcat.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Josh said:
I'm relatively new to Java and have been using Eclipse as my IDE.
Would someone please explain why it discourages the use of the default
package?

It is bad structuring of your source code.

And your class is practically impossible to use
from other classes not residing in default package.

Arne
 
P

Patricia Shanahan

VisionSet wrote:
....
Because the Java spec now forbids it (?).

The JLS says "Unnamed packages are provided by the Java platform
principally for convenience when developing small or temporary
applications or when just beginning development."
[http://java.sun.com/docs/books/jls/second_edition/html/packages.doc.html#35029]

They are not prohibited, and do have valid uses. For example, most
example and test code that I post in newsgroups is unnamed package, to
make it as simple as possible to run.

Patricia
 
V

VisionSet

Patricia Shanahan said:
VisionSet wrote:
...
Because the Java spec now forbids it (?).

The JLS says "Unnamed packages are provided by the Java platform
principally for convenience when developing small or temporary
applications or when just beginning development."
[http://java.sun.com/docs/books/jls/second_edition/html/packages.doc.html#35
029]

They are not prohibited, and do have valid uses. For example, most
example and test code that I post in newsgroups is unnamed package, to
make it as simple as possible to run.

Patricia

Ah yes, thought there was a mention.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top