InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 101. |
What is Serialization and deserialization? |
|
Answer» Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects. |
|
| 102. |
What is the difference between static and non-static variables? |
|
Answer» A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance. |
|
| 103. |
Which class should you use to obtain design information about an object? |
|
Answer» The Class class is used to obtain information about an object's design and java.lang.Class class instance represent classes, interfaces in a running Java application. |
|
| 104. |
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy? |
|
Answer» The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented. |
|
| 105. |
What is the purpose of File class? |
|
Answer» It is used to create objects that provide access to the files and directories of a local file system. |
|
| 106. |
What is the difference between the paint() and repaint() methods? |
|
Answer» The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread. |
|
| 107. |
Which package has light weight components? |
|
Answer» javax.Swing package. All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components. |
|
| 108. |
What is the difference between a Window and a Frame? |
|
Answer» The Frame class extends Window to define a main application window that can have a menu bar. |
|
| 109. |
What are Wrapper classes? |
|
Answer» These are classes that allow primitive types to be accessed as objects. Example: Integer, Character, Double, Boolean etc. |
|
| 110. |
How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters? |
|
Answer» Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns. |
|
| 111. |
Why Vector class is used? |
|
Answer» The Vector class provides the capability to implement a growable array of objects. Vector proves to be very useful if you don't know the size of the array in advance, or you just need one that can change sizes over the lifetime of a program. |
|
| 112. |
Does it matter in what order catch statements for FileNotFoundException and IOException are written? |
|
Answer» Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first. |
|
| 113. |
What invokes a thread's run() method? |
|
Answer» After a thread is started, via its start() method of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed. |
|
| 114. |
How does multi-threading take place on a computer with a single CPU? |
|
Answer» The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially. |
|
| 115. |
What are the ways in which a thread can enter the waiting state? |
|
Answer» A thread can enter the waiting state by invoking its sleep() method, by blocking on IO, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method. |
|
| 116. |
What is NullPointerException? |
|
Answer» A NullPointerException is thrown when calling the instance method of a null object, accessing or modifying the field of a null object etc. |
|
| 117. |
What is final class? |
|
Answer» Final classes are created so the methods implemented by that class cannot be overridden. It can’t be inherited. |
|
| 118. |
Difference between Overloading and Overriding? |
|
Answer» Method overloading increases the readability of the program. Method overriding provides the specific implementation of the method that is already provided by its super class parameter must be different in case of overloading, parameter must be same in case of overriding. |
|
| 119. |
Define composition? |
|
Answer» Holding the reference of the other class within some other class is known as composition. |
|
| 120. |
What is static block? |
|
Answer» It is used to initialize the static data member, It is excuted before main method at the time of classloading. |
|
| 121. |
Can a constructor be made final? |
|
Answer» No, this is not possible. |
|
| 122. |
What is the purpose of default constructor? |
|
Answer» The java compiler creates a default constructor only if there is no constructor in the class. |
|
| 123. |
What is the difference between object oriented programming language and object based programming language? |
|
Answer» Object based programming languages follow all the features of OOPs except Inheritance. JavaScript is an example of object based programming languages. |
|
| 124. |
Define JIT compiler? |
|
Answer» It improves the runtime performance of computer programs based on bytecode. |
|
| 125. |
What is a WAR file? |
|
Answer» This is Web Archive File and used to store XML, java classes, and JavaServer pages. which is used to distribute a collection of JavaServer Pages, Java Servlets, Java classes, XML files, static Web pages etc. |
|
| 126. |
What is JAR file? |
|
Answer» JAR files is Java Archive fles and it aggregates many files into one. It holds Java classes in a library. JAR files are built on ZIP file format and have .jar file extension. |
|
| 127. |
Define JRE i.e. Java Runtime Environment? |
|
Answer» Java Runtime Environment is an implementation of the Java Virtual Machine which executes Java programs. It provides the minimum requirements for executing a Java application; |
|
| 128. |
Explain the following line used under Java Program −public static void main (String args[ ]) |
|
Answer» The following shows the explanation individually −
|
|
| 129. |
Difference between throw and throws? |
|
Answer» It includes:
|
|
| 130. |
What is Comparable Interface? |
|
Answer» It is used to sort collections and arrays of objects using the collections.sort() and java.utils. The objects of the class implementing the Comparable interface can be ordered. |
|
| 131. |
Explain TreeSet? |
|
Answer» It is a Set implemented when we want elements in a sorted order. |
|
| 132. |
Explain Set Interface? |
|
Answer» It is a collection of element which cannot contain duplicate elements. The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are prohibited. |
|
| 133. |
Explain the usage of this() with constructors? |
|
Answer» It is used with variables or methods and used to call constructer of same class. |
|
| 134. |
Define immutable object? |
|
Answer» An immutable object can’t be changed once it is created. |
|
| 135. |
Explain garbage collection in Java? |
|
Answer» It uses garbage collection to free the memory. By cleaning those objects that is no longer reference by any of the program. |
|
| 136. |
An applet extend which class? |
|
Answer» An applet extends java.applet.Applet class. |
|
| 137. |
What is an applet? |
|
Answer» An applet is a Java program that runs in a Web browser. An applet can be a fully functional Java application because it has the entire Java API at its disposal. |
|
| 138. |
What are the two ways in which Thread can be created? |
|
Answer» Thread can be created by: implementing Runnable interface, extending the Thread class. |
|
| 139. |
What do you mean by Multithreaded program? |
|
Answer» A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is called a thread, and each thread defines a separate path of execution. |
|
| 140. |
Why Packages are used? |
|
Answer» Packages are used in Java in-order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations, etc., easier. |
|
| 141. |
Define Packages in Java? |
|
Answer» A Package can be defined as a grouping of related types(classes, interfaces, enumerations and annotations ) providing access protection and name space management. |
|
| 142. |
Give some features of Interface? |
|
Answer» It includes −
|
|
| 143. |
What is the primary benefit of Encapsulation? |
|
Answer» The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this Encapsulation gives maintainability, flexibility and extensibility to our code. |
|
| 144. |
When Abstract methods are used? |
|
Answer» If you want a class to contain a particular method but you want the actual implementation of that method to be determined by child classes, you can declare the method in the parent class as abstract. |
|
| 145. |
What is Abstract class? |
|
Answer» These classes cannot be instantiated and are either partially implemented or not at all implemented. This class contains one or more abstract methods which are simply method declarations without a body. |
|
| 146. |
When super keyword is used? |
|
Answer» If the method overrides one of its superclass's methods, overridden method can be invoked through the use of the keyword super. It can be also used to refer to a hidden field. |
|
| 147. |
Define Inheritance? |
|
Answer» It is the process where one object acquires the properties of another. With the use of inheritance the information is made manageable in a hierarchical order. |
|
| 148. |
What things should be kept in mind while creating your own exceptions in Java? |
|
Answer» While creating your own exception −
|
|
| 149. |
How finally used under Exception Handling? |
|
Answer» The finally keyword is used to create a block of code that follows a try block. A finally block of code always executes, whether or not an exception has occurred. |
|
| 150. |
When throw keyword is used? |
|
Answer» An exception can be thrown, either a newly instantiated one or an exception that you just caught, by using throw keyword. |
|