aksh1t
aksh1t

Reputation: 5448

Java dynamism clarification

I came across this excerpt, under the term Java Buzzwords while reading a book on Java which I did not understand.

Dynamic

Java programs carry with them susbtantial amounts of run-time type information that is used to verify and resolve accesses to objects at run time. This makes it possible to dynamically link code in a safe and expedient manner. This is crucial to the robustness of the Java environment, in which small fragments of bytecode may be dynamically updated on a running system.

My questions are :

  1. What do the words "run-time type information" mean? I would be grateful if an example is provided.
  2. "small fragments of bytecode may be dynamically updated on a running system." According to my understanding, when we use the javac command, Java code is converted into bytecode, and executed by using the java command. So why/how should the fragments of bytecode be updated on a running system?

Upvotes: 3

Views: 356

Answers (3)

fvu
fvu

Reputation: 32973

In addition to what others already said some sources of further information for 2) :

  1. the Eclipselink page on their usage of weaving
  2. ASM is probably the most popular byte-code manipulation framework.

Upvotes: 2

Konstantin Yovkov
Konstantin Yovkov

Reputation: 62864

  1. The compile-time type of a variable is the type it is declared as, while the runtime type is the type of the actual object the variable points to. Let's say we have the following:

    Object obj = new Integer(1);

    The compile-time type of o is Object, while its runtime type will be Integer.

  2. "small fragments of bytecode may be dynamically updated on a running system."

    This basically means that when debugging some java program, you can make some change and recompile the program and then run it again without the necessity to restart the JVM.

Upvotes: 7

JB Nizet
JB Nizet

Reputation: 691943

  1. The JVM, and Java programs running on the JVM, can get the actual type of an object. In Java, it's impossible to pretend that an object has a given type if it doesn't actually have this type. The JVM will check and detect that, and throw an exception.

  2. When debugging some running code, even remotely, it's possible to modify the source code being run, compile it, and tell the JVM to reload the byte-code without having to stop and restart the program. The Java EE containers, and many frameworks, also generate byte-code at runtime and load it in the running JVM.

Upvotes: 4

Related Questions