Tuesday, January 28, 2020

Java Interview Questions


Image result for java images"

 Differentiate between an Array List and a Vector.

ArrayListVector
An ArrayList is not synchronized.A vector is synchronized.
An ArrayList is fast.A vector is slow as it is thread-safe.
If an element is inserted into an ArrayList, it increases its array size by 50 percent.A vector defaults to doubling the size of its array.
An ArrayList does not define the increment size.A vector defines the increment size.
An ArrayList can only use Iterator for traversing.Except for hash table, a vector is the only other class that uses both Enumeration and Iterator.

 Mention the difference between Iterator and Enumeration.

Iterator Enumeration
Iterator is an interface found in the java.util package.Enumeration is an object that generates elements one at a time.
Uses three methods to interface:
  1. hasNext()
  2. next()
  3. remove()
Uses two methods:
  1. hasMoreElements()
  2. nextElement()
Iterators allow removing elements from the given collection during the iteration with well-defined semantics.It is used for passing through a collection, usually of unknown size.
Iterator method names have been improved.The traversing of elements can only be done once per creation.

 Explain the difference between the inner class and the subclass.

Inner ClassSubclass
An inner class is a class that is nested within another class.A subclass is a class that inherits from another class called the superclass.
It provides the access rights for the class which is nesting it and that can access all variables and methods defined in the outer class.It provides access to all public and protected methods and fields of its superclass.

No comments:

Post a Comment

Which Python course is best for beginners?

Level Up Your Python Prowess: Newbie Ninjas: Don't fret, little grasshoppers! Courses like "Learn Python 3" on Codecade...