• +91 9723535972
  • info@interviewmaterial.com

Java Interview Questions and Answers

Java Interview Questions and Answers

Question - 21 : - What's the difference between an interface and an abstract class?

Answer - 21 : - An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

Question - 22 : - Name the containers which uses Border Layout as their default layout?

Answer - 22 : - Containers which uses Border Layout as their default are: window, Frame and Dialog classes.

Question - 23 : - What do you understand by Synchronization?

Answer - 23 : - Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption. E.g. Synchronizing a function: public synchronized void Method1 () { // Appropriate method-related code. } E.g. Synchronizing a block of code inside a function: public myFunction (){ synchronized (this) { // Synchronized code here. } }

Question - 24 : - What is synchronization and why is it important?

Answer - 24 : - With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often causes dirty data and leads to significant errors.

Question - 25 : - What are synchronized methods and synchronized statements?

Answer - 25 : - Synchronized methods are methods that are used to control access to a method or an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

Question - 26 : - What are three ways in which a thread can enter the waiting state?

Answer - 26 : - A thread can enter the waiting state by invoking its sleep() method, by blocking on IO, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.

Question - 27 : - Can a lock be acquired on a class?

Answer - 27 : - Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.

Question - 28 : - What's new with the stop(), suspend() and resume() methods in JDK 1.2?

Answer - 28 : - The stop(), suspend() and resume() methods have been deprecated in JDK 1.2.

Question - 29 : - What is the preferred size of a component?

Answer - 29 : - The preferred size of a component is the minimum component size that will allow the component to display normally.

Question - 30 : - What's the difference between J2SDK 1.5 and J2SDK 5.0?

Answer - 30 : - There's no difference, Sun Microsystems just re-branded this version.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners