Sunday, September 2, 2012

Top 10 tough core Java interview questions answers programming

tough core Java interview questions and answers
What is tough core java interview question ? Why do people look for tough Java questions before going for interview? well I don't thing I need to answer these tough questions because its pretty natural to prepare for tough questions even if you are not expecting tough questions from core Java. If you are prepare for tough and tricky Java interview question than you feel more confident and answer other Java interview question with confidence. On the other hand if you are not prepare for tough and tricky core Java questions than seeing them on Java interview or written test may surprise you. But definition of tough core Java questions is not universal, same Java question which is easy for one programmer might be tough for other Java programmer. That's why it's best to prepare your own list of tough interview questions before appearing on any Java job interview. In this article I am going to share you with my Top 10 tough core Java interview questions and answers, which may help you in Java interview.


10 tough Java interview question and answer

Tough core Java interview questions and answersHere is my list of 10 tough or tricky Java interview questions. These questions are mostly from Core Java and I have not included J2EE questions. As I said you may know answers of these tough Java question or you may not even find it tough enough to challenge your Java knowledge but once upon a time these were asked in various Java interview and many programmer including my friends and colleagues finds them tough to answer.



Why wait and notify is declared in Object class instead of Thread ?
Another tough java question, how can you answer this question if you are not designed Java programming language. anyway some common sense and deep knowledge of Java programming helps to answer such tough core java interview question. See this blog post to learn  Why wait and notify is declared in Object class and not in Thread.


Why multiple inheritance is not supported in Java ?
I found this core Java question really tough to answer because your answer may not satisfy Interviewer, in most cases Interviewer is looking for specific points and if you can bring them, they would be happy. Key to answer this kind of tough question in Java is to prepare topic well to accommodate any follow-ups. See Why multiple inheritance is not supported in Java for answer of this tough Java question.


Why Java does not support operator overloading ?
One more similar category of  tough Java question. C++ supports operator overloading than why not Java? this is the argument Interviewer will give to you and some time even say that + operator is overloaded in Java for String concatenation, Don't be fooled with such arguments. See  Why support operator overloading is not supported in Java for detailed answer of this tricky Java question.

Why String is immutable in Java?
My favorite Java interview question, this is tough, tricky but same time very useful as well. Some interviewer also ask this question as Why String is final in Java. look at this post for some points which make sense on Why String is final or immutable in Java

Why char array is preferred to store password than String in Java?
Another tricky Java question which is based on String and believe me there are only few Java programmer which can answer this question correctly. This is a real tough core Java interview question and again solid knowledge of String is required to answer this. see Why char array is better than String for storing password in Java to find out answer of this tough Java question.

How to create thread-safe singleton in Java using double checked locking?
This Java question is also asked as What is thread-safe singleton  and how to do you write it. Well Singleton created with double checked locking before Java 5 was broker and its possible to have multiple instance of Singleton if multiple thread try to create instance of Singleton at same time. from Java 5 its easy to create thread safe Singleton using Enum. but if interviewer persist with double checked locking then you have to write that code for them. remember to use volatile variable.  See 10 Java singleton interview question for more details on this topic.

Write Java program to create deadlock in Java and fix it ?
One of the classical but tough core Java interview question and you are likely to fail if you have not involved in coding of multi-threaded concurrent Java application. See  how to create and prevent deadlock in Java for complete answer of  this tough core Java interview question

What happens if your Serializable class contains a member which is not  serializable? How do you fix it?
Any attempt to Serialize that class will fail with NotSerializableException, but this can be easily solved by making that variable transient for static in Java. See Top 10 Serialization interview question answers in Java for more details.



Why wait and notify  called from synchronized method in Java?
Another tough core Java question for wait and notify. They are called from synchronized method or synchronized block because wait and modify need monitor on Object on which wait or notify get called. See  Why wait and notify require synchronized context for complete answer of this tough and tricky Java multi-threading question.

Can you override static method in Java? if I create same method in subclass is it compile time error?
No you can not override static method in Java but its not a compile time error to declare exactly same method in sub class, That is called method hiding in Java. See  Can you override static method in Java for complete answer of this tough Java interview question.

These were my list of tough core Java interview question and answers. Some of the Java question doesn't look that tough for experience programmer but they are really tricky to answer for intermediate and beginners in Java. by the way if you have faced any tough Java question in interview then please share with us.

9 comments:

  1. nice blog... self explanatory... :)

    ReplyDelete
  2. Very very good compilation of all good questions.. Thanks. Wish me luck for my interviews ..

    ReplyDelete
  3. Most of the tough questions I faced on programming interviews are from Data Structure and algorithm. Only difficulty arise on complex Java topics like classloaders, socket programming and multithreading. Since, no body ask question from Swing or AWT, those are useless topics to prepare for Java interviews.

    ReplyDelete
  4. I conduct a lot of Java interviews, and I wouldn't ask more than one or two of these questions. If someone can't explain why Java doesn't use operator overloading, maybe the candidate never used C++ and doesn't have a clue what it is. How many people use serialization? I have, but not often. We've got a couple sharp guys who have never used it, but if they had to, they'd have it figured out in no time. The important questions are about software structure, and class design. A person can write perfectly functioning software with a terrible design, and that is the danger. For example if you asked me "How do you create a thread-safe singleton in Java using double-checked locking?" I'd say, "I'm not going to create a singleton. Using global state is a bad design."

    ReplyDelete
    Replies
    1. You nailed it. Testing abilities which is core to programming and software development should be focus of any interview, be it Java, C++ or anything. If a guy had experience in software development, class design, concurrency, data structures and algorithms, he is going to add value in team. Knowing some bits and pieces of Java questions is much easier than to develop skills needed for good software development and maintenance.

      Delete
    2. Yes I too believe interviewers should focus more on candidates ability to design , logic/Algo used for the design and the approach for coding it out. A candidate should have good learning acumen as well because given any new laguage, tool or FW he/she should start using their fundamentals to develop good software products.

      Delete
    3. Completely agree. A lot of time on interview people ask questions on remebering. Why do I need to remember thing, however I am capable of solving porblems and quickly figured thibgs that I never used before. So if somebody asked me questions on remebering I even do not want to work with them.

      Delete
  5. Good collection!! Keep improving .. Add some tough questions from Collections too.

    ReplyDelete

Java67 Headline Animator