CORE JAVA FREQUENTLY ASKED QUESTIONS AND ANSWERS-9
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:
declarations
scriptlets
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