jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes package and import Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "package and import" Watch "package and import" New topic

package and import

adam Lui
Ranch Hand

Joined: Sep 03, 2007
Posts: 186
which one comes first in declaration in a class?
which one is only allowed with one and only one?
Justin Russo
Ranch Hand

Joined: Oct 21, 2007
Posts: 77
Hi Adam

if both are included "package" has to be the first to be included and then followed by the "import"..

if there is only one class "package" is not required unless you have included your class within a package.

"import" is not required if you are refering to classes defined in java.lang package which is loaded by the JVM classloader before you class is executed.

You Want it.. Get it.......the Right Way...<br /> <br />SCJP 5.0 SCWCD 5.0
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274

import is never required

you may say e.g.

java.util.List myList = new java.util.Vector();

without importing anything.

Imports are only for saving some typing work.

I agree. Here's the link: http://aspose.com/file-tools
subject: package and import
It's not a secret anymore!