This week's book giveaway is in the OCAJP forum.We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!

# Basic Question

Anonymous
Ranch Hand
Posts: 18944
Hi,
This is a very basic question that. When u say java SomeFile & say in ur program u imported java.awt.*; or any other packages. Now the question is are all the classes from the imported package loaded into the memory or they are just registered or any thing else.
Bye,
Jiger

Manoj Prithiani
Greenhorn
Posts: 13
Hi Jigar,
All the classes are loaded in memory and their syntaxes checked at compile time. But not the classes within Subpackages

naveen sahu
Ranch Hand
Posts: 48
i think all the classes not loaded

Gregg Dale
Greenhorn
Posts: 7
Actually, the statement
import java.awt.*
is only shorthand. It only tells the compiler that for any instance of a Class MyClass that I call in my code, it may have a fully qualified reference of java.awt.MyClass. It doesn't load any Classes that aren't called for in your code, it merely describes the package(s) in which to look for referenced Classes.
The compiler searches the current package and all "imported" packages to reconcile all Class references in your Code.
[At Java University at Comdex last year the instructor expressed his opinion that "import" had been a poor choice of syntax for that feature.]

Ajith Kallambella
Sheriff
Posts: 5782
'Jiger_ptl',
Welcome to JavaRanch.
May I remind you PROPER NAMES ARE NOW REQUIRED!!
Please Read the JavaRanch naming policy for more details.
Javaranch appreciates your cooperation to comply with the official naming policy.
Ajith

Bosun Bello
Ranch Hand
Posts: 1511
No, none of those classes are loaded into memory. It's basically just telling the compiler that you would like to reference those classes by their short name. The compiler takes care of the mapping, verification, etc.
Bosun
SCJP2

Anonymous
Ranch Hand
Posts: 18944
Hi Friends,
If that is the case then why do saying
java -verbose MyFile
displays the name of all the Classes in the Packages I have imported.
Like
[Loaded sun.java2d.loops.TextRendering from C:\Program Files\JavaSoft\JRE\1.2\li
b\rt.jar]
[Loaded sun.java2d.loops.DrawString from C:\Program Files\JavaSoft\JRE\1.2\lib\r
t.jar]
[Loaded sun.java2d.loops.DrawChars from C:\Program Files\JavaSoft\JRE\1.2\lib\rt
.jar]
[Loaded sun.java2d.loops.DrawBytes from C:\Program Files\JavaSoft\JRE\1.2\lib\rt
.jar]
[Loaded sun.java2d.loops.DrawGlyphVector from C:\Program Files\JavaSoft\JRE\1.2\
lib\rt.jar]
[Loaded sun.java2d.loops.IndexGrayAccelerators from C:\Program Files\JavaSoft\JR
E\1.2\lib\rt.jar]
[Loaded sun.java2d.pipe.AlphaColorPipe from C:\Program Files\JavaSoft\JRE\1.2\li
b\rt.jar]
[Loaded java.awt.Dimension from C:\Program Files\JavaSoft\JRE\1.2\lib\rt.jar]
[Loaded java.awt.geom.Dimension2D from C:\Program Files\JavaSoft\JRE\1.2\lib\rt.
jar]
[Loaded sun.awt.image.BufferedImageGraphics2D from C:\Program Files\JavaSoft\JRE
\1.2\lib\rt.jar]
[Loaded sun.java2d.pipe.ShapeToPolyConverter from C:\Program Files\JavaSoft\JRE\
1.2\lib\rt.jar]
[Loaded sun.java2d.pipe.LineStylePipe from C:\Program Files\JavaSoft\JRE\1.2\lib
\rt.jar]
and many others....
Bye,
Jiger

rchopp
Greenhorn
Posts: 6
Hi,
As my understanding goes..
Those classes that are listed in the verbose mode are the ones used by the JVM internally. Remember that JAVA is a JIT (Just In Time) Compiler. It loads the classes needed when necessary.
Thanks,
Ravi.

subbu smile
Greenhorn
Posts: 2

I think, by writing the full path of a class which we required to import in our programme reduce the compile time.

 Don't get me started about those stupid light bulbs.