*
The moose likes Beginning Java and the fly likes Order of import statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Order of import statements" Watch "Order of import statements" New topic
Author

Order of import statements

Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
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

Joined: Mar 13, 2004
Posts: 1272
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?


Mike Gershman
SCJP 1.4, SCWCD in process
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Order of import statements
 
Similar Threads
Pass by ref- pgm err
import jar in eclipse //
Exclusively Swing
package location
Applet loads very slowly!