126. What Is The Difference Between An Interface & An Abstract Class?
Answer: An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation.
127 .Can An Interface Extend Another Interface?
Answer: Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.
128. If A Method Is Declared As Protected, Where May The Method Be Accessed?
Answer: A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.
129. What Will Happen If Static Modifier Is Removed From The Signature Of The Main Method?
Answer: Program throws "NoSuchMethodError" error at runtime.
130. What Is The Default Value Of An Object Reference Declared As An Instance Variable?
Answer: Null, unless it is defined explicitly.
131. What Is Nested Top-Level Class? Can A Top Level Class Be Private Or Protected?
Answer: If a class is declared within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Nested top-level class is an Inner class.
No, a top level class can not be private or protected. It can have either "public" or no modifier.
132 .Why Do We Need wrapper Classes?
Answer: We can pass them around as method parameters where a method expects an object. It also
provides utility methods.
133. What Is The Difference Between Error & An Exception?
Answer: An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. Exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist.
134. Describe Life Cycle Of Thread?
Answer: A thread is a execution in a program. The life cycle of a thread include:
135. When A Thread Is Created & Started, What Is Its Initial State?
Answer: A thread is in the ready state as initial state after it has been created and started.
136. Explain Suspend, isAlive Method Under Thread Class? What Is currentThread?
Answer: suspend is used to pause or temporarily stop the execution of the thread. IsAlive is used to find out whether a thread is still running or not. Currentthread is a public static method used to obtain a reference to the current thread.
137. Explain Main Thread Under Thread Class Execution?
Answer: The main thread is created automatically and it begins to execute immediately when a program starts. It is a thread from which all other child threads originate.
138. What Is Daemon Thread? Which Method Is Used To Create The Daemon Thread? Which Method Must Be Implemented By All Threads?
Answer: Daemon thread is a low priority thread, which runs intermittently in the background doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.
All tasks must implement the run method
139. What Is The Locale Class?
Answer: The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.
140. What Are Synchronized Methods & Synchronized Statements?
Answer: Synchronized methods are methods that are used to control access to an object. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.
141. What Is Runtime Polymorphism Or Dynamic Method Dispatch?
Answer: Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass.
142. Which Object Oriented Concept Is Achieved By Using Overloading & Overriding?
Answer: Polymorphism
143. What Is Dynamic Binding?
Answer: Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time.
144. Can Constructor Be Inherited? Where & How Can You Use A Private Constructor?
Answer: No, constructor cannot be inherited.
Private constructor is used if you do not want other classes to instantiate the object and to prevent
subclassing.
145. What Is Constructor Chaining & How Is It Achieved In Java?
Answer: A child object constructor always first needs to construct its parent. In Java it is done via an implicit call to the no-args constructor as the first statement.
146. What Are The Advantages Of ArrayList Over Arrays?
Answer: ArrayList can grow dynamically and provides more powerful insertion and search mechanisms than arrays.
147. Why Deletion In LinkedList Is Fast Than ArrayList?
Answer: Deletion in linked list is fast because it involves only updating the next pointer in the node before the deleted node and updating the previous pointer in the node after the deleted node.
148. How Do You Decide When To Use ArrayList & LinkedList?
Answer: If you need to frequently add and remove elements from the middle of the list and only access the list elements sequentially, then LinkedList should be used. If you need to support random access, without inserting or removing elements from any place other than the end, then ArrayList should be used.
149. What Is A Values Collection View ?
Answer: It is a collection returned by the values method of the Map Interface, It contains all the objects present as values in the map.
150. What Is Dot Operator? What Is The Difference Between The >> and >>> Operators?
Answer: The dot operator. is used to access the instance variables and methods of class objects.It is also used to access classes and sub-packages from a package.
The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.
Check Out Other Questions As Well: -
151. What Are Order Of Precedence & Associativity & How Are They Used?
152. What Is Type Casting? What Is Downcasting? Can A Double Value Be Cast To A Byte?
153. Which Method Of The Component Class Is Used To Set The Position & Size Of A Component?
154. What Is The Range Of The Short Type?
155. What Is The Immediate Superclass Of Menu?
156. Does Java Allow Default Arguments?
157. Which Number Is Denoted By Leading Zero In Java? Which Number Is Denoted By Leading 0x Or 0X In Java?
158. Break Statement Can Be Used As Labels In Java?
159. Where Import Statement Is Used In A Java Program?
160. What Are The Steps Involved In A Life Cycle Of An Applet?
161. Why Is The Role Of init Method Under Applets?
162. Which Method Is Called By Applet Class To Load An Image?
163. Define Code As An Attribute Of Applet?
164. Define Canvas?
165. Define Network Programming?
166. What Is A Socket? State The Advantages & Disadvantages Of Sockets?
167. Which Class Is Used By Server Applications To Obtain A Port & Listen For Client Requests?
168. Which Class Represents The Socket That Both The Client & Server Use To Communicate With Each Other?
169. Why Generics Are Used In Java?
170. What Environment Variables Do I Need To Set On My Machine In Order To Be Able To Run Java Programs?
171. Is There Any Need To Import java.lang Package?
172. What Is Externalizable Interface?
173. If System.exit 0; Is Written At The End Of The Try Block, Will The Finally Block Still Execute?
174. What Is The GregorianCalendar Class?
175. What Is The SimpleTimeZone Class?
...Return To Java FAQ's Section
Answer: An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation.
127 .Can An Interface Extend Another Interface?
Answer: Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.
128. If A Method Is Declared As Protected, Where May The Method Be Accessed?
Answer: A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.
129. What Will Happen If Static Modifier Is Removed From The Signature Of The Main Method?
Answer: Program throws "NoSuchMethodError" error at runtime.
130. What Is The Default Value Of An Object Reference Declared As An Instance Variable?
Answer: Null, unless it is defined explicitly.
131. What Is Nested Top-Level Class? Can A Top Level Class Be Private Or Protected?
Answer: If a class is declared within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Nested top-level class is an Inner class.
No, a top level class can not be private or protected. It can have either "public" or no modifier.
132 .Why Do We Need wrapper Classes?
Answer: We can pass them around as method parameters where a method expects an object. It also
provides utility methods.
133. What Is The Difference Between Error & An Exception?
Answer: An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. Exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist.
134. Describe Life Cycle Of Thread?
Answer: A thread is a execution in a program. The life cycle of a thread include:
- Newborn state
- Runnable state
- Running state
- Blocked state
- Dead state
135. When A Thread Is Created & Started, What Is Its Initial State?
Answer: A thread is in the ready state as initial state after it has been created and started.
136. Explain Suspend, isAlive Method Under Thread Class? What Is currentThread?
Answer: suspend is used to pause or temporarily stop the execution of the thread. IsAlive is used to find out whether a thread is still running or not. Currentthread is a public static method used to obtain a reference to the current thread.
137. Explain Main Thread Under Thread Class Execution?
Answer: The main thread is created automatically and it begins to execute immediately when a program starts. It is a thread from which all other child threads originate.
138. What Is Daemon Thread? Which Method Is Used To Create The Daemon Thread? Which Method Must Be Implemented By All Threads?
Answer: Daemon thread is a low priority thread, which runs intermittently in the background doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.
All tasks must implement the run method
139. What Is The Locale Class?
Answer: The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.
140. What Are Synchronized Methods & Synchronized Statements?
Answer: Synchronized methods are methods that are used to control access to an object. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.
141. What Is Runtime Polymorphism Or Dynamic Method Dispatch?
Answer: Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass.
142. Which Object Oriented Concept Is Achieved By Using Overloading & Overriding?
Answer: Polymorphism
143. What Is Dynamic Binding?
Answer: Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time.
144. Can Constructor Be Inherited? Where & How Can You Use A Private Constructor?
Answer: No, constructor cannot be inherited.
Private constructor is used if you do not want other classes to instantiate the object and to prevent
subclassing.
145. What Is Constructor Chaining & How Is It Achieved In Java?
Answer: A child object constructor always first needs to construct its parent. In Java it is done via an implicit call to the no-args constructor as the first statement.
146. What Are The Advantages Of ArrayList Over Arrays?
Answer: ArrayList can grow dynamically and provides more powerful insertion and search mechanisms than arrays.
147. Why Deletion In LinkedList Is Fast Than ArrayList?
Answer: Deletion in linked list is fast because it involves only updating the next pointer in the node before the deleted node and updating the previous pointer in the node after the deleted node.
148. How Do You Decide When To Use ArrayList & LinkedList?
Answer: If you need to frequently add and remove elements from the middle of the list and only access the list elements sequentially, then LinkedList should be used. If you need to support random access, without inserting or removing elements from any place other than the end, then ArrayList should be used.
149. What Is A Values Collection View ?
Answer: It is a collection returned by the values method of the Map Interface, It contains all the objects present as values in the map.
150. What Is Dot Operator? What Is The Difference Between The >> and >>> Operators?
Answer: The dot operator. is used to access the instance variables and methods of class objects.It is also used to access classes and sub-packages from a package.
The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.
Check Out Other Questions As Well: -
151. What Are Order Of Precedence & Associativity & How Are They Used?
152. What Is Type Casting? What Is Downcasting? Can A Double Value Be Cast To A Byte?
153. Which Method Of The Component Class Is Used To Set The Position & Size Of A Component?
154. What Is The Range Of The Short Type?
155. What Is The Immediate Superclass Of Menu?
156. Does Java Allow Default Arguments?
157. Which Number Is Denoted By Leading Zero In Java? Which Number Is Denoted By Leading 0x Or 0X In Java?
158. Break Statement Can Be Used As Labels In Java?
159. Where Import Statement Is Used In A Java Program?
160. What Are The Steps Involved In A Life Cycle Of An Applet?
161. Why Is The Role Of init Method Under Applets?
162. Which Method Is Called By Applet Class To Load An Image?
163. Define Code As An Attribute Of Applet?
164. Define Canvas?
165. Define Network Programming?
166. What Is A Socket? State The Advantages & Disadvantages Of Sockets?
167. Which Class Is Used By Server Applications To Obtain A Port & Listen For Client Requests?
168. Which Class Represents The Socket That Both The Client & Server Use To Communicate With Each Other?
169. Why Generics Are Used In Java?
170. What Environment Variables Do I Need To Set On My Machine In Order To Be Able To Run Java Programs?
171. Is There Any Need To Import java.lang Package?
172. What Is Externalizable Interface?
173. If System.exit 0; Is Written At The End Of The Try Block, Will The Finally Block Still Execute?
174. What Is The GregorianCalendar Class?
175. What Is The SimpleTimeZone Class?
...Return To Java FAQ's Section
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com