Exercise 3 (for those who already know Java) What is the binding time for each o
ID: 3664902 • Letter: E
Question
Exercise 3 (for those who already know Java) What is the binding time for each of the following in a Java program? State it as precisely as possible (language-def- inition time, language-implementation time, compile time, link time, load time, or Exercises 61 runtime).
Explain how each of the following is bound and why it is bound when it is.
a. The location in memory of a local variable in a method.
b. The location in memory of a non-static field of a class.
c. The meaning of the keyword while.
d. The size in memory of a variable of type int.
e. The bytecode for a class.
f. The definition of the method m that is used when a method call of the form a.m() is executed, where a is a reference to an object.
g. The type of a local variable in a function.
h. The value(s) assigned to a variable.
i. The size in memory of a reference.
Explanation / Answer
Association of method definition to the method call is known as binding
there are 2 types of binding
1.static binding or early binding
2.dynamic binding or late binding
Static Binding: the binding which can be resolved at compile time by compiler is know as static binding. All the static,privat and final methods have alwasys been bonded at compile time. These methods cannot be overridden and will always accessed by object of local class
Dynamic Binding: when compiler is not able to resolve the call/binding at compile time,such binding is known as Dynamic Binding. Overriding is a perfect example of dynamic binding as in overriding both parent and child classes have same method
A.Location in memory of local variable :
Stacks are associated with thread in a one-to-one mapping. Stacks are absolutely not associated with methods and classes.
Method calls and local variables are stored on stack. Objects (containing instance variables) are stored on heap. So the object created using:
new A()
will be stored on heap and show method local variable c will be created stored on stack when you call the method.
B.Location in memory of non-static field of a class
Static fields and methods are added into memory when the class is loaded by a ClassLoader. This is when static blocks are also executed and static fields initialized to a provided or default value.
C.Keyword While
Repeats execution while the condition is true.
Keyword while is the most general loop statemens. It uses the following syntax:
while (expression) statement
statement is executed repeatedly as long as the value of expression remains nonzero
D.memory size of variable type int
size memory of int is 4bytes
E. Bytecode class
Java bytecode is the instruction set of the Java virtual machine. Each bytecode is composed by one, or in some cases two, bytes that represent the instruction (opcode), along with zero or more bytes for passing parameters.
F.reference to object
We can assign value of reference variable to another reference variable.
Reference Variable is used to store the address of the variable.
Assigning Reference will not create distinct copies of Objects.
All reference variables are referring to same Object.
G. Type of local variable in a function:
Local variables are declared in methods, constructors, or blocks.
Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor or block.
Access modifiers cannot be used for local variables.
Local variables are visible only within the declared method, constructor or block.
Local variables are implemented at stack level internally.
There is no default value for local variables so local variables should be declared and an initial value should be assigned before the first use.
H: values assigned to a variable
variable is declared depends on what type of variable it is (non-static, static, local, parameter).
EXAMPLE:
int a;
I.Size in memory of a reference
nowhere specified how much bytes a referece variable
VM(virtual machine) if it is 32bit for 32 in JVM or 64Bit for 64 in JVM(java Virtual machine)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.