Search This Blog

Tuesday, December 9, 2014

Java Interview Questions - II

Threads:
1. What happens when we call the start() method of a thread twice.
  i. What happens when we call the start() method again when the first thread is already running ?
  Ans: IllegalThreadStateException will be thrown
  ii. What happens when we call the start() method again after the first thread is completed ?
  Ans: The thread will be called again
2. What is the difference between calling the start() method and run() method directly ?
Ans: Calling start() method spawns a new thread while calling run() method just invokes the method as a normal method invocation
3. What is the difference between user threads and daemon threads ? Will JVM wait for the daemon thread when we use join method ?
4. What is Thread Executor framework ?

CSS:
1. What are the different ways we can specify a style ?
Ans: 1. Using # notation to style a single element referenced using id attribute
     2. Using . notation to style multiple elements specified using class attribute
     3. Using the element name directly
   
Javascript:
1. How to render an HTML table without using the table tag ?
2. How to send a request asynchronously ?
Ans. Using XMLHttpRequest i.e, using AJAX

Collections:
1. What is the difference between HashMap and ConcurrentHashMap ? Why should we use ConcurrentHashMap instead of Hashtable
2. What should be used to sort a list of objects when we need custom soring order ?
3. What method ArrayList uses internally to double its size ?
4. Is it possbile for 2 threads to access and modify a HashMap simultaneously, one adding and other removing the elements ?
5. Is iterator the only way to iterate elements in a HashMap or are there any alternatives to it ?

Servlets:
1. How to track a session in web application ?
Ans: Can use SessionBindingListener which has two callback methods namely : sessoionBound() and sessionUnbound()
2. How to cleanup the user session when the user logs out of a web application ?
Ans: Can use session.invalidate(). To do this automatically when a user closes the browser, there are 2 ways :
  i. Using session-timeout in web.xml
     <session-config>
      <session-timeout>10</session-timeout>
     </session-config>
  ii.Using setMaxInactiveInterval()
      HttpSession session = request.getSession();
      session.setMaxInactiveInterval(10*60);
Remember that i. is in minutes and ii. is in seconds

JSP:
1. Name the implicit objects in JSP :
Ans: application, session, request, response, page, pageContext, out, config and exception
2. What is the use of <%@ page session="false" %>
Ans: For JSPs, by default a session is automatically created for the request if one does not exist. So if your starting page is a JSP, a session would have already been created when you get the first request.

Linux/Unix:
1. Command to get all the running processes
Ans: Process status i.e, ps
2. Command to find the size of the directories
Ans: du
3. Command to find the size of the files in directory
Ans: ls -lah

Database:
1. What is Left outer join ?
2. Why do we use index ?
3. What is a view ? Can we update a view ?

Webservices:
1. What are the difference between SOAP and REST based webservices ? When should we use SOAP/REST ?
2. When the service is down and before hitting the service we want to validate and send a reponse to client saying the service is down please try after sometime ?
Ans: Using interceptors

Struts:
1. How to configure the validator framework in struts ?
2. How to handle double submits in struts ?
3. How to switch between locales ?
4. Can we have multiple action servlets in struts ?

Spring:
1. What are the different scopes in spring ?

No comments: