Sponsored Links

Ad by Google
In my previous post, I have listed top 20 Exception handling interview questions here and 15 core java written interview questions for product based companies. Today, I have decided to post java,j2ee interview questions in different sets and each set will contain exactly 10 questions, which is similar to real time interview questions. The questions are based on real time interview experienced, and its for java,j2ee interview, that means combination of core java+hibernate+spring+algorithm+Design pattern etc. all about the real time interview question and based on real time pattern.
If you are going for java,j2ee profile with Spring+Hibernate+Web Service than this set of questions is all yours.

1. Brief down your role and responsibilities, and what type of project you are working on.
Interviewer start looking into your resume and asked this questions,This is very first question you will faced in any interview, and its your job to tell about your role(s) and designation in your current organization, possible that sometimes your designation is Senior Software Engineer but you are playing two different roles developer as well as sometime you also lead your team in absence of your team lead, so tell all these to the interviewer with smiley :)face.
After that, tell about your current project, what is the main concept(business) of your project, than what was your role in that project as well as what are the different tools and technologies you are using on that project. If you have done anything special on that project than don't forget to remind that.
2. Can you list down the methods of java.lang.Object class
Most of the time interviewer start with this question, even I also ask this question in almost every interviews to check the basic ideas of parent class.Once you listed the methods of Object class, interviewer start asking about any of the methods in details, below are the list of methods of java.lang. Object class.
  1. toString() (read more)
  2. getClass() (read more)
  3. hashCode() (read more)
  4. equals(Object) (read more)
  5. finalize()
  6. clone()
  7. notify()
  8. notifyAll()
  9. wait()
  10. wait(long)
  11. wait(long,int)
After listing, most of the time interviewer ask you about the contracts of equals() and hashCode() methods, or why thread related methods are in java.lang.Object class like wait and notify. So you have to be very much clear about all these methods of object class not only for the interview purpose but for their usage also because this is the parent class in java and everywhere you will face this types of questions. I request you to go get dig into into the deep of each of these methods you can follow my methods of java.lang.Object class tutorial also.

3. What is immutable? Why String is immutable?
Another very hot question in any java interview, every interviewer ask you this question and this is really a very very demanding question or you can say its a ever green java interview question just like how to balance parenthesis using java program with o(n) time complexity.
So before going for an interview, you must have to be very clear about immutable and why immutable required?
Well Immutable means, Object's can be change after its construction. An object consider immutable if its state cannot be change after it is constructed. In jdk very popular immutable classes are String, Integer, Double etc.
That's why String is very popular in java, and of course it has few advantages having immutable compared to mutable object and below are those key advantage -
  • String Constant Pool
  • Security
  • Synchronization
  • Class loading
  • Efficiency
Immutable object are particularly useful in concurrent application, you can read more about the above each points in detail from my separate post called secret of String.
4. What is BlockingQueue?
This question is very effective in threading/collection topic and particularly asked in product based companies. If you are looking for high payee and more secure job than product based company will be your choice and to crack the product based companies interview you have to be very very good in data structure and threading.
Well java.util.concurrent.BlockingQueue is an interface and extends Queue and of course Queue extends Collections, that means its a collection and based on first-in-first-out data structure.
The BlockingQueue was added in JDK 5 and specially design for thread safe producer consumer problem, where one thread is producing and another thread is consuming the resource produced by producer thread.
The various implementation of BlockingQueue is available with different advantages/disadvantages and those are listed below -
  1. ArrayBlockingQueue - Since Java 1.5
  2. LinkedBlockingDeque - Since Java 1.6
  3. LinkedBlockingQueue - Since Java 1.5
  4. LinkedTransferQueue - Since Java 1.7
  5. PriorityBlockingQueue - Since Java 1.5
  6. SynchronousQueue - Since Java 1.5
  7. DelayQueue - Since Java 1.5

5. What are the core classes and interfaces of Hibernate?
Yes, interviewer will not ask you more than 5-6 question related to core java after that, discussion will moves into different technologies like hibernate,spring,ws etc. If it start with Hibernate than most probably it will start with what is difference between get and load method or with this question.

Well Hibernate is a very popular ORM framework and of course each framework has their own core classes and interfaces. Interviewer just want to check your core concept of hibernate and knowledge of basics of hibernate. And of course Hibernate has few core classes and interfaces without them hibernate is nothing, so you have to be very very clear about these api's and their usage, below are the few core classes and interfaces of Hibernate.
  • Configuration (class)
  • ServiceRegistry (interface)
  • SessionFactory (interface)
  • Session (interface)
  • Transaction (interface)
  • Query (interface)
Once you listed the above APIs, next question will be any of the above in details like what is SessionFactory or difference between Session and SessionFactory etc. you can read in details about the above APIs from core classes and interface of Hibernate.

6. What is Second Level Cache in Hibernate and how to configure it?
Ah! you cannot ignore this question and you cannot attend any java,j2ee interview without this topic, so better to instead of reading theory, I would request you to do a quick practical implementation of the second level cache which will helps you to provide more informative regarding this topic.

Second Level Cache - In hibernate second level cache means SessionFactory level cache, and Session is by default first level cache of persistent data. If you need to configure cluster or JVM level cache in your application, than you can use the SessionFactory level cache, cache is used in any application to improve the performance of the application by reducing database hit. To configure second level cache, you need at least one cache provider and than you need to enabled the second level cache in your configuration file very popular cache provider used in any application is EhCacheProvider, must read one of the excellent tutorial on How To Configure Second Level Cache. Once you go through with the above link, I am damn sure no one can beat you in second level cache discussion.
7. What are the different bean scope in Spring?
This question is related to Spring framework and no one can say that, I didn't asked this question in java, j2ee interview. All interviewer will asked this question and start digging into the deep of any of the scope mostly about the default scope and why its default or when global session is used etc.
Well five different types of scope of a spring bean and these are -
  1. Singleton (default) - single object(bean) instance per Spring IOC container.
  2. Prototype - return new object(bean) instance by IOC container in each request.
  3. Request - single object(bean) instance per HTTP request.
  4. Session - single object(bean) instance per HTTP session.
  5. Global Session - single object(bean) instance per global session(used in portlet application).

8. What are differences between ApplicationContext and BeanFactory?
One of the popular question in spring interview, and very basics of spring framework, you can say these are the heart of spring framework. Before going to any interview, be very very clear about the basic nuts and bolts of the frameworks. Of course one of my favorite j2ee interview question, ApplicationContext and BeanFactory both are interfaces provided by spring framework and treated as IOC container. Below are the few key differences between these two interfaces.

  1. The BeanFactoy is the root interface for accessing a Spring bean container and provides basic configuration functionality, whereas ApplicationContext extends BeanFactory interface, and also provides some advance features like configuration of AOP.
  2. The ApplicationContext supports internationalization, event propagation whereas BeanFactory does not support these features
  3. The BeanFactory usage less memory as compared to ApplicaitonContext..
  4. By default ApplicationContext will pre-initialize the beans whereas BeanFactory will lazy initialization.

9. Have you used Design Pattern? What is builder design pattern?
In every java, j2ee interview you will faced at least 1-2 questions related to design patterns, So be prepared with few popular design patterns like singleton, prototype, factory, builder, facade,decorator etc.
Builder design pattern - The design patterns are categorized into different categories and one of the category is object creation pattern, and builder pattern is categorized in object creation pattern. So its all about how object created, although singleton, prototype, factory etc. all are object creation pattern but the work of builder pattern is totaly different than above listed.
Builder pattern is all about solving the problem of telescoping constructor ant-pattern problem. The telescoping constructor ant-pattern occurs when you have huge number of parameters in constructor. Its error prone to maintain  the huge number of parameters in constructor, so instead of constructor it will create another class which will treated as builder, and the job of builder to receive the parameters one by one and construct the object, you can visit my post builder design pattern, to get it in more detail with code example.
Below are the few builder pattern APIs in jdk -
  • java.lang.StringBuilder#append()
  • java.lang.StringBuffer#append()
  • java.nio.ByteBuffer#put()

10. Can you list down few design pattern used in jdk or example of design patterns used in jdk libraries.
Below are the few examples of design patterns used in  jdk libraries -
Abstract Factory Design Patterns -
  • javax.xml.parsers.DocumentBuilderFactory#newInstance()
  • javax.xml.xpath.XPathFactory#newInstance()
Builder Design Patterns -
  • java.lang.StringBuilder#append()
  • java.lang.StringBuffer#append()
Factory Design Patterns -
  • java.util.Calendar#getInstance()
  • java.text.NumberFormat#getInstance()
Singleton Design Patterns - 
  • java.lang.Runtime#getRuntime()
  • java.awt.Desktop#getDesktop()
Adapter Design Patterns -
  • java.util.Arrays#asList()
  • java.io.InputStreamReader(InputStream)

Sponsored Links


Post a Comment