1. What is executeQuery(String query)?
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”.
2. Do you know what is JSON? Can you represent JSON as Java Object?
JSON stands for Javascript object notation and is used to initialize Javascript objects. Yes it can be used as Java object also. Provide more info here
3. Tell me how do you differentiate between Core Java and Enterprise Java?
Core Java is something that provides the API's like regular expression, String handling, collections. But enterprise java involves writing scalable, secure and per-formant applications which can have large user base.
4. Explain me what do you mean by batch processing in JDBC?
Batch processing helps you to group related SQL statements into a batch and execute them instead of executing a single query. By using batch processing technique in JDBC, you can execute multiple queries which makes the performance faster.
5. Tell us how to disable caching on back button of the browser?
<%
response.setHeader(“Cache-Control”,”no-store”);
response.setHeader(“Pragma”,”no-cache”);
response.setHeader (“Expires”, “0”); //prevents caching at the proxy server
%>
6. Explain me what is the purpose of JDBC ResultSet interface?
The ResultSet object represents a row of a table. It can be used to change the cursor pointer and get the information from the database.
7. What is 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.
8. Explain me what is JDBC Connection interface?
The Connection interface maintains a session with the database. It can be used for transaction management. It provides factory methods that returns the instance of Statement, PreparedStatement, CallableStatement and DatabaseMetaData.
9. Tell us what is a finally block? Is there a case when finally will not execute?
Finally block is a block which always executes a set of statements. It is always associated with a try block regardless of any exception that occurs or not.
Yes, finally will not be executed if the program exits either by calling System.exit() or by causing a fatal error that causes the process to abort.
10. Do you know what is the difference between frameworks like Jquery/DOJO and AJAX?
Jquery and DOJO are java script frameworks for writing rich web applications but AJAX is a server communication mechanism which can issue requests without page reload.
11. Tell us how is JSP better than Servlet technology?
JSP is a technology on the server's side to make content generation simple. They are document centric, whereas servlets are programs. A Java server page can contain fragments of Java program, which execute and instantiate Java classes. However, they occur inside HTML template file. It provides the framework for development of a Web Application.
12. Explain me what is the role of JDBC DriverManager class?
The DriverManager class manages the registered drivers. It can be used to register and unregister drivers. It provides factory method that returns the instance of Connection.
13. Tell us what is JDBC DatabaseMetaData interface?
The DatabaseMetaData interface returns the information of the database such as username, driver name, driver version, number of tables, number of views etc.
14. Explain me what do you generally do after you have resolved a problem?
Perform the Root Cause Analysis and make sure the changes done have not effected any other module.
15. Do you know what is synchronization?
Synchronization refers to multi-threading. A synchronized block of code can be executed by only one thread at a time. As Java supports execution of multiple threads, two or more threads may access the same fields or objects. Synchronization is a process which keeps all concurrent threads in execution to be in sync. Synchronization avoids memory consistency errors caused due to inconsistent view of shared memory. When a method is declared as synchronized the thread holds the monitor for that method's object. If another thread is executing the synchronized method the thread is blocked until that thread releases the monitor.
16. Please explain why should we not configure JSP standard tags in web.xml?
We don't need to configure JSP standard tags in web.xml because when container loads the web application and find TLD files, it automatically configures them to be used directly in the application JSP pages. We just need to include it in the JSP page using taglib directive.
In case you are facing any challenges with these java interview questions, please comment your problems in the section below. Apart from this Java Interview Questions Blog.
17. Do you know the role of DispatcherServlet and ContextLoaderListener?
☛ DispatcherServlet is basically the front controller in the Spring MVC application as it loads the spring bean configuration file and initializes all the beans that have been configured. If annotations are enabled, it also scans the packages to configure any bean annotated with @Component, @Controller, @Repository or @Service annotations.
☛ ContextLoaderListener, on the other hand, is the listener to start up and shut down the WebApplicationContext in Spring root. Some of its important functions includes tying up the lifecycle of Application Context to the lifecycle of the ServletContext and automating the creation of ApplicationContext.
18. Tell me what are the steps to connect to a database in java?
☛ Registering the driver class
☛ Creating connection
☛ Creating statement
☛ Executing queries
☛ Closing connection
19. Do you know what is a Spring?
Wikipedia defines the Spring framework as “an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE platform.” Spring is essentially a lightweight, integrated framework that can be used for developing enterprise applications in java.
20. Tell me how to delete a Cookie in a JSP?
The following code explain how to delete a Cookie in a JSP :
Cookie mycook = new Cookie("name1","value1");
response.addCookie(mycook1);
Cookie killmycook = new Cookie("mycook1","value1");
killmycook . set MaxAge ( 0 );
killmycook . set Path ("/");
killmycook . addCookie ( killmycook 1 );
21. Tell me what are the reasons for a page not found error and how will you sort it out?
☛ 1) The URL being sent is wrong
☛ 2) The web.xml mapping is wrong
☛ 3) The web server is down
☛ 4) The application has not been deployed
22. 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.
23. Tell us what kind of HTTP request does the <a href="url">text</a> generate?
It will generate HTTP GET request
24. What is void printStackTrace()?
This method prints the stack trace information to the standard error stream.
25. Tell me what steps will you take for ensuring the proper security of an web application?
Stuff like Encryption, Authentication and Authorization
26. What is synchronized Throwable getCause()?
This method returns the cause of the exception or null id as represented by a Throwable object.
27. 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.
28. Explain me what is JDBC ResultSetMetaData interface?
The ResultSetMetaData interface returns the information of table such as total number of columns, column name, column type etc.
29. 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
30. 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.
31. 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.
32. 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.
☛ 1) Server not starting up. Proper heap size not set
☛ 2) Migrating from JBoss to Weblogic. Wrote a number of XML configurations
1) Check if the customer has not done any customizations
2) Provide a test build same as running at my end (ask customer to take a backup of their app)
35. What is string getMessage()?
This method returns the message String about the exception . The message can be provided through its constructor.