Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Import package or class?

 
Vikas Sood
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Friends
Do we need to import a specific class or can we import the whole package .
Comment.
VikasSood
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a habit of specifying the class, and sorting them, but according to the
Sun code conventions document
3.1.2 Package and Import Statements
The first non-comment line of most Java source files is a package statement. After that, import statements can follow. For example:
package java.awt;
import java.awt.peer.CanvasPeer;

it doesn't say you not to import packages, their example does however import a specific class.
also Java Source File Example
package java.blah;
import java.blah.blahdy.BlahBlah;
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My own rule of thumb is this. If I need two classes or less from a specific package, then I import them by class name. If I need more, then I import the package.
M
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic