Core Java - Interview Questions and Answers

81. What is the class and interface in java to create thread and which is the most advantageous method?

Ans: Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.

82. When you will synchronize a piece of your code?

Ans: When you expect your code will be accessed by different threads and these threads may change a particular data causing data corruption.

83. What is daemon thread and which method is used to create the daemon thread?

Ans: Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.

84. Are there any global variables in Java, which can be accessed by other part of your program?

Ans: No, it is not the main method in which you define variables. Global variables are not possible because concept of encapsulation is eliminated here.

85. What is the difference between applications and applets?

a)Application must be run on local machine whereas applet needs no explicit installation on local machine.
b)Application must be run explicitly within a java-compatible virtual machine whereas applet loads and runs itself automatically in a java-enabled browser.
d)Application starts execution with its main method whereas applet starts execution with its init method.
e)Application can run with or without graphical user interface whereas applet must run within a graphical user interface.

86. How does applet recognize the height and width?

Ans:Using getParameters() method.

87. When do you use codebase in applet?

Ans:When the applet class file is not in the same directory, codebase is used.

88. How do you set security in applets?

Ans: using setSecurityManager() method

89. What is an event and what are the models available for event handling?

Ans: An event is an event object that describes a state of change in a source. In other words, event occurs when an action is generated, like pressing button, clicking mouse, selecting a list, etc. There are two types of models for handling events and they are:

a) event-inheritance model and b) event-delegation model

90. What is source and listener ?

source : A source is an object that generates an event. This occurs when the internal state of that object changes in some way.

listener : A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific types of events. Second, it must implement methods to receive and process these notifications.



Post a Comment

Mới hơn Cũ hơn