What is Abstract factory? And its use?

  1. Users of an Abstract Factory can create families of related objects without any knowledge of their concrete classes.

2.      Using references to interfaces instead of references to concrete classes is an important way of minimizing ripple effects.

3.      The user of an interface reference is always protected from changes to the underlying implementation.

How we restrict to inherit a class?

By using final keyword

How we call a method without creating the instance of an object?

By using the static keyword

How we create a String instance without using new keyword?

In java, internally for String object’s operator overloading is there for = , + signs

= – it will invoke the new keyword and a parameterized constructor of String

+ – generate a new null StringBuffer class, append the new string, then toString() method will be called

What are all the methods in Object class?

toString(), wait(), notify(), notifyAll(), getClass()

When cloning an object, is it generate a new instance? When creating new instance, we made to change in first one, is it reflect in second one?

It will generate a new instance copy of the cloned object.

When there is made a change in original object, it will not reflect in cloned object.

What is the difference between byte and char data type?

Byte – 8 bits (1 byte), range –128 to 127

Char – 16 bits (2 byte), 0 to 2^15

Does java supports multiple inheritance?

Java does not support multiple inheritance.

What is difference between int and Integer? What is the importance of Integer? Where it is used?

Int – it is a primitive data type, Integer – it is a wrapper class for the int data type

We can’t store primitive data types into Collection, so that we convert it as an Integer object.

Difference between Array and ArrayList?

Array – it is not dynamically incremented, we can store primitive data types, it is homogeneous that means all the elements in the array are same type.

ArrayList – dynamically incremented, in which we can’t store primitive data types, we can store different type of objects.

If we use an ArrayList, how it is made thread safe?

By using List list = Collections.synchronizedList(new ArrayList()) method

What is the methods in Resultset Object?

Next(), first(), last(), previous(), getString(), deleteRow(), close()

What is the Exception hierarchy?

Throwable class is super class for all exceptions.

Exception – checked exception, unchecked exception, Error.

What is serialization?

Through serialization we can save and restore the state of an object.

By implementing serializable interface we can achieve serialization. It is a marker interface. There is no method declaration in it.

What are all the OOP’s concepts? Can you write a program for a+b=c by using those concepts?

OOP’s concepts are Encapsulation, Polymorphism and Inheritance.

Encapsulation: Encapsulation is a mechanism that binds together code and data it manipulates, and keeps both safe from outside interference and misuse.

Inheritance: Inheritance is a process by which one object acquires the properties of another object.

Polymorphism: Polymorphism is a feature that allows one interface to be used for a general class of actions.

interface AddInterface {

int addMeth();

}

abstract class AddAbsClass implements AddInterface {

public abstract int addMeth();

}

class AddConClass extends AddAbsClass {

private int a =1;

private int b=2;

private int c;

public static void main(String args[]) {

AddConClass acc = new AddConClass();

System.out.println(“Answer is : “+acc.addMeth());

}

public int addMeth() {

return c=a+b;

}

}

What is the difference between the String and StringBuffer class ?

String – immutable one. That object can not be changed.

StringBuffer – mutable one.

In java, which class polymorphism is implemented?

String class there is lot of methods are implemented method overloading

IndexOf, lastIndexOf, valueOf

Scenario:

A a1 = new A();

A a2;

a2 = a1;

a1 = new A();

in which second a1 create a new memory or it refers the same one?

There are two different memories are allocated, at last a1 refers the second one, a2 refers the first one.

Advertisements