This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android 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: 7549
    
  18

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: 38033
    
  22
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: 60785
        
      65

    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
     
    Similar Threads
    Input from keyboard
    converting a postfix to an infix
    Why can't my class see another class?
    Valid code, but what does it mean?
    ARGH! Package problem while using *