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: Test.java
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 :"+objA.name);
            objA.printMe();
      }

}

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

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");

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

     Output:
a==b
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 
 

   

 



TO BE CONTINUED.....  

65 comments:

  1. 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

    ReplyDelete
  2. 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

    ReplyDelete
  3. 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

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

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. I read your blog it's really good, thanks for sharing valuable information with us.
    Excellent Article, Nice to read your article, very informative.
    Excellent article Top AC mechanics Professional Camera sellers ChennaiCatering Service in ChennaiTop Educational Institute Chennai

    Excellent Article
    swimmingpool contractor chennai
    swimmingpool equipment dealer chennai
    swimmingpool consultant chennai

    ReplyDelete
  7. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.

    Best Java Training Institute Chennai


    ReplyDelete
  8. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    amazon-web-services-training-institute-in-chennai

    ReplyDelete
  9. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    https://bit.ly/2JbBPth

    ReplyDelete
  10. Outstanding blog post, I have marked your site so ideally I’ll see much more on this subject in the foreseeable future.

    java training in chennai | java training in bangalore

    java online training | java training in pune

    ReplyDelete
  11. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in Chennai | rpa training in pune

    rpa training in tambaram | rpa training in sholinganallur

    rpa training in Chennai | rpa training in velachery

    rpa online training | rpa training in bangalore

    ReplyDelete
  12. Good Post, I am a big believer in posting comments on sites to let the blog writers know that they ve added something advantageous to the world wide web.
    python training in rajajinagar
    Python training in btm
    Python training in usa

    ReplyDelete
  13. Really very nice blog information for this one and more technical skills are improve,i like that kind of post.
    DevOps online Training
    DevOps Training in USA

    ReplyDelete
  14. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.

    Best Selenium Training in Chennai | Selenium Training Institute in Chennai | Besant Technologies

    Selenium Training in Bangalore | Best Selenium Training in Bangalore

    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    ReplyDelete
  15. Thanks for sharing this valuable information to our vision. You have posted a worthy blog keep sharing.

    Guest posting sites
    Technology

    ReplyDelete
  16. Thank you for sharing such great information with us. I really appreciate everything that you’ve done here and am glad to know that you really care about the world that we live in
    Java training in Bangalore | Java training in Marathahalli | Java training in Bangalore | Java training in Btm layout

    Java training in Bangalore | Java training in Marathahalli | Java training in Bangalore | Java training in Btm layout

    ReplyDelete
  17. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
    Best Devops Training in pune | Java training in Pune

    ReplyDelete
  18. Fantastic work! This is the type of information that should follow collective approximately the web. Embarrassment captivating position Google for not positioning this transmit higher! Enlarge taking place greater than and visit my web situate
    Python training course in Chennai | Data science training in pune | Data science online training

    ReplyDelete
  19. You have provided a nice article, Thank you very much for this. I hope this will be useful for many people. Please keep on updating these type of blogs with good content.Thank You...
    aws online training
    aws training in hyderabad
    amazon web services(AWS) online training
    amazon web services(AWS) training online

    ReplyDelete
  20. Nice blog..! I really loved reading through this article. Thanks for sharing such
    a amazing post with us and keep blogging...Well written article Thank You for Sharing with Us pmp training Chennai | pmp training centers in Chenai | pmp training institutes in Chennai | pmp training and certification in Chennai | pmp training in velachery

    ReplyDelete
  21. You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us

    angularjs Training in bangalore

    angularjs interview questions and answers

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs-Training in pune

    ReplyDelete
  22. Thanks for such a great article here. I was searching for something like this for quite a long time and at last, I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays. Well written article Thank You for Sharing with Us pmp training fee | | project management training in chennai | project management certification online | project management course online |

    ReplyDelete
  23. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command
    python training institute in marathahalli
    python training institute in btm
    Python training course in Chennai

    ReplyDelete
  24. The great service in this blog and the nice technology is visible in this blog. I am really very happy for the nice approach is visible in this blog and thank you very much for using the nice technology in this blog
    fire and safety course in chennai

    ReplyDelete
  25. I am a regular reader of your blog and being students it is great to read that your responsibilities have not prevented you from continuing your study and other activities. Love

    DevOps Training in Bangalore

    DevOps Training in Bangalore

    DevOps Training in Bangalore

    DevOps Training in Marathahalli

    DevOps Training in Pune

    DevOps Online Training-gangboard

    ReplyDelete
  26. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  27. It would have been the happiest moment for you,I mean if we have been waiting for something to happen and when it happens we forgot all hardwork and wait for getting that happened.
    Microsoft Azure online training
    Selenium online training
    Java online training
    uipath online training
    Python online training


    ReplyDelete
  28. Great article, valuable and excellent article, lots of great information, thanks for sharing with peoples.


    Data Science in Bangalore

    ReplyDelete
  29. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

    ReplyDelete

  30. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.Data Science Courses

    ReplyDelete
  31. Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.
    ir 4.0 training in malaysia

    ReplyDelete
  32. Powerful contents are giving more ideas Regarding Technically...and it's used to enhance my knowledge...Keep doing this help ever
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

    ReplyDelete
  33. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
    hardware and networking training in chennai

    hardware and networking training in tambaram

    xamarin training in chennai

    xamarin training in tambaram

    ios training in chennai

    ios training in tambaram

    iot training in chennai

    iot training in tambaram

    ReplyDelete
  34. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
    web designing training in chennai

    web designing training in omr

    digital marketing training in chennai

    digital marketing training in omr

    rpa training in chennai

    rpa training in omr

    tally training in chennai

    tally training in omr

    ReplyDelete
  35. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area. data science training in Hyderabad

    ReplyDelete
  36. Thanks for provide great Information and looking beautiful blog, really nice required information & the things. I never imagined and i would request, right more blog and blog post like that for us. Thanks you once again
    Java Training in Chennai

    Java Training in Velachery

    Java Training in Tambaram

    Java Training in Porur

    Java Training in OMR

    Java Training in Annanagar


    ReplyDelete