• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Re: Java Import Statement

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic