Java最难的常见面试题

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 help to answer such tough core java interview question. See this blog post to learn Why to wait and notify is declared in Object class and not in Thread. Read more: http://www.java67.com/2012/09/top-10-tough-core-java-interview-questions-answers.html#ixzz5B5z2H1pr
<p><strong>Why wait and notify is declared in Object class instead of Thread ?</strong><br />
Another <a href="http://javarevisited.blogspot.sg/2011/04/top-20-core-java-interview-questions.html">tough java question</a>, how can you answer this question if you are not designed Java programming language. anyway, some common sense and deep knowledge of Java programming help to answer such tough core java interview question. See this blog post to learn <a href="http://javarevisited.blogspot.sg/2012/02/why-wait-notify-and-notifyall-is.html">Why to wait and notify is declared in Object class and not in Thread</a>.<br />
<br />
<br />
<strong>Why is multiple inheritances not supported in Java ?</strong><br />
I found this <em>core Java question</em> 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. The key to answering this kind of tough question in Java is to prepare topic well to accommodate any follow-ups. See <a href="http://javarevisited.blogspot.sg/2011/07/why-multiple-inheritances-are-not.html">Why multiple inheritances are not supported in Java</a> for an answer of this tough Java question.<br />
<br />
<br />
<strong>Why does Java not support operator overloading ?</strong><br />
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 sometimes even say that + operator is overloaded in Java for String concatenation, Don't be fooled by such arguments. See <a href="http://javarevisited.blogspot.sg/2011/08/why-java-does-not-support-operator.html">Why to support operator overloading is not supported in Java</a> for detailed answer of this tricky Java question.<br />
<br />
<strong>Why is String immutable in Java?</strong><br />
My favorite Java interview question, this is tough, tricky but same time very useful as well. Some interviewer also asks this question as Why String is final in Java. look at this post for some points which make sense on <a href="http://javarevisited.blogspot.sg/2010/10/why-string-is-immutable-in-java.html">Why String is final or immutable in Java</a><br />
<br />
<strong>Why char array is preferred to store password than String in Java?</strong><br />
Another <a href="http://javabuddy.hubpages.com/hub/10-most-tricky-question-in-java">tricky Java question</a> which is based on String and believe me there is only few Java programmer which can answer this question correctly. This is a real <em>tough core Java interview question</em> and again the solid knowledge of String is required to answer this. see <a href="http://javarevisited.blogspot.sg/2012/03/why-character-array-is-better-than.html">Why char array is better than String for storing the password in Java</a> to find out the answer to this tough Java question.<br />
<br />
<strong>How to create a thread-safe singleton in Java using double-checked locking?</strong><br />
<a href="http://2.bp.blogspot.com/-OQ_wj5FWmqY/UC-TYphU4pI/AAAAAAAAAds/jUe8AnHTiSo/s1600/50x50.gif"><img alt="Tough core Java interview questions and answers" src="https://2.bp.blogspot.com/-OQ_wj5FWmqY/UC-TYphU4pI/AAAAAAAAAds/jUe8AnHTiSo/s1600/50x50.gif" /></a>This Java question is also asked as What is a <a href="http://javarevisited.blogspot.sg/2012/01/how-to-write-thread-safe-code-in-java.html">thread-safe</a> singleton and how to do you write it. Well, Singleton created with double checked locking before Java 5 was a broker and it's possible to have multiple instances of Singleton if multiple threads try to create an instance of Singleton at the same time. from Java 5 it's easy to <a href="http://javarevisited.blogspot.gr/2012/07/why-enum-singleton-are-better-in-java.html">create thread-safe Singleton using Enum</a>. but if interviewer persists with double checked locking then you have to write that code for them. remember to use a volatile variable. See <a href="http://javarevisited.blogspot.sg/2011/03/10-interview-questions-on-singleton.html">10 Java singleton interview question</a> for more details on this topic.<br />
<br />
<strong>Write Java program to create a deadlock in Java and fix it ?</strong><br />
One of the classical but t<em>ough core Java interview question</em> and you are likely to fail if you have not involved in the coding of multi-threaded concurrent Java application. See <a href="http://javarevisited.blogspot.sg/2010/10/what-is-deadlock-in-java-how-to-fix-it.html"> how to create and prevent deadlock in Java</a> for complete answer of this tough core Java interview question<br />
<br />
<strong>What happens if your Serializable class contains a member which is not serializable? How do you fix it?</strong><br />
Any attempt to Serialize that class will fail with NotSerializableException, but this can be easily solved by making that variable <a href="http://javarevisited.blogspot.sg/2011/09/transient-keyword-variable-in-java.html">transient </a>for static in Java. See <a href="http://javarevisited.blogspot.sg/2011/04/top-10-java-serialization-interview.html">Top 10 Serialization interview question answers in Java</a> for more details.<br />
<br />
<br />
<br />
<strong>Why wait and notify called from synchronized method in Java?</strong><br />
Another tough core Java question for the wait and notify. They are called from <a href="http://javarevisited.blogspot.sg/2011/04/synchronization-in-java-synchronized.html">synchronized method or synchronized block</a> because wait and modify need monitor on Object on which wait or notify-get called. See <a href="http://javarevisited.blogspot.sg/2011/05/wait-notify-and-notifyall-in-java.html">Why to wait and notify require synchronized context</a> for a complete answer to this<em> tough and tricky Java multi-threading question</em>.<br />
<br />
<strong>Can you override static method in Java? if I create the same method in the subclass is it compile time error?</strong><br />
No, you can not override <a href="http://javarevisited.blogspot.sg/2011/11/static-keyword-method-variable-java.html">static method in Java</a> but it's not a compile-time error to declare an exactly same method in a subclass, That is called method hiding in Java. See <a href="http://java67.blogspot.sg/2012/08/can-we-override-static-method-in-java.html">Can you override static method in Java</a> for a complete answer to this tough Java interview question.<br />
<br />
These were my list of <strong>tough core Java interview question and answers</strong>. Some of the Java questions doesn't look that tough for experienced programmer but they are really <em>tricky </em>to answer for intermediate and beginners in Java. by the way, if you have faced any tough Java question in an interview then please share with us.<br />
<br />
Read more: <a href="http://www.java67.com/2012/09/top-10-tough-core-java-interview-questions-answers.html#ixzz5B5z4QttN">http://www.java67.com/2012/09/top-10-tough-core-java-interview-questions-answers.html#ixzz5B5z4QttN</a></p>
评论 (0)
加载评论中…