• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Order of import statements

 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I use Eclise to build the Java applications.
And using that IDE, we can organize the order of import statments.
Are there some general conventions how we should order that?

I have read Java Code Convention, but there is section that define about that...

Correct me if i am wrong..

daniel
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is clear that all import statements must follow the package statement, if any, and precede the rest of the compilation unit. Other than that, I can't think of a case where the order of import statements within a compilation unit has meaning.

What did you have in mind?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are style preferences but no technical reasons that I know of. The Eclpise IDE has a nice "source/organize imports" feature on the right mouse click. It separates JDK imports and other imports by a blank line, sorts both groups, removes any that are not used and changes * to a list of classes. I figure the Eclipse guys gave it more thought than I care to and just use the default style.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic