50+ Java Interview Questions For Google, Microsoft & Adobe Q1. Can == be used on enum? Yes, enums have tight instance controls that allow you to use == to compare instances.
Q2.How can I synchronize two Java processes? It is not possible to do something like you want in Java. Different Java applications will use different JVM's fully separating themselves into different 'blackbox'es. However, you have 2 options:
Use sockets (or channels). Basically one application will open the listening socket and start waiting until it receives some signal. The other application will connect there, and send signals when it had completed something. I'd say this is a preferred way used in 99.9% of applications. You can call winapi from Java (on windows).
Q3. Difference between HashMap and Hashtable in Java? Though both HashMap and Hashtable are based upon hash table data structure, there are subtle differences between them. HashMap is non synchronized while Hashtable is synchronized and because of that HashMap is faster than Hashtable, as there is no cost of synchronization associated with it. One more minor difference is that HashMap allows a null key but Hashtable doesn't.
Q4. What is the difference between wait and notify in Java? Both wait and notify methods are used for inter-thread communication, where the wait is used to pause the thread on a condition, and notify is used to send a notification to waiting threads. Both must be called from synchronized context e.g. synchronized method or block.
Q5. Write a Java program to check if a number is Prime or not? A number is said prime if it is not divisible by any other number except itself. 1 is not considered prime, so your check must start with 2. The simplest solution of this to check every number until the number itself to see if it's divisible or not. When the Interviewer will ask you to improve, you can say