100+ Core Java Interview Questions
100+ Core Java Interview Questions
Home Core Java OOPs Collections Java I/O JSON JSP JSTL Servlet C Tutorial DBMS Perl
Hi Friends, In this article, we have shared 100+ java interview questions for both beginners and
experienced folks.
Table of Contents
1. Basic Questions
2. OOPs interview Questions
3. Exception handling interview Questions
4. Java Multithreading interview Questions
5. Serialization interview Questions
6. String Interview Questions
7. Java Collections interview Questions
8. Applet interview Questions
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.
https://beginnersbook.com/2013/05/java-interview-questions/ 1/30
12/9/2017 100+ Core Java Interview Questions
Simple
Multi-threaded
Distributed Application
Robust
Security
Complexities are removed (Pointers, Operator overloading, Multiple inheritance).
Q) What is javac ?
It produces the java byte code from *.java le. 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
https://beginnersbook.com/2013/05/java-interview-questions/ 2/30
12/9/2017 100+ Core Java Interview Questions
byte 8 bit (are esp. useful when working with a stream of data from a network or a le).
short 16 bit
char 16 bit Unicode
int 32 bit (whole number)
oat 32 bit (real number)
long 64 bit (Single precision)
double 64 bit (double precision)
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 de nes a fully international character set
that can represent all of the characters found in human languages.
Q) Dynamic Initialization?
Java allows variables to be initialized dynamically, using any expression valid at the time the
variable is declared.
https://beginnersbook.com/2013/05/java-interview-questions/ 3/30
12/9/2017 100+ Core Java Interview Questions
casting in java: automatic casting (done automatically) and explicit casting (done by programmer).
Q) Arrays?
An array is a group of xed number of same type values. Read more about Arrays here.
Q) How can I put all my classes and resources into one le and run it?
Use a JAR le. Put all the les in a JAR, then run the app like this:
https://beginnersbook.com/2013/05/java-interview-questions/ 4/30
12/9/2017 100+ Core Java Interview Questions
Q) java.lang.* get imported by default. For using String and Exception classes, you dont need to
explicitly import this package. The major classes inside this package are
Object class
Data type wrapper classes
Math class
String class
System and Runtime classes
Thread classes
Exception classes
Process classes
Class classes
Inheritance
Polymorphism
Data Encapsulation
Abstraction
https://beginnersbook.com/2013/05/java-interview-questions/ 5/30
12/9/2017 100+ Core Java Interview Questions
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.
https://beginnersbook.com/2013/05/java-interview-questions/ 6/30
12/9/2017 100+ Core Java Interview Questions
Q) Can we overload a method by just changing the return type and without changing the signature
of method?
No, We cannot do this.
Q) What is Encapsulation?
Encapsulation means the localization of the information or knowledge within an object.
Encapsulation is also called as Information Hiding. Read it here in detail.
Q) Abstract class?
An abstract class is a class which cant be instantiated (we cannot create the object of abstract
class), we can only extend such classes. It provides the generalized form that will be shared by all of
its subclasses, leaving it to each subclass to ll in the details. We can achieve partial abstraction
using abstract classes, to achieve full abstraction we use interfaces.
https://beginnersbook.com/2013/05/java-interview-questions/ 7/30
12/9/2017 100+ Core Java Interview Questions
https://beginnersbook.com/2013/05/java-interview-questions/ 8/30
12/9/2017 100+ Core Java Interview Questions
Q)THIS keyword?
The THIS keyword is a reference to the current object.
Pass by value Changes made to the parameter of the subroutines have no effect on the argument
used to call it.
Pass by reference Changes made to the parameter will affect the argument used to call the
subroutine.
https://beginnersbook.com/2013/05/java-interview-questions/ 9/30
12/9/2017 100+ Core Java Interview Questions
https://beginnersbook.com/2013/05/java-interview-questions/ 10/30
12/9/2017 100+ Core Java Interview Questions
objectClone () to creates a new object that is same as the object being cloned.
boolean equals(Object obj) determines whether one object is equal to another.
nalize() Called by the garbage collector on an object when garbage collection determines
that there are no more references to the object. A subclass overrides the nalize method to
dispose of system resources or to perform other cleanup.
toString () Returns a string representation of the object.
https://beginnersbook.com/2013/05/java-interview-questions/ 11/30
12/9/2017 100+ Core Java Interview Questions
Q) How many times does the garbage collector calls the nalize() method for an object?
The garbage collector calls the nalize() method Only once for an object.
Q) Exceptions are de ned in which java package? OR which package has de nitions for all the
exception classes?
Java.lang.Exception
This package contains de nitions for Exceptions.
Unchecked exceptions: It is up to the programmer to write the code in such a way to avoid
unchecked exceptions. You would not get a compilation error if you do not handle these exceptions.
These exceptions occur at runtime.
https://beginnersbook.com/2013/05/java-interview-questions/ 13/30
12/9/2017 100+ Core Java Interview Questions
Q) ClassNotFoundException vs NoClassDefFoundError?
1) ClassNotFoundException occurs when loader could not nd the required class in class path.
2) NoClassDefFoundError occurs when class is loaded in classpath, but one or more of the class
which are required by other class, are removed or failed to load by compiler.
https://beginnersbook.com/2013/05/java-interview-questions/ 14/30
12/9/2017 100+ Core Java Interview Questions
Q) What are the main differences between Process and thread? Explain in brief.
1) One process can have multiple threads. A thread is a smaller part of a process.
2) Every process has its own memory space, executable code and a unique process identi er (PID)
while every thread has its own stack in Java but it uses process main memory and shares it with
other threads.
3) Threads of same process can communicate with each other using keyword like wait and notify
etc. This process is known as inter process communication.
https://beginnersbook.com/2013/05/java-interview-questions/ 15/30
12/9/2017 100+ Core Java Interview Questions
sleep() It causes the current thread to suspend execution for a speci ed period. When a thread
goes into sleep state it doesnt release the lock.
wait() It causes current thread to wait until either another thread invokes the notify() method or
the notifyAll() method for this object, or a speci ed amount of time has elapsed.
https://beginnersbook.com/2013/05/java-interview-questions/ 16/30
12/9/2017 100+ Core Java Interview Questions
actually execute it in a Thread, you should call Thread.start() method to start it.
Q) What is Starvation?
Starvation describes a situation where a thread is unable to gain regular access to shared resources
and is unable to make progress. This happens when shared resources are made unavailable for long
periods by greedy threads. For example, suppose an object provides a synchronized method that
often takes a long time to return. If one thread invokes this method frequently, other threads that
also need frequent synchronized access to the same object will often be blocked.
Q) What is deadlock?
Deadlock describes a situation where two or more threads are blocked forever, waiting for each
other.
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.
https://beginnersbook.com/2013/05/java-interview-questions/ 18/30
12/9/2017 100+ Core Java Interview Questions
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.
https://beginnersbook.com/2013/05/java-interview-questions/ 19/30
12/9/2017 100+ Core Java Interview Questions
Unsigned applets can, however, read (but not write) non-class les bundled with your applet on the
server, called resource les
Q) What is container ?
A component capable of holding another component is called as container.
Container
Panel
Applet
https://beginnersbook.com/2013/05/java-interview-questions/ 20/30
12/9/2017 100+ Core Java Interview Questions
Window
Frame
Dialog
Learning)
https://beginnersbook.com/2013/05/java-interview-questions/ 21/30
12/9/2017 100+ Core Java Interview Questions
Learnings)
parseInt to convert string to int.
getBytes string to byte array
Q) showStatus() ?
To display the message at the bottom of the browser when applet is started.
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
https://beginnersbook.com/2013/05/java-interview-questions/ 22/30
12/9/2017 100+ Core Java Interview Questions
adapter class, its suf cient to include only the methods required to override. Straight opposite to
Interface.
Further readings:
If you have nished 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.
Comments
shubham says
https://beginnersbook.com/2013/05/java-interview-questions/ 23/30
12/9/2017 100+ Core Java Interview Questions
good
Reply
abi says
AUGUST 6, 2014 AT 6:39 AM
good
Reply
marimuthu says
NOVEMBER 10, 2014 AT 2:14 AM
Reply
https://beginnersbook.com/2013/05/java-interview-questions/ 24/30
12/9/2017 100+ Core Java Interview Questions
Very Useful.
Reply
David V. says
JANUARY 8, 2015 AT 10:06 PM
The answer for this question is not complete. In interview is necessary explain why it is
faster, you should know how linkedlist works, what O(x) time it takes add, search, del,
etc
Reply
https://beginnersbook.com/2013/05/java-interview-questions/ 25/30
12/9/2017 100+ Core Java Interview Questions
sanjeevakumar says
JANUARY 27, 2015 AT 9:42 AM
Reply
.I had tried overriding a static method and the compiler doesnt give error. We can also
override main() method (which is static).
Reply
Reply
Reply
Thanks,
Neville
Reply
https://beginnersbook.com/2013/05/java-interview-questions/ 27/30
12/9/2017 100+ Core Java Interview Questions
kalaivani says
AUGUST 15, 2015 AT 7:41 PM
Reply
Leave a Reply
Your email address will not be published. Required elds are marked *
Comment
Name *
https://beginnersbook.com/2013/05/java-interview-questions/ 28/30
12/9/2017 100+ Core Java Interview Questions
Email *
Website
POST COMMENT
RECENTLY ADDED..
JSON Tutorial
Java Regular
Expressions Tutorial
Java Annotations
Tutorial
https://beginnersbook.com/2013/05/java-interview-questions/ 29/30
12/9/2017 100+ Core Java Interview Questions
https://beginnersbook.com/2013/05/java-interview-questions/ 30/30