10 points about wait(), notify() and notifyAll() in Java Thread?

If you ask me one concept in Java which is so obvious yet most misunderstood, I would say the wait(), notify() and notifyAll() methods. They are quite obvious because they are the one of the three methods of total 9 methods from java.lang.Object but if you ask when to use the wait(), notify() and notfiyAll() in Java, not many Java developer can answer with surety. The number will go down dramatically if you ask them to solve the producer-consumer problem using wait() and notify(). Many will use if block instead of while loop, many others will get confused on which object they should call wait() and notify()method? Some of them even succeed in creating livelock, deadlock, and other multithreading issues.

9 difference between static vs non-static method in Java [Interview Question]

One of the key differences between a static and a non-static method is that the static method belongs to a class while the non-static method belongs to the instance. This means you can call a static method without creating an instance of the class by just using the name of the class like the  Math.random() for creating random numbers in Java. Often utility methods that don't use the member variables of the class are declared static. On the other hand, you need an instance of the class to call a non-static method in Java. You cannot call it without creating an object because they are dependent upon the member variables which have different values for different instances.

Difference between StringIndexOutOfBoundsException and ArrayIndexOutOfBoundsException in Java

Though both StringIndexOutOfBoundsException and ArrayIndexOutOfBoundsException are children of IndexOfBoundsException class, former is thrown by methods of String and related class (e.g. StringBuffer and StringBuilder) to indicate that an index is either negative or greater than the size of the String, or more general not valid. For example, charAt() method throws StringIndexOutOfBoundsException when an index is equal to the length of String? why? because String is backed by character array where index starts at 0 and ends at length -1. The ArrayIndexOutOfBoundsException is  also quite similar to former but thrown by code which deals with array access to indicate that array is accessed by invalid index. The index is either negative or greater than or equal to the length of the array.