[Logo]
Forums Register Login
how does 'import' work
When I want to write a program with StringTokenizer (for example) and write 'import java.util.*;' near the top of my file, is the compiler including *everything* from java.util or does it just choose what has been mentioned in the code?
Gar,

The import statement does not do any "including". It is a (very) convenient way for the compiler to find classes that are required when compiling your class. It also cuts down on a lot of typing. For example, if you choose to not use an import statement for the StringTokenizer class, you would have to qualify the package name of the class every time you use it in your code:

e.g. java.util.StringTokenizer instead of just the class name StringTokenizer.

The '*' in java.util.* means import all classes in the java.util package. Again, the '*' is a wildcard used for convenience. If you were using more than one class from the java.util package, you would have to specify more than one import statement for each class you were using if you chose to not use a wildcard import.

Regards,
JD
[ April 07, 2005: Message edited by: John Dell'Oso ]
With other words, imports don't have any effect on class files, they just make writing java source code more convenient.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Dec 12, 2017 03:57:34.