0% found this document useful (0 votes)
10 views39 pages

combine

Hsksj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views39 pages

combine

Hsksj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

SANJIVANI K. B. P.

POLYTECHNIC
Department of Computer Technology
KOPARGAON – 423601, DIST: AHMEDNAGAR
2024-2025

Class Test: [Unit IV - Networking Basics] Date: / /2024


Name : Set: I
Roll No :

1. UDP stands for


a. User Data Port b. User Datagram Protocol c. Used Data Provider d. User Data Protocol

2. IPv6 uses ________.


a. 4 groups of 8 bits each b. 4 group of 8 hexa‐decimal digits
c. 8 groups of 4 digits each d. 8 groups of 4 hexa‐decimal digits each

3. Communication using TCP protocol is and .


a. Connection less, Iterative b. Collection less, concurrent c. Connection oriented, Iterative d. Connection oriented, concurrent

4. Name the class which is used to create a port where the server will listen.
(a) Server (b) Socket (c) ServerSocket (d) SocketServer

5.Which of these is a not a factory method of InetAddress class?


a. static InetAddress getLocalHost( ) b. static InetAddress getByName(String hostname)
c. static InetAddress getAllName(String hostname) d. static InetAddress[ ] getAllByName(String hostname)

6. Which from the below use “Middle tier”.


a. 3 tier b. 4 tier c. n ‐ tier d. all of the above

7. What is the use of WriteUTF( ) method?


a. This method writes a string into underlying output stream. b. This method reads a sting from underlying input stream.
c. This method writes a byte array into underlying output stream. d. This method writes a character array into underlying output

8. Which of these is a bundle of information passed between machines?


a. MIME b. Cache c. Datagram d. Socket

9. int getServerPort( ) method ____________


a. returns the port number on which this request was received. b. returns the port name on which the request was received.
c. returns the server number on which this request was received. d. returns the port number on which this response/request was
received.

10. In this constructor ServerSocket(int port, int max_queue) what is the default value for max_queue?
a. 100 b. 50 c. 75 d. 80

11. The constructor of URL can throw an exception called ______


a. MalformedUrlException b. UrlNotFoundException d. UrlException d. UrlSourceNotFoundException

12. Which IP address is multicast IP address?


a. 192.168.2.32 b. 235.55.45.2 c. 12.22.1.2 d. None of these

13. How many ports of TCP/IP are reserved for specific protocols?
a. 10 b. 1024 c. 2048 d. 512

14. How many bits are in a single IP address?


a. 8 b. 16 c. 32 d. 64

15. Which of these is a full form of DNS?


a. Data Network Service b. Data Name Service c. Domain Network Service d. Domain Name System
1
16. Which of these class is used to encapsulate IP address and DNS?
a. DatagramPacket b. URL c. InetAddress d. ContentHandler

17. Network programming in any language definitely needs to deal with____ and ____.
a. user names; port numbers b. IP addresses; link‐ layer address c. IP addresses; port numbers d. None of the choices are correct

18. The class used in Java network programming for socket address is the ____ class.
a. InetAddress b. Socket address c. InetSocketAddress d. None of the choices are correct

19. Which of the following protocol follows connection less service?


a. TCP b. TCP/IP c. UDP d. HTTP

20. Which method is establish a connection between server and client?


a. accept() b. open() c).getLocalHost() d. openConnection()

21. Which of these package contains classes and interfaces for networking?
A. java.io B. java.util C. java.net D. javax.swing

22. In the following URL, identify the protocol identifier? https://mcqmate.com:8080/course.php


A. https B. php C. //mcqmate.com:80/course.php D. 8080

23. Which 5 parameters uniquely identify a connection?


a. Local IP, Remote IP, Local MAC, Remote MAC and Protocol b. Local IP, Local PORT, Remote MAC, Remote PORT and Protocol
c. Local MAC, Local PORT, Remote MAC, Remote PORT and Protocol d. Local IP, Local PORT, Remote IP, Remote PORT and
Protocol

24. Which of the following statement is NOT true?


A. TCP is a reliable but slow.
B. UDP is not reliable but fast.
C. In HTTP, all communication between two computers
are encrypted
D. File Transfer Protocol (FTP) is a standard Internet protocol for transmitting files between computers on the Internet over TCP/IP
connections.

25. Which of the following statement is TRUE?


A. With stream sockets there is no need to establish any connection and data flows between the processes are as continuous
streams.
B. Stream sockets are said to provide a connection‐less service and UDP protocol is used
C. Datagram sockets are said to provide a connection‐oriented service and TCP protocol is used
D. With datagram sockets there is no need to establish any connection and data flows between the processes are as packets.

26. Which of the following method call is valid to obtain the server's hostname by invoking an applet?
A. getCodeBase().host() B. getCodeBase().getHost() C. getCodeBase().hostName() D. getCodeBase().getHostName()

27. The server listens for a connection request from a client using which of the following statement?
A. Socket s = new Socket(ServerName, port); B. Socket s = serverSocket.accept()
C. Socket s = serverSocket.getSocket() D. Socket s = new Socket(ServerName);

28. The client requests a connection to a server using which of the following statement?
A. Socket s = new Socket(ServerName, port);
B. Socket s = serverSocket.accept();
C. Socket s = serverSocket.getSocket();
D. Socket s = new Socket(ServerName);

29. To connect to a server running on the same machine with the client, which of the following cannotbe used for the
hostname?
30. A. “localhost” B. "127.0.0.1" C. InetAddress.getLocalHost() D. "127.0.0.0"

2
31. In the socket programming, for an IP address, which can be used to find the host name and IP address of a client/
server?

A. The ServerSocket class B. The Socket class C. The InetAddress class D. The Connection interface

31. To create an InputStream on a socket, say s, which of the following statement is necessary?
A. InputStream in = new InputStream(s); B. InputStream in = s.getInputStream();
C. InputStream in = s.obtainInputStream(); D. InputStream in = s.getStream();

32. Which of the following protocols is/are for splitting and sending packets to an address across a network?
A. TCP/IP B. FTP C. SMTP D. UDP

33. Which of the following type of JDBC driver, is also called Type 1 JDBC driver?
A. JDBC‐ODBC Bridge plus ODBC driver B. Native‐API, partly Java driver C. JDBC‐Net, pure Java driver D. Native‐protocol, pure
Java driver

34. Select the method used to create URL connection.


a. URL Connection b. open Connection c. URL d. URL Decoder

35. Which of the following type of JDBC driver, is also called Type 2 JDBC driver?
A. JDBC‐ODBC Bridge plus ODBC driver B. Native‐API, partly Java driver C. JDBC‐Net, pure Java driver D. Native‐protocol,
pure Java driver

36. Which of the following holds data retrieved from a database after you execute an SQL query using Statement objects?
A. ResultSet B. JDBC driver C. Connection D. Statement

37. Which of the following is not a valid type of ResultSet?


A. ResultSet.TYPE_FORWARD_ONLY
B.ResultSet.TYPE_SCROLL_INSENSITIVE
C. ResultSet.TYPE_SCROLL_SENSITIVE
D. ResultSet.TYPE_BACKWARD_ONLY

38. class Permission in java.security package is


(a) static (b) abstract (c) final (d) None of these

39. 8 Resolver in DNS system maps .


(a) Domain name to IP address
(b) IP address to domain name
(c) Domain name to MAC address
(d) MAC address to IP address

40. URL is an acronym for?


A. Uniform Resource Locator B. Unified Resource Locator C. Uniform Restore Locator D. Unified Restore Locator

41. URL stands for Uniform Resource Locator and represents a resource on the World Wide Web, such as a Web page or FTP
directory.
A. True B. False

42 Which class is used to create servers that listen for either local client or remote client programs?
A. ServerSockets B. httpServer C. httpResponse D. None of the above

43. Which constructor of DatagramSocket class is used to creates a datagram socket and binds it with the given Port Number?
A. DatagramSocket(int port) B. DatagramSocket(int port, InetAddress address)
C. DatagramSocket() D. None of the above

44. Which methods are commonly used in ServerSocket class?


A. public OutputStream getOutputStream() B. public Socket accept() C. public synchronized void close() D. None of the above

45. Which classes are used for connection‐less socket programming?


A. DatagramSocket B. DatagramPacket C. Both A & B D.None of the above

3
46. Which method of URL class represents a URL and it has complete set of methods to manipulate URL in Java?
A. java.net.URL B. java.net.URLConnection C. Both A & B D. None of the above

47. The_________class is used to create TCP server.


a. Server b. SocketServer c. ServerSocket d. Socket

48. Which package provides core functionality?


A. java.net B. java.rmi C. java.lang D. java.math

49. The DatagramSocket and DatagramPacket classes are not used for connection‐less socket programming.
A. True B. False

50. A server socket can connect to clients.


(a) 1 (b) 2 (c) 10 (d) multiple

51. Connection oriented communication is possible using classes of Java.


(a) Socket and ServerSocket (b) DatagramSocket and DatagramPacket (c) Both of these (d) None of these

52. Which of these method of DatagramPacket class is used to find the destination address?
(a) findAddress( ) (b) getAddress( ) (c) address( ) (d) whoIs( )

53. Which of the following step establishes a connection with a database?


A. Import packages containing the JDBC classes needed for database programming.
B. Register the JDBC driver, so that you can open a communications channel with the database.
C. Open a connection using the DriverManager.getConnection () method.
D. Execute a query using an object of type Statement.

54. Which is the correct syntax for getLocalHost( ) method?


(a) public static InetAddress getLocalHost( ) throws UnknownHostException
(b) public static IpAddress getLocalHost( ) throws UnknownHostException
(c) public static String getLocalHost( ) throws UnknownHostException
(d) public static void getLocalHost( ) throws UnknownHostException

55. The client in socket programming must know which informations?


a. IPaddress of Server b. Port number c. Both A & B d. None of the above

56. The URLConnection class can be used to read and write data to the specified resource
referred by the URL
a. True b. False

57. Datagram is basically an information but there is no guarantee of its content, arrival or
arrival time.
a. True b. False

58. method is used to retrieve file name specified in URL.


(a) getFile( ) (b) getUrl( ) (c) getFileUrl( ) (d) getLocalFile( )

59. What does the java.net.InetAddress class represent?


a. Socket b. IP Address c. Protocol d. MAC Address

60. The flush() method of PrintStream class flushes any uncleared buffers in memory
a. True b. False

61. Which method of ServerSocket will wait for a client to initiate communication and then communication with the client?
a. wait( ) b. connect( ) c. waitForClient( ) d. WaitForConnect( )

62.A server socket can connect to ________ clients.


a. 1 b. 2 c. 10 d. multiple

63. Resolver in DNS system maps __________.


a. Domain name to IP address b. IP address to domain name c. Domain name to MAC address d. MAC address to IP address
4
64. TCP does not supports Multicasting and Broadcasting because ______________.
a. It supports full duplex communication. b. It provides error control. c. It provides flow d. It is connection oriented protocol

65. Which is the proper method to retrieve the host name of local machine?
a. static InetAddress getLocalHost( ) throws UnknownHostException
b. static InetAddress getByName(String host_name ) throws UnknownHostException
c. static InetAddress getAllByName(String host_name ) throws UnknownHostException

5
Sanjivani Rural Education Society’s
SANJIVANI K. B. P.
POLYTECHNIC
Department of Computer Technology
KOPARGAON – 423601, DIST:
AHMEDNAGAR
2024-2025

Class Test : [ Unit ll – Swing ] Date : / /2024


Name : Set : l
Roll no. :

1. Which package is used for Swing components in Java?


a) java.awt b) javax.swing c) java.util d) java.io

2. Which method is used to set the text of a JLabel in Swing?


a) setText() b) setTextLabel() c) setLabel() d) setTextValue()

3. How do you add components to a JFrame in Swing?


a) addComponent() method b) append() method c) insertComponent() method d) add() met

4. How do you make a Swing component visible on the screen?


a) setVisible(true) method b) show() method c) display() method d) open() method

5. The Components in JApplet are added to


a) Current JApplet Class b)ContentPane c)Both A and B d) None

6. How many Options can be selected in JRadioButton at a time?


a) Only One b) Multiple c)It is defined in the program d)Only a maximum of six

7. Frame class Entends Windows : a) True b) False.

8. Which is the container class?


a) Window b) Frame c) Dialog d)All of the above.

9. Swing is based on ____ architecture


a)Client server b)Model view controller c)Layered d)None of these

10. Which of the following is the top-level container in Swing?


a) JPanel b) JFrame c) JButton d) JLabel

11. Which component can be used to create a tabbed pane?


a) JTabbedPane b) JPaneTab c) JTabPane d) JTabbedPanel

12. Which method is used to set the alignment of text in a JLabel?


a) setAlignment() b) setTextAlign() c) setHorizontalAlignment() d) setLabelAlignment()

13. Which method is used to set the icon of a JButton?


a) setIcon() b) setButtonIcon() c) setImage() d) setGraphic()

14. MVC architecture is used by Applet?


a)True b)False
15. . Swing components are ______________ .
a)Platform dependent b)Platform independent c)Both A & B d)Platform oriented

16. The Swing Component classes that are used in Encapsulates a mutually exclusive set of buttons?
a) AbstractButton b) ButtonGroup c) JButton d) ImageIcon

17. In swing MVC architecture , C stands for ___________ .


a)Controller b)Container c)Class d)None of These

18. Default Orientation of progress bar is _________________ .


a)Horizontal b)Vertical c)Both A and B d)None of these

19. Which of the following architecture does the swing framework use ?
a) MVC b) MVP c) Layered Architecture d) Master-slave Architectur

20. What is the purpose of JTree?


a). To show data in the form of parent and child nodes. b). To show data in list view .
c)To show data in tabular form. d). To show d

21. . A tree represent a __________ view of data.


a) Structural b)Hierchical c)Multiple d) Singl

22. Which component displays following output?

a) JTable b) JTree
c) JToolTip d) None of the above

23. What is the default alignment of text in a JLabel?


a) Left b) Center c) Right d)Top

24. Which class is used to display an image in a Swing application?


a) JImage b) JImageIcon c) ImageComponent d) ImageIcon

25. A ____ is the basic class for all SWING UI components?


a)Container b) Jcomponent c)Component d)JButton

26. __________ is a Swing layout manager that arranges components in a row & a column.
a)BoxLayout b)GridLayout c)BorderLayout d)FlowLayout

27. Which swing components use ListSelectionModel


a) JTree and JTable b)JComboBox c) Jlist and Jtable d)JButton and JList

28. Which statements is missing in the given code below


import javax.swing.*;
public class FirstSwingExample
{ public static void main ( String [] args)
{ Jframe f =new Jframe();
Jbutton b = new Jbutton ("click") ;
a) f.setVisible(); b)import java.io.*;
b. setBounds( 130,100,100,40); c) f.SetVisible(true); d)f.getVisible(true);
f. add(b);
f.seSize(400,500);
f.setLayout (null); } }
29. Which package is used to add progress bar in an application?
a)javax.swing.JProgressBar b)javax.awt.JprogressBar c)java.JprogressBar d)javax.JprogressBar

30. Which Components are used in Following output?


a) JRadioButton ,JTextField b)JComboBox,JTextfield
c)JTextArea, JButton d)JTree, JLabel

31. Which component is display area for a short string of text, image or both?
a)Jbutton b)JLabel c)JTextfield d)JTextArea

32. To creat panel of borderlayout use_________


a)Jpanel p=new Jpanel(new BorderLayout()) b)Jpanel = new BorderLayout()
c)BorderLayout = new Jpanel(p) d)None of these

33. In Swing JButton class is derived from____


a)JToggledButton b)AbstractButton c)JComponent d)None of these

34. From following list Which is not Swing class?


a)JMenuItem b)JToolBar c)Jdailog d)JImageIcon

35. Which of these following is not a component of swing


a)JFrame b)JTree c)JList d)JButton

36. Which of the following swing components do not have an Icon parameter in its constructor?
a)JTextField b)JTextArea c)Both a and b d)none of these

37. Which of the following is not a constructor of JTree


a) JTree() b) JTree(int x) c)Both a and b d)None of these

38. Which of the following is not a swing class?


a)JSwing b)JList c)Both a and b d)None of these

39. Which method is used to close a swing frame?


a)setDefaultCloseOperation() b)Jclose() c)setClose() d)None of these

40. Which Swing component’s default layout manager arranges components in a top-to-bottom order?
a)JPanel b) JFrame c)JToolBar d) JScrollPane

41. What is the default horizontal alignment of text in a JLabel?


a)Center b)Left c)Right d)Justify

42. Which swing component is used for inputting a single line of text
a)JLabel b)JTextArea c)JTextField d)JButton

43. What method is used to add a component to a swing container


a)insert() b)append() c)appendComponent() d)add()

44. What method is used to set the text of a JLabel?


a)changeText() b)setText() c)modifyText() d)updateText()

45. Which method is used to enable or disable a JButton?


a)setActive() b)setEnabled() c)setClickable() d()setInteractive()
46. Which Swing component would you use to create a dropdown menu?
a)JComboBox b)JMenu c)JCheckBox d)JList

47. Which Swing class is used to create a dialog box?


a)JFrame b)JPanel c)JDailog d)JOptionPane

48. When adding a JComponent to a container, which of these methods is called by default?
a)insert() b)append() c)put() d)add()

49. Which method call will NOT affect the size of a JFrame?
a)pack() b)setPrefferedSize() c)setSize() d)setBounds()

50. Which component automatically updates its display when its Model changes?
a)JTable b)JList c)JComboBox d)JTextArea

51. Which method can be used to change the font of a JButton?


a)setFont() b) setTextFont() c) applyFont() d) changeFont()

52. In which method is the Graphics object provided for painting in Swing?
a)paint() b)render() c)paintComponent() d)draw()

53. What will JTable.getValueAt(row, col) return if the cell is empty?


a) "" b)null c)0 d)false

54. Which method is used to handle mouse clicks on a component?


a)mouseClicked() b)mouseEvent() c)mousePressed() d)mouseRelreased()

55. Which method should be used to remove all items from a JComboBox?
a)clear() b)reset() c)deleteAll() d)removeAllItems()

56. Which component is typically used to create a navigation bar in Swing?


a)JMenuBar b)JToolBar c)Jpanel d)JTrabbedPane

57. Which of the following is NOT a direct method to change a component’s foreground color?
a)setTextColor() b)setForeground c)setColor d)setPaintColor

58. What is the default layout manager of a JPanel?


a)FlowLayout b)GridLayout c)BorderLayout d)BoxLayout

59. Which method is used to make a JFrame visible?


a)show() b)display() c)setVisible() d)open()

60. What is the default behavior of JScrollPane when its viewport is empty?
a) Displays an empty scroll pane b)Shows a placeholder message.
c)Automatically hides itself. D) Throws an exception.

61. What happens if you call setText(null) on a JLabel?

a) The label is hidden. b)The label’s text is set to null.


c)The label throws an exception. d) The label displays an empty string.

62. JFrame is a subclass of JComponent.


a)True b)False
Sanjivani Rural Education Society’s

SANJIVANI K. B. P. POLYTECHNIC
Department of Computer Technology
KOPARGAON – 423601, DIST: AHMEDNAGAR
2023-2024

Class Test: [Unit III-Event Handling] Date: / /2023


Name : Set: I
Roll No :

1. Which of the following is the top-level interface for handling events in Java
a) EventListener b) EventObject c) ActionEvent d) WindowEvent

2. Which method is invoked when an action is performed on a button


a) actionPerformed() b) itemStateChanged() c) mouseClicked() d) windowClosed()

3. Which package contains the event handling classes in Java?


a) java.io b) java.util c) java.awt.event d) java.net

4. Which interface should be implemented to handle keyboard events in Java?


a) MouseListener b) KeyListener c) ActionListener d) FocusListener
5. What does the addActionListener method do?
a) Adds a listener for mouse events b) Adds a listener for key events
c) Adds a listener for action events d) Adds a listener for focus events

6. Which of the following methods is used to handle mouse click events?


a) mouseClicked() b) mousePressed() c) mouseReleased() d) All of the above

7. What is the purpose of the WindowAdapter class?


a) To handle key events b) To provide default implementations for window events
c) To create window components d) To handle action events

8. Which event is generated when a component gains focus?


a) KeyEvent b) FocusEvent c) ActionEvent d) MouseEvent

9. Which method is invoked when a component is resized?


a) componentResized() b) componentMoved() c) componentHidden() d) componentShown()

10. Which event class is used to handle mouse motion events?


a) MouseEvent b) MouseMotionEvent c) MouseMotionListener d) MouseAdapter

11. What is the return type of the getSource() methodl in event handling?
a) Object b) String c) int d) Event

12. Which interface is used to handle events related to items in a component like checkboxes?
a) ItemListener b) ActionListener c) KeyListener d) WindowListener

13. What is the function of the dispatchEvent() method?


a) To generate an event b) To delegate event handling to another object c) To terminate event processing
d) To queue an event for later processing

14. Which of the following methods is part of the WindowListener interface?


a) windowOpened() b) windowClosed() c) windowClosing() d) All of the above

15. Which event occurs when a user presses and releases a key?
a) KeyPressed b) KeyReleased c) KeyTyped d) All of the above
16. Which class is used as a base class for all AWT events?
a) EventObject b) ActionEvent c) AWTEvent d) Event

17. What is the purpose of the EventQueue class in Java?


a) To hold all events b) To synchronize event handling
c) To manage the order of event processing d) To dispatch events to listeners

18. Which listener interface handles the movement of a window?


a) ComponentListener b) WindowListener c) MouseMotionListener d) ActionListener

19. Which of the following methods is used to remove an action listener from a button?
a) removeActionListener() b) deleteActionListener() c) unregisterActionListener()d) detachActionListener()

20. What does the isConsumed() method in an event object indicate?


a) Whether the event has been processed
b) Whether the event should be ignored
c) Whether the event is still in the queue
d) Whether the event source is null

21. Which class is the base class for all event classes in Java?
a) EventObject b) AWTEvent c) ComponentEvent d) ActionEvent

22. Which interface is used to handle action events in Java?


a) ActionListener b) MouseListener c) KeyListener d) WindowListener

23. Which method must be implemented when using the ActionListener interface?
a) actionPerformed() b) actionEvent() c) actionTriggered() d) performAction()

24. What is the purpose of the addActionListener method?


a) To register a component for mouse events b) To add a component to a container
c) To register an action listener with a component d) To remove an action listener from a component

25. Which of the following is a valid event type for the MouseListener interface?
a) mouseClicked b) keyPressed c) componentResized d) windowClosed

26. What is the purpose of the mouseReleased method in the MouseListener interface?
a) To handle mouse button presses b) To handle mouse movements
c) To handle mouse button releases d) To handle mouse clicks

27. Which interface is used to handle keyboard events in Java?


a) KeyListener b) KeyEvent c) KeyAdapter d) KeyEventListener

28. Which method in the WindowListener interface is called when a window is closed?
a) windowClosing b) windowClosed c) windowActivated d) windowDeactivated

29. What is the use of the ComponentAdapter class?


a) To handle mouse events b) To handle key events
c) To provide empty implementations of the ComponentListener methods d) To handle window events

30. In Java Swing, which class provides the JButton component?


a) javax.swing.JButton b) javax.swing.JButtonComponent c) java.awt.JButton d) javax.swing.AbstractButton

31. Which method is used to set the title of a JFrame?


a) setWindowTitle() b) setTitle() c) changeTitle() d) updateTitle()

32. What event does the windowStateChanged method handle?


a) When the window is resized b) When the window state changes (e.g., maximized or minimized)
c) When the window is moved d) When the window is activated

33. Which interface provides a method for handling focus events?


a) FocusListener b) FocusEvent c) FocusAdapter d) FocusHandler
34. How can you listen to a JTextField for user input?
a) Add a FocusListener to the JTextField b) Add an ActionListener to the JTextField
c) Add a MouseListener to the JTextField d) Add a WindowListener to the JTextField

35. Which method in the ActionEvent class retrieves the command string associated with the event?
a) getActionCommand() b) getCommand() c) retrieveCommand() d) getEventCommand()

36. Which method in the MouseAdapter class is used to handle mouse clicked events?
a) mouseClicked() b) mousePressed() c) mouseReleased() d) mouseEntered()

37. What is the default event handling model for Swing components?
a) Event delegation model b) Event broadcasting model c) Event handling model d) Event propagation model

38. Which class is used to create a graphical user interface window in Java Swing?
a) JFrame b) JPanel c) JWindow d) JFrameWindow

39. How do you handle changes in the size of a component in Java?


a) By implementing the ComponentListener interface b) By implementing the ContainerListener interface
c) By using a ComponentAdapter d) Both a) and c)

40. Which method in the ItemListener interface handles item state changes?
a) itemStateChanged() b) itemChanged() c) stateChanged() d) itemSelected()

41. Which class is used to create a menu item in Swing?


a) JMenuItem b) JMenu c) JMenuBar d) JMenuComponent

42. Which method in the WindowAdapter class is called when a window is minimized?
a) windowIconified() b) windowMinimized() c) windowClosed() d) windowDeiconified()

43. Which interface should be implemented to handle mouse drag events?


a) MouseMotionListener b) MouseDragListener c) MouseEventListener d) MouseInputListener

44. Which method in FocusListener is called when a component gains focus?


a) focusGained() b) focusAcquired() c) focusReceived() d) focusObtained()

45. Which class provides an implementation for the WindowListener interface in an adapter form?
a) WindowAdapter b) WindowHandler c) WindowListenerAdapter d) WindowEventAdapter

46. How do you register a MouseListener with a component?


a) component.addMouseListener(new MouseListenerImplementation());
b) component.addMouseListener(MouseListenerImplementation.getInstance());
c) component.registerMouseListener(new MouseListenerImplementation());
d) component.setMouseListener(new MouseListenerImplementation());

47. What does the windowOpened() method of WindowListener do?


a) It is called when a window is first opened b) It is called when a window is minimized
c) It is called when a window is closed d) It is called when a window is activated

48. Which event is generated when a component is resized?


a) ComponentEvent b) ResizeEvent c) SizeEvent d) ComponentResizedEvent

49. Which method in the MouseMotionListener interface is invoked when the mouse is dragged?
a) mouseDragged() b) mouseMoved() c) mousePressed() d) mouseReleased()

50. How can you listen for changes in the state of a checkbox in Swing?
a) Implement ItemListener and register it with the checkbox
b) Implement ActionListener and register it with the checkbox
c) Implement FocusListener and register it with the checkbox
d) Implement MouseListener and register it with the checkbox
Sanjivani Rural Education Society’s

SANJIVANI K. B. P. POLYTECHNIC
Department of Computer Technology
KOPARGAON – 423601, DIST: AHMEDNAGAR
2023-2024

Class Test: [Unit I-AWT] Date: / /2023


Name : Set: I
Roll No :

1. Which class cannot be subclassed (or extended) in java?


a) abstract class b) parent class c) Final class d) None of above

2. Can we declare abstract static method


a) Yes b) No

3. Can we access private class outside the package


a) Yes b) No

4. Why we use array as a parameter of main method


a) it is syntax b) Can store multiple values c) Both of above d) None of above

5. Suspend thread can be revived by using


a) start() method b) Suspend() method c) resume() method d) yield() method

6.Runnable is
a) Class b) Method c) Variable d) Interface

7. Which collection class associates values with keys, and orders the keys according to their naturalorder
a) java.util.HashSet b) java.util.LinkedList c) java.util.TreeMap d) java.util.SortedSet

8. Which method is used to perform DML statements inJDBC


a) execute() b) executeUpdate() c) executeQuery() d) None of above

9. In Runnable, many threads share the same object instance


a) True b) False

10. Program which executes applet is known as


a) applet engine b) virtual machine c) JVM d) None of above

11. What does the following line of code do? TextField tf = new TextField(10);
(a) will set 10 to TextField as its initial text b) Will set the character capacity to 10
(c) Both A & B d) None of These

12. Frame is a standard window, which is of Window class from AWT hierarchy?
a) Derived class / Subclass b) Base class / Super class c) Root class d) Family class

13. A is a passive AWT control that do not generate any event?


a) Button b) RadioButton c) Choice d) Label
14. The default layout manager of Frame is .
a) FlowLayout b) BorderLayout c) GridLayout d) CardLayout

15. Which method is used to check the status of checkbox?


a) getStatus( ) b) getState( ) c) isChecked( ) d) getChecked( )
16. Which of the following method is used to set a TextComponent to read‐only mode?
a) Editable( ) b) nonEditable( ) c) setEchoChar( ) d) setEditable( )

17. generates action events when an item is double‐clicked.


a) List b) Checkbox c) MenuItem d) TextField

18. Which of the following does not have its default layout as BorderLayout.
a) Frame b) Dialog c) JApplet d) All of Above

19. Which of the following statement about GUI component is wrong?


a) swing exists since the version 1.2 of the JDK
b) AWT stands for Abstract Window Toolkit
c) You cannot place AWT component on swing container
d) The AWT classes are deprecated.

20.Which of the following package is used for Graphical User Interface?


a) java.applet b) java.awt c) java.awt.image d) java.io

21. What are the variables defined in Dimension?


a) length and width b) height and length c) height and width d) None of these

22. Which AWT component is not editable?


a) Button b) TextField c) FlowLayout d) Label

23. Current text of Label can be obtained using .


a) setAlignment( ) b) getAlignment( ) c) getText( ) d) setText( )

24. The method places a Menu m into the MenuBar mb.


a) mb.addMenuItem(m) b) mb.addItem(m) c) mb.add(m) d) None of these

25. Which of these Components cannot be added to Frame?


a) Label b) Button c) CheckboxGroup d) All of above

26. What is use of second parameter given in Label constructor : Label(String, int)
(a) Specifies height of label in terms of pixels
(b) specifies width of label in terms of pixels

27.Which of these classes can be added to any container class, using the add method defined incontainer
class?
a) Button b) CheckboxMenuItem c) Menu d)MenuBar

28.Which of the following methods can be used to change the size of a java.awt.Component object?
a) dimension() b) setSize() c) area() d) size()

29.Which of the following methods can be used to remove a java.awt.Component object from thedisplay?
a) disappear() b) delete() c) remove() d) hide()
30.These two ways are used to create a Frame
1.By creating the object of Frame class(association)2.By extending Frame class
(inheritance)
a)True b) False

31. The tittle of the frame can be set in AWT using the method.
a) setHeading b) setTitle c) createTitle d) settitle

32. Which are passive controls that do not support any interaction with the user?
a) Choice b) List
c) Labels c) Settitle
33.How Many ways can be align the label in a container?a) 1 b) 2
c) 3 d) 4

34. By which method we can set or change the text in a Label in AWT?
a) setText() b) getText() c) addText() d) all of these

35. Default layout manager for subclasses of window is


a) CardLayout b) BorderLayout c) Frame d) BorderLayout

36.Each menu is associated with a list of menu items:


a) Checkbox b) Drop-down c) Choice d) None of these

37.Which is the immediate super class of Applet?


a) Container b) Component c) Frame d) Panel

38.Which class encapsulates a blank window upon which we can draw?


a) Window b) Frame c) Applet d) Canvas

39.Color class can create object of it using which of the following color values?
a) RGB b) RYB c) CMY d) HSB

40.Which of the following style is not supported by Font class?


a) Font.UNDERLINE b) Font.ITALIC c) Font.PLAIN d) Font.BOLD

41.Which of the following is passive AWT control?


a) Label b) Button c) Checkbox d) TextField

42.A checkbox is a control that consist of a


a) Combination of a small box b) A label
c) Combination of a large box and a label d) Both a & b

43. All AWT controls are subclass of which class?


a) Component b) Container c) AWT Control d) Window

44. The concept of Menu Bar can be implemented by using three java classes‐
a) Menu b) MenuBar c) MenuItem d) All of these

45. Which method is used to append the text at the end of TextArea?
a) append() b) add() c) appendAt() d) addAt()
46. The immediate super class of TextArea is
a) TextField b) TextBox c) TextComponent d) Component

47. Which is the container that doesn’t contain title bar and menu bars. It can have other componentslike button, text
field etc?
a) Window b) Frame c) Panel d) Container

48. Which object can be constructed to show any number of choices in the visible window?
a) Choice b) Menu c) List d) Checkbox

49. By which method we can set or change the text in a label in AWT?
a) setText() b) getText() c) addText() d) all of these

50. On which side applet always executed?


a) Server side b) Client side

51. Applet can be embedded in


a) HTML document b) Word document c) Gif file d) Rtf file

52. Which of the following is true about applet?


a) Applets do not have a main() method.
b) Applets must run under applet viewer or web browser
c) The user I/O is not performed using java’s stream I/O class
d) All of these.

53. Executable applet is


a) applet file b) java html c) java file d) class file

54. Java applet are used to create applications


a) Graphical b) User interactive c) Both a & b d) None of the above

55. Which of these functions is called to display the output of an applet?


a) Display() b)paint() c) displayApplet() d)show()

56. Which of these methods is a part of Abstract Window Toolkit ( AWT )?


a) Display() b) Paint() c) Show() d) All of these .

57. Which of these functions is called to display the output of an applet ?


a) display() b) paint() c) displayApplet() d) Show()

58. Which of these methods is a part of Abstract Window Toolkit(AWT)?


a) display() b) paint() c) show() d) all of the above .

59. Which object can be constructed to show any number of choices in the visible window?
a) Label b) Choice c) List d) Checkbox

60. Which of the following class is derived from the container class?
a) Component b) Panel c) MenuComponent d) List
61. Give the abbreviation of AWT.

A.Applet Windowing Toolkit. B. Abstract Windowing Toolkit. C.Absolute Windowing Toolkit. D.Both A& B

62. Which is the container that contain title bar and can have MenuBars .it can have other component like Button
,textfield, etc ?
A. Panel B. Frame C. Window D. Container

63. Which is a component in AWT that can contain another components like button, textfield, labels, etc?
A. Window B. Container C. Panel D. Frame

64. AWT is used for GUI programming java ?


A. True B. False

65. Which class provides many methods for graphics programming ?


A. Java.awt B. java.graphics C. java.awt.graphics D. none of the above

66. These two ways are used to create a Frame By creating object of Frame class ( association ), By extending Frame
class ( inheritance ).
A. True B.False

67. Which is the container that doesn’t contain title bar and MenuBar. It can have components like button, textfield,
etc ?
A. Window B. Frame C. Panel D.Container

68. How many types of control does AWT supports these controls are subclasses of components
A. 7 B. 6 C. 5 D. 8

69. Which are passive controls that do not support any interaction with the user ?
A. Choice B. List C. Label D. Checkbox

70. By which method you can set or change the text in a label ?
A. setText() B. getText() C. Both A & B D. none of the above

71. Which class is used to create a pop – up list of items from which the user may choose ?
A. List B. Choice C. Labels D. CheckBox

72. Which object can be constructed to show any number of choices in the visible window ?
A. Labels B. Choice C. List D. CheckBox

73. Which is used to store data and partial result , as well as to perform dynamic linking , return values for methods ,
and dispatch exceptions ?
A. Window B. Panel C. Frame D. Container

74. The following way is used to create a frame is by creating the object of frame class ?
A. Inheritance B. association C. Both A & B D. none of above

75. AWT more powerful components like table ,list, scroll panes, color chooser, tabbed pane ?
A. True B. False
Sanjivani Rural Education Society’s

SANJIVANI K. B. P. POLYTECHNIC
Department of Computer Technology
KOPARGAON – 423601, DIST: AHMEDNAGAR / 63
2023-2024
Sub Name : Advanced Java Programming (AJP-22517) Course Code : CM-5-I
Name : Date: / /2023
Roll No : Set: II
Practice Test: [ Unit V- Interacting with Database]

1. What does JDBC stand for? –


a) Java Database Control b) Java Database Connectivity c) Java Data Binding Connector d) Java Database Console

2. Which package in Java contains the JDBC classes?


a) java.sql b) java.jdbc c) java.db d) java.connection

3. In JDBC, which interface is responsible for making a connection to the database?


a) Driver b) Connection c) Statement d) ResultSet

4. Which of the following is used to execute SQL queries in JDBC?


a) DriverManager b) Connection c) ResultSet d) PreparedStatement

5. What is the purpose of the `ResultSet` interface in JDBC?


a) To connect to the database b) To execute SQL queries c) To store query results d) To create a database table

6. Which of the following is not a type of JDBC driver?


a) Type 1 b) Type 2 c) Type 4 d) Type 6

7. Which driver type is known as the “Thin driver” in JDBC?


a) Type 1 b) Type 2 c) Type 3 d) Type 4

8. What is the purpose of the `PreparedStatement` interface in JDBC?


a) To connect to the database b) To store query results c) To precompile SQL statements d) To execute DDL commands

9. Which method is used to establish a connection to the database in JDBC?


a) createConnection() b) openConnection() c) getConnection() d) establishConnection()

10. Which of the following is not a valid SQL data type in JDBC?
a) VARCHAR b) INT c) DOUBLE d) BOOLEAN

11. What is the purpose of the `Statement` interface in JDBC?


a) To connect to the database b) To execute SQL queries c) To precompile SQL statements d) To store query results

12. In JDBC, which exception is thrown when there is a problem with the SQL syntax?
a) SQLException b) SQLSyntaxException c) SQLQueryException d) SyntaxError

13. Which method is used to execute a query in JDBC and retrieve the results in a `ResultSet`?
a) executeQuery() b) executeUpdate() c) execute() d) executeBatch()

14. What is the purpose of the `Connection` interface in JDBC?


a) To execute SQL queries b) To store query results c) To manage the connection to the database d) To compile SQL

15. In JDBC, what is the role of the `DriverManager` class?


a) To establish a connection to the database b) To execute SQL queries
c) To manage the result set d) To manage the connection pool database

16. Which of the following is not a JDBC driver?


A. MySQL Connector/J B. PostgreSQL JDBC Driver C. Microsoft SQL Server JDBC Driver D. ODBC Driver

17. Which of the following is used to create a JDBC connection to a database?


A. DriverManager.getConnection() B. Connection.getConnection()
C. Statement.getConnection() D. PreparedStatement.getConnection()

18. Which of the following is used to execute an SQL query in JDBC?


A. Statement.executeQuery() B. Connection.executeQuery()
C. PreparedStatement.executeQuery() D. ResultSet.executeQuery()

19. Which of the following is used to close a JDBC connection?


A. Connection.close() B. Statement.close() C. PreparedStatement.close() D. ResultSet.close()

20. Which of the following is used to handle exceptions in JDBC?


A. try-catch block B. throws clause C. finally block D. All of the above

21. Which of the following is a benefit of using a PreparedStatement in JDBC?


A. It prevents SQL injection. B. It improves performance. C. Both A and B. D. None of the above.

22. Which of the following is a JDBC transaction?


A. A sequence of database operations that are treated as a single unit. B. A way to rollback database changes if an error occurs.
C. Both A and B. D. None of the above.

23 Which of the following is a JDBC connection isolation level?


A. READ UNCOMMITTED B. READ COMMITTED C. REPEATABLE READ
D. SERIALIZABLE E. All of the above

24. Which of the following is a JDBC savepoint?


A. A point in a transaction where you can rollback to if an error occurs.
B. A way to commit a subset of the changes made in a transaction.
C. Both A and B.
D. None of the above.

25. Which of the following is a JDBC batch update?


A) A way to execute multiple SQL statements at once. B) A way to improve the performance of bulk database operations.
C) Both A and B. D). None of the above.

26. The package contains classes that help in connecting to a database, sending SQL statements to the database and process
the query request.
(a)connection.sql (b)b.sql (c)pkg.sql (d)java.sql

27. Which of the following is not a type of JDBC driver?


(a)100% pure Java Driver (b)JDBC–net pure Java Driver
(c)JDBC–Native API driver (d)JDBC–Native pure Java Driver

28.In JDBC imports all Java classes that are concern with Database connectivity.
(a) javax.sql (b)java.mysql (c)java.sql (d)com.sql

29.Database programming using Java throws which of the following exception?


(a)SQLException (b)ClassNotFoundException (c)None of these (d) Both of these

30.In the below statement, which type of query can be used with executeUpdate() method. statement.executeUpdate(query here)
(a)Insert, Update, Delete (b)Insert, Select, Delete (c)Only Select (d) Any Query

31. What is purpose of next( ) method?


(a) to retain the next element in a series. (b) to retain next table.
(c) to retain next record in a series. (d) None of the above

32.What are the major component of the jdbc?


a) DriverManager, DriverConnection, Statement and Resultset b) DriverManager, DriverConnection, and Resultset
c) DriverManager, DriverConnection, Statement d) DriverManager, Connection, Statement and Resultset
33. How Many Transaction isolation levels divide the JDBC through the connection interface?
a) 3 b) 4 c) 7 d) 2

34. Identify the isolation level the prevents the dirty in the JDBC connection class?
a) TRANSACTION_READABLE_READ
b) TRANSACTION_READ_COMMITED
c) TRANSACTION_READ_UNCOMMITED
d) TRANSACTION_NONE

35. In order to transfer data between a database and an application written in the Java programming language, the JDBC API
provides which of these methods?
a. Methods on the ResultSet class for retrieving SQL SELECT results as Java types.
b. Methods on the PreparedStatement class for sending Java types as SQL statement parameters.
c. Methods on the CallableStatement class for retrieving SQL OUT parameters as Java types.
d. All mentioned above

36. The JDBC API has always supported persistent storage of objects defined in the Java programming language through the
methods getObject and setObject.
a. True b. False

37.Which JDBC type represents a "single precision" floating point number that supports seven digits of mantissa?
a. REAL b. DOUBLE c. FLOAT d. INTEGER

38. Which method is used for retrieving streams of both ASCII and Unicode characters is new in the JDBC 2.0 core API?
a. getCharacterStream b. getBinaryStream c. getAsciiStream d. getUnicodeStream

39. How many Result sets available with the JDBC 2.0 core API?
a. 2 b. 3 c. 4 d. 5

40. Abbreviate the term UDA?


a. Unified Data Access b. Universal Data Access
c. Universal Digital Access d. Uniform Data Access

41. The performance of the application will be faster if you use PreparedStatement interface because query is compiled only once.
a. True b. False

42. Which method Drops all changes made since the previous commit/rollback?
a. public void rollback() b. public void commit()
c. public void close() d. public Statement createStatement()

43. The intent is for JDBC drivers to implement nonscrollable result sets using the support provided by the underlying database
systems.
a. True b. False

44. Which methods returns a stream that simply provides the raw bytes from the database without any conversion?
a. getCharacterStream b. getBinaryStream c. getAsciiStream d. getUnicodeStream

45. Which of the following is a JDBC batch update?


A. A way to execute multiple SQL statements at once.
B. A way to improve the performance of bulk database operations.
C. Both A and B.
D. None of the above.

46. Which of the following is not a JDBC driver?


A. MySQL Connector/J B. PostgreSQL JDBC Driver
C. Microsoft SQL Server JDBC Driver D. ODBC Driver

47. Which of the following is used to close a JDBC connection?


A. Connection.close() B. Statement.close() C. PreparedStatement.close() D. ResultSet.close()
48. Where is metadata stored in MySQL.
A) in the MySQL database metadata B)In the MySQL database metasql C)In the MySQL database mysql

49. Which JDBC driver types can you use in a three-tier architecture and if the web server and the DBMS are running on the same
machine.
a)Type 1 b)Type 2 c)Type 3 and 4 d)Type 1, Type 2, Type 3 and Type 4

50. Which driver Network connection is indirect that a JDBC client makes to a middleware process that acts as a bridge to the
DBMS server?
a)JDBC-NET b)JDBC-ODBC Bridge c)Native api as basis d)native protocol as basis

51. Which of the following is correct about JDBC?


a)JDBC Architecture decouples an abstraction from its implementation b)JDBC Follows a bridge design pattern
c)both of the above d)none of the above\

53. Which of the following is used to execute an SQL query in JDBC?


A. Statement.executeQuery() B. Connection.executeQuery()
C. PreparedStatement.executeQuery() D. ResultSet.executeQuery()

54. What must be the first characters of a database URL?


a)db, b)db; c)jdbc, d)odbc

55. What is, in terms of JDBC, a DataSource?


a) A DataSource is the basic service for managing a set of JDBC drivers
b) A DataSource is the Java representation of a physical data source
c) A DataSource is a registry point for JNDI-services
d) A DataSource is a factory of connections to a physical data source

56. Which of the following is a benefit of database normalization?


A. It can improve the performance of database applications.
B. It can reduce the amount of data that needs to be stored in the database.
C. It can make the database easier to maintain and update.
D. All of the above

57. Which of the following is a type of database join?


A. INNER JOIN B. LEFT JOIN C. RIGHT JOIN D. All of the above

58. Which of the following is a database normalization form?


A. 1NF B. 2NF C. 3NF D. All of the above

59. Which of the following describes the correct sequence of the steps involved in making a connection with a database.
1. Loading the driver 2. Process the results.
3. Making the connection with the database. 4. Executing the SQL statements.
A. 1,3,4,2 B. 1,2,3,4 C. 2,1,3,4 D. 4,1,2,3

60. All raw data types (including binary documents or images) should be read and uploaded to the database as an array of
a. byte b. int c. Boolean d. char

61. Which of the following is a connection pool?


A. A set of connections to a database that can be reused by multiple threads
B. A type of database that is optimized for performance

62. Which statement type is used to execute SQL queries that do not return results, such as INSERT, UPDATE, and DELETE
statements?
A. PreparedStatement B. Statement

63. Which method is used to commit a transaction in JDBC?


A. commit() B. rollback()
Sanjivani Rural Education Society’s
SANJIVANI K. B. P.
POLYTECHNIC
Department of Computer Technology
KOPARGAON – 423601, DIST:
AHMEDNAGAR
2024-2025

Class Test : [ Unit ll – Swing ] Date : / /2024


Name : Set : ll
Roll no. :

1. Which layout manager arranges components in a single row or column?


a) BorderLayout b)GridLayout c)FlowLayout d) CardLayout

2. How can you add items to a JComboBox?


a) comboBox.addItem("Item"); b) comboBox.add("Item");
c) comboBox.setItem("Item"); d) comboBox.addElement("Item");

3. What is wrong with the following code?


JFrame frame = new JFrame();
frame.setVisible(true);
frame.setSize(200, 200);
a) The setVisible call should come after setSize b) JFrame should not be used without a title
c) JFrame must have a layout manager d) There is no error

4. JFrame extends java.awt.Frame. a) True b) False

5. Which of the following is not a component of JTree?


a) TreeModel b) TreeCellRenderer c) TreePath d) JTableModel

6. What is the purpose of JTabbedPane?


a) To create multi-tabbed panes in a single container b) To handle table data
c) To display trees d) To manage layouts

7. Which of the following is true about JComboBox?


a) It allows multiple selections b) It provides a drop-down list of options
c) It allows single-line text input d) It cannot be edited

8. Which layout is used to stack components on top of each other?


a) CardLayout b) FlowLayout c) GridLayout d) BorderLayout

9. Which of these is an abstract class in Swing?


a) JButton b) JLabel c) JComponent d) JPanel

10. Which component is used to create a pop-up menu in Swing?


a) JPopup b) JPopupMenu c) JMenu d) JDialog

11. Which Swing class is responsible for providing window decorations?


a) JWindow b) JRootPane c) JFrame d) JPanel

12. Which method is called when a component needs to be redrawn in Swing?


a) refresh() b) render() c) paintComponent() d) redraw()
13. Which method is used to select multiple items in a JList?
a) setMultipleSelection() b) setSelectionMode() c) setMultipleMode() d) setMultiSelect()

14. What will the following code display when run?


JFrame frame = new JFrame();
frame.setLayout(new GridLayout(2, 1));
frame.add(new JLabel("Label 1"));
a) Two labels, one below the other b) Two labels, side by side
frame.add(new JLabel("Label 2")); c) A single label d) Compilation error
frame.setSize(200, 200);
frame.setVisible(true);

15. What is the purpose of JPasswordField?


a) To display hidden input characters for passwords b) To select options from a drop-down menu
c) To display a progress bar d) To display pop-up dialogs

16. Find the error in the following code:


JFrame frame = new JFrame(); a) setDefaultCloseOperation value is incorrect b) setSize must be called first
frame.setVisible(true);
frame.setSize(200, 200); c) JFrame should have a title d) There is no error
frame.setDefaultCloseOperation(JFrame.EXIT);

17. Which Swing component is best for displaying multiple lines of text?
a) JLabel b) JTextField c) JTextArea d) JButton

18. What will be the output if the following code is executed?


JFrame frame = new JFrame();
frame.setTitle("Hello");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
a) "null" b) "Hello"
System.out.println(frame.getTitle()); c) Runtime exception d) "JFrame"

19. What will happen if frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE) is called?


a) The window will not close when the user clicks the close button b) The window will close normally
c) A compilation error occurs d) The window minimizes

20. Find the error in the following code:


JFrame frame = new JFrame(); a) setDefaultCloseOperation value is incorrect b) setSize must be called first
frame.setVisible(true); c) JFrame should have a title d) There is no error
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT);

21. Which method is used to disable a button in Swing?


a) setEnable(false) b) setEnabled(false) c) disable() d) lock()

22. Which of the following correctly instantiates a JFrame with the title "MyApp" and sets its close operation?
a) JFrame frame = new JFrame(); frame.setTitle("MyApp"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b) JFrame frame = new JFrame("MyApp"); frame.setCloseOperation(JFrame.EXIT_ON_CLOSE);
c) JFrame frame = new JFrame("MyApp"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
d) JFrame frame = new JFrame("MyApp"); frame.setVisible(true);

23. A JFrame cannot contain more than one JPanel at a time. a) True b) False

24. What does JTextField inherit from?


a) JComponent b) JPanel c) JTextComponent d) JLabel

25. In Swing, which layout manager arranges components in a grid?


a) FlowLayout b) BorderLayout c) GridLayout d) BoxLayout
26. JList allows multiple selection by default. a) True b) False

27. A JButton can have both an icon and text at the same time. a) True b) False

28. Which method is used to get the selected item from a JComboBox?
a) getText() b) getSelectedItem ()c) getSelection() d) getSelected()

29. Which of the following is a non-editable text component in Swing?


a) JLabel b) JTextField c) JTextArea d) JPasswordField

30. The setPreferredSize() method guarantees the final size of a JComponent. a) True b) False

31. What is the main reason behind a NullPointerException in a Swing application?


a) Swing components are not initialized b) Syntax error
c) Incorrect imports d) Infinite loop

32. What will happen if setVisible(true) is not called for a JFrame object?
a) The frame will be visible. b) The frame will not be created.
c) The frame will be created but not visible. d) The frame will throw an exception.

33. Which of the following is NOT a valid layout manager in Swing?


a) FlowLayout b) BoxLayout c) BorderLayout d) ColumnLayout

34. Which of the following is responsible for handling events in a Swing application?
a) JComponent b) JFrame c) Event Queue d) ActionListener

35. What will be the output if repaint() is called on a JPanel?


a) The panel will be re-rendered immediately. b) It will call the paintComponent() method asynchronously
c) It will do nothing. d) It will throw an exception.

36. Which method is used to set the size of a JButton in Swing?


a) setSize() b) setPreferredSize() c) setButtonSize() d) setBounds()

37. What is the correct way to make a JPanel scrollable?


a) Add the panel directly to the JFrame b) Add the panel inside a JScrollPane
c) Add a JScrollBar directly to the JPanel d) Override the paintComponent method

38. If you forget to call super.paintComponent(g) in the paintComponent() method of a JPanel, what will happen?
a) Nothing b) The background may not be cleared properly
c) The panel will not be displayed d) The application will crash

39. What is the correct way to attach an ActionListener to a JButton?


a) button.setAction(new ActionListener()) b) button.addActionListener(new ActionListener())
c) button.setListener(new ActionListener()) d) button.addAction(new ActionListener())

40. Which of the following is responsible for handling events in a Swing application?
a) JComponent b) JFrame c) Event Queue d) ActionListener

41. In a GridLayout, how are components placed?


a) Row by row b) Column by column c) Based on specified weights d) Randomly

42. Which method is used to set the position and size of a JComponent?
a) setBounds() b) setPosition() c) setLayout() d) setFrame()
43. What is the output of the following code?
JFrame frame = new JFrame();
frame.setSize(300, 300); a) A frame of size 300x300 is visible. b) A frame is visible but its size is undefined.
frame.setVisible(true); c) Nothing happens. d) A frame appears but its content is not visible

44. Which of the following statements is true regarding JTextArea?


a) It can display multiple lines of text. b) It can display only one line of text.
c) It automatically wraps text. d) It cannot display text.

45. Find the missing statement: To add a menu bar to a JFrame, use ______.
a)frame.setComponent(menuBar) b) frame.add(menuBar)
c) frame.setMenu(menuBar) d) frame.setJMenuBar(menuBar)

46. Which statement is true about JPanel and JFrame?


a) Both are containers. b) Only JPanel is a container.
c) Only JFrame is a container. d) Neither of them is a container.

47. What will be the output if a JTextField has a width of 10 but is set with text of 20 characters?
a) The text will be truncated. b) The text will automatically scroll.
c) An exception will occur. d) The text will be completely visible.

48. What will be the output of the following code? a) The button will be placed at the center of the panel.
JPanel panel = new JPanel(); b) The button will be placed at the left side of the panel.
panel.add(new JButton("Click")); c) The button will not be visible.
panel.setLayout(new FlowLayout()); d) An exception will occur.

49. What happens if you call setLayout(null) on a JFrame?


a) No layout manager will be used, and you must manually set component positions.
b) A default layout manager will be applied.
c) The layout manager will be FlowLayout.
d) It will throw an exception.

50. Find the missing statement: To refresh the content of a JPanel, call ______.
a) repaint() b) setLayout() c) updateComponent() d) reload()

51. . Which of the following components is used to create a text box where the user can enter a single line of text?
a) JTextArea b) JTextField c) JLabel d) JEditorPane

52. Find the missing statement: To respond to a selection event in a JComboBox, use ______.
a) addSelectionListener() b) addActionListener()
c) addItemListener() d) addComboListener()

53. What will happen if a null layout manager is set in a JPanel?


a) Components will be laid out automatically. b) Components must be manually positioned.
c) An exception will occur. d) The layout will default to FlowLayout.

54. What will be the output if repaint() is called on a JPanel?


a) The panel will be re-rendered immediately.
b) It will call the paintComponent() method asynchronously.
c) It will do nothing.
d) It will throw an exception.
Sanjivani Rural Education Society’s

SANJIVANI K. B. P. POLYTECHNIC
Department of Computer Technology
KOPARGAON – 423601, DIST: AHMEDNAGAR / 63
2024-2025
Sub Name : Advanced Java Programming (AJP -22517) Course Code : CM-5-I
Name : Date: / /2024
Roll No : Set: I
Practice Test: [ Unit VI -Severlet ]

1. What is a servlet in Java?


a) A type of coffee b) A server-side Java program c) A type of Java class d) A type of Java exception

2. Which package provides the classes for servlets?


a) javax.servlet b) java.servlet c) javax.server d) java.server

3. Which HTTP methods can a servlet handle?


a) GET and POST b) GET, POST, PUT, and DELETE
c) GET, POST, and UPDATE d) GET, POST, DELETE, and MODIFY

4. In which method should you override to handle GET requests in a servlet?


a) doGet() b) doPost() c) doRequest() d) handleGet()

5. Which of the following is not a servlet life cycle method?


a) init() b) service() c) destroy() d) run()

6. What is the purpose of the `init()` method in a servlet?


a) To perform cleanup tasks before the servlet is destroyed b) To handle client requests
c) To initialize the servlet before serving client requests d) To redirect requests to other servlets

7. Which method is responsible for destroying a servlet?


a) finalize() b) destroy() c) close() d) cleanup()

8. What is the default scope of a servlet?


a) Request b) Session c) Application d) Page

9. Which object represents a client's request to the servlet container?


a) HttpServletRequest b) HttpServletResponse c) ServletContext d) HttpSession

10. Which method can be used to send a response to the client in a servlet?
a) getRequest() b) sendResponse() c) getResponse() d) HttpServletResponse.getWriter()

11. How can you obtain the value of a request parameter in a servlet?
a) Using the `request.getAttribute()` method b) Using the `request.getParameter()` method
c) Using the `request.getSession()` method d) Using the `request.getAttribute()` method

12. What is the default URL mapping for a servlet in web.xml?


a) /servlet/* b) /servlets/* c) /app/* d) /servlet-name/*
13. What is the purpose of the `web.xml` file in a servlet application?
a) To configure servlet mappings b) To define servlet classes
c) To specify HTML templates d) To store database connection details

14. Which HTTP status code indicates that a resource is not found?
a) 200 OK b) 302 Found c) 404 Not Found d) 500 Internal Server Error

15. Which interface must a servlet implement to handle session events?


a) HttpSessionListener b) HttpSessionAttributeListener
c) ServletContextListener d) ServletRequestListener

16. How can you store session data in a servlet?


a) Using the `HttpServletRequest` object b) Using the `ServletContext` object
c) Using the `HttpSession` object d) Using the `HttpServletResponse` object

17. What is the purpose of the `ServletContext` in a servlet application?


a) To store session data b) To manage the servlet life cycle
c) To share data among servlets d) To store servlet configuration parameters

18. How can you set an attribute in the `ServletContext` in a servlet?


a) Using the `setContextAttribute()` method b) Using the `setAttribute()` method
c) Using the `addAttribute()` method d) Using the `context.set()` method

19. What is the purpose of the `RequestDispatcher` interface in servlets?


a) To send an HTTP request to another server
b) To include the content of another resource in the response
c) To forward the request to another resource within the same servlet context
d) To send a response to the client

20. Which of the following is NOT a valid way to create a servlet in Java?
a) Extending the `HttpServlet` class b) Implementing the `Servlet` interface
c) Using the `new` keyword d) Extending the `GenericServlet` class

21. What is a servlet filter used for?


a) To process requests before they reach a servlet b) To filter out invalid HTTP methods
c) To filter out client IP addresses d) To filter out invalid session data

22. Which of the following is true about servlet filters?


a) Filters can only be used with servlets and not with JSP.
b) Filters can modify the response but not the request.
c) Filters cannot change the order of execution of servlets.
d) Filters can be configured in the web.xml file.

23. What is the purpose of the `doFilter()` method in a servlet filter?


a) To forward the request to another servlet b) To send a response to the client
c) To process the request and response d) To destroy the filter

24. How can you invalidate a session in a servlet?


a) session.invalidate() b) session.invalidateSession() c) session.destroy() d) session.remove()

25. Which of the following is NOT a valid method of communication between servlets?
a) Using the `ServletContext` b) Using the `HttpServletResponse`
c) Using the `RequestDispatcher` d) Using HTTP sessions

26. What is the purpose of the `javax.servlet.annotation.WebServlet` annotation?


a) To define a servlet class b) To configure servlet mappings c) To specify request parameters d) To declare a servlet filter

27. Which HTTP method is used to retrieve data from the server in a safe and idempotent way?
a) GET b) POST c) PUT d) DELETE

28. Which method is called when a session is created in a servlet?


a) sessionCreated() b) sessionInitialized() c) initSession() d) createSession()

29. How can you obtain the session ID in a servlet? a) session.getSessionID() b)


session.getID() c) session.getId() d) session.getSessionId()

30. What is the purpose of the `ServletContext.getAttribute()` method?


a) To retrieve a session attribute b) To retrieve a request attribute
c) To retrieve a servlet context attribute d) To retrieve a response attribute

31. What is the purpose of the `HttpServletRequest.setAttribute()` method?


a) To set a session attribute b) To set a request attribute
c) To set a servlet context attribute d) To set a response attribute

32. Which of the following is NOT a valid HTTP status code?


a) 200 OK b) 300 Redirect c) 400 Bad Request d) 500 Internal Server Error

33. What is the purpose of the `ServletContext.getInitParameter()` method?


a) To retrieve a servlet's initialization parameter b) To retrieve a session attribute
c) To retrieve a request attribute d) To retrieve a servlet context attribute

34. What is the purpose of the `HttpServletResponse.setContentType()` method?


a) To set the HTTP response status code b) To set the content length of the response
c) To set the content type of the response d) To send a redirect response

35. Which of the following is NOT a valid content type for an HTTP response?
a) text/html b) application/json c) image/png d) audio/mp3

36. What is the purpose of the `ServletContext.getContextPath()` method?


a) To retrieve the context path of a servlet b) To retrieve the context path of a session
c) To retrieve the context path of a request d) To retrieve the context path of the servlet container

40. What is the purpose of the `HttpServletResponse.setStatus()` method?


a) To set the HTTP response status code b) To set the content type of the response
c) To set the character encoding of the response d) To set the content length of the response

41. Which of the following is NOT a valid HTTP status code for a successful response?
a) 200 OK b) 201 Created c) 204 No Content d) 404 Not Found

42. Which of the following is NOT a valid HTTP response header?


a) Content-Type b) Location c) Set-Cookie d) Request-Method

43. What is the purpose of the `HttpServletResponse.addCookie()` method?


a) To set an HTTP response header b) To add a cookie to the client's browser
c) To add a session attribute d) To add a request parameter

44. Which of the following is NOT a valid method of managing session tracking in servlets?
a) Using cookies b) Using URL rewriting c) Using session IDs d) Using request attributes

45. Which of the following is NOT a valid content type for an HTTP response?
a) text/html b) application/json c) image/jpeg d) audio/wav

46. What is the purpose of the `HttpServletResponse.reset()` method?


a) To reset the servlet's configuration parameters b) To reset the servlet's initialization parameters
c) To reset the HTTP response to its initial state d) To reset the HTTP request to its initial state

47. What is the purpose of the `HttpServletResponse.sendError()` method?


a) To send a redirect response b) To send an error response with a specified status code
c) To send an error response with a status code of 200 OK d) To send a response with no content

48. What is the purpose of the `HttpServletResponse.setStatus()` method?


a) To set the HTTP response status code b) To set the content type of the response
c) To set the character encoding of the response d) To set the content length of the response

49. What is the purpose of the `ServletContext.getContextPath()` method?


a) To retrieve the context path of a servlet b) To retrieve the context path of a session
c) To retrieve the context path of a request d) To retrieve the context path of the servlet container

50. What does the term "servlet container" refer to?


a) A physical container used to ship servlets b) software component manages execution of servlets
c) A data structure for storing servlet instances d) A security mechanism for servlets

51. Which of the following is NOT a valid HTTP response header in a servlet?
a) Content-Type b) Location c) Session-ID d) Set-Cookie

52. What is the purpose of the `ServletContextListener` interface in servlets?


a) To listen for changes in session attributes b) To listen for changes in servlet context attributes
c) To listen for changes in request parameters d) To listen for changes in response headers

53. How can you include the content of another resource in a servlet response?
a) By using the `RequestDispatcher.include()` method b) By using the `HttpServletResponse.include()` method
c) By using the `RequestDispatcher.forward()` method d) By using the `HttpServletResponse.forward()` method

54. How can you obtain the value of a servlet's initialization parameter in a servlet?
a) Using the `initParameter()` method of the `ServletConfig` object
b) Using the `getParameter()` method of the `HttpServletRequest` object
c) Using the `getAttribute()` method of the `ServletContext` object
d) Using the `getParameter()` method of the `HttpServletResponse` object

55.How is the dynamic interception of requests and responses to transform the information done.
a)sevlet container b)servlet config c)servlet context d)sevlet filter

56.Which type of servletengine is a server that includes built-in support


for servlets. c)StandaloneServletEngine d)None of the above
a)Add-onServletEngine b)EmbeddedServletEngine

57.What type of servlet use this method


b)HttpServlet c)All of the above d)None of the above
doGet(),doPost(),doHead(),doDelete(),doTrace().
a)GenericServlet

58.Which Cookie it is valid for single session only and it is removed each time when the user closes the browser. a)President
Cookie
b)Non-president cookie
c)all of the above
d)None of the above

59.Session is the part of the SessionTracking and it is for maintaining the client state at server side.
a)true b)false c)none d)All

60.When destroy() method of a filter is called?


a)the destroy() method is called only once at the end of the life cycle of a filter
b)the destroy() method is called after the filter has executed the doFilter() method
c)the destroy() method is called only once at the beginning of the life cycle of a filter
d)the destroy() method is called after the filter has executed

61.Web server is used for loading the init() method of servlet.


a)true b)false c)None d)All

62 .Servlets handle multiple simultaneous requests by using threads.


a)true b)false c)None d)All

63.Which method is used send the same request and response objects to another servlet in RequestDispatcher().
a)forward b)sendRedirect() c)Both a and a d)None of the above
Sanjivani Rural Education Society’s

SANJIVANI K. B. P. POLYTECHNIC
Department of Computer Technology
KOPARGAON – 423601, DIST: AHMEDNAGAR
2023-2024
/60
Sub : AJP (22517) Pratice Test: [Unit IV - Networking Basics] Date : / /2023
Name : Course Code : CM-5-I
Roll No : Set : II

1. What does the acronym "HTTP" stand for in the context of web communication?
A. Hyperlink Transfer Protocol B. Hypertext Transfer Protocol
C. Hyper Transfer Text Protocol D. High-Speed Text Protocol

2. In Java, which class is commonly used to establish a server socket for network communication?
A. Socket B. ServerSocket C. DatagramSocket D. InetAddress

3. Which Java package provides classes for working with sockets and networking?
A. java.net B. java.io C. java.lang D. java.util

4. Which protocol is typically used for sending email in Java applications?


A. HTTP B. FTP C. SMTP D. POP3

5. Which Java class is used to represent an IP address?


A. IPAdress B. InetAddress C. IPHost D. HostAddress

6. What is the purpose of the "URLConnection" class in Java?


A. To represent a URL connection B. To establish a secure SSL connection
C. To handle HTTP requests and responses D. To encode and decode URLs

7. In Java, which protocol is used for transferring files over the network?
A. HTTP B. FTP C. TCP D. UDP

8. Which Java class is used to read and write binary data over a network stream?
A. BufferedReader B. BufferedWriter C. ObjectInputStream D.DataInputStream

9. What is the role of the "SocketTimeoutException" in Java networking?


A. It indicates a successful network connection.
B. It occurs when a socket is closed gracefully.
C. It signals a timeout when waiting for data on a socket.
D. It represents an error in the socket's IP address.

10. Which Java class allows you to create and manage URL objects?
A. URLBuilder B. URLManager C. URLEncoder D. URLConnection

11. What does HTTP stand for in the context of networking?


a) Hyper Transfer Text Protocol b) Hypertext Transfer Protocol
c) Hyperlink Text Transfer Protocol d) Hypertext Transmission Protocol

12. Which Java class is used for creating network sockets?


a) Socket b) ServerSocket c) DatagramSocket d) InetAddress

13. Which protocol is commonly used for sending email in Java applications?
a) FTP b) SMTP c) HTTP d) Telnet

14. In Java, which class is used to represent an IP address?


a) IP b) IPAddress c) InetAddress d) InetAddressUtils

15. Which Java library is commonly used for making HTTP requests?
a) java.net b) javax.servlet c) java.http d) java.httpclient

16. What does DNS stand for?


a) Dynamic Network System b) Domain Name System c) Data Network Service d) Digital Network Security

17. Which port is commonly used for HTTP communication?


a) 21 b) 80 c) 443 d) 8080

18. Which Java class is used for handling UDP (User Datagram Protocol) communication?
a) DatagramSocket b) UDPSocket c) DatagramConnection d) UDPConnection

19. Which Java class is used for reading from and writing to streams?
a) Stream b) InputStream c) OutputStream d) StreamReader

20. What is the primary purpose of a firewall in a network?


a) To increase network speed b) To block all incoming and outgoing traffic
c) To protect the network from unauthorized access and threats d) To reroute network traffic

21. Which Java method is used to establish a connection to a remote server using TCP/IP?
a) connect() b) open() c) accept() d) bind()

22. Which protocol is used for secure communication over the internet?
a) SSL b) HTTP c) FTP d) Telnet

23. What is the purpose of the InetAddress class in Java?


a) To represent IP addresses b) To establish socket connections c) To send emails d) To read from files

24. Which of the following is not a valid IP address format?


a) 192.168.1.1 b) 300.200.100.50 c) 10.0.0.1 d) 172.16.0.0

25. Which Java class is used for creating a server socket?


a) SocketServer b) ServerSocket c) TCPServer d) NetworkServer

26. In Java, which protocol is commonly used for sending and receiving email?
a. FTP b. SMTP c. HTTP d. POP3

27. What is the purpose of the HttpURLConnection class in Java?


a. To connect to a database b. To establish a secure connection
c. To work with HTTP connections d. To create a UDP socket

28. Which Java class is used for reading and writing data to a network socket?
a. ServerSocket b. Socket c. DatagramSocket d. InputStreamReader

29. In Java networking, what is the purpose of the InetAddress.getByName() method?


a. To get the IP address of a domain name b. To retrieve the host's hostname
c. To set the local host's IP address d. To create a new InetAddress object

30. What is the role of the java.net.URL class in networking?


a. To read and write files locally b. To manage database connections
c. To represent a Uniform Resource Locator d. To encrypt data during transmission

31.Which Java package is commonly used for socket programming?


a. java.sql b. java.io c. java.util d. java.net

32. Which exception is typically thrown when a network operation fails in Java?
a. NetworkException b. IOException c. MalformedURLException d. DataFormatException

33. Which Java class is commonly used to establish a client-server connection for network communication?
a) Socket b) Datagram c) URLConnection d) HttpRequest

34. Which of these class is used to encapsulate IP address and DNS?


a) DatagramPacket b) URL c) InetAddress d) ContentHandler

35. Which class is used to create servers that listen for either local client or remote client programs?
a. ServerSockets b. httpServer c. httpResponse d. None of the above

36. What does IP stand for in networking?*


a. Internet Protocol b. Internet Port c. Internal Protocol d. Internet Portability

37. Which class in Java allows you to create a client socket?


a. ServerSocket b. Socket c. DatagramSocket d. InetAddress

38. Which socket type is used for UDP communication in Java?


a. DatagramSocket b. ServerSocket c. Socket d. MulticastSocket

39. What is the main advantage of TCP over UDP in networking?


a. Lower latency b. Connection-oriented c. Suitable for broadcasting d. Simple error handling

40. Which of these class is used to encapsulate IP address and DNS?


a) DatagramPacket b) URL c) InetAddress d) ContentHandler

41.The client in socket programming must know which informations?


a. IPaddress of Server b. Port number c. Both A & B d. None of the above
42. What does the java.net.InetAddress class represent?
a. Socket b. IP Address c. Protocol d. MAC Address
43. Which classes are used for connection-less socket programming?
a. DatagramSocket b. DatagramPacket c. Both A & B d.None of the above

44. Which methods are commonly used in ServerSocket class?


a. public OutputStream getOutputStream() b. public Socket accept()
c. public synchronized void close() d. None of the above

45. Show some networking terminologies given below?


A. IP Address B. Protocol C. MAC Address D. All mentioned above

46. TCP,FTP,Telnet,SMTP,POP etc. are examples of ?


A. Socket B. IP Address C. Protocol D. MAC Address

47. Which classes are used for connection-oriented socket programming?


A. Socket B. ServerSocket C. Both A & B D. None of the above

48. Which class can be used to create a server socket. This object is used to establish communication with the clients?
A. ServerSocket B. Socket C. Both A & B D. None of the above
49. Which methods are commonly used in ServerSocket class?
A. public OutputStream getOutputStream() B. public Socket accept()
C. public synchronized void close() D. None of the above

50. URL is an acronym for?


A. Uniform Resource Locator B. Unified Resource Locator C. Uniform Restore Locator D. Unified Restore Locator

52. The URLConnection class can be used to read and write data to the specified resource referred by the URL?
A. True B. False

53. The java.net.InetAddress class represents an?


A. Socket B. IP Address C. Protocol D. MAC Address

54. In InetAddress class which method it returns the host name of the IP Address?
A. public String getHostName() B. public String getHostAddress()
C. public static InetAddress getLocalHost() D. None of the above

55. Which classes are used for connection-less socket programming?


A. DatagramSocket B. DatagramPacket C. Both A & B D. None of the above

56 . Check whether the following code is correct or not?


import javax.net.*;
import java.io.*;
public class Net1
{
public static void main(String args[])
{
try
{
InetAddress ip=InetAddress.getByName("www.javapoint.com");
System.out.println("Host Name: "+ip.getHostName());
System.out.println("Host Address: "+ip.getHostAddress());
}
catch(Exception e)
{
System.out.println(e);
}
}
}

a. Correct b. Incorrect

57. Figure out the error(s) in the following code?


import javax.net.*;
import java.io.*;
public class Net1
{
public static void main(String args[])
{
try
{
InetAddress ip=InetAddress.getByName("www.javapoint.com");
System.out.println("Host Name: "+ip.getHostNam());
System.out.println("Host Address: "+ip.getHostAddress());
}
catch(Exception e)
{
System.out.println(e);
}
}
}

a. In import package b. In Try c. In System.out.println d. Both (a) and (c)

58. In the following code, do we require try-catch compulsorily?


import javax.net.*;
import java.io.*;
public class Net1
{
public static void main(String args[])
{
try
{
InetAddress ip=InetAddress.getByName("www.javapoint.com");
System.out.println("Host Name: "+ip.getHostName());
System.out.println("Host Address: "+ip.getHostAddress());
}
catch(Exception e)
{
System.out.println(e);
}
}
}

a. Yes b. No

59. Check whether the following code is correct or not?


import javax.net.*;
public class Net1
{
public static void main(String args[])throws Exception
{
URL u=new URL("https://www.google.com");
System.out.println("Protocol: "+u.getProtocol());
System.out.println("Port: "+u.getPort());
System.out.println("Host: "+u.getHost());
System.out.println("File: "+u.getFile());
System.out.println("Ref: "+u.getRef());
System.out.println("Exit: "+u.getExternalForm());
}
}

a. Correct b. Incorrect
60. Check out whether the following code contains error(s) or not.
import javax.net.*;
public class Net1
{
public static void main(String arg[])throws MaiformedURLException
{

URL u=new URL("https://www.google.com");


System.out.println("Protocol: "+u.getProtocol());
System.out.println("Port: "+u.getPort());
System.out.println("Host: "+u.getHost());
System.out.println("File: "+u.getFile());
System.out.println("Ref: "+u.getRef());
System.out.println("Exit: "+u.getExternalForm());
}
}

a. No Errors Present b.Errors Present

61. Check out whether the following code contains error(s) or not.
import java.io.*;
import java.net.*;
import java.util.Date;
public class URLINFORMATION
{
public static void main(String args[])
{
URL =new URL("http://www.msbte.com");
URLConnection con = url.openConnection();
System.out.println("");
System.out.println(url);
System.out.println("Date:"+new Date(con.getDate()));
System.out.println("Content-Type"+con.getContentType());
System.out.println("Expiers:"+con.getExpiration());
System.out.println("Last-Modified:"+new Date(con.getLastModified()));
int len = con.getContentLength();
System.out.println("Content-Length:"+len);
}
}

a. In URLConnection Line b. In URlCreation Line

c. Both (a) and (b) d. None

62. Check whether the following code is correct or not?


import java.io.*;
import java.net.*;
public class InetDemo222
{
public static void main(String args[])
{
try
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
address = InetAddress.getByName("www.google.com");
System.out.println(address);
InetAddress sw[] = InetAddress.getAllByName("www.yahoo.com");
for(int i=0; i<sw.length;i++)
{
System.out.println(sw[i]);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

a . Correct b. Incorrect

63. Which of the following Java code snippets correctly opens a server socket on port 8080?

(A) ServerSocket = new ServerSocket(8080);


(B) Socket serverSocket = new ServerSocket(8080);
(C) ServerSocket = new Socket(8080);
(D) Socket = new Socket();
socket.bind(new InetSocketAddress(8080));

a. (A) b. (B) c. (C) d. (D)

64. Which Java code snippet is used to establish a client socket connection to a server at IP address "192.168.1.100" and port 12345?

(A) Socket = new Socket("192.168.1.100", 12345);


(B) Socket = new Socket(12345, "192.168.1.100");
(C) Socket = new Socket("192.168.1.100");
socket.connect(new InetSocketAddress(12345));
(D) ServerSocket = new ServerSocket(12345);
Socket socket = serverSocket.accept();

a. (A) b. (B) c. (C) d. (D)

65. Which of the following Java code snippets is used to set up a UDP socket for sending and receiving datagrams?

(A) Socket socket = new Socket();


(B) DatagramSocket datagramSocket = new DatagramSocket();
(C) ServerSocket serverSocket = new ServerSocket();
(D) DatagramSocket datagramSocket = new DatagramSocket(12345);

a. (A) b. (B) c. (C) d. (D)


66. In Java, which of the following code snippets demonstrates how to read data from a client socket using an InputStream?

(A) Socket socket = new Socket("localhost", 8080);


DataOutputStream out = new DataOutputStream(socket.getOutputStream());
(B) ServerSocket serverSocket = new ServerSocket(8080);
Socket socket = serverSocket.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
(C) Socket socket = new Socket("localhost", 8080);
DataInputStream in = new DataInputStream(socket.getInputStream());
(D) Socket socket = new Socket("localhost", 8080);
OutputStream out = socket.getOutputStream();

a. (A) b. (B) c. (C) d. (D)

67. Which of the following Java code snippets correctly sends an HTTP GET request to a server at "example.com" on port 80?

(A) Socket socket = new Socket("example.com", 80);


PrintWriter out = new PrintWriter(socket.getOutputStream());
out.println("GET / HTTP/1.1");
(B) Socket socket = new Socket("example.com", 80);
OutputStream out = socket.getOutputStream();
PrintWriter writer = new PrintWriter(out);
writer.println("GET / HTTP/1.1");
(C) Socket socket = new Socket("example.com", 80);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
writer.write("GET / HTTP/1.1");
(D) URL url = new URL("http://example.com");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

a. (A) b. (B) c. (C) d. (D)

68. You want to create a Java program to establish a client-server connection. Which code snippet correctly creates a client socket
and connects to a server running on "localhost" at port 8080?

(A) Socket clientSocket = new Socket("localhost", 8080);


(B) ServerSocket serverSocket = new ServerSocket(8080);
(C) DatagramSocket datagramSocket = new DatagramSocket(8080);
(D) Socket clientSocket = new Socket("localhost");

a. (A) b. (B) c. (C) d. (D)

69. You are developing a Java program to establish a server-client connection. Which code snippet correctly creates a server socket
that listens on port 8888 and accepts incoming connections from clients?

(A) ServerSocket serverSocket = new ServerSocket(8888);


(B) Socket serverSocket = new Socket("localhost", 8888);
(C) Socket serverSocket = new Socket(8888);
(D) ServerSocket serverSocket = new ServerSocket("localhost", 8888);

a. (A) b. (B) c. (C) d. (D)

You might also like