What is use of parseQueryString
Parses a query string and builds a hashtable of key-value pairs, where the values are arrays of strings. The query string should have the form of a string packaged by the GET or POST method.
What Class.forName will do while loading drivers
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.
When does an object become detached
myCar” is a persistent object at this stage.
Session session1 = sessionFactory.openSession();
Car myCar = session1.get(Car.class, carId);
session1.close();
once the session is closed “myCar” becomes a detached objectyou can now pass the “myCar” object all the way upto the presentation tier. It can be modified without any effect to your database table.
myCar.setColor(“Red”); //no effect on the database
When you are ready to persist this change to the database, it can be reattached to another session as shown below:
Session session2 = sessionFactory.openSession();
Transaction tx = session2.beginTransaction();
session2.update(myCar); //detached object ”myCar” gets re-attached
tx.commit(); //change is synchronized with the database.
session2.close()
How to Retrieve Warnings
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
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();
}
}
Explain about version field
Application level data integrity constants are important if you are making changes to offline information which is again backed by database. Higher level locking or versioning protocol is required to support them. Version field usage comes at this stage but the design and implementation process is left to the developer
Difference between forward and response.sendRedirect
- Forward : when forward is used server forwards the request to the new url and the control stays on the same page. in other words it just forward the request to new url and come back fomr where forward is called.
- sendRedirect : sendRedirect forward the request to url as new request and the cotrol goes to the destination page and never come back to the calling page
Write your own strategy with Interceptor.isUnsaved()
When you reattach detached objects, you need to make sure that the dependent objects are reattached as well.
What are the implicit objects
Implicit objects are objects that are created by the web container and contain information related to a particular request, page, or application.
They are:
Request, response, pageContext, session, application, out, config, page, exception.
The code in a finally clause will never fail to execute, right
Using System.exit(1); in try block will not allow finally code to execute
How would you decide what style of Web Service to use? SOAP WS or REST
In general, a REST based Web service is preferred due to its simplicity, performance, scalability, and support for multiple data formats. SOAP is favored where service requires comprehensive support for security and transactionalreliability.
The answer really depends on the functional and non-functional requirements. Asking the questions listed below will help you choose.
Does the service expose data or business logic? (REST is a better choice for exposing data, SOAP WS might be a better choice for logic).Do the consumers and the service providers require a formal contract? (SOAP has a formal contract via WSDL)
- Do we need to support multiple data formats?
- Do we need to make AJAX calls? (REST can use the XMLHttpRequest)
- Is the call synchronous or asynchronous?
- Is the call stateful or stateless? (REST is suited for statless CRUD operations)
- What level of security is required? (SOAP WS has better support for security)
- What level of transaction support is required? (SOAP WS has better support for transaction management)
- Do we have limited band width? (SOAP is more verbose)
- What’s best for the developers who will build clients for the service? (REST is easier to implement, test, and maintain)