Thursday, October 25, 2007

Java Interview Questions -Part 13


16. What is synchronization and why is it important?
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.
________________________________________
17. What are synchronized methods and synchronized statements?
Synchronized methods are methods that are used to control access to 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.
________________________________________
18. What are three ways in which a thread can enter the waiting state?
A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O, 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.
________________________________________
19. Can a lock be acquired on a class?
Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.
________________________________________
20. What's new with the stop(), suspend() and resume() methods in JDK 1.2?
The stop(), suspend() and resume() methods have been deprecated in JDK 1.2.
________________________________________
21. What is the preferred size of a component?
The preferred size of a component is the minimum component size that will allow the component to display normally.
________________________________________
22. What method is used to specify a container's layout?
The setLayout() method is used to specify a container's layout.
________________________________________
23. Which containers use a FlowLayout as their default layout?
The Panel and Applet classes use the FlowLayout as their default layout.
________________________________________
24. What is thread?
A thread is an independent path of execution in a system.
________________________________________
25. What is multithreading?
Multithreading means various threads that run in a system.
________________________________________
26. How does multithreading take place on a computer with a single CPU?
The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.
________________________________________
27. How to create multithread in a program?
You have two ways to do so. First, making your class "extends" Thread class. Second, making your class "implements" Runnable interface. Put jobs in a run() method and call start() method to start the thread.
________________________________________
28. Can Java object be locked down for exclusive use by a given thread?
Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it.
________________________________________
29. Can each Java object keep track of all the threads that want to exclusively access to it?
Yes.
________________________________________
30. What state does a thread enter when it terminates its processing?
When a thread terminates its processing, it enters the dead state.
________________________________________
31. What invokes a thread's run() method?
After a thread is started, via its start() method of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.
________________________________________
32. What is the purpose of the wait(), notify(), and notifyAll() methods?
The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to communicate each other.
________________________________________
33. What are the high-level thread states?
The high-level thread states are ready, running, waiting, and dead.
________________________________________
34. What is the Collections API?
The Collections API is a set of classes and interfaces that support operations on collections of objects.
________________________________________
35. What is the List interface?
The List interface provides support for ordered collections of objects.
________________________________________
36. How does Java handle integer overflows and underflows?
It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
________________________________________
37. What is the Vector class?
The Vector class provides the capability to implement a growable array of objects
________________________________________
38. What modifiers may be used with an inner class that is a member of an outer class?
A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
________________________________________
39. If a method is declared as protected, where may the method be accessed?
A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared

0 comments:

Advertisement

 

Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com