Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Which is more efficient? "import java.package.subpackage" or "import java.package.*"

  1. #1
    Member Andrew R's Avatar
    Join Date
    Jul 2013
    Location
    San Pedro Sula, Honduras
    Posts
    58
    My Mood
    Inspired
    Thanks
    11
    Thanked 1 Time in 1 Post

    Question Which is more efficient? "import java.package.subpackage" or "import java.package.*"

    Hello forums!

    How are you doing today, this lovely Sunday morning ? I hope you are doing great. So I've got another questiong for you.

    Which is more efficient in terms of Runtime?

    import java.package.subpackage
    or
    import java.package.*

    Does it make a significant difference at all?


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,104
    Thanks
    169
    Thanked 780 Times in 726 Posts
    Blog Entries
    5

    Default Re: Which is more efficient? "import java.package.subpackage" or "import java.package.*"

    Which is more efficient in terms of Runtime?
    Neither. Imports are used for compilation.

    Does it make a significant difference at all?
    When trying to read someone else's code, especially if it relies on 3rd party libraries, using the explicit syntax is more favorable in my opinion as it makes it easier to to track down API's. Another issue that can arise from the '*' syntax is class name conflicts, which can result in compile time errors. As an example, there is List in both the java.awt and in java.util packages:
    import java.awt.*;
    import java.util.*;
    public class NameConflict{
        public void testConflict(){
            //error with JDK - compiler doesn't know which List to use
            List<String> list = new ArrayList<String>();
        }
    }

  3. The Following 3 Users Say Thank You to copeg For This Useful Post:

    Andrew R (August 18th, 2013), helloworld922 (August 18th, 2013), jps (August 18th, 2013)

Similar Threads

  1. Replies: 2
    Last Post: June 29th, 2013, 03:47 AM
  2. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  3. Replies: 1
    Last Post: August 5th, 2012, 05:01 AM
  4. Replies: 3
    Last Post: December 7th, 2011, 01:03 AM
  5. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM