Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Import statements sequence have any effect?

Tags:

java

import

I have this doubt from long time, When ever I write the class using eclipse, the import statements use to populate automatically.

Does the order of import statements have any effect 1)on the programming execution speed? 2)Any standard coding practice is there for the same.

like image 363
gmhk Avatar asked Aug 17 '10 07:08

gmhk


2 Answers

Import statements have no effect on execution speed at all. They only matter at compile-time. If you fully-qualify every name you use, the generated bytecode will be exactly the same.

As for coding conventions, I typically put all the static imports at the top, in alphabetical order, followed by other imports, in alphabetical order. Eclipse does this automatically, and also allows you to group particular third-party APIs.

By keeping the order consistent, it means you don't get as much to worry about in diffs at code review time.

like image 174
Jon Skeet Avatar answered Oct 13 '22 02:10

Jon Skeet


http://www.javaperformancetuning.com/news/qotm031.shtml

In short: import is only used by the compiler, so it will not affect runtime performance (possibly only compilation time, but usually it's negligible), and as far as I know the order doesn't matter.

like image 37
Andrei Fierbinteanu Avatar answered Oct 13 '22 02:10

Andrei Fierbinteanu