Skip to main content

Page VI - Java Interview Questions With Answers.

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:
  • 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

Popular posts from this blog

Tell Me Something About Yourself - Interview Answers.

Try to introduce some of your most important employment-oriented skills as well as your education and accomplishments to the interviewer. Answer to this question is very important because it positions you for the rest of the interview . That's why this statement is often called the "Positioning Statement". One should take the opportunity to show his/her communication skills by speaking clearly and concisely in an organized manner. Since there is no right or wrong answer for this question hence it is important to appear friendly. YOUR ANSWERS CAN BE: 1) I am a person with strong interpersonal skills and have the ability to get along well with people . I enjoy challenges and looking for creative solutions to problems. 2) Besides the details given in my resume, I believe in character values, vision and action. I am quick in learning from mistakes. I am confident that the various tests that you have conducted will corroborate my competencies apti...

HR Interview Questions With Simple Answers - Top 30.

Here are some very important HR questions which are often asked during Interviews and I believe these answers can really help you to get through....... Click on them to view the answer: 1) Tell Me Something About Yourself ? 2) What Are Your Strengths? 3) What Are Your Weaknesses? 4) How Do You Handle Pressure / Can You Work Well Under Pressure? 5) What Are Your Short Term Goals? 6) What Are Your Long Term Goals? 7) Where Do You See After 5 Years? 8) Why Should We Hire You? 9) What Is Your Salary Expectation? 10) Why Do You Want To Leave Your Current Job? 11) Do You Prefer To Work Alone Or As A Team Player? 12) What Made You Choose Your Major / Stream? 13) Why Didn’t You Pursue A Career In Your Major / Stream? 14) Why Do You Want To Work For Us? 15) Are You Willing To Travel? 16) Are You Willing To Take Risks? 17) What Do You Know About This Company? 18) What Do You Seek From A Job? 19) How Do You Evaluate Success? 20) Dur...

Sample Cover Letter / Job Application.

To The General Manager (HR) [ Name and Designation (Bold Words)] Infosys Limited Delhi – 110001 Uttam Agrawal Gandhi Chowk, Bhartee Street [ Name Bhawanipatna, Kalahandi Contact Address Orissa – 766001 Telephone No.] Ph. no - +91-9438170446 [Sub: Application for the position of ___________ in your esteemed organization.] Respected Sir, (Always use ‘Respected’) With reference to your advertisement dated 14th may’ 08 in The Times of India for the position of ___________ . I would like to place myself as a strong contender before you. OR This has reference to your advertisement dated 14th may’ 08 in The Times of India for the position of ____________. In the said connection I take this opportunity to apply for the said position as a strong contender. /*This is the Introduction i.e the first paragraph of your application/* ( Now the Second Paragraph is the Self Introduction) Try to start the second paragraph with the below mentioned lines: - I have the p...