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

21⟩ Explain me what are the important benefits of using Hibernate Framework?

Some of the important benefits of using hibernate framework are:

☛ Hibernate eliminates all the boiler-plate code that comes with JDBC and takes care of managing resources, so we can focus on business logic.

☛ Hibernate framework provides support for XML as well as JPA annotations, that makes our code implementation independent.

☛ Hibernate provides a powerful query language (HQL) that is similar to SQL. However, HQL is fully object-oriented and understands concepts like inheritance, polymorphism and association.

☛ Hibernate is an open source project from Red Hat Community and used worldwide. This makes it a better choice than others because learning curve is small and there are tons of online documentations and help is easily available in forums.

☛ Hibernate is easy to integrate with other Java EE frameworks, it’s so popular that Spring Framework provides built-in support for integrating hibernate with Spring applications.

☛ Hibernate supports lazy initialization using proxy objects and perform actual database queries only when it’s required.

☛ Hibernate cache helps us in getting better performance.

☛ For database vendor specific feature, hibernate is suitable because we can also execute native sql queries.

Overall hibernate is the best choice in current market for ORM tool, it contains all the features that you will ever need in an ORM tool.

 141 views

22⟩ Please explain what is the difference between execute, executeQuery, executeUpdate?

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.

Statement executeQuery(String query) is used to execute Select queries and returns the ResultSet. ResultSet returned is never null even if there are no records matching the query. When executing select queries we should use executeQuery method so that if someone tries to execute insert/update statement it will throw java.sql.SQLException with message “executeQuery method can not be used for update”.

Statement executeUpdate(String query) is used to execute Insert/Update/Delete (DML) statements or DDL statements that returns nothing. The output is int and equals to the row count for SQL Data Manipulation Language (DML) statements. For DDL statements, the output is 0.

You should use execute() method only when you are not sure about the type of statement else use executeQuery or executeUpdate method.

 170 views

23⟩ Please explain what purpose does the keywords final, finally, and finalize fulfill?

Final:

Final is used to apply restrictions on class, method and variable. Final class can’t be inherited, final method can’t be overridden and final variable value can’t be changed. Let’s take a look at the example below to understand it better.

class FinalVarExample {

public static void main( String args[])

{

final int a=10; // Final variable

a=50; //Error as value can't be changed

}

Finally

Finally is used to place important code, it will be executed whether exception is handled or not. Let’s take a look at the example below to understand it better.

class FinallyExample {

public static void main(String args[]){

try {

int x=100;

}

catch(Exception e) {

System.out.println(e);

}

finally {

System.out.println("finally block is executing");}

}}

}

Finalize

Finalize is used to perform clean up processing just before object is garbage collected. Let’s take a look at the example below to understand it better.

class FinalizeExample {

public void finalize() {

System.out.println("Finalize is called");

}

public static void main(String args[])

{

FinalizeExample f1=new FinalizeExample();

FinalizeExample f2=new FinalizeExample();

f1= NULL;

f2=NULL;

System.gc();

}

}

 125 views

26⟩ Explain me how to handle exceptions in Spring MVC Framework?

Spring MVC Framework provides the following ways to help us achieving robust exception handling.

☛ Controller Based:

We can define exception handler methods in our controller classes. All we need is to annotate these methods with @ExceptionHandler annotation.

☛ Global Exception Handler:

Exception Handling is a cross-cutting concern and Spring provides @ControllerAdvice annotation that we can use with any class to define our global exception handler.

☛ HandlerExceptionResolver implementation:

For generic exceptions, most of the times we serve static pages. Spring Framework provides HandlerExceptionResolver interface that we can implement to create global exception handler. The reason behind this additional way to define global exception handler is that Spring framework also provides default implementation classes that we can define in our spring bean configuration file to get spring framework exception handling benefits.

 133 views

28⟩ What is executeUpdate(String query)?

Statement executeUpdate(String query) is used to execute Insert/Update/Delete (DML) statements or DDL statements that returns nothing. The output is int and equals to the row count for SQL Data Manipulation Language (DML) statements. For DDL statements, the output is 0.

 145 views

29⟩ Explain me what are the differences between Checked Exception and Unchecked Exception?

Checked Exception:

☛ The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions.

☛ Checked exceptions are checked at compile-time.

☛ Example: IOException, SQLException etc.

Unchecked Exception:

☛ The classes that extend RuntimeException are known as unchecked exceptions.

☛ Unchecked exceptions are not checked at compile-time.

☛ Example: ArithmeticException, NullPointerException etc.

 152 views

31⟩ Do you know bean in Spring and List the different Scopes of Spring bean?

Beans are objects that form the backbone of a Spring application. They are managed by the Spring IoC container. In other words, a bean is an object that is instantiated, assembled, and managed by a Spring IoC container.

There are five Scopes defined in Spring beans.

☛ Singleton: Only one instance of the bean will be created for each container. This is the default scope for the spring beans. While using this scope, make sure spring bean doesn’t have shared instance variables otherwise it might lead to data inconsistency issues because it’s not thread-safe.

☛ Prototype: A new instance will be created every time the bean is requested.

☛ Request: This is same as prototype scope, however it’s meant to be used for web applications. A new instance of the bean will be created for each HTTP request.

☛ Session: A new bean will be created for each HTTP session by the container.

☛ Global-session: This is used to create global session beans for Portlet applications.

 130 views

32⟩ Explain me how to integrate Spring and Hibernate Frameworks?

We can use Spring ORM module to integrate Spring and Hibernate frameworks, if you are using Hibernate 3+ where SessionFactory provides current session, then you should avoid using HibernateTemplate or HibernateDaoSupport classes and better to use DAO pattern with dependency injection for the integration.

Also Spring ORM provides support for using Spring declarative transaction management, so you should utilize that rather than going for hibernate boiler-plate code for transaction management.

 129 views

33⟩ Can you name the different modules of the Spring framework?

Some of the important Spring Framework modules are:

☛ Spring Context – for dependency injection.

☛ Spring AOP – for aspect oriented programming.

☛ Spring DAO – for database operations using DAO pattern

☛ Spring JDBC – for JDBC and DataSource support.

☛ Spring ORM – for ORM tools support such as Hibernate

☛ Spring Web Module – for creating web applications.

☛ Spring MVC – Model-View-Controller implementation for creating web applications, web services etc.

 122 views

35⟩ Do you know what are the different methods of session management in servlets?

Session is a conversational state between client and server and it can consists of multiple request and response between client and server. Since HTTP and Web Server both are stateless, the only way to maintain a session is when some unique information about the session (session id) is passed between server and client in every request and response.

Some of the common ways of session management in servlets are:

☛ User Authentication

☛ HTML Hidden Field

☛ Cookies

☛ URL Rewriting

☛ Session Management API

 129 views

39⟩ Tell me how does cookies work in Servlets?

☛ Cookies are text data sent by server to the client and it gets saved at the client local machine.

☛ Servlet API provides cookies support through javax.servlet.http.Cookie class that implements Serializable and Cloneable interfaces.

☛ HttpServletRequest getCookies() method is provided to get the array of Cookies from request, since there is no point of adding Cookie to request, there are no methods to set or add cookie to request.

☛ Similarly HttpServletResponse addCookie(Cookie c) method is provided to attach cookie in response header, there are no getter methods for cookie.

 117 views

40⟩ Tell us what are some of the important Spring annotations which you have used?

Some of the Spring annotations that I have used in my project are:

☛ @Controller – for controller classes in Spring MVC project.

☛ @RequestMapping – for configuring URI mapping in controller handler methods. This is a very important annotation, so you should go through Spring MVC RequestMapping Annotation Examples

☛ @ResponseBody – for sending Object as response, usually for sending XML or JSON data as response.

☛ @PathVariable – for mapping dynamic values from the URI to handler method arguments.

☛ @Autowired – for autowiring dependencies in spring beans.

☛ @Qualifier – with @Autowired annotation to avoid confusion when multiple instances of bean type is present.

☛ @Service – for service classes.

☛ @Scope – for configuring scope of the spring bean.

☛ @Configuration, @ComponentScan and @Bean – for java based configurations.

AspectJ annotations for configuring aspects and advices, @Aspect, @Before, @After, @Around, @Pointcut etc.

 106 views