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.
| 201. |
What Are The Approaches That You Will Follow For Making A Program Very Efficient? |
|
Answer» By AVOIDING too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related CLASSES BASED on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for REMOTE invocations Avoiding creation of variables within a loop and lot more. By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more. |
|
| 202. |
What Is The Implementation Of Destroy Method In Java.. Is It Native Or Java Code? |
|
Answer» This METHOD is not IMPLEMENTED. This method is not implemented. |
|
| 204. |
What Is The Base Class For Error And Exception? |
|
Answer» Throwable Throwable |
|
| 205. |
What Is Reflection? |
|
Answer» Reflection ALLOWS programmatic ACCESS to information about the FIELDS, methods and CONSTRUCTORS of loaded CLASSES, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions. Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions. |
|
| 206. |
What Is The Purpose Of Void Class? |
|
Answer» The Void class is an uninstantiable PLACEHOLDER class to HOLD a reference to the Class OBJECT representing the primitive JAVA TYPE void. The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void. |
|
| 207. |
What Is The Basic Difference Between String And Stringbuffer Object? |
|
Answer» STRING is an IMMUTABLE OBJECT. STRINGBUFFER is a MUTABLE object. String is an immutable object. StringBuffer is a mutable object. |
|
| 208. |
What Is Mutable Object And Immutable Object? |
|
Answer» If a OBJECT value is changeable then we can call it as MUTABLE object. (EX., StringBuffer, …) If you are not allowed to CHANGE the value of an object, it is immutable object. (Ex., String, INTEGER, Float, …) If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …) |
|
| 209. |
What Is The Finalize Method Do? |
|
Answer» Before the invalid objects get GARBAGE collected, the JVM GIVE the USER a chance to clean up some resources before it got garbage collected. Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected. |
|
| 210. |
How Will You Invoke Any External Process In Java? |
|
Answer» Runtime.getRuntime().EXEC(….) Runtime.getRuntime().exec(….) |
|
| 211. |
What Is A Daemon Thread? |
|
Answer» These are the THREADS which can run WITHOUT USER INTERVENTION. The JVM can exit when there are daemon thread by killing them abruptly. These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly. |
|
| 212. |
What Kind Of Thread Is The Garbage Collector Thread? |
|
Answer» It is a daemon thread. |
|
| 213. |
What Is Garbage Collection? What Is The Process That Is Responsible For Doing That In Java? |
|
Answer» RECLAIMING the UNUSED memory by the invalid OBJECTS. Garbage collector is RESPONSIBLE for this PROCESS. Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process. |
|
| 214. |
What Are The Different Identifier States Of A Thread? |
|
Answer» The DIFFERENT IDENTIFIERS of a THREAD are: R - Running or runnable thread, S - SUSPENDED thread, CW - Thread waiting on a condition variable, MW - Thread waiting on a monitor LOCK, MS - Thread suspended waiting on a monitor lock. The different identifiers of a Thread are: R - Running or runnable thread, S - Suspended thread, CW - Thread waiting on a condition variable, MW - Thread waiting on a monitor lock, MS - Thread suspended waiting on a monitor lock. |
|
| 215. |
What Are Some Alternatives To Inheritance? |
|
Answer» Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance VARIABLE, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each MESSAGE you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really MAKE sense. On the other hand, it MAKES you WRITE more code, and it is harder to re-use (because it is not a subclass). Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass). |
|
| 216. |
What Is The Catch Or Declare Rule For Method Declarations? |
|
Answer» If a checked exception may be THROWN WITHIN the body of a method, the method MUST either catch the exception or declare it in its throws clause. If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause. |
|
| 217. |
What Does It Mean That A Method Or Class Is Abstract? |
|
Answer» An ABSTRACT class cannot be instantiated. Abstract methods MAY only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. Each subclass of an abstract class MUST override the abstract methods of its superclasses or it ALSO should be DECLARED abstract. An abstract class cannot be instantiated. Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. Each subclass of an abstract class must override the abstract methods of its superclasses or it also should be declared abstract. |
|
| 218. |
What Does It Mean That A Class Or Member Is Final? |
|
Answer» A final class cannot be inherited. A final method cannot be overridden in a SUBCLASS. A final field cannot be CHANGED after it's INITIALIZED, and it MUST include an initializer statement where it's DECLARED. A final class cannot be inherited. A final method cannot be overridden in a subclass. A final field cannot be changed after it's initialized, and it must include an initializer statement where it's declared. |
|
| 219. |
How Are This() And Super() Used With Constructors? |
|
Answer» this() is USED to INVOKE a constructor of the same class. SUPER() is used to invoke a superclass constructor. this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor. |
|
| 220. |
What Is The Difference Between A Break Statement And A Continue Statement? |
|
Answer» A BREAK statement RESULTS in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current LOOP iteration and RETURN control to the loop statement. A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement. |
|
| 221. |
What Is Constructor Chaining And How Is It Achieved In Java ? |
|
Answer» A child object constructor always first needs to construct its PARENT (which in turn calls its parent constructor.). In Java it is done VIA an implicit call to the no-args constructor as the first STATEMENT. A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first statement. |
|
| 222. |
What Is The Difference Between Method Overriding And Overloading? |
|
Answer» Overriding is a method with the same name and arguments as in a PARENT, WHEREAS overloading is the same method name but DIFFERENT arguments Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments |
|
| 223. |
How Many Static Init Can You Have ? |
|
Answer» As MANY as you want, but the static initializers and class variable initializers are executed in textual ORDER and may not refer to class variables declared in the class WHOSE DECLARATIONS appear textually after the use, even though these class variables are in SCOPE. As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope. |
|
| 224. |
What Happens To A Static Var That Is Defined Within A Method Of A Class ? |
|
Answer» Can't do it. You'll GET a COMPILATION ERROR Can't do it. You'll get a compilation error |
|
| 225. |
Can A Method Be Overloaded Based On Different Return Type But Same Argument Type ? |
|
Answer» No, because the METHODS can be CALLED without using their return type in which CASE there is ambiquity for the COMPILER No, because the methods can be called without using their return type in which case there is ambiquity for the compiler |
|
| 226. |
What Is The Difference Between An If Statement And A Switch Statement? |
|
Answer» The if STATEMENT is used to select among two alternatives. It USES a boolean EXPRESSION to decide which alternative should be executed. The switch statement is used to select among MULTIPLE alternatives. It uses an int expression to determine which alternative should be executed. The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed. |
|
| 227. |
What Is The Diffrence Between Inner Class And Nested Class? |
|
Answer» When a CLASS is defined WITHIN a SCOPE od another class, then it becomes inner class. If the access MODIFIER of the inner class is static, then it becomes nested class. When a class is defined within a scope od another class, then it becomes inner class. If the access modifier of the inner class is static, then it becomes nested class. |
|
| 228. |
What Is The Difference Between A While Statement And A Do Statement? |
|
Answer» A while statement checks at the beginning of a loop to see WHETHER the NEXT loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always EXECUTE the body of a loop at least once. A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once. |
|
| 229. |
Which Characters May Be Used As The Second Character Of An Identifier,but Not As The First Character Of An Identifier? |
|
Answer» The DIGITS 0 through 9 MAY not be used as the FIRST CHARACTER of an identifier but they may be used after the first character of an identifier. The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier. |
|
| 230. |
What Does It Mean That A Method Or Field Is "static"? |
|
Answer» Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you CHANGE the value of a static variable in a PARTICULAR OBJECT, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That's how library methods like System. out. println() work. out is a static field in the java.lang.System class. Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That's how library methods like System. out. println() work. out is a static field in the java.lang.System class. |
|
| 231. |
Why Isn't There Operator Overloading? |
|
Answer» Because C++ has PROVEN by example that operator OVERLOADING MAKES code ALMOST impossible to MAINTAIN. Because C++ has proven by example that operator overloading makes code almost impossible to maintain. |
|
| 232. |
What Is The Range Of The Short Type? |
|
Answer» The RANGE of the SHORT TYPE is -(2^15) to 2^15 - 1. The range of the short type is -(2^15) to 2^15 - 1. |
|
| 233. |
What Is The Range Of The Char Type? |
|
Answer» The RANGE of the CHAR TYPE is 0 to 2^16 - 1. The range of the char type is 0 to 2^16 - 1. |
|
| 234. |
Can An Anonymous Class Be Declared As Implementing An Interface And Extending A Class? |
|
Answer» An anonymous class may IMPLEMENT an INTERFACE or extend a SUPERCLASS, but may not be declared to do both. An anonymous class may implement an interface or extend a superclass, but may not be declared to do both. |
|
| 235. |
What Restrictions Are Placed On The Location Of A Package Statement Within A Source Code File? |
|
Answer» A package STATEMENT must appear as the first LINE in a source CODE file (excluding blank LINES and COMMENTS). A package statement must appear as the first line in a source code file (excluding blank lines and comments). |
|
| 236. |
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. 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. |
|
| 237. |
Which Non-unicode Letter Characters May Be Used As The First Character Of An Identifier? |
|
Answer» The non-Unicode LETTER CHARACTERS $ and _ MAY appear as the FIRST character of an identifier. The non-Unicode letter characters $ and _ may appear as the first character of an identifier. |
|
| 238. |
What Is A Local, Member And A Class Variable? |
|
Answer» VARIABLES declared within a method are "local" variables. Variables declared within the class i.e not within any METHODS are "MEMBER" variables (GLOBAL variables). Variables declared within the class i.e not within any methods and are DEFINED as "static" are class variables. Variables declared within a method are "local" variables. Variables declared within the class i.e not within any methods are "member" variables (global variables). Variables declared within the class i.e not within any methods and are defined as "static" are class variables. |
|
| 239. |
What Modifiers Are Allowed For Methods In An Interface? |
|
Answer» Only public and ABSTRACT MODIFIERS are ALLOWED for METHODS in INTERFACES. Only public and abstract modifiers are allowed for methods in interfaces. |
|
| 240. |
What Is Externalizable? |
|
Answer» Externalizable is an Interface that extends Serializable Interface. And sends DATA into Streams in COMPRESSED FORMAT. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in) Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in) |
|
| 241. |
Can We Define Private And Protected Modifiers For Variables In Interfaces? |
|
Answer» No No |
|
| 242. |
Why Does Java Not Support Operator Overloading? |
|
Answer» Operator overloading MAKES the code very DIFFICULT to read and maintain. To maintain code simplicity, Java doesn't SUPPORT operator overloading. Operator overloading makes the code very difficult to read and maintain. To maintain code simplicity, Java doesn't support operator overloading. |
|
| 243. |
If I Only Change The Return Type, Does The Method Become Overloaded? |
|
Answer» No it doesn't. There should be a CHANGE in METHOD ARGUEMENTS for a method to be OVERLOADED. No it doesn't. There should be a change in method arguements for a method to be overloaded. |
|
| 244. |
Which Oo Concept Is Achieved By Using Overloading And Overriding? |
|
Answer» Polymorphism. Polymorphism. |
|
| 245. |
What Is A Marker Interface? |
|
Answer» An Interface which doesn't have any DECLARATION INSIDE but still enforces a MECHANISM. An Interface which doesn't have any declaration inside but still enforces a mechanism. |
|
| 248. |
Can An Interface Be Final? |
|
Answer» Not POSSIBLE. Doing it will RESULT in COMPILATION ERROR. Not possible. Doing it will result in compilation error. |
|
| 249. |
Why Is An Interface Be Able To Extend More Than One Interface But A Class Can't Extend More Than One Class? |
|
Answer» Basically JAVA doesn't allow multiple inheritance, so a CLASS is restricted to EXTEND only ONE Class. But an Interface is a pure abstraction model and doesn't have inheritance hierarchy like classes(do remember that the base class of all classes is Object). So an Interface is ALLOWED to extend more than one Interface. Basically Java doesn't allow multiple inheritance, so a Class is restricted to extend only one Class. But an Interface is a pure abstraction model and doesn't have inheritance hierarchy like classes(do remember that the base class of all classes is Object). So an Interface is allowed to extend more than one Interface. |
|
| 250. |
Can A Class Extend More Than One Class? |
|
Answer» Not possible. A CLASS can extend only one class but can implement any NUMBER of INTERFACES. Not possible. A Class can extend only one class but can implement any number of Interfaces. |
|