Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Java class loading

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

when does actually java class loading happens. If i have a ear file with 1000 classes all these classes loaded into JVM while deploying to app server (i.e Jboss) or server start?

if classes loaded where does all loaded classes get stored in JVM ? how it will be in case of dynamic class loading ( using reflection)

Appreciate your inputs
 
Marshal
Posts: 27372
88
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
In general, classes are loaded the first time other code tries to use them. That's called "lazy loading" and it's the normal way for Java to do things. It's possible that there might be special circumstances under which a customized class-loader loads classes before they are actually used (that's called "eager loading") but I'm not familiar with any such circumstances. And as for reflection, it works the normal way, i.e. if your reflection-based code asks to load a class, then it will load that class if it hasn't already been loaded. I find it difficult to comprehend how you could write a JVM to load a class early on the grounds that it might be used later by reflection-based code.

As for where loaded classes are stored, um... They are stored in memory like anything else. I'm not sure what you were trying to ask there.
 
Marshal
Posts: 76464
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some classes are probably always loaded. For example the String class is always needed because its name is mentioned in the main method, so it may be loaded eagerly when the JVM starts.

But there is no need for anybody to know such information, unless they are designing VMs.
 
She'll be back. I'm just gonna wait here. With this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic