Java programming interview questions – New list
I am trying to put here some less discussed interview questions on java, as recruiters have become intelligent and changed their question patterns little different. Questioned asked during interview for a 2 years of experienced person compared to 4+ varies greately, in former people check mostly knowledge of oops and ability of do basic programming , but in case of more experienced programmers they can ask intricate details of java programming and questions related to frameworks.
General / Core Java Questions
1. How is IP address of client/user machine detected at server side.
A. Servlet request parameter holds this information ip = request.getRemoteAddress();
2. Static and dynamic class loading
A. Static loading : new MyClass() & dynamic loading : Class.forName(“com.example.ClassName”);
3. Use cases for java annotations
A. Compile time code error checking for example @Override,
4. How does web container talks to other application in same container?
5. If you are using a non-string class as key in java Collection for storing objects, what goes in hashCode() and equals() method for that class.
A. equals() will return your ctieria for search match for example, in get(), delete(), methods of your collection, hashCode() should return untique number for that object it can be additional int/long id field for that class. For more information Implementing hashCode() and equals() in your classes
6. Why it is recommended to use Serial version uid for Serializable classes in java
A. During reading and writing serializable objects in bytestream same class definition must be used whose object is being written and read,, take an example when an object is serialized using a class which is later updated and when you try to read old bytes back it can cause serious problems so each time you update a class you also update serial version uid this will throw run time exception and thus prevents any wrong results.
7. What is thread pooling and how we can control it in Apache Tomcat Server
A. Thread pooling is creating fixed number of thread initially when application is loaded and all subsequent requests are handled by spare threads instead of creating new threads for every new request, if no threads are available request will go into ques, this helps in lowering server loads, number of active thread in pool can be configured at server.xml file namely with “maxThreads” and “minSpareThreads”.
8. Why is factory pattern used in java
A. Instead of using “new” operator for creating objects of a class one can use Factory method where attributes of resulting objects are not known until runtime, A Factory class is used for this whose static method for example Factory.create(“animal-type”) can return objects from Dog, Cat or Horse class depending on conditions but because all of them belong to super class Animal we can assign something like Animal a = Factory.create(“type”).
Another example who have used GWT (Google Web Toolkit) framework uses frequently GWT.create(“classname”)
Framework Related Questions
1. In strut2 list the functionality offered by default and commonly created interceptors
A. ParametersInterceptor invokes setter method of an Action class, validation, workflow,
2. What are Entity types in hibernate and how one can use them to find records.
A.
3. What are HQL Query in Hybernate
A. It is short for Hybernate Query language it is more powerful than normal SQL for example it supports Object oriented relationships, it is shorter and case sensitive example “from User” brings list of all users or “from User WHERE id=123″ etc
External reference
http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs.php [Hibernate Interview Questions]