## Java, J2EE, JSP, Servlet, Hibernate Interview Questions
*Click
if you like the project. Pull Request are highly appreciated.*
### Table of Contents
* *[Java 8 Interview Questions](java8-questions.md)*
* *[Multithreading Interview Questions](multithreading-questions.md)*
* *[Collections Interview Questions](collections-questions.md)*
* *[Hibernate Interview Questions](hibernate-questions.md)*
* *[JDBC Interview Questions](JDBC-questions.md)*
* *[Java Programs](java-programs.md)*
* *[Java String Methods](java-string-methods.md)*
* *[JSP Interview Questions](jsp-questions.md)*
* *[Servlets Interview Questions](servlets-questions.md)*
* *[Java Design Pattern Questions](java-design-pattern-questions.md)*
* *[Java Multiple Choice Questions](java-multiple-choice-questions-answers.md)*
## Q. ***What are the types of Exceptions? Explain the hierarchy of Java Exception classes?***
Exception is an error event that can happen during the execution of a program and disrupts its normal flow.
**Types of Java Exceptions**
**1. Checked Exception**: The classes which directly inherit `Throwable class` except RuntimeException and Error are known as checked exceptions e.g. IOException, SQLException etc. Checked exceptions are checked at compile-time.
**2. Unchecked Exception**: The classes which inherit `RuntimeException` are known as unchecked exceptions e.g. ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc. Unchecked exceptions are not checked at compile-time, but they are checked at runtime.
**3. Error**: Error is irrecoverable e.g. OutOfMemoryError, VirtualMachineError, AssertionError etc.
**Hierarchy of Java Exception classes**
The java.lang.Throwable class is the root class of Java Exception hierarchy which is inherited by two subclasses: Exception and Error.
Example:
```java
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public class CustomExceptionExample {
public static void main(String[] args) throws MyException {
try {
processFile("file.txt");
} catch (MyException e) {
processErrorCodes(e);
}
}
private static void processErrorCodes(MyException e) throws MyException {
switch(e.getErrorCode()){
case "BAD_FILE_TYPE":
System.out.println("Bad File Type, notify user");
throw e;
case "FILE_NOT_FOUND_EXCEPTION":
System.out.println("File Not Found, notify user");
throw e;
case "FILE_CLOSE_EXCEPTION":
System.out.println("File Close failed, just log it.");
break;
default:
System.out.println("Unknown exception occured," +e.getMessage());
e.printStackTrace();
}
}
private static void processFile(String file) throws MyException {
InputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
throw new MyException(e.getMessage(),"FILE_NOT_FOUND_EXCEPTION");
} finally {
try {
if(fis !=null) fis.close();
} catch (IOException e) {
throw new MyException(e.getMessage(),"FILE_CLOSE_EXCEPTION");
}
}
}
}
```
**Aggregation**: We call aggregation those relationships whose **objects have an independent lifecycle, but there is ownership**, and child objects cannot belong to another parent object.
Example: Since Organization has Person as employees, the relationship between them is Aggregation. Here is how they look like in terms of Java classes
```java
public class Organization {
private List employees;
}
public class Person {
private String name;
}
```
**Composition**: We use the term composition to refer to relationships whose objects **don’t have an independent lifecycle**, and if the parent object is deleted, all child objects will also be deleted.
Example: Since Engine is-part-of Car, the relationship between them is Composition. Here is how they are implemented between Java classes.
```java
public class Car {
//final will make sure engine is initialized
private final Engine engine;
public Car(){
engine = new Engine();
}
}
class Engine {
private String type;
}
```
| Aggregation | Composition |
|---|---|
| Aggregation is a weak Association. | Composition is a strong Association. |
| Class can exist independently without owner. | Class can not meaningfully exist without owner. |
| Have their own Life Time. | Life Time depends on the Owner. |
| A uses B. | A owns B. |
| Child is not owned by 1 owner. | Child can have only 1 owner. |
| Has-A relationship. A has B. | Part-Of relationship. B is part of A. |
| Denoted by a empty diamond in UML. | Denoted by a filled diamond in UML. |
| We do not use "final" keyword for Aggregation. | "final" keyword is used to represent Composition. |
| Examples: - Car has a Driver. - A Human uses Clothes. - A Company is an aggregation of People. - A Text Editor uses a File. - Mobile has a SIM Card. | Examples: - Engine is a part of Car. - A Human owns the Heart. - A Company is a composition of Accounts. - A Text Editor owns a Buffer. - IMEI Number is a part of a Mobile. |
## Q. ***What is the difference between factory and abstract factory pattern?***
The Factory Method is usually categorised by a switch statement where each case returns a different class, using the same root interface so that the calling code never needs to make decisions about the implementation.
For example credit card validator factory which returns a different validator for each card type.
```java
public ICardValidator GetCardValidator (string cardType)
{
switch (cardType.ToLower())
{
case "visa":
return new VisaCardValidator();
case "mastercard":
case "ecmc":
return new MastercardValidator();
default:
throw new CreditCardTypeException("Do not recognise this type");
}
}
```
Abstract Factory patterns work around a super-factory which creates other factories. This factory is also called as factory of factories. This type of design pattern comes under creational pattern as this pattern provides one of the best ways to create an object.
In Abstract Factory pattern an interface is responsible for creating a factory of related objects without explicitly specifying their classes. Each generated factory can give the objects as per the Factory pattern.
## Q. ***What are the methods used to implement for key Object in HashMap?***
**1. equals()** and **2. hashcode()**
Class inherits methods from the following classes in terms of HashMap
* java.util.AbstractMap
* java.util.Object
* java.util.Map
## Q. ***What is difference between the Inner Class and Sub Class?***
Nested Inner class can access any private instance variable of outer class. Like any other instance variable, we can have access modifier private, protected, public and default modifier.
```java
class Outer {
class Inner {
public void show() {
System.out.println("In a nested class method");
}
}
}
class Main {
public static void main(String[] args) {
Outer.Inner in = new Outer().new Inner();
in.show();
}
}
```
A subclass is class which inherits a method or methods from a superclass.
```java
class Car {
//...
}
class HybridCar extends Car {
//...
}
```
## Q. ***Can we import same package/class two times? Will the JVM load the package twice at runtime?***
We can import the same package or same class multiple times. The JVM will internally load the class only once no matter how many times import the same class.
## Q. ***Distinguish between static loading and dynamic class loading?***
**Static Class Loading**: Creating objects and instance using `new` keyword is known as static class loading. The retrieval of class definition and instantiation of the object is done at compile time.
```java
class TestClass {
public static void main(String args[]) {
TestClass tc = new TestClass();
}
}
```
**Dynamic Class Loading**: Loading classes use `Class.forName()` method. Dynamic class loading is done when the name of the class is not known at compile time.
```java
Class.forName (String className);
```
## Q. ***What is the difference between transient and volatile variable in Java?***
**Transient**: The transient modifier tells the Java object serialization subsystem to exclude the field when serializing an instance of the class. When the object is then deserialized, the field will be initialized to the default value; i.e. null for a reference type, and zero or false for a primitive type.
```java
public transient int limit = 55; // will not persist
public int b; // will persist
```
**Volatile**: The volatile modifier tells the JVM that writes to the field should always be synchronously flushed to memory, and that reads of the field should always read from memory. This means that fields marked as volatile can be safely accessed and updated in a multi-thread application without using native or standard library-based synchronization.
```java
public class MyRunnable implements Runnable {
private volatile boolean active;
public void run() {
active = true;
while (active) {
}
}
public void stop() {
active = false;
}
}
```
## Q. ***How many types of memory areas are allocated by JVM?***
JVM is a program which takes Java bytecode and converts the byte code (line by line) into machine understandable code. JVM perform some particular types of operations:
* Loading of code
* Verification of code
* Executing the code
* It provide run-time environment to the users
**Types of Memory areas allocated by the JVM:**
**1. Classloader**: Classloader is a subsystem of JVM that is used to load class files.
**2. Class(Method) Area**: Class(Method) Area stores per-class structures such as the runtime constant pool, field and method data, the code for methods.
**3. Heap**: It is the runtime data area in which objects are allocated.
**4. Stack**: Java Stack stores frames.It holds local variables and partial results, and plays a part in method invocation and return. Each thread has a private JVM stack, created at the same time as thread.
**5. Program Counter Register**: PC (program counter) register. It contains the address of the Java virtual machine instruction currently being executed.
**6. Native Method Stack**: It contains all the native methods used in the application.
## Q. ***What will be the initial value of an object reference which is defined as an instance variable?***
The object references are all initialized to `null` in Java. However in order to do anything useful with these references, It must set to a valid object, else you will get NullPointerExceptions everywhere you try to use such default initialized references.
## Q. ***How can constructor chaining be done using this keyword?***
Java constructor chaining is a method of calling one constructor with the help of another while considering the present object. It can be done in 2 ways –
* **Within same class**: It can be done using `this()` keyword for constructors in the same class.
* **From base class**: By using `super()` keyword to call a constructor from the base class.
```java
// Java program to illustrate Constructor Chaining
// within same class Using this() keyword
class Temp
{
// default constructor 1
// default constructor will call another constructor
// using this keyword from same class
Temp() {
// calls constructor 2
this(5);
System.out.println("The Default constructor");
}
// parameterized constructor 2
Temp(int x) {
// calls constructor 3
this(10, 20);
System.out.println(x);
}
// parameterized constructor 3
Temp(int x, int y) {
System.out.println(10 + 20);
}
public static void main(String args[]) {
// invokes default constructor first
new Temp();
}
}
```
Ouput:
```
30
10
The Default constructor
```
```java
// Java program to illustrate Constructor Chaining to
// other class using super() keyword
class Base
{
String name;
// constructor 1
Base() {
this("");
System.out.println("No-argument constructor of base class");
}
// constructor 2
Base(String name) {
this.name = name;
System.out.println("Calling parameterized constructor of base");
}
}
class Derived extends Base
{
// constructor 3
Derived() {
System.out.println("No-argument constructor of derived");
}
// parameterized constructor 4
Derived(String name) {
// invokes base class constructor 2
super(name);
System.out.println("Calling parameterized constructor of derived");
}
public static void main(String args[]) {
// calls parameterized constructor 4
Derived obj = new Derived("test");
// Calls No-argument constructor
// Derived obj = new Derived();
}
}
```
Output:
```
Calling parameterized constructor of base
Calling parameterized constructor of derived
```
## Q. ***Can you declare the main method as final?***
Yes. We can declare main method as final. But, In inheritance concept we cannot declare main method as final in parent class. It give compile time error. The main method has to be public because it has to be called by JVM which is outside the scope of the package and hence would need the access specifier-public.
```java
public class Test {
public final static void main(String[] args) throws Exception {
System.out.println("This is Test Class");
}
}
class Child extends Test {
public static void main(String[] args) throws Exception {
System.out.println("This is Child Class");
}
}
```
Output
```
Cannot override the final method from Test.
```
## Q. ***What is the difference between the final method and abstract method?***
Final method is a method that is marked as final, i.e. it cannot be overridden anymore. Just like final class cannot be inherited anymore.
Abstract method, on the other hand, is an empty method that is ought to be overridden by the inherited class. Without overriding, you will quickly get compilation error.
## Q. ***What is the difference between compile-time polymorphism and runtime polymorphism?***
There are two types of polymorphism in java:
1) Static Polymorphism also known as compile time polymorphism
2) Dynamic Polymorphism also known as runtime polymorphism
**Example of static Polymorphism**
Method overloading is one of the way java supports static polymorphism. Here we have two definitions of the same method add() which add method would be called is determined by the parameter list at the compile time. That is the reason this is also known as compile time polymorphism.
```java
class SimpleCalculator
{
int add(int a, int b) {
return a + b;
}
int add(int a, int b, int c) {
return a + b + c;
}
}
public class Demo
{
public static void main(String args[]) {
SimpleCalculator obj = new SimpleCalculator();
System.out.println(obj.add(10, 20));
System.out.println(obj.add(10, 20, 30));
}
}
```
Output:
```
30
60
```
**Runtime Polymorphism (or Dynamic polymorphism)**
It is also known as Dynamic Method Dispatch. Dynamic polymorphism is a process in which a call to an overridden method is resolved at runtime, thats why it is called runtime polymorphism.
```java
class ABC {
public void myMethod() {
System.out.println("Overridden Method");
}
}
public class XYZ extends ABC {
public void myMethod() {
System.out.println("Overriding Method");
}
public static void main(String args[]) {
ABC obj = new XYZ();
obj.myMethod();
}
}
```
Output:
```
Overriding Method
```
## Q. ***Can you achieve Runtime Polymorphism by data members?***
No, we cannot achieve runtime polymorphism by data members. Method is overridden not the data members, so runtime polymorphism can not be achieved by data members.
## Q. ***Can you have virtual functions in Java?***
In Java, all non-static methods are by default **virtual functions**. Only methods marked with the `keyword final`, which cannot be overridden, along with `private methods`, which are not inherited, are non-virtual.
**Virtual function with Interface**
```java
/**
* The function applyBrakes() is virtual because
* functions in interfaces are designed to be overridden.
**/
interface Bicycle {
void applyBrakes();
}
class ACMEBicycle implements Bicycle {
public void applyBrakes(){ //Here we implement applyBrakes()
System.out.println("Brakes applied"); //function
}
}
```
## Q. ***What is covariant return type?***
It is possible to have different return type for a overriding method in child class, but child’s return type should be sub-type of parent’s return type. Overriding method becomes variant with respect to return type. The covariant return type specifies that the return type may vary in the same direction as the subclass.
```java
class SuperClass {
SuperClass get() {
System.out.println("SuperClass");
return this;
}
}
public class Tester extends SuperClass {
Tester get() {
System.out.println("SubClass");
return this;
}
public static void main(String[] args) {
SuperClass tester = new Tester();
tester.get();
}
}
```
Output:
```
Subclass
```
## Q. ***What is the difference between abstraction and encapsulation?***
* Abstraction solves the problem at design level while Encapsulation solves it implementation level.
* In Java, Abstraction is supported using `interface` and `abstract class` while Encapsulation is supported using access modifiers e.g. public, private and protected.
* Abstraction is about hiding unwanted details while giving out most essential details, while Encapsulation means hiding the code and data into a single unit e.g. class or method to protect inner working of an object from outside world.
| Abstraction | Encapsulation |
|---|---|
| Abstraction is a process of hiding the implementation details and showing only functionality to the user. | Encapsulation is a process of wrapping code and data together into a single unit |
| Abstraction lets you focus on what the object does instead of how it does it. | Encapsulation provides you the control over the data and keeping it safe from outside misuse. |
| Abstraction solves the problem in the Design Level. | Encapsulation solves the problem in the Implementation Level. |
| Abstraction is implemented by using Interfaces and Abstract Classes. | Encapsulation is implemented by using Access Modifiers (private, default, protected, public) |
| Abstraction means hiding implementation complexities by using interfaces and abstract class. | Encapsulation means hiding data by using setters and getters. |
System.gc() and Runtime.gc() which is used to send request of Garbage collection to JVM but it’s not guaranteed that garbage collection will happen. If there is no memory space for creating a new object in Heap Java Virtual Machine throws OutOfMemoryError or java.lang.OutOfMemoryError heap space
## Q. ***How to create marker interface?***
An interface with no methods is known as marker or tagged interface. It provides some useful information to JVM/compiler so that JVM/compiler performs some special operations on it. It is used for better readability of code. Example: **Serializable, Clonnable** etc.
Syntax:
```java
public interface Interface_Name {
}
```
Example:
```java
/**
* Java program to illustrate Maker Interface
*
**/
interface Marker { }
class A implements Marker {
//do some task
}
class Main {
public static void main(String[] args) {
A obj = new A();
if (obj instanceOf Marker){
// do some task
}
}
}
```
## Q. ***How serialization works in java?***
Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.
Example:
```java
/**
* Serialization and Deserialization
* example of a Java object
*
**/
import java.io.*;
class Employee implements Serializable {
private static final long serialversionUID =
129348938L;
transient int a;
static int b;
String name;
int age;
// Default constructor
public Employee(String name, int age, int a, int b) {
this.name = name;
this.age = age;
this.a = a;
this.b = b;
}
}
public class SerialExample {
public static void printdata(Employee object1) {
System.out.println("name = " + object1.name);
System.out.println("age = " + object1.age);
System.out.println("a = " + object1.a);
System.out.println("b = " + object1.b);
}
public static void main(String[] args) {
Employee object = new Employee("ab", 20, 2, 1000);
String filename = "shubham.txt";
// Serialization
try {
// Saving of object in a file
FileOutputStream file = new FileOutputStream(filename);
ObjectOutputStream out = new ObjectOutputStream(file);
// Method for serialization of object
out.writeObject(object);
out.close();
file.close();
System.out.println("Object has been serialized\n"
+ "Data before Deserialization.");
printdata(object);
// value of static variable changed
object.b = 2000;
}
catch (IOException ex) {
System.out.println("IOException is caught");
}
object = null;
// Deserialization
try {
// Reading the object from a file
FileInputStream file = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(file);
// Method for deserialization of object
object = (Employee)in.readObject();
in.close();
file.close();
System.out.println("Object has been deserialized\n"
+ "Data after Deserialization.");
printdata(object);
System.out.println("z = " + object1.z);
}
catch (IOException ex) {
System.out.println("IOException is caught");
}
catch (ClassNotFoundException ex) {
System.out.println("ClassNotFoundException is caught");
}
}
}
```
## Q. ***What are the various ways to load a class in Java?***
**a). Creating a reference**:
```java
SomeClass someInstance = null;
```
**b). Using Class.forName(String)**:
```java
Class.forName("SomeClass");
```
**c). Using SystemClassLoader()**:
```java
ClassLoader.getSystemClassLoader().loadClass("SomeClass");
```
**d). Using Overloaded Class.forName()**:
```java
Class.forName(String name, boolean initialize, ClassLoader loader);
```
## Q. ***Java Program to Implement Singly Linked List?***
The singly linked list is a linear data structure in which each element of the list contains a pointer which points to the next element in the list. Each element in the singly linked list is called a node. Each node has two components: data and a pointer next which points to the next node in the list.
Example:
```java
public class SinglyLinkedList {
// Represent a node of the singly linked list
class Node{
int data;
Node next;
public Node(int data) {
this.data = data;
this.next = null;
}
}
// Represent the head and tail of the singly linked list
public Node head = null;
public Node tail = null;
// addNode() will add a new node to the list
public void addNode(int data) {
// Create a new node
Node newNode = new Node(data);
// Checks if the list is empty
if(head == null) {
// If list is empty, both head and tail will point to new node
head = newNode;
tail = newNode;
}
else {
// newNode will be added after tail such that tail's next will point to newNode
tail.next = newNode;
// newNode will become new tail of the list
tail = newNode;
}
}
// display() will display all the nodes present in the list
public void display() {
// Node current will point to head
Node current = head;
if(head == null) {
System.out.println("List is empty");
return;
}
System.out.println("Nodes of singly linked list: ");
while(current != null) {
// Prints each node by incrementing pointer
System.out.print(current.data + " ");
current = current.next;
}
System.out.println();
}
public static void main(String[] args) {
SinglyLinkedList sList = new SinglyLinkedList();
// Add nodes to the list
sList.addNode(10);
sList.addNode(20);
sList.addNode(30);
sList.addNode(40);
// Displays the nodes present in the list
sList.display();
}
}
```
**Output:**
```java
Nodes of singly linked list:
10 20 30 40
```
## Q. ***While overriding a method can you throw another exception or broader exception?***
If a method declares to throw a given exception, the overriding method in a subclass can only declare to throw that exception or its subclass. This is because of polymorphism.
Example:
```java
class A {
public void message() throws IOException {..}
}
class B extends A {
@Override
public void message() throws SocketException {..} // allowed
@Override
public void message() throws SQLException {..} // NOT allowed
public static void main(String args[]) {
A a = new B();
try {
a.message();
} catch (IOException ex) {
// forced to catch this by the compiler
}
}
}
```
## Q. ***What is checked, unchecked exception and errors?***
**1. Checked Exception**:
* These are the classes that extend **Throwable** except **RuntimeException** and **Error**.
* They are also known as compile time exceptions because they are checked at **compile time**, meaning the compiler forces us to either handle them with try/catch or indicate in the function signature that it **throws** them and forcing us to deal with them in the caller.
* They are programmatically recoverable problems which are caused by unexpected conditions outside the control of the code (e.g. database down, file I/O error, wrong input, etc).
* Example: **IOException, SQLException** etc.
```java
import java.io.*;
class Main {
public static void main(String[] args) {
FileReader file = new FileReader("C:\\assets\\file.txt");
BufferedReader fileInput = new BufferedReader(file);
for (int counter = 0; counter < 3; counter++)
System.out.println(fileInput.readLine());
fileInput.close();
}
}
```
output:
```
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code -
unreported exception java.io.FileNotFoundException; must be caught or declared to be
thrown
at Main.main(Main.java:5)
```
After adding IOException
```java
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
FileReader file = new FileReader("C:\\assets\\file.txt");
BufferedReader fileInput = new BufferedReader(file);
for (int counter = 0; counter < 3; counter++)
System.out.println(fileInput.readLine());
fileInput.close();
}
}
```
output:
```java
Output: First three lines of file “C:\assets\file.txt”
```
**2. Unchecked Exception**:
* The classes that extend **RuntimeException** are known as unchecked exceptions.
* Unchecked exceptions are not checked at compile-time, but rather at **runtime**, hence the name.
* They are also programmatically recoverable problems but unlike checked exception they are caused by faults in code flow or configuration.
* Example: **ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException** etc.
```java
class Main {
public static void main(String args[]) {
int x = 0;
int y = 10;
int z = y/x;
}
}
```
Output:
```java
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Main.main(Main.java:5)
Java Result: 1
```
**3. Error**:
**Error** refers to an irrecoverable situation that is not being handled by a **try/catch**.
Example: **OutOfMemoryError, VirtualMachineError, AssertionError** etc.
## Q. ***What is difference between ClassNotFoundException and NoClassDefFoundError?***
`ClassNotFoundException` and `NoClassDefFoundError` occur when a particular class is not found at runtime. However, they occur at different scenarios.
`ClassNotFoundException` is an exception that occurs when you try to load a class at run time using `Class.forName()` or `loadClass()` methods and mentioned classes are not found in the classpath.
`NoClassDefFoundError` is an error that occurs when a particular class is present at compile time, but was missing at run time.
## Q. ***What do we mean by weak reference?***
In Java there are four types of references differentiated on the way by which they are garbage collected.
1. Strong Reference
1. Weak Reference
1. Soft Reference
1. Phantom Reference
**1. Strong Reference**: This is the default type/class of Reference Object. Any object which has an active strong reference are not eligible for garbage collection. The object is garbage collected only when the variable which was strongly referenced points to null.
```java
StrongReferenceClass obj = new StrongReferenceClass();
```
Here `obj` object is strong reference to newly created instance of MyClass, currently obj is active object so can't be garbage collected.
**2. Weak Reference**: A weakly referenced object is cleared by the Garbage Collector when it’s weakly reachable.
Weak reachability means that an object has neither strong nor soft references pointing to it. The object can be reached only by traversing a weak reference. To create such references `java.lang.ref.WeakReference` class is used.
```java
/**
* Java Code to illustrate Weak reference
*
**/
import java.lang.ref.WeakReference;
class WeakReferenceExample {
public void message() {
System.out.println("Weak Reference Example!");
}
}
public class MainClass {
public static void main(String[] args) {
// Strong Reference
WeakReferenceExample obj = new WeakReferenceExample();
obj.message();
// Creating Weak Reference to WeakReferenceExample-type object to which 'obj'
// is also pointing.
WeakReference| Method | Description |
|---|---|
| public final Class getClass() | returns the Class class object of this object. The Class class can further be used to get the metadata of this class. |
| public int hashCode() | returns the hashcode number for this object. |
| public boolean equals(Object obj) | compares the given object to this object. |
| protected Object clone() throws CloneNotSupportedException | creates and returns the exact copy (clone) of this object. |
| public String toString() | returns the string representation of this object. |
| public final void notify() | wakes up single thread, waiting on this object's monitor. |
| public final void notifyAll() | wakes up all the threads, waiting on this object's monitor. |
| public final void wait(long timeout)throws InterruptedException | causes the current thread to wait for the specified milliseconds, until another thread notifies (invokes notify() or notifyAll() method). |
| public final void wait(long timeout,int nanos)throws InterruptedException | causes the current thread to wait for the specified milliseconds and nanoseconds, until another thread notifies (invokes notify() or notifyAll() method). |
| public final void wait()throws InterruptedException | causes the current thread to wait, until another thread notifies (invokes notify() or notifyAll() method). |
| protected void finalize()throws Throwable | is invoked by the garbage collector before object is being garbage collected. |