Translate

Wednesday, January 2, 2013

Core Java Interview Question Part-7


Q) Class

            Class encapsulate the run-time state of an object or interface. Methods in this class are

static Class forName(String name) throws ClassNotFoundException
getClass()
getClassLoader()
getConstructor()
getField()
getDeclaredFields()
getMethods()
getDeclearedMethods()
getInterface()
getSuperClass()

Q) java.jlang.Reflect (package)

            Reflection is the ability of software to analyse it self, to obtain information about the field, constructor, methods & modifier of class. You need this information to build software tools that enables you to work with java beans components.

Q) InstanceOf

            Instanceof means by which your program can obtain run time type information about an object.
Ex:- A a = new A();
       a.instanceOf A;
 
Q) Java pass arguments by value are by reference?
A) By value
 
Q) Java lack pointers how do I implements classic pointer structures like linked list?
A) Using object reference.
 
Q) java. Exe

Micro soft provided sdk for java, which includes “jexegentool”. This converts class file into a “.Exec”  form. Only disadvantage is user needs a M.S java V.M installed.

Q) Bin & Lib in jdk?

Bin contains all tools such as javac, appletviewer and awt tool.
Lib contains API and all packages.


  
Collections Frame Work


Q)        
Collection classes
Collection Interfaces
Legacy classes
Legacy interface
Abstract collection
Collection
Dictionary
Enumerator
Abstract List
List
Hash Table

Abstract Set
Set
Stack

Array List
Sorted Set
Vector

Linked List
Map
Properties

Hash set
Iterator


Tree Set



Hash Map



Tree Map



Abstract Sequential List



           
Collection Classes

      Abstract collection à Implements most of the collection interfaces.
     
      Abstract List à Extends Abstract collection & Implements List Interface. A.L allow “random access”.

Methods>> void add (int index, Object element), boolean add(Object o), boolean addAll(Collection c), boolean addAll(int index, Collection c), Object remove(int index), void clear(), Iterator iterator().

      Abstract Set à Extends Abstract collection & Implements Set interface.

Array List à Array List extends AbstractList and implements the List interface. ArrayList is a variable length    of array of object references, ArrayList support dynamic array that grow as needed. A.L allow rapid random access to element but slow for insertion and deletion from the middle of the list. It will allow duplicate elements. Searching is very faster.
A.L internal node traversal from the start to the end of the collection is significantly faster than Linked List traversal.
      à A.L is a replacement for Vector.
     
Methods>>void add (int index, Object element), boolean add(Object o), boolean addAll(Collection c), boolean addAll(int index, Collection c), Object remove(int index), void clear(), object get(int index), int indexOf(Object element),  int latIndexOf(Object element), int size(), Object [] toArray(). 

Linked List à Extends AbstactSequentialList and implements List interface. L.L provide optimal sequence access, in expensive insertion and deletion from the middle of the list, relatively slow for random access. When ever there is a lot of insertion & deletion we have to go for L.L. L.L is accessed via a reference to the first node of the list. Each subsequent node is accessed via a reference to the first node of the list. Each subsequent node is accessed via the link-reference number stored in the previous node.
     
Methods>> void addFirst(Object obj), addLast(Object obj), Object getFirst(), Object getLast(),void add (int index, Object element), boolean add(Object o), boolean addAll(Collection c), boolean addAll(int index, Collection c), Object remove(int index), Object remove(Object o), void clear(), object get(int index), int indexOf(Object element), int latIndexOf(Object element), int size(), Object [] toArray(). 

Hash Set à Extends AbstractSet & Implements Set interface, it creates a collection that uses HashTable for storage, H.S does not guarantee the order of its elements, if u need storage go for TreeSet. It will not allow duplicate elements
     
      Methods>>boolean add(Object o), Iterator iterator(), boolean remove(Object o), int size().

Tree Set à Extends Abstract Set & Implements Set interface. Objects are stored in sorted, ascending order. Access and retrial times are quite fast. It will not allow duplicate elements
     
Methods>> boolean add(Object o), boolean addAll(Collection c), Object first(), Object last(), Iterator iterator(), boolean remove(Object o).

Hash Map à Extends Abstract Map and implements Map interface. H.M does not guarantee the order of elements, so the order in which the elements are added to a H.M is not necessary the order in which they are ready by the iterate. H.M permits only one null values in it while H.T does not
     
      à HashMap is similar to Hashtable.
     
Tree Map à implements Map interface, a TreeMap provides an efficient means of storing key/value pairs in sorted order and allow rapid retrieval.
    
      Abstract Sequential List à Extends Abstract collection; use sequential access of its elements.

No comments: