"import" is just an instruction to the compiler. The compiler needs to find other classes so it knows whether your usage of the other classes is legal, but the other classes aren't copied into your .class file. You could import a thousand other packages, and it wouldn't change the size of your .class file by a single byte.
No. No classes are ever included in any other class. Every class is in its own separate file. "import" just tells the compiler where to find other classes so that the compiler can make sure you're passing the right arguments when you call the other class's methods, and so on.
If you use the class, either by subclassing or by instantiation, then the classloader will bring it into your object code from a class file and thus make your runtime code larger.
By the way, it would be easier to understand your posts if you don't use so many abbreviations. They make reading the post sortof like figuring out a whole bunch of personalized license plates at one time.
[ September 29, 2004: Message edited by: Jeff Bosch ] [ September 29, 2004: Message edited by: Jeff Bosch ]
Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Joined: Aug 10, 2004
will the compiler replace that particular 'import' statement with any other reference, which uniqly identify that particular class on interpretation?
Joined: Jul 30, 2003
Probably. Classes are assigned id's. The Java Language Specification on Sun's website has that information, though it's hardly a beginner topic. Just curious -- what are you trying to figure out here? What will you use the information for?
That compiles to *exactly* the same byte code, it is just a shorthand.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Basically, import statements let you abbreviate class names, leaving off the package name. The compiled bytecode will have the full class name, including its package name.
This means your compiled program will include a reference to the class in the limited sense that the compiler uses the CLASSPATH to figure out which package contains the class you want from among your own package and the packages referred to in import statements. It then concatenates the proper package name with the class name you used in your source program and uses the full name in the bytecode.
However, even though the compiler locates a .class file for each class you want and checks that you used that class correctly, it doesn't include the actual location of that .class file in the bytecode, just the fully qualified class name. This means that at execution time your CLASSPATH can be different than at compile time (often on a different machine) and a .class file used at execution time may be different than one you used at compile time. However, if the members of the class found at execution time don't match your source program as to member name and method signature, the jvm wil raise an exception.
This is one reason that many instructors recommend that you start learning Java using the command line interface so you learn to get the CLASSPATHs and directory structure correct and can debug them later. IDE's manage this for you but then you don't learn.