Monday 23 October 2017

JAVA Interview Questions Page4

The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this Encapsulation gives maintainability, flexibility and extensibility to our code.
An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
It includes −
  • Interface cannot be instantiated
  • An interface does not contain any constructors.
  • All of the methods in an interface are abstract.
A Package can be defined as a grouping of related types(classes, interfaces, enumerations and annotations ) providing access protection and name space management.
Packages are used in Java in-order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations, etc., easier.
A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is called a thread, and each thread defines a separate path of execution.
Thread can be created by: implementing Runnable interface, extending the Thread class.
An applet is a Java program that runs in a Web browser. An applet can be a fully functional Java application because it has the entire Java API at its disposal.
An applet extends java.applet.Applet class.
It uses garbage collection to free the memory. By cleaning those objects that is no longer reference by any of the program.
An immutable object can’t be changed once it is created.
It is used with variables or methods and used to call constructer of same class.
It is a collection of element which cannot contain duplicate elements. The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are prohibited.
It is a Set implemented when we want elements in a sorted order.
It is used to sort collections and arrays of objects using the collections.sort() and java.utils. The objects of the class implementing the Comparable interface can be ordered.
It includes:
  • Throw is used to trigger an exception where as throws is used in declaration of exception.
  • Without throws, Checked exception cannot be handled where as checked exception can be propagated with throws.

No comments:

Post a Comment