Vous êtes sur la page 1sur 4

Question: What is the immediate superclass of the Dialog class?

Answer: Window Question: What interface is extended by AWT event listeners? Answer: All AWT event listeners extend the java.util.EventListener interface. Question: Explain about Deadlock state of a thread Answer: Synchronizing run() is a good example of a simple deadlock scenario, where a thread is blocked forever, waiting for something to happen that can~t. Let~s look at a few examples that are more realistic than this. The most common deadlock scenario occurs when two threads are both waiting for each other to do something. The following (admittedly contrived) code snippet makes what~s going on painfully obvious: see code at: http://www.javagalaxy.com:8080/Threads/View.jsp?slno=3&tbl=0 Now, imagine a scenario whereby one thread (call it Wilma) calls fred(), passes through the synchronization of lock_1, and is then preempted, allowing another thread (call it Betty) to execute. Betty calls barney(), acquires lock_2, and tries to acquire lock_1, but can~t because Wilma has it. Betty is now blocked, waiting for lock_1 to become available, so Wilma wakes up and tries to acquire lock_2 but can~t because Betty has it. Wilma and Betty are now deadlocked. Neither one can ever execute. (Note that lock_1 and lock_2 have to be one-element arrays rather than simple ints, because only objects have monitors in Java; the argument to synchronized must be an object. An array is a firstclass object in Java; a primitive-type such as int is not. Consequently, you can synchronize on it. Moreover, a one-element array is efficient to bring into existence compared to a more elaborate object (like an Integer) since it~s both small and does not require a constructor call. Also, note that I can keep the reference to the lock as a simple Object reference, since I~ll never access the array elements. Question: What is a daemon thread? Answer: Daemon threads are service providers for other threads running in the same process as the daemon thread. When the only remaining threads in a process are daemon threads, the interpreter exits. This is because when only daemon threads remain, there is no other thread for which a daemon thread can provide a service. An example would be AWT-Event threads. Another example would be a mail daemon. When a mail message is recieved by a mail server it generally needs to be forwarded on to another machine. One way to do this is to have a daemon check for mail every so often and cause the mail to be forwarded. Uma

Comment title: same as the question You can make a thread daemon thread by using Java API. Thread.setDaemon(true). Daemon threads are primarily useful in standalone Java applications and in the implementation of the Java system itself, but not in applets. Since an applet runs inside of another Java application, any daemon threads it creates will continue to live until the controlling application exits--probably not the desired effect. Question: Can you explain the difference between green threads and native threads? Answer: Green threads is thread mechanism implemented in JVM itself. It is blind and can run on any OS, so actually all threads are run in one native thread and scheduling is up to JVM. This is disadvantageously for SMP systems, since only one processor can serve Java application. Native threads is a mechanism based on OS threading mechanism. This allows to use features of hardware and OS. For example,there is IBM~s JDK for AIX that supports native threads. The perfomance of applications can be highly imploved by this. Question: Can an Interface have an inner class? Answer: Yes public interface abc { static int i=0; void dd(); class a1 { a1() { int j; System.out.println("in interfia"); }; public static void main(String a1[]) { System.out.println("in interfia"); } } } Satish.b Comment title: excetion failure

I have run this program it is giving as no such method error main It is giving that error can u please tell me the correct way to run the program Regards

Satish.B Posted: Tue Apr 25 08:21:36 CDT 2006 Comment title: same as the question package corejava; public interface abc { static int i=0; void dd(); class a1 { a1() { int j; System.out.println("in interface"); }; public static void main(String a1[]) { System.out.println("in interface"); } } } /*execute this way * go one folder back * e.g. c:\code\corejava c:\code> java corejava.abc$a1 */ Posted: Wed Apr 26 04:31:00 CDT 2006 meera Comment title: its not working in net beans so let me know how to execute it.

Uma Maheswar

Question: What is Externalizable? Answer: Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)

Comment title: Externalizable, serialiazable

What is serializable, externazable. What purpose we can use it. It is related to database/programing. I am get some confusio two points.

Vous aimerez peut-être aussi