JAVA MULTIPLE CHOICE QUESTIONS WITH ANSWERS
UNIT – 1 ( NETWORKING )
1. Java networking classes belong to ______ package.
A) [Link]
B) [Link]
C) [Link]
D) [Link]
Answer: C) [Link]
2. The class used to represent an IP address in Java is:
A) URL
B) InetAddress
C) Socket
D) ServerSocket
Answer: B) InetAddress
3. IPv4 address consists of:
A) 16 bits
B) 32 bits
C) 64 bits
D) 128 bits
Answer: B) 32 bits
4. IPv6 address contains:
A) 32 bits
B) 64 bits
C) 128 bits
D) 256 bits
Answer: C) 128 bits
5. A client program connects to a server using:
A) Socket
B) ServerSocket
C) URL
D) URI
Answer: A) Socket
6. A server listens for client requests using:
A) InetAddress
B) URLConnection
C) ServerSocket
D) DatagramPacket
Answer: C) ServerSocket
7. UDP communication in Java uses:
A) Socket
B) DatagramPacket
C) ServerSocket
D) URLConnection
Answer: B) DatagramPacket
8. A URL represents:
A) IP address
B) Web resource location
C) Network protocol
D) File storage
Answer: B) Web resource location
9. Opening a communication link with a URL is done using:
A) URLConnection
B) InetAddress
C) ServerSocket
D) Pattern
Answer: A) URLConnection
10. HttpURLConnection is mainly used for:
A) FTP communication
B) HTTP communication
C) UDP communication
D) Database connection
Answer: B) HTTP communication
11. URI stands for:
A) Universal Resource Internet
B) Uniform Resource Identifier
C) Universal Remote Interface
D) Uniform Remote Internet
Answer: B) Uniform Resource Identifier
12. Cookies help websites to:
A) Store images
B) Track user sessions
C) Encrypt data
D) Transfer files
Answer: B) Track user sessions
13. Regular expressions in Java are available in:
A) [Link]
B) [Link]
C) [Link]
D) [Link]
Answer: A) [Link]
14. Reflection in Java allows:
A) Network communication
B) Runtime inspection of classes
C) File compression
D) Image processing
Answer: B) Runtime inspection of classes
15. RMI in Java is mainly used for:
A) Remote method invocation
B) File storage
C) URL connection
D) Cookie management
Answer: A) Remote method invocation
UNIT – 2 ( SWING )
1. Which package is mainly used for Swing components in Java?
A) [Link]
B) [Link]
C) [Link]
D) [Link]
Answer: B) [Link]
2. Swing is part of which Java library?
A) AWT
B) JFC (Java Foundation Classes)
C) JDBC
D) RMI
Answer: B) JFC
3. In Swing architecture, MVC stands for:
A) Model View Control
B) Model View Controller
C) Main View Controller
D) Model View Class
Answer: B) Model View Controller
4. Which component is used to display text or images in Swing?
A) JButton
B) JTextField
C) JLabel
D) JTable
Answer: C) JLabel
5. Which class is used to display images in Swing?
A) ImageDisplay
B) ImageIcon
C) ImageView
D) IconImage
Answer: B) ImageIcon
6. Which component allows the user to enter a single line of text?
A) JTextArea
B) JLabel
C) JTextField
D) JTable
Answer: C) JTextField
7. Which component represents a push button in Swing?
A) JToggleButton
B) JButton
C) JCheckBox
D) JRadioButton
Answer: B) JButton
8. Which component displays hierarchical data in Swing?
A) JTable
B) JTree
C) JComboBox
D) JList
Answer: B) JTree
9. Which component is used to display data in rows and columns?
A) JList
B) JComboBox
C) JTable
D) JScrollPane
Answer: C) JTable
10. Which container allows switching between multiple tabs?
A) JPanel
B) JTabbedPane
C) JFrame
D) JTree
Answer: B) JTabbedPane
11. Which component provides scroll bars to another component?
A) JList
B) JScrollPane
C) JTable
D) JComboBox
Answer: B) JScrollPane
12. Which component displays a list of items from which one or more can be selected?
A) JComboBox
B) JList
C) JTable
D) JTextField
Answer: B) JList
13. Which component provides a drop-down list?
A) JList
B) JTable
C) JComboBox
D) JScrollPane
Answer: C) JComboBox
14. Event handling in Swing is based on which concept?
A) Thread model
B) Delegation Event Model
C) Memory model
D) Data model
Answer: B) Delegation Event Model
15. Which class is used as the main window container in Swing applications?
A) JPanel
B) JFrame
C) JLabel
D) JTextField
Answer: B) JFrame
UNIT – 3 ( SWING MENUS )
1. Which component is used to create a menu bar in Swing?
A) JMenu
B) JMenuItem
C) JMenuBar
D) JPopupMenu
Answer: C) JMenuBar
2. Which class represents a menu in Swing?
A) JMenuItem
B) JMenu
C) JMenuBar
D) JPopupMenu
Answer: B) JMenu
3. Which class represents an item in a menu?
A) JMenu
B) JMenuBar
C) JMenuItem
D) JPanel
Answer: C) JMenuItem
4. Which menu item allows only one option to be selected?
A) JCheckBoxMenuItem
B) JRadioButtonMenuItem
C) JMenuItem
D) JButton
Answer: B) JRadioButtonMenuItem
5. Which menu item allows multiple selections?
A) JMenuItem
B) JRadioButtonMenuItem
C) JCheckBoxMenuItem
D) JButton
Answer: C) JCheckBoxMenuItem
6. Which component is used to create shortcut keys for menu items?
A) Tooltip
B) Accelerator
C) Border
D) Layout
Answer: B) Accelerator
7. Mnemonics in menu items are used for:
A) Styling
B) Keyboard shortcuts using Alt key
C) Images
D) Scrollbars
Answer: B) Keyboard shortcuts using Alt key
8. Which class is used to create a popup menu?
A) JMenu
B) JMenuItem
C) JPopupMenu
D) JToolBar
Answer: C) JPopupMenu
9. Which component is used to create a toolbar in Swing?
A) JMenuBar
B) JPanel
C) JToolBar
D) JPopupMenu
Answer: C) JToolBar
10. Which component is used to add separators between menu items?
A) JSeparator
B) JMenuBar
C) JPanel
D) JLabel
Answer: A) JSeparator
11. Which method is used to add a menu to a menu bar?
A) addItem()
B) add()
C) insert()
D) append()
Answer: B) add()
12. Which method is used to set tooltip text for a component?
A) setText()
B) setMenu()
C) setToolTipText()
D) setLabel()
Answer: C) setToolTipText()
13. Which class defines common behavior for menu and toolbar items?
A) Event
B) Action
C) Frame
D) Model
Answer: B) Action
14. Popup menus usually appear when the user performs:
A) Left click
B) Double click
C) Right click
D) Scroll
Answer: C) Right click
15. Where is the menu bar usually placed in a Swing application?
A) Bottom of frame
B) Top of frame
C) Center of frame
D) Inside panel
Answer: B) Top of frame
UNIT – 4 ( JDBC )
1. JDBC stands for
A) Java Database Connectivity
B) Java Data Control
C) Java Database Control
D) Java Dynamic Connection
Answer: Java Database Connectivity
2. JDBC is used to connect Java with ______.
A) Database
B) Browser
C) Network
D) Server
Answer: Database
3. Which package is used for JDBC?
A) [Link]
B) [Link]
C) [Link]
D) [Link]
Answer: [Link]
4. JDBC driver is used for ______.
A) Database connection
B) Printing
C) Networking
D) Gaming
Answer: Connection
5. How many types of JDBC drivers are there?
A) 2
B) 3
C) 4
D) 5
Answer: 4
6. The JDBC-ODBC bridge driver is called ______ driver.
A) Type 1
B) Type 2
C) Type 3
D) Type 4
Answer: Type 1
7. Method used to execute SQL query.
A) executeQuery()
B) print()
C) start()
D) run()
Answer: executeQuery
8. Method used to update database.
A) executeUpdate()
B) executeRun()
C) executePrint()
D) executeStart()
Answer: executeUpdate
9. Servlet is a ______ program.
A) Java
B) C
C) Python
D) HTML
Answer: Java
10. Servlet runs on ______.
A) Server
B) Client
C) Browser
D) Mobile
Answer: Server
11. The servlet package is ______.
A) [Link]
B) [Link]
C) [Link]
D) [Link]
Answer: [Link]
12. The software used to run servlets is ______.
A) Tomcat
B) Eclipse
C) NetBeans
D) Chrome
Answer: Tomcat
13. Servlet life cycle method for initialization.
A) init()
B) start()
C) begin()
D) open()
Answer: init
14. Servlet life cycle method to handle request.
A) service()
B) start()
C) call()
D) handle()
Answer: service
15. Servlet life cycle method for destroying servlet.
A) destroy()
B) delete()
C) remove()
D) finish()
Answer: destroy
UNIT – 5 ( JSP )
1. JSP stands for ______.
A) Java Server Page
B) Java Script Page
C) Java Service Page
D) Java Simple Page
Answer: A) Java Server Page
2. JSP is mainly used to create ______ web pages.
A) Static
B) Dynamic
C) Offline
D) Local
Answer: B) Dynamic
3. MVC stands for ______.
A) Model View Controller
B) Model View Component
C) Main View Control
D) Model Value Controller
Answer: A) Model View Controller
4. Which directive is used to define page settings in JSP?
A) page
B) include
C) taglib
D) import
Answer: A) page
5. JSP scripting elements are written inside ______.
A) <% %>
B) <# #>
C) <& &>
D) <@ @>
Answer: A) <% %>
6. Variable scope in JSP defines the ______ of a variable.
A) Color
B) Size
C) Lifetime
D) Speed
Answer: C) Lifetime
7. Error handling in JSP is done using ______ page.
A) Login
B) Error
C) Home
D) Main
Answer: B) Error
8. JavaBeans are used to ______ data in JSP.
A) Store
B) Delete
C) Compile
D) Print
Answer: A) Store
9. JSP tag extensions help to create ______ tags.
A) HTML
B) Custom
C) XML
D) Java
Answer: B) Custom
10. Taglib directive is used to define ______ library.
A) Tag
B) Java
C) Script
D) HTML
Answer: A) Tag
11. Tag handlers are written using ______ language.
A) Python
B) Java
C) C++
D) PHP
Answer: B) Java
12. Dynamic attributes allow tags to accept ______ attributes.
A) Fixed
B) Static
C) Flexible
D) Limited
Answer: C) Flexible
13. JSP is executed on the ______ side.
A) Client
B) Server
C) Browser
D) User
Answer: B) Server
14. Designing an online store in JSP is an example of ______ application.
A) Desktop
B) Web
C) Mobile
D) Offline
Answer: B) Web
15. JSP works mainly with ______ language.
A) C
B) Java
C) Python
D) PHP
Answer: B) Java