Thursday, June 24, 2010

CORE JAVA CONTINUES ... 4

QUESTION: What is the range of the short type?
ANSWER: The range of the short type is -(2^15) to 2^15 - 1.

QUESTION: What is the purpose of garbage collection?
ANSWER: The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources may be reclaimed and reused.

QUESTION: How may 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

QUESTION: What information is needed to create a TCP Socket? (Networking)
ANSWER: The Local System?s IP Address and Port Number. And the Remote System's IPAddress and Port Number.

QUESTION: What Class.forName will do while loading drivers? (JDBC)
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.
 
QUESTION: How to Retrieve Warnings? (JDBC)
ANSWER: SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object
E.g.
SQLWarning warning = stmt.getWarnings();
if (warning != null) {
while (warning != null) {
System.out.println("Message: " + warning.getMessage());
System.out.println("SQLState: " + warning.getSQLState());
System.out.print("Vendor error code: ");
System.out.println(warning.getErrorCode());
warning = warning.getNextWarning();
}
}

QUESTION: How many JSP scripting elements are there and what are they? (JSP)
ANSWER: There are three scripting language elements:
  1. declarations
  2. scriptlets
  3. expressions
QUESTION: In the Servlet 2.4 specification SingleThreadModel has been deprecates, why? (JSP)

ANSWER: Because it is not practical to have such model. Whether you set isThreadSafe to true or false, you should take care of concurrent client requests to the JSP page by synchronizing access to any shared objects defined at the page level.

 
QUESTION: what are stored procedures? How is it useful? (JDBC)

ANSWER: A stored procedure is a set of statements/commands which reside in the database. The stored procedure is precompiled and saves the database the effort of parsing and compiling sql statements everytime a query is run. Each Database has it's own stored procedure language, usually a variant of C with a SQL preproceesor. Newer versions of db's support writing stored procs 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.

 
QUESTION: What do you understand by private, protected and public?

ANSWER: These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.  

 
QUESTION: What is Downcasting ? 
ANSWER: Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy

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

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

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

 

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

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

 1. 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.
2. The instance variables of the objects are initialized to their default values.
3. 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.
4. 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.

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

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

 
QUESTION: Wha is the output from System.out.println("Hello"+null); 
ANSWER: Hellonull