aspose file tools*
The moose likes Beginning Java and the fly likes Re: Java Import Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Re: Java Import Statement" Watch "Re: Java Import Statement" New topic
Author

Re: Java Import Statement

Joe Cheung
Ranch Hand

Joined: Oct 18, 2002
Posts: 104
Dear all,

In terms of performance on compilation or run-time, is it strongly recommended that programmers should use import statement for the required classes only like using "import java.util.Map;" rather then using it for the whole package such as "import java.util.*;"? If so, what is the rationale behind?

Thanks!
Joe


Joe
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

It makes absolutely no performance difference at runtime, and no observable difference at compile time. Where it matters is not performance, but in the understandability and maintainability of the code. If you use very specific imports, or so the theory goes, then the person reading your code can very quickly understand where each class that's referred to comes from.

Personally, I find this rationale very weak in these days of powerful IDEs. If you're reading code in an IDE, it can tell you instantly what package any given class belongs to in an instant.

Another slightly more defensible position says that using very specific imports makes it clear what dependencies a class has. Again, tools can tell you this same information, but the imports do give you a good idea, at a glance.


[Jess in Action][AskingGoodQuestions]
Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129
I don't know whether I can rise a question in this thread.

Even If we are using import java.util.*;, the JIT compiler will compile the class that we are required and not all the class in util. Whether it is true?
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

It doesn't have anything to do with JIT. The import statements are just a direction for the compiler to find which class to use. Importing a "whole package" makes no difference in the resulting bytecode than importing a single class.

Creating and Using Packages
Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129
It's a general question: Why we are using JIT compiler. Whether it has been included in JRE? What is the significance of using JIT compiler?
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

Why we are using JIT compiler. Whether it has been included in JRE? What is the significance of using JIT compiler?
The Java HotSpot Virtual Machine, v1.4.1

It's a long read, but you can skip forward to page 4...
[ July 08, 2005: Message edited by: Steve Morrow ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Re: Java Import Statement