aspose file tools*
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
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: 14111
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How java programs work