Basic Java Interview Question and Answers

61. What is a Runtime class?
  The runtime class encapsulates the runtime environment. You cannot instantiate a runtime object. However, you can get a reference to the current runtime object by calling the static method Runtime.getRuntime(). Once a reference to the current runtime object is obtained, you can call several methods that control the state and behavior of the JVM.
 
Your Name Your Email-ID
Your Answer
62. How do the threads communicate with each other in multithreaded programming?
  The threads can communicate with each other using the inter process communication mechanism via the wait(), notify(), and notifyAll() methods.
  • wait() tells the calling thread to give up the monitor and go to sleep until some other thread enters the same monitor and calls notify().
  • notify() wakes up the first thread that called wait() on the same object.
  • notifyAll() wakes up all the threads that called wait() on the same object. The highest priority thread will run first.
 
Your Name Your Email-ID
Your Answer
63. Can I have multiple main methods in the same class?
  No the program fails to compile. The compiler says that the main method is already defined in the class.
 
Your Name Your Email-ID
Your Answer
64. Can an application have multiple classes having main method?
  Yes, it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.
 
Your Name Your Email-ID
Your Answer