Ans) A weak reference is one that does not prevent the referenced object from being garbage collected. You might use them to manage a
HashMap to look up a cache of objects. A weak reference is a reference that does not keep the object it refers to alive. A weak reference is
not counted as a reference in garbage collection. If the object is not referred to elsewhere as well, it will be garbage collected.
Ans) The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread
could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method
sleep() is defined in the class Thread.
4) What will be the output on executing the following code.
public class MyClass {
public static void main (String args[] ) {
int abc[] = new int [5];
System.out.println(abc);
}
}
A Error array not initialized
B 5
C null
D Print some junk characters
Ans) D
It will print some junk characters to the output. Here it will not give any compile time or runtime error because we have declared and
initialized the array properly. Event if we are not assigning a value to the array, it will always initialized to its defaults.
5)What will be the output on executing the following code.
public class MyClass {
public static void main (String args[] ) {
int abc[] = new int [5];
System.out.println(abc[0]);
}
}
A Error array not initialized
B 5
C 0
D Print some junk characters
Ans) C. Here it will not give any compile time or runtime error because we have declared and initialized the array properly. Event if
we are not assigning a value to the array, it will always initialized to its defaults. So the array will be initialized with values zero.
6)What is a marker interface ?
Ans)An interface that contains no methods. Eg: Serializable, Cloneable, SingleThreadModel etc. It is used to just mark java classes that
support certain capability.
We cannot override static methods. We cannot access any object variables inside static method. Also the this reference also not
available in static methods.
Ans)JVM stands for Java Virtual Machine. It is the run time for java programs. All are java programs are running inside this JVM only. It
converts java byte code to OS specific commands. In addition to governing the execution of an application's byte codes, the virtual machine
handles related tasks such as managing the system's memory, providing security against malicious code, and managing multiple threads of
program execution.
10)What is JIT?
Ans)JIT stands for Just In Time compiler. It compiles java byte code to native code.
Disclaimers: No
claims are made about the accuracy of any of the document presented in this site
and no responsibility is taken for any errors. All the links provided in this
site are individual compilation, however no claims are made about the accuracy
and authenticity of the respective contents.