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 7 of 7

Thread: import question

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default import question

    I see you can import in 2 ways:

    import java.util.*;

    or

    import java.util.Scanner/Random/etc;

    if I used the first one it imports all the librarys within that (directory?). If so would that add to a bigger file size?

    - Nicky


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,318
    Thanks
    53
    Thanked 2,392 Times in 2,346 Posts

    Default Re: import question

    would that add to a bigger file size?
    No. I think of the import statement as an extension of the classpath. It tells the compiler where to look for class definitions. It does not cause more class files to be included in your class file.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: import question

    Quote Originally Posted by Norm View Post
    No. I think of the import statement as an extension of the classpath. It tells the compiler where to look for class definitions. It does not cause more class files to be included in your class file.
    Better question then: why does Java bother with importing and not integrate it in already?

    - Nicky

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,318
    Thanks
    53
    Thanked 2,392 Times in 2,346 Posts

    Default Re: import question

    To allow the user to select which classes are to be used.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    73
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: import question


  6. #6
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: import question

    Just personal preference here, but I find importing only the classes you need
    is more logical than importing the entire library. For example, most console based
    Java applications will at a minimum have about two imports depending on what is going on.

    Swing and AWT development is different, and in those situations, unless the programmer is
    learning each class individually, then it does make sense to import the whole library.

    Just my two cents

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  7. #7
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    73
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: import question

    My preference has everything to do with the IDE I am, or am not using. Eclipse, Netbeans, etc. can maintain and primp the imports list to any degree. Why not let them handle this grunt work?

    If I'm hacking a little thing in a text editor, I'm going to boilerplate all the java.lang.*; and what-have-you as early as possible and leave it that way.

Similar Threads

  1. import TerminalIO.KeyboardReader ; to import java.util.*;
    By qwqw in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 13th, 2014, 08:22 AM
  2. I have a question about import statements
    By syedk01 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: August 27th, 2013, 07:47 AM
  3. Import if Import is Found, Else
    By blazedGinger in forum Java Theory & Questions
    Replies: 5
    Last Post: March 9th, 2013, 05:43 PM
  4. "The import ___ cannot be resolved" (stupid noob question)
    By RobG in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 18th, 2010, 02:09 PM
  5. import question
    By bardd in forum Java Theory & Questions
    Replies: 1
    Last Post: November 20th, 2010, 08:27 AM