Sr.Java Web Developer

  Home  Java Programing  Sr.Java Web Developer


“Sr.Java Web Developer related Frequently Asked Questions by expert members with professional career as Sr.Java Web Developer. These list of interview questions and answers will help you strengthen your technical skills, prepare for the new job interview and quickly revise your concepts”



64 Sr.Java Web Developer Questions And Answers

1⟩ What is execute(String query)?

Statement execute(String query) is used to execute any SQL query and it returns TRUE if the result is an ResultSet such as running Select queries. The output is FALSE when there is no ResultSet object such as running Insert or Update queries. We can use getResultSet() to get the ResultSet and getUpdateCount() method to retrieve the update count.

 152 views

3⟩ Tell me what is JDBC Driver?

JDBC Driver is a software component that enables java application to interact with the database. There are 4 types of JDBC drivers:

☛ JDBC-ODBC bridge driver

☛ Native-API driver (partially java driver)

☛ Network Protocol driver (fully java driver)

☛ Thin driver (fully java driver)

 142 views

4⟩ Explain me what is a servlet?

☛ Java Servlet is server side technologies to extend the capability of web servers by providing support for dynamic response and data persistence.

☛ The javax.servlet and javax.servlet.http packages provide interfaces and classes for writing our own servlets.

☛ All servlets must implement the javax.servlet.Servlet interface, which defines servlet lifecycle methods. When implementing a generic service, we can extend the GenericServlet class provided with the Java Servlet API. The HttpServlet class provides methods, such as doGet() and doPost(), for handling HTTP-specific services.

☛ Most of the times, web applications are accessed using HTTP protocol and thats why we mostly extend HttpServlet class. Servlet API hierarchy is shown in below image.

 181 views

5⟩ Explain me what are the advantages of Hibernate over JDBC?

Some of the important advantages of Hibernate framework over JDBC are:

☛ Hibernate removes a lot of boiler-plate code that comes with JDBC API, the code looks more cleaner and readable.

☛ Hibernate supports inheritance, associations and collections. These features are not present with JDBC API.

☛ Hibernate implicitly provides transaction management, in fact most of the queries can’t be executed outside transaction. In JDBC API, we need to write code for transaction management using commit and rollback.

☛ JDBC API throws SQLException that is a checked exception, so we need to write a lot of try-catch block code. Most of the times it’s redundant in every JDBC call and used for transaction management. Hibernate wraps JDBC exceptions and throw JDBCException or HibernateException un-checked exception, so we don’t need to write code to handle it. Hibernate built-in transaction management removes the usage of try-catch blocks.

☛ Hibernate Query Language (HQL) is more object oriented and close to java programming language. For JDBC, we need to write native sql queries.

☛ Hibernate supports caching that is better for performance, JDBC queries are not cached hence performance is low.

☛ Hibernate provide option through which we can create database tables too, for JDBC tables must exist in the database.

☛ Hibernate configuration helps us in using JDBC like connection as well as JNDI DataSource for connection pool. This is very important feature in enterprise application and completely missing in JDBC API.

► Hibernate supports JPA annotations, so code is independent of implementation and easily replaceable with other ORM tools. JDBC code is very tightly coupled with the application.

 141 views

7⟩ Do you know what is the jspDestroy() method?

jspDestry() method is invoked from javax.servlet.jsp.JspPage interface whenever a JSP page is about to be destroyed. Servlets destroy methods can be easily overridden to perform cleanup, like when closing a database connection.

 164 views

8⟩ What is String toString()?

This method returns the information in String format. The returned String contains the name of Throwable class and localized message.

 145 views

9⟩ Please explain can we write multiple catch blocks under single try block?

Yes we can have multiple catch blocks under single try block but the approach should be from specific to general. Let’s understand this with a programmatic example.

public class Example {

public static void main(String args[]) {

try {

int a[]= new int[10];

a[10]= 10/0;

}

catch(ArithmeticException e)

{

System.out.println("Arithmetic exception in first catch block");

}

catch(ArrayIndexOutOfBoundsException e)

{

System.out.println("Array index out of bounds in second catch block");

}

catch(Exception e)

{

System.out.println("Any exception in third catch block");

}

}

 152 views

10⟩ Do you know how to create a custom Exception?

To create you own exception extend the Exception class or any of its subclasses.

☛ class New1Exception extends Exception { } // this will create Checked Exception

☛ class NewException extends IOException { } // this will create Checked exception

☛ class NewException extends NullPonterExcpetion { } // this will create UnChecked exception

 170 views

11⟩ Explain me what are the important methods of Java Exception Class?

Methods are defined in the base class Throwable. Some of the important methods of Java exception class are stated below.

☛ String getMessage() – This method returns the message String about the exception . The message can be provided through its constructor.

☛ public StackTraceElement[] getStackTrace() – This method returns an array containing each element on the stack trace. The element at index 0 represents the top of the call stack whereas the last element in the array represents the method at the bottom of the call stack.

☛ Synchronized Throwable getCause() – This method returns the cause of the exception or null id as represented by a Throwable object.

☛ String toString() – This method returns the information in String format. The returned String contains the name of Throwable class and localized message.

☛ void printStackTrace() – This method prints the stack trace information to the standard error stream.

 172 views

12⟩ Tell us what is difference between Error and Exception?

An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors you can not repair them at runtime.Though error can be caught in catch block but the execution of application will come to a halt and is not recoverable.

While exceptions are conditions that occur because of bad input or human error etc. e.g. FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc.

 153 views

13⟩ Tell us what is Hibernate Framework?

Object-relational mapping or ORM is the programming technique to map application domain model objects to the relational database tables. Hibernate is java based ORM tool that provides framework for mapping application domain objects to the relational database tables and vice versa.

Hibernate provides reference implementation of Java Persistence API, that makes it a great choice as ORM tool with benefits of loose coupling. We can use Hibernate persistence API for CRUD operations. Hibernate framework provide option to map plain old java objects to traditional database tables with the use of JPA annotations as well as XML based configuration.

Similarly hibernate configurations are flexible and can be done from XML configuration file as well as programmatically.

 135 views

14⟩ Please explain what is exception hierarchy in java?

The hierarchy is as follows:

Throwable is a parent class of all Exception classes. There are two types of Exceptions: Checked exceptions and UncheckedExceptions or RunTimeExceptions. Both type of exceptions extends Exception class whereas errors are further classified into Virtual Machine error and Assertion error.

 150 views

15⟩ Do you know what is composition in Java?

Composition is again specialized form of Aggregation and we can call this as a “death” relationship. It is a strong type of Aggregation. Child object dose not have their lifecycle and if parent object deletes all child object will also be deleted. Let’s take again an example of relationship between House and rooms. House can contain multiple rooms there is no independent life of room and any room can not belongs to two different house if we delete the house room will automatically delete.

 174 views

19⟩ Tell me what are the JDBC API components?

The java.sql package contains interfaces and classes for JDBC API.

Interfaces:

☛ Connection

☛ Statement

☛ PreparedStatement

☛ ResultSet

☛ ResultSetMetaData

☛ DatabaseMetaData

☛ CallableStatement etc.

Classes:

☛ DriverManager

☛ Blob

☛ Clob

☛ Types

☛ SQLException etc.

 152 views