Core Java Interview Questions and answers

Whether you are a fresher or experienced most of questions that you will face in core java interview are mentioned here. The list below is made from most commonly asked question during java interview. This page contains most important questions and their answers. You can nagivate to other page(s) for detailed questions on various topics like OOPs concepts interview questions, collection framework interview questions etc. Link to navigate are given at top and bottom of the page.


Overview : Most Imp Questions Java Basic Interview Questions
OOPS Concepts Interview Questions Exception Handling Questions
MultiThreading & Concurrency API Java API : String, File I/O
Collection Framework Questions Advanced Questions

Core Java : Basic Interview Questions

JDK : JDK stands for Java Development Kit. It is a complete bundle containing JRE, java compiler and other utilities for development of java programs. JDK is required to write/compile java programs.

JRE : JRE stands for Java Runtime Environment. It provides the minimum requirements for executing a java application. JRE consists of JVM, java core liberaries and supportiong files. You need JRE to run java programs/applications. When you download JDK you get JRE along with it. You can download JRE seperately as well.

JVM : JVM stands for Java Virtual Machine. Its a virtual machine that converts java bytecode into machine language and executes it. Java Virtual machine gets created when you run a java program. All java programs/application run within JVM. It is JVM that makes java platform independent.

Its JVM (and bytecode) that makes java plateform independent. You write a java program and compile it to generate .class file. The .class file contains bytecode. This bytecode can now be executed at any platform with the help of corresponding JVM.
Note: There is seperate JVM for each platform. The JVM for unix will convert bytecode into unix machine code while the JVM for windows will convert same bytecode into windows machine code.

Java OOPs Concepts Interview Questions

OOPs stands for Object Oriented Programming Structure. There are 4 main OOPs concepts:

Abstraction

Showing only what is relevent to one by hiding unncessary compalixities.

Encapsulation

To wrap up data the the functions that operate on this data into one single unit.

Inheritance

Child class inherite the properties of Parent/base class.

Polymorphism

Poly (many) + Morphs (forms). There are two types of Polymorphism in Java:
Method Overloading (or compile time ploymorphism) and Method Overriding(or runtime polymorphism).
Interface Abstract class
All methods of Interface must be abstract. Abstract class can have abstract methods as well as concrete methods.
All method of interface are abstract and public by default. No such default behaviour for methods of Abstract class.
All variables of Interface are public static final by default. This is not case with Abstract class
Method Overloading Method Overriding
Method overloading is done among methods of same class. Method over-riding is done among method of parent and child class.
Signature of methods must be different with same name. Method name and signature must be same, however return type must be same or narrow in child class.
Access specifier is irrelevant in method overloading. Access specifier of method in child class must be same or higher.
Makes part of static binding i.e. resolved at the compile time itself. Makes part of dynamic binding i.e. resolved at run time.
Yes, abstract class can have constructor, and infact it always has one. If you don't define explicitly it will have default constructor.
The construcotr is used for inheritance. When you extend a class, you need constructor in that class.
Static means related to class and not to object of the class.

Any member of a class (method or variable) can be marked as static, which means it can be accessed directly with class name without object of the class.
Abstraction means hiding of unnecessary compalixities from user.

Java Exception Handling Interview Questions

Exception class hierarchy starts with 'Throwable' class which extends Object. Below diagram explains it:
exception
Throw Throws
Throw clause is used to throw an exception from from your code. Throws clause is used to declare that a method don't handle and hence may throw a particular excepton.
Make a class that extends RuntimeException or Exception based on whether you want to make a checked or unchecked exception respectively.
Finally block is used in exception handling to write the piece of code that must be excuted in all scenario, whether exception occurs or not. It's normally used for freeing up resources like dataSource etc.

Java Collection Framework Interview Questions

ArrayList and LinkedList both implement List interface and their methods are almost same, still there are some differences as explained below:
ArrayList LinkedList
Search is very fast in ArrayList as it maintain index based system. O(1) Search is slow, as it has to traverse through all elements. O(n)
Modification (insert or delete) to ArrayList is slow. Modification to LinkedList is very fast.
Memory consumption is low. Memory consumption is high as it maintains data and 2 pointers for neighbor nodes.
Use it when the collection has less moodification and more retrival. Use it when you collection is expected to undergo multiple modification (especially in between elements).
Either through keySet() or through entrySet();
Abstraction means hiding of unnecessary compalixities from user.

Java Threading Interview Questions

Synchronization is the process of accessing shared resources by multiple threads in such a way that no resource can be accessed by multiple thread at one particular moment of time.
In Java synchronization is achieved either through synchronized block or synchronized method.
Object.wait() Thread.sleep()
Wait method is defined inside Object class. Sleep method is defined inside Thread class and is static method.
You call wait on an object and the code must be inside a synchronized context (method or block). You call sleep on Thread class and code may or may not be in synchronized context.
Wait releases lock of the object on which its waiting. sleep method don't release lock of the Thread.
Waiting thread can be woken-up by notify or notifyAll methods. Sleep-ing thread is woken-up automatically once the time is complete.

Core Java : Java API Interview Questions

Abstraction means hiding of unnecessary compalixities from user.
Abstraction means hiding of unnecessary compalixities from user.
Abstraction means hiding of unnecessary compalixities from user.

Core Java : Other Important Interview Questions

Abstraction means hiding of unnecessary compalixities from user.
Abstraction means hiding of unnecessary compalixities from user.



<< Previous Page : 1 2 3 4 5 6 7 8 Next >>