WorksheetsAdvance Java Unit-1 and 2
Total questions: 94
Worksheet time: 47mins
What is a thread in Java?
A program
A process
Smallest unit of execution
A class
Every Java program starts with which thread?
Child thread
User thread
Main thread
Daemon thread
Which method starts a new thread?
run()
init()
start()
execute()
Which method contains code executed by a thread?
start()
run()
main()
stop()
Calling run() directly will:
Create new thread
Stop JVM
Act like normal method
Cause error
How many ways are there to create a thread in Java?
1
2
3
4
Which interface is used to create a thread?
Serializable
Cloneable
Runnable
Callable
Thread priority range is:
0–5
1–10
1–5
0–10
Default thread priority is:
1
3
5
10
Which method pauses thread execution?
stop()
wait()
sleep()
join()
sleep() method throws:
IOException
RuntimeException
InterruptedException
NullPointerException
Which method waits for another thread to finish?
sleep()
wait()
join()
stop()
setDaemon(true) means:
Thread becomes main
Thread becomes background
Thread stops
JVM stops
JVM exits when:
Main thread ends
Only daemon threads remain
Any thread ends
Garbage collector runs
Which method checks thread status?
isAlive()
isRunning()
isActive()
status()
Which keyword prevents data inconsistency?
final
static
synchronized
volatile
Synchronization is used to:
Increase speed
Stop threads
Control shared resource access
Create threads
wait() method:
Stops thread permanently
Releases lock and waits
Sleeps thread
Ends thread
notify() method:
Stops all threads
Wakes all threads
Wakes one waiting thread
Pauses thread
notifyAll() wakes:
One thread
Main thread
All waiting threads
Daemon thread
Window is a:
Container
Layout
Listener
Event
Window has title bar?
Yes
No
Frame is subclass of:
Panel
Window
Applet
Dialog
Frame supports menu bar?
Yes
No
Which package contains Frame class?
java.io
java.util
java.awt
javax.swing
setSize() method is used for:
Visibility
Color
Window size
Layout
setVisible(true) makes frame:
Close
Hidden
Appear
Resize
Which is top-level container?
Button
Label
Frame
TextField
Graphics class is used to:
Handle events
Draw shapes
Store data
drawLine() draws:
Circle
Rectangle
Line
Text
Which method draws text?
drawText()
print()
drawString()
write()
Which class handles colors?
Paint
RGB
Color
Graphics
Color.RED represents:
Green
Blue
Red
Black
FontMetrics gives:
Font style
Font size only
Font measurements
Font color
stringWidth() returns:
Height
Width of string
Font size
Color
Label is used for:
Input
Display text
Click
Scroll
Button generates:
ItemEvent
MouseEvent
ActionEvent
KeyEvent
Checkbox allows:
Single selection
Multiple selection
No selection
Text input
Scrollbar is used for:
Text input
Navigation
Display
Click
TextField allows:
Multi-line input
Single-line input
No input
Image input
TextArea supports:
Single line
Multiple lines
Images
Buttons
TextArea belongs to:
java.io
java.sql
java.awt
java.net
Checkbox default state can be:
Only false
Only true
True or false
Null
Layout manager arranges:
Threads
Windows
Components
Events
setLayout(null) means:
Automatic layout
Grid layout
Manual positioning
Flow layout
Button is clickable component?
Yes
No
Label is editable?
Yes
No
Scrollbar can be:
Vertical only
Horizontal only
Both
None
AWT stands for:
Abstract Window Toolkit
Advanced Window Tool
Application Window Tool
Automatic Window Toolkit
AWT is:
Platform independent
Platform dependent
Both
Event handling in Button uses:
KeyListener
ActionListener
MouseListener
WindowListener
TextField fires event on:
Mouse click
Scroll
Enter key
Resize
Frame close button belongs to:
Window
Frame
Panel
Applet
GUI components belong to:
java.lang
java.util
java.awt
java.io
Which control is read-only?
TextField
TextArea
Label
Checkbox
Java Applet runs inside:
JVM only
Command prompt
Web browser
Server
Which method is called only once in applet life cycle?
start()
paint()
init()
destroy()
Which method is used to draw graphics in applet?
draw()
display()
paint()
show()
Applet does NOT have which method?
init()
start()
main()
destroy()
Which method is called when applet becomes visible?
init()
start()
paint()
stop()
Applet extends which class?
Frame
Panel
Applet
Window
Applet uses which default layout?
BorderLayout
GridLayout
FlowLayout
Null
Applet security restriction is:
Can access local file
Can run OS commands
Cannot access local file
Can shut down system
Which tag was originally used for applet in HTML?
<java>
<applet>
<object>
<script>
Which method is called when browser closes applet?
stop()
destroy()
init()
paint()
Applet programming is:
Server side
Client side
Database side
Compiler side
Which method stops applet temporarily?
destroy()
stop()
init()
Applet runs without main() because:
Browser controls execution
JVM blocks it
Compiler ignores it
OS controls it
Applet is:
Console based
GUI based
Database based
Text based
Swing classes are present in which package?
java.awt
java.io
javax.swing
java.util
Swing components are:
Heavyweight
Lightweight
OS dependent
Hardware dependent
Which is a Swing top-level container?
JPanel
JButton
JFrame
JLabel
JButton generates which event?
ItemEvent
ActionEvent
WindowEvent
MouseEvent
Which component is used to display text in Swing?
JButton
JTextField
JLabel
JTextArea
JTextField allows:
Multiple line input
Image input
Single line text
Table data
Which component is used for password input?
JTextArea
JTextField
JPasswordField
JLabel
JCheckBox allows:
Only one selection
Multiple selections
No selection
Text entry
JRadioButton is used with:
JPanel
JFrame
JMenuBar is added to:
JPanel
JFrame
JButton
JTextArea
JOptionPane is used for:
Database
File handling
Dialog boxes
Layout
JTable is used to display:
Images
Buttons
Tabular data
Text only
Swing follows which architecture?
Client-server
MVC
Monolithic
Procedural
Swing is built on top of:
JavaFX
AWT
Applet
Servlet
Swing application starts execution from:
init()
start()
main()
paint()
Which component supports multiple lines of text?
JTextField
JLabel
JTextArea
JButton
Which Swing component displays list of items?
JTable
JList
JComboBox
JMenu
JComboBox is also called:
Text box
Drop-down list
Table
Dialog
Swing uses which event model?
Polling
Delegation
Interrupt
Thread model
Swing components start with letter:
A
S
J
Which is NOT a Swing component?
JButton
JCheckBox
Button
JTextField
JLabel is:
Editable
Read-only
Clickable
Scrollable
Swing applications are:
Browser dependent
Platform dependent
Platform independent
OS dependent
JPanel is used for:
Drawing only
Grouping components
Closing window
Event handling
Which layout is default for JPanel?
BorderLayout
GridLayout
FlowLayout
Null
