difference between "import" with and without wildcard.

Discussion in 'Java' started by Peter Rilling, Mar 25, 2005.

  1. I am new to Java and am wondering what is the difference between using and
    not using a wildcard in the "import" statement. Are there performance
    issues with importing all classes versus just the ones that are used?
    Peter Rilling, Mar 25, 2005
    #1
    1. Advertising

  2. Peter Rilling wrote:
    > I am new to Java and am wondering what is the difference between using and
    > not using a wildcard in the "import" statement. Are there performance
    > issues with importing all classes versus just the ones that are used?
    >
    >


    When you do import javax.swing.* you import *all* classes in the
    javax.swing package. If you import javax.swing.JLabel you only
    import the JLabel class.
    Afaik, the import is only used at compile time, so only a performance
    issue can exist at compile time (if you import a whole load of classes
    it takes longer to check if the class you are using is part of that
    collection). But at runtime this won't make any difference.
    Most of the time it is clearer to import only the classes you plan to
    use so somebody reading you code knows directly what classes will be used.

    hth
    Elie
    Elie De Brauwer, Mar 25, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,059
  2. Grant Robertson

    Wildcard vs. Import

    Grant Robertson, Jun 6, 2007, in forum: XML
    Replies:
    2
    Views:
    373
    Grant Robertson
    Jun 7, 2007
  3. Eric Hanchrow
    Replies:
    1
    Views:
    355
    Arnaud Delobelle
    May 9, 2008
  4. J. Cliff Dyer
    Replies:
    2
    Views:
    322
    Chuckk Hubbard
    May 8, 2008
  5. Replies:
    7
    Views:
    820
Loading...

Share This Page