• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class loading

 
Ranch Hand
Posts: 33
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone please explain me class loading phase in java.also
when class loading starts?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

arunseege paramashivappa wrote:Can anyone please explain me class loading phase in java.also
when class loading starts?


That's too big a topic to cover in a single post. My suggestion: look at this or this.

Winston
 
arunseege paramashivappa
Ranch Hand
Posts: 33
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks winston.But again i will come back with lot of questions...
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch after 1½ years.
 
arunseege paramashivappa
Ranch Hand
Posts: 33
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class loading starts at compile time or runtime.m confused with class loading phase and object creation phase .
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, classes aren't loaded at compile time. The compiler simply turns your Java source code into Java bytecode, to be run at some future time. At that future time, when you run the program, that's when classes are loaded.

You can't create an object of class X until you have loaded class X. Does that answer your question about the phases?
 
Ranch Hand
Posts: 233
1
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

you can find a lot of information here.
Compilation generates only the .class files (bytecodes). The loading starts when we invoke java command, and then an object/instance of java.lang.Class type is created into which the static members of the class that you execute (java ClassName) get memory, and from thereon, the heap memory, the stacks area (where methods exeute) are created depending upon your program logic and thus follows the processing of your coding logic.

Thank you
 
arunseege paramashivappa
Ranch Hand
Posts: 33
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul.thanks rajdeep.So class loading starts whenever we say Animal a = new Animal().
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More precisely, when the JVM first encounters a mention of the Animal class.
 
arunseege paramashivappa
Ranch Hand
Posts: 33
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But when Class Lion extends Class Animal.

when we say java Lion,when superclass get loaded.

Per discussions went earlier class gets loaded when class name encounters.Since Animal is superclass of Lion it has to get loaded ,but when it will be loaded...
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a hint: Assume that the people who designed Java were reasonably competent and knew what they were doing.

Now, you correctly point out that you can't load the Lion class until the Animal class has been loaded. So when you try to load Lion, you need Animal to be loaded. So what will happen?
 
arunseege paramashivappa
Ranch Hand
Posts: 33
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi paul,
what question m asking exactly is, in a class hierarchy when the superclass get loaded?.
In the Lion Animal inheritence tree, when i say,

java Lion

will all the classes(super classes) in the inherence tree get loaded or just Lion class get loaded.



 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You couldn’t get a better hint than what Paul C has already told you. What do you think will happen?
 
arunseege paramashivappa
Ranch Hand
Posts: 33
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I Think all the classes in The inheritence tree gets loaded .after saying Java Lion suppose jvm encounters Lion lion=new Lion() ,constructor chaining starts ,at that time it needs super class already loaded .this is my understanding,please correct me if m wrong.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at the Java Language Specification’s (JLS) version, and I think you will find you are correct

But the JLS is not easy to read.
 
The City calls upon her steadfast protectors. Now for a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic