Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JAVA 4C123 3

Total questions: 55

Worksheet time: 41mins

Name
Class
Date
1.

How many ways a thread can be created in Java multithreading?

a)

1

b)

2

c)

5

d)

10

2.

Which method is used to make main thread to wait for all child threads

a)

Join ()

b)

Sleep ()

c)

Wait ()

d)

Stop ()

3.

Which will contain the body of the thread in Java?

a)

Start()

b)

Run()

c)

Main()

d)

Execute()

4.

Thread priority in Java is?

a)

Integer

b)

Float

c)

Double

d)

Long

5.

Q) What is maximum thread priority in Java

a)

10

b)

12

c)

5

d)

8

6.

Q) Execution of a java thread begins on which method call?

a)

Start ()

b)

Run ()

c)

Execute ()

d)

Launch ()

7.

Q) Which method is used to check if a thread is running?

a)

isAlive()

b)

run ()

c)

alive ()

d)

keepAlive()

8.

Q) Min and Max priority of a thread in Java multithreading are

a)

1, 10

b)

0,10

c)

0,255

d)

1,256

9.
Which of these is not a Thread state?
a)
New
b)
Runnable
c)
sleep
d)
terminated
10.

1. The capability to control the access of multiple threads to any shared resource is called_____________

a)

Synchronization

b)

Multitasking

c)

multithreading

d)

None

11.

Identify the correct mutual exclusion approach:

synchronized(this)

{

….

….

}

a)

Synchronized method

b)

Synchronized block

c)

Static Synchronization

d)

None

12.

Identify the correct mutual exclusion approach:

synchronized static returntype method(parameters)

{

}

a)

synchronized method

b)

synchronized block

c)

static synchronization

d)

None

13.

_____________tells calling thread to give up monitor and go to sleep until some other thread enters the same monitor and call notify.

a)

wait()

b)

notify()

c)

notifyAll()

d)

start()

14.

______________wakes up a thread that called wait() on same object.

a)

start()

b)

run()

c)

notify()

d)

sleep()

15.

_________wakes up all the threads that called wait() on same object.

a)

notify()

b)

notifyAll()

c)

wait()

d)

sleep()

16.

wait() releases the lock on the shared resource.

a)

True

b)

False

17.

What is multithreaded programming?

a)

It’s a process in which two different processes run simultaneously

b)

It’s a process in which two or more parts of same process run simultaneously

c)

It’s a process in which many different process are able to access same information

d)

It’s a process in which a single process can access information from many sources

18.

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);

}

}

a)

4

b)

5

c)

0

d)

1

19.

Which of these method of Thread class is used to find out the priority given to a thread?

a)

get()

b)

ThreadPriority()

c)

getPriority()

d)

getThreadPriority()

20.

Which of this keyword must be used to inherit a class?

a)

super

b)

this

c)

extends

d)

extent

21.

A class member declared protected becomes a member of subclass of which type?

a)

public member

b)

private member

c)

protected member

d)

static member

22.

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();

}

}

a)

0

b)

1

c)

2

d)

Compilation Error

23.

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();

}

}

a)

2 2

b)

3 3

c)

2 3

d)

3 2

24.

Using which of the following, multiple inheritance in Java can be implemented?

a)

Interfaces

b)

Multithreading

c)

Protected methods

d)

Private methods

25.

If super class and subclass have same variable name, which keyword should be used to use super class?

a)

super

b)

this

c)

upper

d)

classname

26.

Which inheritance in java programming is not supported

a)

Multiple inheritance using classes

b)

Multiple inheritance using interfaces

c)

Multilevel inheritance

d)

Single inheritance

27.

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)

a. Banner using Applet

b)

b. Basic Applet

c)

c. Display clock

d)

d. None of the above

28.

The APPLET tag is used to start an applet from both an HTML document and from an applet viewer.

a)

a. True

b)

b. False

29.

What invokes immediately after the start() method and also any time the applet needs to repaint itself in the browser?

a)

a. stop()

b)

b. init()

c)

c. paint()

d)

d. destroy()

30.

There are ................ methods of an applet life cycle.

a)

2

b)

5

c)

7

d)

9

31.

The .......... method contains the actual code of the applet and starts the applet.

a)

start()

b)

stop()

c)

destroy()

d)

None

32.

The .............. method destroys the applet after its work is done.

a)

start()

b)

stop()

c)

destroy()

d)

All

33.

Whether JApplet is a Class or a Interface

a)

Class

b)

Interface

c)

It is a special Concept

d)

None of the options

34.

Graphics Class is belongs to which package

a)

javax.applet

c)

java.awt

35.

which method(s) belongs to Graphics class

a)

drawString()

b)

drawLine()

c)

drawCircle()

d)

drawMyShape

36.

which of the following method will execute first

a)

init()

b)

start()

c)

paint()

37.

Which of the following layouts would be good to use for GUI that resembles a computer keyboard?

a)

Flow Layout

b)

Border Layout

c)

Grid Layout

d)

Null Layout

38.

Which components are needed to get above shown output

a)

TextField, Label

b)

List, Button

c)

Choice, Button

d)

Button, TextField

39.

Observe the following code

What will be the output of the above program?

a)

The output is obtained in Frame with two layouts: Frame layout and Flow Layout.

b)

The output is obtained in Applet with two layouts: Frame layout and Flow Layout.

c)

The output is obtained in Applet with two layouts: Frame layout and Border Layout.

d)

The output is obtained in Applet with two layouts: Border layout and Flow Layout.

40.

Which components are needed to get above shown output

a)

Menu, MenuItem, MenuBar, Frame

b)

List, Label, MenuItem ,MenuBar

c)

Choice, MenuItem, TextField, MenuBar

d)

Label, Frame, Button, MenuBar

41.

Which components are used in the above output?

a)

Applet, Label

b)

Label, TextField, Button

c)

Applet, Button

d)

Grid Layout, Label, Button

42.

Select the proper output for following code

a)
b)
c)
d)
43.

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);

}

}

a)

Container contentPane = getContentPane();

contentPane.setLayout(new BorderLayout());

b)

JPanel jp = new JPanel();

jp.setLayout(new GridLayout(20, 20));

c)

int b = 0;

for(int i = 0; i < 20; i++) {

for(int j = 0; j < 20; j++) {

jp.add(new JButton("Button " + b));

++b;

d)

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;

44.

Which class can be used to represent a checkbox with a textual label that can appear in a menu?

a)

MenuBar

b)

MenuItem

c)

CheckboxMenuItem

d)

Checkbox

e)

Menu

45.

Which layout manager places components in one of five regions: north, south, east, west, and center?

a)

BorderLayout

b)

GridLayout

c)

FlowLayout

d)

CardLayout

46.

Which class encapsulate AWT related events?

a)

AWTEvent

b)

Event

47.

Which class dispatches events to multiple listeners?

a)

AWTEventMulticaster

b)

EventMulticaster

c)

AWTMulticaster

d)

AWTEvent

48.

Which LayoutManager emulate index cards and only one on the top is showing?

a)

CardLayout

b)

GridLayout

c)

GridBagLayout

d)

FlowLayout

49.

________ creates a POP-UP list with single selection and single visible item only.

a)

Choice

b)

List

50.

What code adds this JButton to this JPanel?

JPanel panel = new JPanel();

JButton button = new JButton();

a)

panel.add(button);

b)

button.add(panel);

c)

frame.add(panel);

d)

panel.add(JButton);

51.

What object type handles Java's layouts?

a)

Layout Manager

b)

Layout Scheduler

c)

Layout Operator

d)

Layout Director

52.

How can we figure out which button was clicked inside our actionPerformed?

a)

e.getSource()

b)

e.getSource

c)

getSource()

d)

getButtonClicked()

e)

e.getButtonClicked()

53.

Which method do we use to put text onto a panel?

a)

g.drawString(...)

b)

g.setText(...)

c)

g.setColor(...)

d)

g.fillRect(...)

54.

What are the different types of controls in AWT?

a)

Labels

b)

Checkboxes

c)

List

d)

All the choice

55.

Give the abbreviation of AWT?

a)

Applet Windowing Toolkit

b)

Abstract Windowing Toolkit

c)

Absolute Windowing Toolkit

d)

None of the above