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!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic Question

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Any comments.
Bye,
Jiger
 
Manoj Prithiani
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think all the classes not loaded
 
Gregg Dale
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
Any answer.
Bye,
Jiger
 
rchopp
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic