Reputation: 5448
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 :
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
Reputation: 32973
In addition to what others already said some sources of further information for 2) :
Upvotes: 2
Reputation: 62864
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
.
"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
Reputation: 691943
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.
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