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.
| 151. |
What Is The Use Of Bin And Lib In Jdk? |
|
Answer» BIN contains all tools such as JAVAC, APPLETVIEWER, awt TOOL, ETC., whereas lib contains API and all packages. Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages. |
|
| 152. |
What Are Methods And How Are They Defined? |
|
Answer» Methods are functions that OPERATE on instances of CLASSES in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the FIRST three parts MENTIONED above. Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above. |
|
| 153. |
What Is The Difference Between Constructor And Method? |
|
Answer» CONSTRUCTOR will be automatically INVOKED when an object is CREATED whereas method has to be CALLED explicitly. Constructor will be automatically invoked when an object is created whereas method has to be called explicitly. |
|
| 154. |
What Is An Object And How Do You Allocate Memory To It? |
|
Answer» OBJECT is an instance of a class and it is a SOFTWARE unit that combines a structured SET of data with a set of operations for inspecting and manipulating that data. When an object is CREATED using new operator, memory is allocated to it. Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it. |
|
| 155. |
What Are Class, Constructor And Primitive Data Types? |
|
Answer» Class is a template for multiple OBJECTS with similar features and it is a blue print for objects. It DEFINES a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: BYTE, short, int, long, float, double, boolean, CHAR. Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char. |
|
| 156. |
What Is Oops? |
|
Answer» Object oriented PROGRAMMING ORGANIZES a PROGRAM around its data, i. e. , objects and a set of well DEFINED interfaces to that data. An object-oriented program can be characterized as data controlling ACCESS to code. Object oriented programming organizes a program around its data, i. e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code. |
|
| 157. |
What Is The Difference Between Assignment And Initialization? |
|
Answer» Assignment can be done as many times as DESIRED WHEREAS initialization can be done only once. Assignment can be done as many times as desired whereas initialization can be done only once. |
|
| 158. |
What Are Encapsulation, Inheritance And Polymorphism? |
|
Answer» Encapsulation is the mechanism that binds together code and data it manipulates and keeps both SAFE from outside INTERFERENCE and misuse. INHERITANCE is the PROCESS by which one object acquires the properties of another object. Polymorphism is the feature that allows one interface to be USED for general class actions. Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse. Inheritance is the process by which one object acquires the properties of another object. Polymorphism is the feature that allows one interface to be used for general class actions. |
|
| 159. |
What Is The Difference Between Procedural And Object-oriented Programs? |
|
Answer» a) In PROCEDURAL program, programming logic follows certain procedures and the instructions are executed ONE after ANOTHER. In OOP program, unit of program is object, which is NOTHING but combination of data and CODE. a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code. |
|
| 160. |
How Can I Implement A Thread-safe Jsp Page? |
|
Answer» You can make your JSPs thread-safe by having them IMPLEMENT the SingleThreadModel interface. This is done by ADDING the DIRECTIVE <%@ page isThreadSafe="false" % > within your JSP page. You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" % > within your JSP page. |
|
| 161. |
Why Does Jcomponent Have Add() And Remove() Methods But Component Does Not? |
|
Answer» Because JComponent is a SUBCLASS of CONTAINER, and can CONTAIN other COMPONENTS and jcomponents. Because JComponent is a subclass of Container, and can contain other components and jcomponents. |
|
| 162. |
How Do I Include Static Files Within A Jsp Page? |
|
Answer» Static resources should ALWAYS be included USING the JSP include directive. This way, the inclusion is performed just once during the translation phase. Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not ADVISABLE as the inclusion is then performed for each and every REQUEST. Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request. |
|
| 163. |
What Are Stored Procedures? How Is It Useful? |
|
Answer» A stored procedure is a set of statements/commands which reside in the DATABASE. The stored procedure is pre-compiled and saves the database the effort of parsing and compiling sql statements everytime a query is run. Each database has its own stored procedure language, usually a VARIANT of C with a SQL preproceesor. Newer versions of db’s SUPPORT writing stored procedures in Java and Perl too. Before the advent of 3-tier/n-tier architecture it was pretty common for stored procs to implement the business logic( A lot of systems still do it). The biggest advantage is of course SPEED. Also certain kind of data manipulations are not achieved in SQL. Stored procs provide a mechanism to do these manipulations. Stored procs are also useful when you want to do Batch updates/exports/houseKeeping kind of stuff on the db. The overhead of a JDBC CONNECTION may be significant in these cases. A stored procedure is a set of statements/commands which reside in the database. The stored procedure is pre-compiled and saves the database the effort of parsing and compiling sql statements everytime a query is run. Each database has its own stored procedure language, usually a variant of C with a SQL preproceesor. Newer versions of db’s support writing stored procedures in Java and Perl too. Before the advent of 3-tier/n-tier architecture it was pretty common for stored procs to implement the business logic( A lot of systems still do it). The biggest advantage is of course speed. Also certain kind of data manipulations are not achieved in SQL. Stored procs provide a mechanism to do these manipulations. Stored procs are also useful when you want to do Batch updates/exports/houseKeeping kind of stuff on the db. The overhead of a JDBC Connection may be significant in these cases. |
|
| 164. |
How Many Jsp Scripting Elements Are There And What Are They? |
|
Answer» There are three SCRIPTING language ELEMENTS: DECLARATIONS, scriptlets, EXPRESSIONS. There are three scripting language elements: declarations, scriptlets, expressions. |
|
| 165. |
What Class.forname Will Do While Loading Drivers? |
|
Answer» It is used to CREATE an INSTANCE of a driver and REGISTER it with the DRIVERMANAGER. When you have loaded a driver, it is available for making a connection with a DBMS. It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS. |
|
| 166. |
What Information Is Needed To Create A Tcp Socket? |
|
Answer» The Local SYSTEM?s IP Address and Port NUMBER. And the REMOTE System’s IPADDRESS and Port Number. The Local System?s IP Address and Port Number. And the Remote System’s IPAddress and Port Number. |
|
| 167. |
How Many Messaging Models Do Jms Provide For And What Are They? |
|
Answer» JMS provide for TWO messaging models, publish-and-subscribe and point-to-point QUEUING. JMS provide for two messaging models, publish-and-subscribe and point-to-point queuing. |
|
| 168. |
The Code In A Finally Clause Will Never Fail To Execute, Right? |
|
Answer» USING System.exit(1); in TRY block will not allow FINALLY code to execute. Using System.exit(1); in try block will not allow finally code to execute. |
|
| 169. |
Can We Use The Constructor, Instead Of Init(), To Initialize Servlet? |
|
Answer» Yes , of course you can use the constructor instead of INIT(). There’s nothing to stop you. But you shouldn’t. The original reason for init() was that ancient versions of Java couldn’t dynamically INVOKE constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet CONTAINERS still will only CALL your no-arg constructor. So you won’t have access to a ServletConfig or Servlet Context. Yes , of course you can use the constructor instead of init(). There’s nothing to stop you. But you shouldn’t. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or Servlet Context. |
|
| 170. |
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. The Class class is used to obtain information about an object’s design. |
|
| 171. |
What Is The Purpose Of Finalization? |
|
Answer» The purpose of finalization is to GIVE an unreachable OBJECT the OPPORTUNITY to PERFORM any cleanup processing before the object is garbage collected. The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected. |
|
| 172. |
What An I/o Filter? |
|
Answer» An I/O FILTER is an OBJECT that reads from ONE stream and writes to another, usually altering the data in some WAY as it is passed from one stream to another. An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another. |
|
| 173. |
What Is Your Platform's Default Character Encoding? |
|
Answer» If you are running Java on ENGLISH WINDOWS PLATFORMS, it is probably Cp1252. If you are running Java on English SOLARIS platforms, it is most likely 8859_1. If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1. |
|
| 174. |
What Interface Must An Object Implement Before It Can Be Written To A Stream As An Object? |
|
Answer» An OBJECT must IMPLEMENT the SERIALIZABLE or Externalizable INTERFACE before it can be written to a STREAM as an object. An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object. |
|
| 175. |
How Can My Application Get To Know When A Httpsession Is Removed? |
|
Answer» Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and implement the FUNCTIONALITY what you NEED in valueUnbound() METHOD. Create an instance of that class and put that instance in HTTPSESSION. Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and implement the functionality what you need in valueUnbound() method. Create an instance of that class and put that instance in HttpSession. |
|
| 176. |
Whats The Difference Between Notify() And Notifyall()? |
|
Answer» notify() is used to unblock one WAITING thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for EFFICIENCY) when only one blocked thread can benefit from the CHANGE (for example, when freeing a buffer back into a POOL). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a “writer” lock on a file might permit all “READERS” to resume). notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a “writer” lock on a file might permit all “readers” to resume). |
|
| 177. |
Why Are There No Global Variables In Java? |
|
Answer» Global variables are considered BAD form for a variety of reasons: Adding STATE variables breaks referential TRANSPARENCY (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables), State variables lessen the COHESION of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state, When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once. For these reasons, JAVA decided to ban global variables. Global variables are considered bad form for a variety of reasons: Adding state variables breaks referential transparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables), State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state, When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once. For these reasons, Java decided to ban global variables. |
|
| 178. |
What Is The Difference Amongst Jvm Spec, Jvm Implementation, Jvm Runtime ? |
|
Answer» The JVM spec is the blueprint for the JVM GENERATED and owned by SUN. The JVM IMPLEMENTATION is the ACTUAL implementation of the spec by a VENDOR and the JVM runtime is the actual running instance of a JVM implementation. The JVM spec is the blueprint for the JVM generated and owned by Sun. The JVM implementation is the actual implementation of the spec by a vendor and the JVM runtime is the actual running instance of a JVM implementation. |
|
| 179. |
Describe What Happens When An Object Is Created In Java? |
|
Answer» Several things happen in a particular ORDER to ensure the OBJECT is constructed properly: Memory is allocated from heap to HOLD all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data. The instance variables of the objects are initialized to their default values. The constructor for the most derived class is invoked. The first thing a constructor does is call the consctructor for its superclasses. This process continues until the constrcutor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. THUS, the constructor for the base class completes first and constructor for the most derived class completes LAST. Several things happen in a particular order to ensure the object is constructed properly: Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data. The instance variables of the objects are initialized to their default values. The constructor for the most derived class is invoked. The first thing a constructor does is call the consctructor for its superclasses. This process continues until the constrcutor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last. |
|
| 180. |
What Does The "final" Keyword Mean In Front Of A Variable? A Method? A Class? |
|
Answer» FINAL for a VARIABLE: value is CONSTANT. FINAL for a METHOD: cannot be overridden. FINAL for a class: cannot be DERIVED. FINAL for a variable: value is constant. FINAL for a method: cannot be overridden. FINAL for a class: cannot be derived. |
|
| 181. |
What Is The Difference Between Instanceof And Isinstance? |
|
Answer» instanceof is used to check to see if an object can be cast into a SPECIFIED type WITHOUT throwing a cast class exception. isInstance() Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the JAVA language instanceof operator. The method returns TRUE if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns FALSE otherwise. instanceof is used to check to see if an object can be cast into a specified type without throwing a cast class exception. isInstance() Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false otherwise. |
|
| 182. |
Why Does It Take So Much Time To Access An Applet Having Swing Components The First Time? |
|
Answer» Because behind EVERY swing COMPONENT are many Java objects and resources. This takes TIME to create them in memory. JDK 1.3 from Sun has some improvements which may LEAD to faster execution of Swing applications. Because behind every swing component are many Java objects and resources. This takes time to create them in memory. JDK 1.3 from Sun has some improvements which may lead to faster execution of Swing applications. |
|
| 183. |
What Is Skeleton And Stub? What Is The Purpose Of Those? |
|
Answer» Stub is a client SIDE representation of the server, which TAKES care of COMMUNICATING with the remote server. Skeleton is the server side representation. But that is no more in use… it is DEPRECATED LONG before in JDK. Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK. |
|
| 184. |
What Is The Final Keyword Denotes? |
|
Answer» final keyword DENOTES that it is the final IMPLEMENTATION for that method or VARIABLE or class. You can’t OVERRIDE that method/variable/class any more. final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more. |
|
| 185. |
What Is The Significance Of Listiterator? |
|
Answer» You can ITERATE BACK and FORTH. You can iterate back and forth. |
|
| 186. |
What Is The Major Difference Between Linkedlist And Arraylist? |
|
Answer» LINKEDLIST are MEANT for sequential accessing. ARRAYLIST are meant for RANDOM accessing. LinkedList are meant for sequential accessing. ArrayList are meant for random accessing. |
|
| 187. |
What Is Nested Class? |
|
Answer» If all the METHODS of a INNER CLASS is STATIC then it is a NESTED class. If all the methods of a inner class is static then it is a nested class. |
|
| 188. |
What Is Inner Class? |
|
Answer» If the methods of the INNER CLASS can only be ACCESSED via the INSTANCE of the inner class, then it is CALLED inner class. If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class. |
|
| 189. |
What Is Composition? |
|
Answer» HOLDING the reference of the other class WITHIN some other class is known as COMPOSITION. Holding the reference of the other class within some other class is known as composition. |
|
| 190. |
What Is Aggregation? |
|
Answer» It is a SPECIAL TYPE of composition. If you EXPOSE all the METHODS of a composite class and route the METHOD call to the composite method through its reference, then it is called aggregation. It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation. |
|
| 191. |
What Are The Methods In Object? |
|
Answer» CLONE, equals, wait, finalize, GETCLASS, hashCode, NOTIFY, NOTIFYALL, toString. clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString. |
|
| 192. |
Can You Instantiate The Math Class? |
|
Answer» You can’t instantiate the MATH class. All the METHODS in this class are static. And the constructor is not PUBLIC. You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public. |
|
| 193. |
What Is Singleton? |
|
Answer» It is one of the DESIGN PATTERN. This falls in the CREATIONAL pattern of the design pattern. There will be only one INSTANCE for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton GETINSTANCE() { return s; } // all non static methods … } It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … } |
|
| 194. |
How Will You Get The Platform Dependent Values Like Line Separator, Path Separator, Etc., ? |
|
Answer» USING Sytem.getProperty(…) (line.separator, path.separator, …) Using Sytem.getProperty(…) (line.separator, path.separator, …) |
|
| 195. |
What Is The Purpose Of Assert Keyword Used In Jdk1.4.x? |
|
Answer» In ORDER to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, WITHOUT that the method does NOTHING. In order to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, without that the method does nothing. |
|
| 196. |
Is Jvm A Compiler Or An Interpreter? |
|
Answer» Interpreter Interpreter |
|
| 197. |
What Is Jit And Its Use? |
|
Answer» Really, just a very fast compiler… In this incarnation, PRETTY much a one-pass compiler — no OFFLINE COMPUTATIONS. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate CODE. In theory terms, it’s an on-line problem. Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem. |
|
| 198. |
How Will You Load A Specific Locale? |
|
Answer» USING ResourceBundle.getBundle(…); Using ResourceBundle.getBundle(…); |
|
| 199. |
What Is Locale? |
|
Answer» A LOCALE object REPRESENTS a specific geographical, political, or cultural REGION. A Locale object represents a specific geographical, political, or cultural region. |
|
| 200. |
What Is A Databasemetadata? |
|
Answer» COMPREHENSIVE INFORMATION about the DATABASE as a WHOLE. Comprehensive information about the database as a whole. |
|