wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How long is a class loaded for? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How long is a class loaded for?" Watch "How long is a class loaded for?" New topic

How long is a class loaded for?

Richard Hayward
Ranch Hand

Joined: Feb 15, 2012
Posts: 68
Suppose this code:

>java StaticScopeTest

Is there an absolute guarantee that the jvm will not need so much ram during the execution of whatever complicated stuff happens at line 10, it decides to unload MyClass, and consequently, when line 11 is reached, MyClass.x is back to zero?

meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

When you run your program thru command >java StaticScopeTest , Classloader loads this class in memory, and it will be there till it's execution.

My one regret in life is that I am not someone else.
- Woody Allen
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41119
The only way for a class to get unloaded (i.e., GCed) is if its classloader gets unloaded. In this particular case -where the only classloaders involved are the ones the JVM creates for running the app- there is no possibility of the class getting unloaded before the JVM exits.

In general, you never need to worry about classes getting unloaded unless you're using code whose very point is to do just that - like OSGi environments. For the purposes of the exam, there's nothing to worry about.

Ping & DNS - my free Android networking tools app
Richard Hayward
Ranch Hand

Joined: Feb 15, 2012
Posts: 68
Thanks for the clarification guys.

I agree. Here's the link: http://aspose.com/file-tools
subject: How long is a class loaded for?
Similar Threads
access modifiers
basic Q.
Exception declaration not seen
Constructors and colours
Number of instances