Set - 1

Question 21 :

What's the difference between an interface and an abstract class?

Answer :

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 :

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


Question 23 :

What do you understand by Synchronization?

Answer :

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 :

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 :

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.