• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can a JVM application leverage types that did not exist when the app was compiled?  RSS feed

 
Mustafa Garhi
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys was reading this article at
http://www.developer.com/java/other/article.php/10936_2248831_1/Java-Class-Loading-The-Basics.htm


"Dynamic linking allows types to be incrementally incorporated into a running JVM. Dynamic extension allows the decision as to which types are loaded into a JVM to be deferred until runtime. This means that an application hosted by the JVM can leverage types that were previously unknown, or perhaps did not even exist, when the application was compiled. Dynamic linking and extension support the notion of runtime assembly of code, a notion of critical importance to server-side containers (e.g. application servers)."

I was just wondering what has the author meant by -
'or perhaps did not even exist, when the application was compiled'??
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means that programs can use classes that didn't (necessarily) exist when the program was compiled: Java can instantiate arbitrary classes at runtime. So, for example, we might write a class that implements an interface. A program that uses that class can be written before that implementation existed.

(Via reflection we don't even need to have an interface implementation or subclass, but that's a different issue, and probably not what they were referring to.)
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static method Class.forName(String className) can
load a newly delivered .class file. Check it out.
Jim ... ...
 
Mustafa Garhi
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm .. Thanks JH n DN ..

In simpler words : you can compile an app or a class that uses another types even when the types actually do not exist.

Be it polymorphism or reflection one would need the actual type at runtime if i am not wrong?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want a type at runtime yes, you'd need the type at runtime.

That seems obvious, though, so I may have misunderstood you.
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You compile using Interface (or super class) references only. These,
of course, must exist when you build the program. Later, you can deliver
the class that implements (or overrides) what was first shipped to give you
the behavior you want. You also must provide the implementing (or child)
class name; with a property file, user entry, etc. Or the class name can
be shipped with the original build.
Jim ... ...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!