WorksheetsJAVA 4C123 3
Total questions: 55
Worksheet time: 41mins
How many ways a thread can be created in Java multithreading?
1
2
5
10
Which method is used to make main thread to wait for all child threads
Join ()
Sleep ()
Wait ()
Stop ()
Which will contain the body of the thread in Java?
Start()
Run()
Main()
Execute()
Thread priority in Java is?
Integer
Float
Double
Long
Q) What is maximum thread priority in Java
10
12
5
8
Q) Execution of a java thread begins on which method call?
Start ()
Run ()
Execute ()
Launch ()
Q) Which method is used to check if a thread is running?
isAlive()
run ()
alive ()
keepAlive()
Q) Min and Max priority of a thread in Java multithreading are
1, 10
0,10
0,255
1,256
1. The capability to control the access of multiple threads to any shared resource is called_____________
Synchronization
Multitasking
multithreading
None
Identify the correct mutual exclusion approach:
synchronized(this)
{
….
….
}
Synchronized method
Synchronized block
Static Synchronization
None
Identify the correct mutual exclusion approach:
synchronized static returntype method(parameters)
{
}
synchronized method
synchronized block
static synchronization
None
_____________tells calling thread to give up monitor and go to sleep until some other thread enters the same monitor and call notify.
wait()
notify()
notifyAll()
start()
______________wakes up a thread that called wait() on same object.
start()
run()
notify()
sleep()
_________wakes up all the threads that called wait() on same object.
notify()
notifyAll()
wait()
sleep()
wait() releases the lock on the shared resource.
True
False
What is multithreaded programming?
It’s a process in which two different processes run simultaneously
It’s a process in which two or more parts of same process run simultaneously
It’s a process in which many different process are able to access same information
It’s a process in which a single process can access information from many sources
What is the priority of the thread in the following Java Program?
class multithreaded_programing {
public static void main(String args[])
{
Thread t = Thread.currentThread(); System.out.println(t);
}
}
4
5
0
1
Which of these method of Thread class is used to find out the priority given to a thread?
get()
ThreadPriority()
getPriority()
getThreadPriority()
Which of this keyword must be used to inherit a class?
super
this
extends
extent
A class member declared protected becomes a member of subclass of which type?
public member
private member
protected member
static member
class A
{
int i;
void display()
{
System.out.println(i);
}
}
class B extends A
{
int j;
void display()
{
System.out.println(j);
}
}
class inheritance_demo
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
0
1
2
Compilation Error
What will be the output of the following Java program?
class A
{
int i;
}
class B extends A
{
int j;
void display()
{
super.i = j + 1;
System.out.println(j + " " + i);
}
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
2 2
3 3
2 3
3 2
Using which of the following, multiple inheritance in Java can be implemented?
Interfaces
Multithreading
Protected methods
Private methods
If super class and subclass have same variable name, which keyword should be used to use super class?
super
this
upper
classname
Which inheritance in java programming is not supported
Multiple inheritance using classes
Multiple inheritance using interfaces
Multilevel inheritance
Single inheritance
The following example shows the creation of a
import java.applet.*;
import java.awt.*;
public class Main extends Applet{
public void paint(Graphics g){
g.drawString("Welcome in Java Applet.",40,20);
}
}
a. Banner using Applet
b. Basic Applet
c. Display clock
d. None of the above
The APPLET tag is used to start an applet from both an HTML document and from an applet viewer.
a. True
b. False
What invokes immediately after the start() method and also any time the applet needs to repaint itself in the browser?
a. stop()
b. init()
c. paint()
d. destroy()
There are ................ methods of an applet life cycle.
2
5
7
9
The .......... method contains the actual code of the applet and starts the applet.
start()
stop()
destroy()
None
The .............. method destroys the applet after its work is done.
start()
stop()
destroy()
All
Whether JApplet is a Class or a Interface
Class
Interface
It is a special Concept
None of the options
Graphics Class is belongs to which package
which method(s) belongs to Graphics class
drawString()
drawLine()
drawCircle()
drawMyShape
which of the following method will execute first
init()
start()
paint()
Which of the following layouts would be good to use for GUI that resembles a computer keyboard?
Flow Layout
Border Layout
Grid Layout
Null Layout
Which components are needed to get above shown output
TextField, Label
List, Button
Choice, Button
Button, TextField
Observe the following code
What will be the output of the above program?
The output is obtained in Frame with two layouts: Frame layout and Flow Layout.
The output is obtained in Applet with two layouts: Frame layout and Flow Layout.
The output is obtained in Applet with two layouts: Frame layout and Border Layout.
The output is obtained in Applet with two layouts: Border layout and Flow Layout.
Which components are needed to get above shown output
Menu, MenuItem, MenuBar, Frame
List, Label, MenuItem ,MenuBar
Choice, MenuItem, TextField, MenuBar
Label, Frame, Button, MenuBar
Which components are used in the above output?
Applet, Label
Label, TextField, Button
Applet, Button
Grid Layout, Label, Button
Select the proper output for following code
To get the following output complete the below code
importjava.awt.*;
importjavax.swing.*;
/*
<applet code="jscroll" width=300 height=250>
</applet>
*/
public class jscroll extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
}
}
// Add panel to a scroll pane
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPanejsp = new JScrollPane(jp, v, h);
// Add scroll pane to the content pane
contentPane.add(jsp, BorderLayout.CENTER);
}
}
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
JPanel jp = new JPanel();
jp.setLayout(new GridLayout(20, 20));
int b = 0;
for(int i = 0; i < 20; i++) {
for(int j = 0; j < 20; j++) {
jp.add(new JButton("Button " + b));
++b;
JPaneljp = new JPanel();
jp.setLayout(new GridLayout(3,3));
int b = 0;
for(int i = 0; i <3; i++) {
for(int j = 0; j <3; j++) {
jp.add(new JButton("Button " + b));
++b;
Which class can be used to represent a checkbox with a textual label that can appear in a menu?
MenuBar
MenuItem
CheckboxMenuItem
Checkbox
Menu
Which layout manager places components in one of five regions: north, south, east, west, and center?
BorderLayout
GridLayout
FlowLayout
CardLayout
Which class encapsulate AWT related events?
AWTEvent
Event
Which class dispatches events to multiple listeners?
AWTEventMulticaster
EventMulticaster
AWTMulticaster
AWTEvent
Which LayoutManager emulate index cards and only one on the top is showing?
CardLayout
GridLayout
GridBagLayout
FlowLayout
________ creates a POP-UP list with single selection and single visible item only.
Choice
List
What code adds this JButton to this JPanel?
JPanel panel = new JPanel();
JButton button = new JButton();
panel.add(button);
button.add(panel);
frame.add(panel);
panel.add(JButton);
What object type handles Java's layouts?
Layout Manager
Layout Scheduler
Layout Operator
Layout Director
How can we figure out which button was clicked inside our actionPerformed?
e.getSource()
e.getSource
getSource()
getButtonClicked()
e.getButtonClicked()
Which method do we use to put text onto a panel?
g.drawString(...)
g.setText(...)
g.setColor(...)
g.fillRect(...)
What are the different types of controls in AWT?
Labels
Checkboxes
List
All the choice
Give the abbreviation of AWT?
Applet Windowing Toolkit
Abstract Windowing Toolkit
Absolute Windowing Toolkit
None of the above
