150 Java Interview Questions & Answers - Java Code Geeks - 2025
150 Java Interview Questions & Answers - Java Code Geeks - 2025
Let’s go…!
ADVERTISEMENT
:
Java Interview Questions and Answers – video
Table Of Contents
A.Object Oriented Programming (OOP)
B.General Questions about Java
C.Java Threads
D.Java Collections
E.Garbage Collectors
F.Exception Handling
G.Java Applets
H.Swing
I.JDBC
J.Remote Method Invocation (RMI)
K.Servlets
L.JSP
Reusability of code.
Encapsulation
Polymorphism
Inheritance
Object-Oriented
Platform independent
High Performance
Multithreaded
Portable
Secure
Hello World
5. What is Abstraction?
Abstraction is the process of separating ideas from specific instances
and thus, develop classes in terms of their own functionality, instead
of their implementation details. Java supports the creation and
existence of abstract classes that expose interfaces, without
including the actual implementation of all methods. The abstraction
technique aims to separate the implementation details of a class from
its behavior.
Employee Class
:
01 public class Employee extends Person
02 {
03 private String name;
04
05 public Employee(String name)
06 {
07 this.name = name;
08 }
09 public String getName()
10 {
11 return this.name;
12 }
13 public static void main (String args[])
14 {
15 Employee employee = new Employee("John Wilson"
16
17 System.out.println("Employee's Name "+ employee.getNa
18
19 Person person = new Employee("Thomas Smith"
20
21 System.out.println("Employee-Person's Name "
22
23
24 }
25 }
6. What is Encapsulation?
Encapsulation provides objects with the ability to hide their internal
characteristics and behavior. Each object provides a number of
methods, which can be accessed by other objects and change its
internal data. In Java, there are three access modifiers: public,
private and protected. Each modifier imposes different access rights
to other classes, either in the same or in external packages. Some of
the advantages of using encapsulation are listed below:
Student Class
8. What is Polymorphism?
Polymorphism is the ability of programming languages to present the
same interface for differing underlying data types. A polymorphic type
is a type whose operations can also be applied to values of some
other type.
You can see the example below where Vehicle interface has the
method increaseVelocity. Truck, Train and Aeroplane implement the
Vehicle Interface and the method increases the velocity to the
appropriate velocity related to the vehicle type.
Polymorphism
Calculator Class
:
01 public class Calculator {
02
03 public int subtract(int a, int b)
04 {
05 return a-b;
06 }
07 public double subtract( double a, double b)
08 {
09 return a-b;
10 }
11
12 public static void main(String args[])
13 {
14 Calculator calculator = new Calculator();
15 System.out.println("Difference of 150 and 12 is "
16 System.out.println("Difference of 15.5 and 15.4 is "
17 }}
Shape Class
Rectangle Class
:
01 public class Rectangle extends Shape{
02
03 @Override
04 public void getArea()
05 {
06 System.out.println("Rectangle Area");
07
08 }
09
10
11
12 public static void main(String args[])
13 {
14 Shape shape = new Shape();
15
16 shape.getArea();
17
18 Rectangle rectangle = new Rectangle();
19
20 rectangle.getArea();
21 }
22 }
Mammal Class
TestInheritance Class
Car class
:
01 public class Car
02 {
03 private Tire[] tires;
04
05 private Door[] doors;
06
07 private Steering steering;
08
09 private Window[] windows;
10 }
11
12 class Tire
13 {
14
15 }
16
17 class Door
18 {
19
20 }
21
22 class Steering
23 {
24
25 }
26
27 class Window
28 {
29
30 }
JDK JRE
JDK stands for the term : Java JRE stands for the term: Java
Development Kit. Runtime Environment.
Static method
byte
short
int
long
float
double
boolean
char
Default Constructor
1 public Man()
2 {
3 System.out.println("Man is created");
4 }
Constructor
:
1 private String name;
2
3 public Employee(String name)
4 {
5 this.name = name;
6 }
Copy Constructor
Multiple Inheritance
Also, check out the Abstract class and Interface differences for JDK
8.
Instance properties
:
cannot be there in an Instance properties can be there in an
interface. abstract class.
Pass by Value
:
01 public class ComputingEngine
02 {
03 public static void main(String[] args)
04 {
05 int x = 15;
06 ComputingEngine engine = new ComputingEngine();
07 engine.modify(x);
08 System.out.println("The value of x after passing by v
09 }
10 public void modify(int x)
11 {
12 x = 12;
13 }
14 }
Pass by Reference
:
01 public class ComputingEngine
02 {
03 public static void main(String[] args)
04 {
05
06 ComputingEngine engine = new ComputingEngine();
07
08
09 Computation computation = new Computation(
10 engine.changeComputedValue(computation);
11
12 System.out.println("The value of x after passing by r
13
14 }
15
16
17
18 public void changeComputedValue(Computation computation)
19 {
20 computation = new Computation();
21 computation.x = 40;
22 }
23 }
24
25
26 class Computation
27 {
28 int x;
29 Computation(int i) { x = i; }
30 Computation() { x = 1; }
31 }
Volatile Variable
:
1 public class DistributedObject {
2
3 public volatile int count = 0;
4
5 }
Transitent variable
Static Binding
:
01 public class Shape
02 {
03 public void getArea()
04 {
05 System.out.println("Shape Area");
06 }
07
08
09 public static void main(String args[])
10 {
11 Shape shape = new Shape();
12
13 shape.getArea();
14 }
15 }
Dynamic Binding
ensure that only one instance of the singleton class ever exists
Singleton Class
ADVERTISEMENT
C.Java Threads
36. What is the di!erence between processes and
threads?
A process is an execution of a program, while a Thread is a single
execution sequence within a process. A process can contain multiple
threads. A Thread is sometimes called a lightweight process.
Processes Threads
Process is related to
Process consists of multiple threds.
execution of a program .
Processes communicate
Threads of a process can
with each other using inter-
communicate with each other.
process communication .
Synchronized is used
Synchronized is used to
to sleep over the
Synchronized access the same Object
Sleeping thread from
from multiple threads..
multiple threads.
for multi-thread-
Usage for time-synchronization
synchronization
D.Java Collections
:
44. What are the basic interfaces of Java Collections
Framework?
Java Collections Framework provides a well-designed set of
interfaces and classes that support operations on a collections of
objects. The most basic interfaces that reside in the Java Collections
Framework are:
Collection Hierarchy
Array ArrayList
Array should not have values Array List can have values of
of different data types different data types.
E.Garbage Collectors
61. What is the purpose of garbage collection in Java,
and when is it used?
The purpose of garbage collection is to identify and discard those
objects that are no longer needed by the application, in order for the
resources to be reclaimed and reused.
Finalize Method
F.Exception Handling
69. What are the di!erences between Checked
Exception and Unchecked Exception?
Checked Exception Unchecked Exception
Throw Throws
Finally is a block that always executes when the try block exits
even if an unexpected exception occurs.
G.Java Applets
75. What is an Applet?
A java applet is program that can be included in a HTML page and be
:
executed in a java enabled client browser. Applets are used for
creating dynamic and interactive web applications.
Applet Lifecycle
H.Swing
84. What is the di!erence between a Choice and a
List?
A Choice is displayed in a compact form that must be pulled down, in
order for a user to be able to see the list of all available choices. Only
one item may be selected from a Choice. A List may be displayed in
:
such a way that several List items are visible. A List supports the
selection of one or more List items.
98. What is the design pattern that Java uses for all
Swing components?
The design pattern used by Java for all Swing components is the
Model View Controller (MVC) pattern.
MVC
I.JDBC
99. What is JDBC?
JDBC is an abstraction layer that allows users to choose between
databases. JDBC enables developers to write database applications
in Java, without having to concern themselves with the underlying
:
details of a particular database.
Interfaces:
Driver
Connection
Statement
PreparedStatement
CallableStatement
ResultSet
Classes:
DriverManager
SQLException
Class.forName
:
01 public class ClassLoader
02 {
03
04 public static void main(String[] args) {
05
06 try
07 {
08 Class cls = Class.forName("BasicClass"
09
10 .....
11
12 System.out.println("Class = " + cls.getName());
13
14 }
15
16 catch(ClassNotFoundException exception)
17 {
18 System.out.println(exception.toString());
19 }
20
21 }
RMI Architecture
Stub and Skeleton layer : This layer lies just beneath the view of
the developer. This layer is responsible for intercepting method
calls made by the client to the interface and redirect these calls
to a remote RMI Service.
RMI Flow
K.Servlets
122. What is a Servlet?
The servlet is a Java programming language class used to process
client requests and generate dynamic web content. Servlets are
mostly used to process or store data submitted by an HTML form,
provide dynamic content and manage state information that does not
exist in the stateless HTTP protocol.
Servlet Lifecycle
The code below shows the BasicServlet class which has doGet and
doPost methods to be implemented.
SendRedirect Forward
L.JSP
140. What is a JSP Page?
A Java Server Page (JSP) is a text document that contains two types
of text: static data and JSP elements. Static data can be expressed
in any text-based format, such as HTML or XML. JSP is a technology
that mixes static content with dynamically-generated content. See
JSP example here.
Declarations
JSP Expresssion
1 <html>
2 <head><title>My Blog</title></head>
3
4 <body>
5 <p>Today's Date is: <%= (new java.util.Date()).toLocaleS
6 </body>
7 </html>
application
page
request
response
session
exception
out
config
pageContext
Core:
Variable support
Flow control
URL management
Miscellaneous
XML:
Core
Flow control
Transformation
Internationalization:
Locale
Message formatting
Database:
SQL
Functions:
:
Collection length
String manipulation
More Tutorials
What is Java used for
Sign up
3 Reply
Reply to aerobless
Hope this will help you for java interview more…
http://net-informations.com/java/cjava/default.htm
Crow
3 Reply
:
user 5 years ago
Reply to aerobless
good luck for you
0 Reply
2 Reply
0 Reply
0 Reply
3 Reply
:
Jeffrey Burch 10 years ago
4 Reply
0 Reply
0 Reply
0 Reply
0 Reply
0 Reply
:
Tk 10 years ago
-1 Reply
0 Reply
0 Reply
0 Reply
0 Reply
:
Guarav 10 years ago
0 Reply
1 Reply
0 Reply
nice infrmation
1 Reply
nice infrmation
0 Reply