This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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?

boolean b = true;<br />System.out.println ("I believe in Java.<br />Java will make my dream come " + b);
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:
subject: package and import
Similar Threads
Bollywood Quiz
Doubt in Garbage Collection...........
Stars program help
Mandrake 10.1 / Fedora / Suse
Application Server vs JUnit Performance Issue