Thursday, March 12, 2009

What are dynamic class loaders (CoreJava)

Question :What are dynamic class loaders? (CoreJava)
Answer :This is a mechanism of loading classes at runtime. They have following
a. lazyloading - load classes only when they are required. This helps in
memory management.
b. type safety linkate - Dynamic loading of a class should not require
additional run-time checks in order to
guarantee type safety. Adds link-time checks by replacing run-time checks.
They are performed only once.
c. User defined class loaders - Programmers have the control to load
classes in their applications. A user can
define a class loader to load classes from remote location.
d. Multiple namespaces - Class loaders provide separate namespaces for
different software components. For
example an applet running in a browser loads classes from different jar
files. Assume that the classes loaded
from different jar files have same name but they are treated as distinct
types by JVM
Class cla = Class.forName( "com.javagalaxy.util.MyClass" );
MyClass tCla = (MyClass)cla.newInstance( );

No comments: