You not login as Registered User...
basic concept of java

Ques-1-> What is the difference between an Abstract class and Interface?

Ans-> If a class implements an interface then it has to provide public definition of all interface methods otherwise the class is declared as abstract.

  • classes support 0 – 100% abstraction. Interfaces support 100% abstraction.
  • An abstract class can have nonabstract methods. An interface is a collection of implicit abstract methods.
  • An abstract class can have instance variables. An interface cannot have instance variables.
  • An abstract class can define constructor. An interface cannot define constructor.
  • An abstract class can have any visibility: public, protected, private or none (package). An interface's visibility must be public or none (package).
  • An abstract class inherits from Object and includes methods such as clone () and equals ().

Ques-2-> What are checked and unchecked exceptions?

Ans-> Checked Exception are those exceptions which are forced by the compiler either to be properly caught or declared to be thrown.

  • Unchecked exceptions are those exceptions which are not forced by the compiler either to be properly caught or declared to be thrown.
  • Checked exceptions: Exceptions that inherit from the Exception class are checked exceptions and it programmatically handled. Examples - SQLException, IOxception.
  • Unchecked exceptions: RuntimeException also extends from Exception, but which cannot be programmatically handled. Example Unchecked exceptions are NullPointerException, OutOfMemoryError, DivideByZeroException typically, programming errors.

Ques-3-> What is serialization?

Serialization is the process of converting the state of an object into a sequence of bytes in such a manner that given this sequence of bytes object with the same state can be reconstructed at a later stage.

  • ObjectOutputStream
  • ObjectInputStream

These classes are used to serialize & deserialize the objects.

writeObject() method of ObjectOutputStream is used for serializing objects.

public void writeObject(Object o) throws NotSerilizableException;

NOTE: Facility of serialization is not provided to objects of all classes by default.

In order to serialize objects of a class, class must implement java.io.Serializable interface. This is a marker interface.

A marker interface is an interface that doesn’t contain any methods.

Example

interface Serializable { }

Marker interfaces are used to mark a class as part of a group so that some additional service can be provided to the classes of this group.

Facility of serializable is not provided by default to objects of all classes because state of all objects must not be serialized.

State of objects can be of two types-

  • Application Specific.
  • System/JRE Specific.

Ques-4-> Why there are some null interfaces in java? What does it mean? Give me some null interfaces in JAVA?

Ans-> Null interfaces act as markers. They just tell the compiler that the objects of this class need to be treated differently. Some marker interfaces are: Serializable, Remote, Cloneable.

A marker interface is an interface that doesn’t contain any methods.

Example

interface Serializable { }

Ques-5-> Is synchronized a modifier? Identifier? What is it?

Ans-> It's a modifier. Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class.

Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

Ques-6-> What is singleton class? Where is it used?

Ans-> Singleton is a design pattern meant to provide one and only one instance of an object. Other objects can get a reference to this instance through a static method (class constructor is kept private).

Why do we need one? Sometimes it is necessary, and often sufficient, to create a single instance of a given class. This has advantages in memory management, and for Java, in garbage collection.

Moreover, restricting the number of instances may be necessary or desirable for technological or business reasons-for example, we may only want a single instance of a pool of database connections.

Ques-7-> is strings a wrapper class?

String is a class, but not a wrapper class. Wrapper classes like (Integer) exist for each primitive type. They can be used to convert a primitive data value into an object, and vice versa.

© 2014   Powered By ITSWS Pvt. Ltd.. All Rights Reserved.