Saturday, September 24, 2011

15 Must Know Java Interview Questions After 2 Years of Experience


Interview Questions that every developer should have the answer

Enterprise Java Application development is growing every day and new features being introduced but the the beginners have always start from the basics. The questions listed below are what in general a Java developer should be able to answer after 2 years of experience. (Assuming no prior exposure to Java)



Core Java
1) What is the purpose of serialization?
2) What is the difference between JDK and JRE?
3) What is the difference between equals and ==?
4) When will you use Comparator and Comparable interfaces?
5) What is the wait/notify mechanism?
6) What is the difference between checked and unchecked exceptions?
7) What is the difference between final, finally and finalize?
JEE
8) What is the difference between web server and app server?
9) Explain the Struts1/Struts2/MVC application architecture?
10) What is the difference between forward and sendredirect?
General
11) How does a 3 tier application differ from a 2 tier one?
12) How does the version control process works?
13) What is the difference between JAR and WAR files?
Databases
14) What is a Left outer join?
15) What is the difference between UNION and UNION ALL?

15 Interview Questions for JEE Web Application Developer


1) How do you differentiate between Core Java and Enterprise Java?
Expected Ans: 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.

2) What do you generally do after you have resolved a problem?
Expected Ans: Perform the Root Cause Analysis and make sure the changes done have not effected any other module.

3) What is JSON? Can you represent JSON as Java Object?
Expected Ans: 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

4) What kind of HTTP request does the <a href="url">text</a> generate?
Expected Ans: It will generate HTTP GET request

5) What are the common browser issues you will keep in mind while creating a web application?
Expected Ans:
1) User pressing back/refresh button
2) Browser crashing
3) Session issues
4) Compatibility across web browsers

6) What steps will you take for ensuring the proper security of an web application?
Expected Ans: Stuff like Encryption, Authentication and Authorization

7) The Server and Database are working fine at your end but not on customer machine. What will you do?
Expected Ans:
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)
3) Check out how the customer is using the application


8) A web application is running but pages are loading slow. How will you figure out what the problem is?
Expected Ans: Look for threading, database, caching issues.

9) What is the difference between frameworks like Jquery/DOJO and AJAX?
Expected Ans: 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.

10) What are the reasons for a page not found error and how will you sort it out?
Expected Ans:
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

11) How will you know whether a Java file is a servlet or not?
Expected Ans: It will extend from HttpServlet class

12) When will you use Servlet and JSP or MVC framework?

Expected Ans: While framework provides a number of components and allows one to concentrate more on the business logic but Servlets and JSP are used for controller and view layer respectively.

13) What are the common issues you have faced in web applications and how did you resolve them?
Expected Ans:
1) Server not starting up. Proper heap size not set
2) Migrating from JBoss to Weblogic. Wrote a number of XML configurations
Any other generic problems faced during development/support


14) How do you keep yourself updated about the latest web technologies?
Expected Ans: Whatever websites/blogs/forums/authors you follow.

15) What was the last technical book you read?
Expected Ans: Whatever you have read

Friday, September 23, 2011

Tricky Java Interview Questions


Here are some Java interview questions which are un-common

1) What is the performance effect of a large number of import statements which are not used?
Ans: They are ignored if the corresponding class is not used.


2) Give a scenario where hotspot will optimize your code?
Ans: If we have defined a variable as static and then initialized this variable in a static block then the Hotspot will merge the variable and the initialization in a single statement and hence reduce the code.

3) What will happen if an exception is thrown from the finally block?
Ans: The program will exit if the exception is not catched in the finally block.


4) How does decorator design pattern works in I/O classes?
Ans: The various classes like BufferedReader , BufferedWriter workk on the underlying stream classes. Thus Buffered* class will provide a Buffer for Reader/Writer classes.


5) If I give you an assignment to design Shopping cart web application, how will you define the architecture of this application. You are free to choose any framework, tool or server?
Ans: Usually I will choose a MVC framework which will make me use other design patterns like Front Controller, Business Delegate, Service Locater, DAO, DTO, Loose Coupling etc. Struts 2 is very easy to configure and comes with other plugins like Tiles, Velocity and Validator etc. The architecture of Struts becomes the architecture of my application with various actions and corresponding JSP pages in place.

6) What is a deadlock in Java? How will you detect and get rid of deadlocks?
Ans: Deadlock exists when two threads try to get hold of a object which is already held by another object.


7) Why is it better to use hibernate than JDBC for database interaction in various Java applications?
Ans: Hibernate provides an OO view of the database by mapping the various classes to the database tables. This helps in thinking in terms of the OO language then in RDBMS terms and hence increases productivity.

8) How can one call one constructor from another constructor in a class?
Ans: Use the this() method to refer to constructors.

9) What is the purpose of intern() method in the String class?
Ans: It helps in moving the normal string objects to move to the String literal pool


10) How will you make your web application to use the https protocol?
Ans: This has more to do with the particular server being used than the application itself. Here is how it can be done on tomcat: