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...

What Is (Are) Your Weakness (Weaknesses)? - Interview Answers

There’s a saying – “However small the thorn maybe it has the ability to pierce.” Never say you are a Workaholic, a Perfectionist, etc. because it sounds negative. Try to convert these negative biased qualities into positive ones. For Example, In   place of Workaholic you can say you are a hard worker and always willing to work for extra hours. In place of Perfectionist , you can say you are detail oriented and like to set high standard for work. “Try to specify your weakness as your strength and also highlight it as a benefit.” Your answers can be: 1) One of my weaknesses as I perceive is occasional compromise on time for quality and perfection. 2) I feel I am not very detail-oriented . I’m a person that wants accomplish as much as possible. I realized this hurts quality and therefore I‘m trying hard to find a balance between quality and quantity. 3) At times even when I need help, I try to solve my own problems instead of asking a co-worker who might know...

What Is (Are) Your Strengths? - Interview Answers

This is a simple and popular interview question. Generally people answer it in two ways. There are people who simply state their strength like “I am Young, Dynamic, Intelligent, Smart and so on…”. Such answer is neither right nor wrong but does not help u in any way also. Secondly there are peoples who state their strengths and explain them how he can use his strength for the job and industry. Do not simply state your strength. Everyone has some strength, all you need is to convert them into benefits. In short, try to advertise yourself by converting your features into strengths. “EVERYONE CLAIM THEY ARE HONEST, HARDWORKING, SMART AND SO ON….. BUT WITH AN EXAMPLE IT IS MUCH MORE BELIEVABLE.” Your answers can be : 1) I am a hard worker and because of this ability I can work for additional hours to accomplish my tasks.I am commitment oriented and hence I always enjoy the trust and confidence of my team mates which enables me to perform my duties very easily. 2) I am a...