Sunday, 24 August 2014

Java / J2ee interview questions for experience java developer

Interview generally starts with:
                 *  Tell me about yourself.
                 * Tell me about your current project and your role in it. And few related questions on project, if he gets what you have explained.

       Then they start with core java. Be very much perfect in core java concepts, because this is the section which will decide your fate in interview. Even if you suck at j2ee part, and if you are very much good at core java concepts then consider you are almost in. Best book I suggest for core java preparation is SCJP (OCJP) by Kathy Sierra.  And following are few important questions for your quick review.

     Key point to remember:  Do not answer the question if you don’t know the answer. It’s better than answering it wrong.


Core Java interview questions for experienced developer:

  1.   Explain OOPS concepts with example.
  2.  What is difference between abstraction and encapsulation?
  3.  What is difference between abstract class and Interface?
  4.   What is polymorphism? Explain with example.
  5.   Can we override static method?
  6.  Can we overload the static method?
  7.  What is base class of java?And what methods it provides? Ans: It's Object and methods are : Clone(), equals(), hashCode(), finalize(), notify(), notifyAll(), wait(), toString()
  8. How variables are defined in interface and how to access it?
  9.  Explain System.out.println() in detail     
  10. What is final object in java? 
  11. What is static import in java?
  12. What is agreement between equals() and  hashcode() methods in java?
  13. What will print on console, if I don’t override toString() method and I pass object to  System.out.println()? Ans: If you don’t override toString() method & pass object to System.out.println(), then it will print classname followed by @ symbol, followed by unsigned hexadecimal representation of objects  hashcode. 

Now as you are 3+ years of experience, generally interviewers don’t ask you direct question. They might ask you to consider a scenario and asks questions in-between or expect you to correct him, if he is going wrong somewhere. Consider the following scenarios: 

Scenario 1:
I have two classes A & B. Where class B extends class A. And now I’m having one more Test class, to test it. Now I have created one reference of class B and provide it object of class A. Like, 
                  B obj = new A();   

Here, he expects you to correct him, that you cannot store object of parent class into reference of base class.

Scenario 2:
File name:
class A{
      String name = "Parent Class";
      public void printMe(){
            System.out.println("This is parent class");

class B extends A{
      String name = "Base Class";
      public void printMe(){
            System.out.println("This is base class");
public class Test {
      public static void main(String[] args) {
            A objA = new B();
            System.out.println("Name is :";


Now when I run this test class, what will be the output?

Name is :Parent Class
This is base class

Now few things to learn here:

      #   Java file may contain more than one class classes, but only one public class. And this public class name should be same as that of file name.
     #  Java provides method overriding but not variable overriding. That is why, when I print variable name, it will pick up the variable definition from the class of which reference is created i.e. A. And method of the class of which object is created i.e. B.


       Interview question on String class in Java:

  1. What is difference between String, StringBuffer and StingBuilder? In what scenarios they should be used?
  2. What is String.intern() method?
  3. What is mutable and immutable class? Where does String class belongs to? How to write immutable class
  4. What will be output for following:
String a = "abc";
            String b = "abc";
            String c = new String("abc");
            String d = new String("abc");

                  System.out.println("a equals b");
                  System.out.println("a equals c");
                  System.out.println("c equals d");

a equals b
a equals c
c equals d


Important point about String, you should know:

  1. String is final class, this means you cannot extend it or inherit it.
  2. String is immutable. This means, every time you assign value to it, it will be stored at new memory location.
  3. Whenever we assign value to String variable directly using double quote (without new keyword), it will check for that value in String pool and if it exists, it directly reference to that memory location without creating new one.
  4. And whenever we use new keyword, it creates new memory location to store that object.
  5. As we know == checks for memory location to compare, it will not return true for a==c & c==d  (.equals() method checks for value in object)


       Interview question on Serialization in Java: 

  1.  What is serialization? Why we use it? How did you use it? Short Ans : The primary purpose of serialization is to write an object into a stream, so that it can be transported through network and object can be rebuild from it on the other end. And other  purpose is to store state of object and retrieve it back. Or you can say to persist the object  across the sessions.
  2. I serialize the object which contains reference of non serialized object? Ans: No, it will throw nonSerializableException
  3. Explain steps of serialization
  4. What are transient variables?  Give real time example.  Ans:  Variables which you don't want to serialized are marked as transient. Example age in student object is kept transient, so as to it will be calculated on the basis of its birth date and current date comparison.
  5. Can we mark method as transient ? Ans: No 





  1. Tks very much for your post.

    Avoid surprises — interviews need preparation. Some questions come up time and time again — usually about you, your experience and the job itself. We've gathered together the most common questions so you can get your preparation off to a flying start.

    You also find all interview questions at link at the end of this post.

    Source: Top 10 interview questions and answers

    Best rgs

  2. Excellent post!!! Java is most popular and efficient programming language available in the market today. It helps developers to create stunning desktop/web applications loaded with stunning functionalities. Java Course in Chennai | Best JAVA Training in Chennai

  3. The future of automation testing tool is on the positive tool. As the demand of quality web application keeps on increasing, the tool like Selenium IDE is getting very popular all over the world. Thus, taking Selenium Training in Chennai will help you to enter software testing industry. Best Selenium training institute in Chennai

  4. wow really nice. It will be helpful for the people those who are ready to crack the interview and please also for remind what they have learned throughout concept.

    SEO Training in Chennai

  5. I just want to say I’m new to weblog and certainly savored this page. Almost certainly I’m likely to bookmark your website . You actually have outstanding well written articles. Cheers for sharing with us your website.

    Seo Training in Chennai

  6. After looking into this blog on your site, I really like your technique of writing a blog. I bookmarked it to my bookmarking site list and will be checking back it for my future reference. Take a look at my website as well and let me know your opinion.
    Android training in chennai>

  7. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

  8. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
    Digital Marketing Company in India

  9. Learning new technolgy would help oneself at hard part of their career. And staying updated is the only way to survive in current position. Your content tells the same. Thanks for sharing this information in here. Keep blogging like this. Android Training in Chennai

  10. Its very useful to me. Wonderful blog.. Thanks for sharing informative Post.

    Installment loans
    Payday loans
    Title loans


  11. Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much

    Personal Installment Loans
    Payday Cash Advance loan
    Title Car loan
    Cash Advance Loan

  12. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

  13. Candid institute Spring and Hibernate course provides a comprehensive introduction to Spring and Hibernate open source frameworks as well as Web Services and AJAX. Suitable for both Spring3/Hibernate3 and Spring4/Hibernate4, the course includes coverage of the core Spring and Hibernate capabilities, as well as the integration capabilities provided by Spring.
    Spring boot training

  14. The Spring Framework is a lightweight framework for developing Java enterprise applications. It provides high performing, easily testable and reusable code. Spring handles the infrastructure as the underlying framework so that you can focus on your application.Spring is modular in design, thereby making creation, handling and linking of individual components so much easier. Spring implements Model View Container(MVC) design pattern.
    spring mvc validation example

  15. Thanks for sharing this good blog.This is very important and imformative blog for Java . very interesting and usefulblog
    Java Online Training Hyderabad