Ut 2 JPR (314317) (Set 1) Model Answer
Ut 2 JPR (314317) (Set 1) Model Answer
Instructions:
1. All questions are compulsory
2. Illustrate your answer with neat sketches wherever necessary
3. Figures to the right indicate full marks
4. Assume suitable data if necessary
5. Preferably, write the answers in sequential order
Q.1. Attempt any FIVE of the following 10
Q.N TL
Question CO
o. O
a Define Thread Priority.
Ans:-In java each thread is assigned a priority which affects the order in
which it is scheduled for running.Thread priority is used to decide when to
switch from one running thread to another. Threads of same priority are
given equal treatment by the javascheduler.
3.4 3
Thread priorities can take value from 1-10. Thread class defines
defaultpriority constant values as
MIN_PRIORITY=1
NORM_PRIORITY=5(DefaultPriority)
MAX_PRIORITY = 10
b Enlist any 2 Event class and Event listener Interface. 4.5 4
ans:-
Event class:-
1.Action event class
2.Item event class
3. Key event class
4. Mouse event class
5. text event class
Q.N TL C
Question
o. O O
a Explain Event Handling in java. 4.4 4
ans:-In Java, event handling is the mechanism by which a program responds
to user actions or system events, such as button clicks, mouse movements, or
keyboard input, using the Delegation Event Model. It consists of four main
components:
1. Event Source
2. Event Object
3. Event Listener
4. Event Handler
1.Events:
2. Event Sources:
3.Event Listeners:
A listener is an object that listens for events and responds when the event
occurs.
ActionListener
MouseListener
KeyListener
4. Event Handler:
The event handler is the method that executes when an event occurs.
Event listeners implement specific interfaces and override methods to define
event-handling behavior.
The listener implements the Listener Interface and defines the event-
handling method.
t.start();
3. Running State
When a thread is in the Running state, it means the CPU has given it time to
execute.
The thread keeps running until:
o It voluntarily gives up control (for example, by calling yield()).
o A higher-priority thread takes over and interrupts it (preemption).
4. Blocked State:-
A thread can be temporarily suspended or blocked from entering into
the runnable and running state by using either of the following
thread method.
o suspend() : Thread can be suspended by this method. It can be
rescheduled by resume().
o wait(): If a thread requires to wait until some event occurs, it can be
done using wait method and can be scheduled to run again by
notify().
o sleep(): We can put a thread to sleep for a specified time period
using sleep(time) where time is in ms. It reenters the runnable state
as soon as period has elapsed /over.
5. Dead State:-
1. Border Layout:-
o The BorderLayout is used to arrange the components in five
regions: north, south, east, west, and center.
o Each region (area) may contain one component only. It is the
default layout of a frame or window.
o The BorderLayout provides five constants for each region:
public static final int NORTH
public static final int SOUTH
public static final int EAST
public static final int WEST
public static final int CENTER
Constructors
BorderLayout(): creates a border layout but with no gaps between the
components.
BorderLayout(int hgap, int vgap): creates a border layout with the
given horizontal and vertical gaps between the components.
Note: BorderLayout is the default layout manager for a JFrame's
content pane.
Example:-
Uses of JTree:
Example:-
f Write a java program in which thread A will display the even numbers 3.3 3
in between 1 to 20 and thread B will display odd numbers in between 1
to 20.
Ans:-
g Write a program to retrieve Host name and IP address using
InetAddress
Class.
Ans:-
5.2 5