Interview Questions
Interview Questions
Interview Questions
1.
Basic Questions
2.
3.
4.
5.
6.
7.
8.
Basic Questions
Q) Is Java platform independent?
Yes. Java is a platform independent language. We can write java code on one
platform and run it on another platform. For e.g. we can write and compile the code
on windows and can run it on Linux or any other supported platform. This is one of
the main features of java.
Q) What all memory areas are allocated by JVM?
Heap, Stack, Program Counter Register and Native Method Stack
Q) Java vs. C ++?
The following features of java make it different from the C++:
Simple
Multi-threaded
Distributed Application
Robust
Security
Q) What is javac ?
It produces the java byte code from *.java file. It is the intermediate representation
of your source code that contains instructions.
Q) What is class?
Class is nothing but a template that describes the data and behavior associated with
instances of that class
Q) What is the base class of all classes?
java.lang.Object
byte 8 bit (are esp. useful when working with a stream of data from a
network or a file).
short 16 bit
Note: Any time you have an integer expression involving bytes, shorts, ints and literal
numbers, the entire expression is promoted to int before the calculation is done.
Q) What is Unicode?
Java uses Unicode to represent the characters. Unicode defines a fully international
character set that can represent all of the characters found in human languages.
Q) What are Literals?
A literal is a value that may be assigned to a primitive or string variable or passed as
an argument to a method.
Q) Dynamic Initialization?
Java allows variables to be initialized dynamically, using any expression valid at the
time the variable is declared.
Q) What is Type casting in Java?
To create a conversion between two incompatible types, we must use a cast. There
are two types of casting in java: automatic casting (done automatically) and explicit
casting (done by programmer).
Q) Arrays?
An array is a group of fixed number of same type values. Read more about Arrays
here.
Q) What is BREAK statement in java?
It is also referred as terminator. In Java, the break statement can be used in following
two cases:
Object class
Math class
String class
Thread classes
Exception classes
Process classes
Class classes
Inheritance
Polymorphism
Data Encapsulation
Abstraction
Q) What is inheritance?
The process by which one class acquires the properties and functionalities of another
class. Inheritance brings reusability of code in a java application.Read more here.
Q) Does Java support Multiple Inheritances?
When a class extends more than one classes then it is called multiple inheritance.
Java doesnt support multiple inheritance whereas C++ supports it, this is one of the
difference between java and C++. Refer this: Why java doesnt support multiple
inheritance?
Q) What is Polymorphism and what are the types of it?
Polymorphism is the ability of an object to take many forms. The most common use of
polymorphism in OOPs is to have more than one method with the same name in a
single class. There are two types of polymorphism: static polymorphism and dynamic
polymorphism, read them in detail here.
Q) What is the method overriding?
It is a feature using which a child class overrides the method of parent class. It is only
applicable when the method in child class has the signature same as parent class.
Read more about method overriding here.
It can be used to access a method of the superclass that has been hidden by
subclass (Calling parent class version, In case of method overriding).
OR Runtime.getRuntime().gc().
Q) What is Map?
Map interface maps unique keys to values. A key is an object that we use to retrieve a
value later. A map cannot contain duplicate keys: Each key can map to at most one
value.
Q) What is Set?
A Set is a Collection that cannot contain duplicate elements.
Q) Why ArrayList is better than Arrays?
Array can hold fixed number of elements. ArrayList can grow dynamically.
Q) What is the difference between ArrayList and LinkedList?
1) LinkedList store elements within a doubly-linked list data structure. ArrayList store
elements within a dynamically resizing array.
2) LinkedList is preferred for add and update operations while ArrayList is a good
choice for search operations. Read more here.
Q) For addition and deletion. Which one is most preferred: ArrayList or LinkedList?
LinkedList. Because deleting or adding a node in LinkedList is faster than ArrayList.
Q) For searches. Which one is most preferred: ArrayList or LinkedList?
ArrayList. Searching an element is faster in ArrayList compared to LinkedList.
Q) What is the difference between ArrayList and Vector?
1) Vector is synchronized while ArrayList is not synchronized.
2) By default, Vector doubles the size of its array when it is re-sized internally.
ArrayList increases by half of its size when it is re-sized. More details.
Q) What is the difference between Iterator and ListIterator?
Following are the major differences between them:
1) Iterator can be used for traversing Set, List and Map. ListIterator can only be used
for traversing a List.
2) We can traverse only in forward direction using Iterator. ListIterator can be used
for traversing in both the directions(forward and backward). Read more
at: ListIterator vs Iterator.
Q) Difference between TreeSet and SortedSet?
TreeSet implements SortedSet interface.
Q) What is the difference between HashMap and Hashtable?
1) Hashtable is synchronized. HashMap is not synchronized.
2) Hashtable does not allow null keys or values. HashMap allows one null key and any
number of null values. Read more here.
Q) What is the difference between Iterator and Enumeration?
1) Iterator allows to remove elements from the underlying collection during the
iteration using its remove() method. We cannot add/remove elements from a
collection when using enumerator.
2) Iterator has improved method names.
Enumeration.hasMoreElement() -> Iterator.hasNext()
Enumeration.nextElement() -> Iterator.next().
2.
Advantage of adapter: To perform any window listener, we need to include all the
methods used by the window listener whether we use those methods are not in our
class like Interfaces whereas with adapter class, its sufficient to include only the
methods required to override. Straight opposite to Interface.
Further readings:
If you have finished reading above interview questions then you can go through the
below tutorials to sharpen your knowledge in java. We will keep adding new question
and answers to the above list.