Technical interview questions and answers are essential for any Java Interview because Java is one of the most widely used programming languages in software development. Companies expect candidates to know OOP concepts, multithreading, exceptions, JDBC, collections, and real-time coding questions. Java interviews are commonly part of campus placements and software development roles in companies such as TCS, Infosys, Wipro, Cognizant, and Accenture. For freshers and job seekers, understanding Java concepts clearly makes it easier to clear technical rounds, online coding tests, and project discussions. This guide includes the most important and frequently asked Java interview questions with detailed explanations to help you prepare efficiently. These questions will help you gain confidence during software developer interviews and competitive placement tests.
Java professionals should deepen their expertise through J2EE development concepts and data structures fundamentals
Showing 10 of 301 questions
101. What one should take care of while serializing the object?
One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializableException.
102. What type of parameter passing does Java support?
In Java the arguments are always passed by value .
103. What will be the default values of all the elements of an array defined as an instance variable?
If the array is an array of primitive types, then all the elements of the array will be initialized to the default value corresponding to that primitive type. e.g. All the elements of an array of int will be initialized to 0, while that of boolean type will be initialized to false. Whereas if the array is an array of references (of any type), all the elements will be initialized to null.
104. What will be the initial value of an object reference which is defined as an instance variable?
The object references are all initialized to null in Java. However in order to do anything useful with these references, you must set them to a valid object, else you will get NullPointerExceptions everywhere you try to use such default initialized references.
105. What will be the output of the following statement? System.out.println ("1" + 3);
It will print 13.
106. When a thread is created and started, what is its initial state?
A thread is in the ready state after it has been created and started.
107. When you serialize an object, what happens to the object references included in the object?
The serialization mechanism generates an object graph for serialization. Thus it determines whether the included object references are serializable or not. This is a recursive process. Thus when an object is serialized, all the included objects are also serialized alongwith the original obect.
108. Which java.util classes and interfaces support event handling?
The EventObject class and the EventListener interface support event processing.
109. Which methods of Serializable interface should I implement?
The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.
110. Why do we need wrapper classes?
It is sometimes easier to deal with primitives as objects. Moreover most of the collection classes store objects and not primitive data types. And also the wrapper classes provide many utility methods also. Because of these resons we need wrapper classes. And since we create instances of these classes we can store them in any of the collection classes and pass them around as a collection. Also we can pass them around as method parameters where a method expects an object.