Core java interview questions and answers

 Posted On  | Yashwant Chavan | Views :- 5783

Find Java Interview Question, Thread , Collection, Wrapper Classes, Overloading , Overriding and Many More...

Question #1:-What is the difference between creating String using new () and literal? When we create string using new () instance created on heap and not added into string pool while String created using literal are created in String pool itself which exists in Perm area of heap.


package com.net.example;

public class StringExample {
	public static void main(String[] args) {
		String stringPoolObj = "Test"; //String pool object
		String heapObject = new String("Test"); // object on heap
		
		// Define one more object
		String sameAsTest = "Test"; // Pointing to same "Test" Object
	}

}

Question #2:-What are the principle concepts of OOPS?There are four Oops building blocks.

A) Abstraction Abstraction refers to the act of representing essential features without including the background details or explanations.

B) Polymorphism Polymorphism is briefly described as "one interface, many implementations." Polymorphism is a characteristic 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 more than one form.

C) Inheritance Inheritance promote code reuse and polymorphism. Inheritance is the process by which objects of one class acquire the properties of objects of another class.The class that does the inheriting is called a subclass

D) Encapsulation Encapsulation is a technique used for hiding the properties and behaviors of an object and allowing outside access only as appropriate. It prevents other objects from directly altering or accessing the properties or methods of the encapsulated object.

Question #3:-What is Final Keyword? Final Keyword comes in three flavor along with variable, method and class. When it comes with variable you can not change the value of final variable. When it comes with method you can not override final method. And when it comes with class you can extend final class i.e. No Subclass (String class).

Question #4:-What is Final Method? You can not override the final method in sub class, You can not change its functionality. Most of the core classes contains final method like Math class Methods

Question #5:-Is is possible to define Final method in abstract class and Why? Its not possible to define final method in abstract class, Because Final method block the overloading and abstract method insist to override the method, So its contradict.

Question #6:-How to create Thread Instance? There are two ways to create a Threads. By Extending the Thread class and another way is Implement the Runnable Interface. Know more about this.

Question #7:-What is the output of this ? It gives compilation error, because println() method have overloaded version of Object and String so there is ambiguity to choose which println().


		System.out.println(null);

Question #8:-What is Transient Variables? When object is serialize using Serialization, it is going to writing the state of object into file. But if you want to skip particular variable which you don't want to serialize at that time you can make that variable as Transient variable

Question #9:-What are the Thread state?


1] New State
2] Runnable State
3] Running State
4] Waiting / Block State
5] Dead State

Question #10:-What IS-A and HAS-A Relationship?


1] IS-A relationship is base on Inheritance of Class or Interface.
2] e.g. Honda IS A Car , (Honda instanceof Car ) returns true
3] You can achieve IS-A relationship using "extends" and "implements" keywords for Class and Interface respectively. 

1] HAS-A Its Base on use of reference of another class.
2] e.g. Car HAS-A Music Player. Means Both are specialized classes , Car class Has a Reference of  Music Player class object.

class Car{
private MusicPlayer player; //HAS-A relationship
}

class MusicPlayer{
//player specific properties.
}

Question #11:-Is abstract class have Constructor ?Yes abstract class have Constructor.

Question #12:-Which are method of Object class?


public final Class getClass();
public int hashCode();
public boolean equals(Object obj);
protected Object clone();
public String toString();
public final void notify();
public final void notifyAll();
public final void wait(long timeout)throws InterruptedException;
public final void wait(long timeout,int nanos)throws InterruptedException;
public final void wait()throws InterruptedException;
protected void finalize()throws Throwable;

Question #12:-Is there is any way to create instance of Java Object with out using new operator? You can use Class.forName to create instance of object.

Class.forName("Your Class Name").newInstance();

Question #13:- What is jdk1.5 features? Find Java 1.5 features details with examples.

Question #14:- What are pass by reference and passby value? In Java Objects are passed by reference, and primitives are passed by value. Pass By Reference means the passing the address itself rather than passing the value. Pass by value means passing a copy of the value.

Question #15:- How to find out object in List of Objects? To find out object in the List you need to use contains() method. Which returns Boolean whether that object is present or not. For that you need to override the equals method in your object class.

Tags Interview Questions 

HTML Comment Box is loading comments...

Hi I am Yashwant Chavan founder of www.technicalkeeda.com, Purpose of this website to share the programming knowledge in the form post , blogs and articles.

Latest Updates

Stay updated with latest post, articles and technical discussions.

Most Popular Articles



© technicalkeeda.com 2014