Monday, December 24, 2018

Java Interview Questions

In this Java Interview Questions blog, I am going to show you the list of some of the 
most important Java Interview Questions and Answers which will set you apart in the interview process. Java program is used by approx 10 Million developers worldwide 
to develop applications for 15 Billion devices supporting Java. Also used to creator 
make applications for trending technologies like Big Data to household devices like
Mobiles and DTH boxes. And hence today, Java is used everywhere!
Java Interview Questions
Java Interview Questions all you want to know about Java interviews


As a Java professional, it is essential to know the right buzzwords, learn the right technologies and prepare the right answers to commonly asked Java Interview Questions. Here’s a definitive list of top Java Interview Questions that will guarantee a breeze-through to the next level.

Q1. Why Java is platform independent?

Platform independent practically means “write once run anywhere”. Java is called so because of its byte codes that can run on any system irrespective of its underlying operating system.

Q2. Why java is not 100% Object-oriented?

Java is not 100% Object-oriented because it makes use of eight primary data types such as boolean, byte, char, int, float, double, long, short which are not objects.

Q3. What are constructors in Java?

In Java, constructor refers to a block of code which is used to initialize an object. It must have the same name as that of the class. Also, it has no return type and it is automatically called when an object is created.
There are two types of constructors:
Default constructor
Parameterized constructor

Q4. What is the difference between equals() and == ?

Equals() method is defined in Object class in Java and used for checking equality of two objects defined by business logic.
“==” or equality operator in Java is a binary operator provided by Java programming language and used to compare primitives and objects. public boolean equals(Object o) is the method provided by the Object class. The default implementation uses == operator to compare two objects. For example: method can be overridden like String class. equals() method is used to compare the values of two objects.

Q5. What is Polymorphism?

Polymorphism is briefly described as “one interface, many implementations”. Polymorphism is a features of being able to assign a different meaning or usage to something in different contexts – specifically, to allow an entity such as a variable, a function, or an object to have enough form. There are two types of polymorphism.

Q6. What is association?

Association is a relationship where all object have their own lifecycle and there is no owner. Let’s take an example of Teacher and Student. Multiple students can associate with a single teacher and a single student can associate with multiple teachers but there is no ownership between the objects and both have their own lifecycle. These relationship can be one to one, One to many, many to one and many to many.

Q7. What do you mean by aggregation?

Aggregation is a specialized form of Association where all object have their own lifecycle but there is ownership and child object can not belongs to another parent object. Let’s take an example of Department and teacher. A single teacher can not belongs to multiple departments, but if we delete the department teacher object will not destroy.

Q9. What is composition in Java?

Composition is again specialized form of Aggregation and we can call this as a “death” relationship. It is a strong type of Aggregation. Child object dose not have their lifecycle and if parent object deletes all child object will also be deleted. Let’s take again an example of relationship between House and rooms. House can contain multiple rooms there is no independent life of room and any room can not belongs to two different house if we delete the house room will automatically delete.

Q10. Why there are no concrete implementations of Iterator interface?

Iterator interface declare methods for iterating a collection but it’s implementation is responsibility of the Collection implementation classes. Every collection class that returns an iterator for traversing has it’s own Iterator implementation nested class.
This allows collection classes to chose whether iterator is fail-fast or fail-safe. For example ArrayList iterator is fail-fast whereas CopyOnWriteArrayList iterator is fail-safe.


0 comments:

Post a Comment