Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How java programs work

 
Momen Travolta
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Jonas Isberg
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jesper for correcting my confused terminology.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic