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
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.
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
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.would that add to a bigger file size?
If you don't understand my answer, don't ignore it, ask a 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.
Good ref: Java: Packages and Import
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)
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.