user485498
user485498

Reputation:

Using Java's default package in Eclipse

In Eclipse, when I start a new Project, I go through the wizard, and when I get to writing my first class for that project I am asked to select a package. Sometimes out of laziness I just choose the default package.

The wizard warns me this is discouraged. Even if I ignore the warnings I never have any problems with the application due to this. Or at least, so far I have never had any problem.

So why does Eclipse want me to create a new package?

Upvotes: 8

Views: 14486

Answers (2)

Makoto
Makoto

Reputation: 106389

Eclipse, and most other IDEs, are geared towards large projects. Hobbyist programming and small-scale assignments can get by in IDEs often, but be aware that the general assumption would be for larger projects - anything between 10 and 5,000+ classes.

There is also a chance that you create a class which has a similar name to something in the Java API - for example:

Ambiguity in instantiating the class (throw new MarshalException();) if both classes exist on the same classpath is a compilation error.

Upvotes: 12

Jason Dunkelberger
Jason Dunkelberger

Reputation: 1252

You actually can't import classes from the default package. I understand it's allowed as a convenience or for very small (one class file) tasks.

Upvotes: 0

Related Questions