This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Shortcut notation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Shortcut notation" Watch "Shortcut notation" New topic
Author

Shortcut notation

Charles Angemeyer
Greenhorn

Joined: Dec 18, 2012
Posts: 22
Recently I was experimenting with Bufferedreader and came across a web example that you see below.
(I only included the top part of the code).
My question is this: Wouldn't I want to use some abreviation notation for the import statements?
Wouldn't import.java.io.* be better than listing each out individually? Many thanks.

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7696
    
  20

Charles Angemeyer wrote:My question is this: Wouldn't I want to use some abreviation notation for the import statements?
Wouldn't import.java.io.* be better than listing each out individually?

You certainly can, but I tend not to; and it sounds like you're probably using an IDE, most of which create them as you've shown.

I guess my question to you is: why would you bother? The savings are ONLY at compile time (and even then we're talking milliseconds); it makes absolutely no difference whatsoever to your runtime class.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38467
    
  23
Using individual imports has two advantages.
  • 1: You have a list of classes (etc) used in your application (or at least in the current class).
  • 2: There is less risk of collisions, eg between Timers.
  • Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61092
        
      66

    Campbell Ritchie wrote:Using individual imports has two advantages.
  • 1: You have a list of classes (etc) used in your application (or at least in the current class).
  • 2: There is less risk of collisions, eg between Timers.


  • This. I always list them out individually. My IDE can hide them during editing if they seem to be in the way, but that is rare.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
     
    Don't get me started about those stupid light bulbs.
     
    subject: Shortcut notation