This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How java programs work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How java programs work" Watch "How java programs work" New topic
Author

How java programs work

Momen Travolta
Greenhorn

Joined: Mar 19, 2010
Posts: 8
Just few questions about how Java programs work:-

1)Are classes loaded to memory even if they are not instantiated yet? (I think yes)
2)When are classes loaded? on demand? or once the app. is executed?
3)I think contructors are for constructing new objects, while classes are loaded to memory without the need for constructors (even implicit constructors.) Is that correct?
Jonas Isberg
Ranch Hand

Joined: Mar 18, 2003
Posts: 118
1)Are classes loaded to memory even if they are not instantiated yet? (I think yes)
2)When are classes loaded? on demand? or once the app. is executed?

I would say/guess that the classes are loaded at the latest when they are needed
by the virtual machine at runtime/execution. (You can use a class that is never instantiated,
e.g. static methods.)
3)I think contructors are for constructing new objects, while classes are loaded to memory without the need for constructors (even implicit constructors.) Is that correct?

Constructors are used when creating objects from classes.
I believe classes can have static construcors initializers that run when the
class is loaded.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Jonas Isberg wrote:I believe classes can have static construcors that run when the class is loaded.

A class can have a static initializer (it's not called a "static constructor") that's run when the class is loaded and initialized:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jonas Isberg
Ranch Hand

Joined: Mar 18, 2003
Posts: 118
Thanks Jesper for correcting my confused terminology.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How java programs work
 
Similar Threads
jconsole
How many Java Classes can be loaded
Why make process size so huge on WindowsXP?
Basic Question
Possible to spin off independant JVM?