intjava

  1. What is transient variable?
    Transient variable can't be serialize. For example if avariable is declared as transient in a Serializable class and the class iswritten to an ObjectStream, the value of the variable can't be written tothe stream instead when the class is retrieved from the ObjectStream thevalue of the variable becomes null.
  2. What do you understand by Synchronization?
    Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption.
  3. What is Collection API?
    The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces. Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.Example of interfaces: Collection, Set, List and Map.
  4. Is Iterator a Class or Interface? What is its use?
    Iterator is an interface which is used to step through the elements of a Collection.
  5. What is similarities/difference between an Abstract class and Interface?
    • Differences are as follows:
    • * Interfaces provide a form of multiple inheritance. A class can extend only one other class. * Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc. * A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class. * Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast. Similarities: * Neither Abstract classes or Interface can be instantiated.
  6. How to define an Abstract class?
    A class containing abstract method is called Abstract class. An Abstract class can't be instantiated. Example of Abstract class:abstract class testAbstractClass { protected String myString; public String getMyString() { return myString; } public abstract string anyAbstractFunction();}
  7. How to define an Interface?
    In Java Interface defines the methods but does not implementthem. Interface can include constants. A class that implements theinterfaces is bound to implement all the methods defined in Interface.Emaple of Interface:public interface sampleInterface {public void functionOne();public long CONSTANT_ONE = 1000;}
  8. Explain the user defined
    Exceptions?
    User defined Exceptions are the separate Exception classes defined by the user for specific purposed. An user defined can created by simply sub-classing it to the Exception class. This allows custom exceptions to be generated (using throw) and caught in the same way as normal exceptions.Example:class myCustomException extends Exception { // The class simply has to exist to be an exception}
  9. Explain garbage collection?
    Garbage collection is one of the most important feature of Java. Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. User program cann't directly free the object from memory, instead it is the job of the garbage collector to automatically free the objects that are no longer referenced by a program. Every class inherits finalize() method from java.lang.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists. In Java, it is good idea to explicitly assign null into a variable when no more in use. I Java on calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected.
  10. How you can force the garbage collection?
    Garbage collection automatic process and can't be forced.
Author
vagabond
ID
45640
Card Set
intjava
Description
java interview
Updated