Chapter 01 Introduction to AWT
Subject: - Advanced Java Programming
(22517)
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 1 of 29
Chapter 01 Introduction to AWT
Chapter Marks With
Name of chapter
No. Option
1 Abstract Windowing Toolkit(AWT) 12
2 Swings 10
3 Event Handling 12
4 Networking Basics 10
5 Interacting with Database 12
6 Servlets 14
10
Total Marks: - 70
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 2 of 29
Chapter 01 Introduction to AWT
COURSE: - Advanced Java Programming (22517)
PROGRAMME: - Information Technology
CO. NO. Course Outcome
CO- 517.01 Develop Programs using GUI Framework (AWT and Swing).
CO- 517.02 Handle events of AWT and Swing components.
CO- 517.03 Develop Programs to handle events using Java Programming
CO- 517.04 Develop Java Programs using networking concepts.
CO- 517.05 Develop Programs using database.
CO- 517.06 Develop Programs using Servlets.
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 3 of 29
Chapter 01 Introduction to AWT
-----------------------------------------------------------------------------------------------------------
Total Marks-12
-----------------------------------------------------------------------------------------------------------
MCQ Question
(Total number of Question=Marks*3=12*3=36)
Note: Correct answer is marked with bold.
1. AWT Means?
(a) Abstract Windows Toolkit (b) Advanced Web Toolkit
(c) Abstract Web Toolkit (d) Advanced Web Technology
2. Which is the immediate super class of Applet?
(a) Container (b) Component
(c) Frame (d) Panel
3. The setSize( ) method is defined by this class…
(a) Applet (b) Component
(c) Frame (d) Panel
4. Which class encapsulates a blank window upon which we can draw?
(a) Applet (b) Canvas
(c) Window (d) Frame
5. What are the variables defined in ‗Dimension‘ class?
(a) length and width (b) height and length
(c) height and width (d) len and wid
6. If we want to hide the window, we can use this method…
(a) setVisible( ) (b) show( )
(c) setHidden( ) (d) view( )
7. Color class can create object of it using following color values?
(a) RGB (b) RYB
(c) CMY (d) HSB
8. The setColor( ) is the method of which class?
(a) Applet (b) Graphics
(c) Color (d) Object
9. Which of the following style is not supported by Font class?
(a) Font.UNDERLINE (b) Font.ITALIC
(c) Font.PLAIN (d) Font.BOLD
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 4 of 29
Chapter 01 Introduction to AWT
10. All the AWT controls are subclasses of which class?
(a) Component (b) Container
(c) AWTControl (d) Window
11. How you can remove all the controls from the applet?
(a) Using remove( ) method.
(b) Using removeAll( ) method.
(c) Using removeAllControls( ) method.
(d) It is not possible to remove all controls using single method.
12. Which of the following is passive AWT control?
(a) Label (b) Button
(c) Checkbox (d) TextField
13. Which alignment is not supported by Label?
(a) Label.RIGHT (b) Label.LEFT
(c) Label.CENTER (d) Label.BASELINE
14. How can we create Radio buttons?
(a) Using ButtonGroup class (b)Using CheckboxGroup class
(b) Using RadioButton (d) class Using Button class
15. How to add the names in choice controls?
(a) At the time of creation itself. (b) Using addName( ) method.
(c) Using addItem( ) method. (d) Using add( ) method.
16. Multiple selections are allowed in…
(a) Menu (b) CheckboxGroup
(c) List (d) Choice
17. How can we copy the ‗List‘s contents into ‗Choice‘s contents
(a) This is not possible.
(b) Using copyInto( ) method of List
(c) Directly assigning List object to Choice object.
(d) Using copyFrom( ) method.
18. What is default block-increment of Scrollbar?
(a) 10
(b) 5
(c) 1
(d) We cannot use block increment in scrollbars
19. The immediate super class of TextArea is…
(a) TextField (b) TextBox
(c) TextComponent (d) Component
20. Is it possible to change display character of TextField? How?
(a) Not possible.
(b) Yes, by using setChar( ) method.
(c) Yes, by using setEchoChar( ) method.
(d) Yes, by using setDisplayChar( ) method.
21. Is it possible to center the text typed in TextField? How?
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 5 of 29
Chapter 01 Introduction to AWT
(a) Not possible.
(b) Yes, by using setAlignment( ) method.
(c) Yes, by using setPosition( ) method.
(d) Yes, by putting values in the constructor itself.
22. Which method is used to append the text at the end of TextArea?
(a) append( ) (b) add( )
(c) appendAt( ) (d) addAt( )
23. FlowLayout does not support this value of alignment…
(a) FlowLayout.LEFT
(b) FlowLayout.CENTER
(c) FlowLayout.RIGHT
(d) FlowLayout.BASELINE
24. The setLayout( ) is the method of which class?
(a) Applet (b) LayoutManager
(c) FlowLayout (d) Graphics
25. BorderLayout does not support this value of alignment…
(a) BorderLayout.WEST
(b) BorderLayout.EAST
(c) BorderLayout.NORTH
(d) BorderLayout.MIDDLE
26. The correct constructor of Insets( ) which uses the values is…
(a) Insets(int top, int left, int bottom, int right)
(b) Insets(int bottom, int right, int top, int left)
(c) Insets(int right, int top, int left, int bottom)
(d) Insets(Dimesnion d1, Dimension d2)
27. The various controls supported by AWT are
(a) Labels, push buttons
(b) Checkboxes, choice, list
(c) Scroll bars, text area, text field
(d) All of these
28. The concept of the menu bar canbe implemented by using three java classes—
(a) MenuBar (b) Menu
(c) MenuItem (d) All of these
29. The most commonly used layout managers are
(a) FlowLayout (b) BorderLayout
(c) GridLayout (d) All of these
30. The constructor which the Text Event class defines.
(a) TextEvent(Object source, int event_type)
(b) textevent (Object source, int event_type)
(c) textevent (object Source, float event_type)
(d) textevent (Object source, string event_type)
31. In Java an event is an which specifies the change of state in the source.
(a) Class (b) Object
(c) Int (d) String
32. The name of the event classes are_
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 6 of 29
Chapter 01 Introduction to AWT
(a) ActionEvent, ComponentEvent
(b) ContainerEvent, FocusEvent
(c) ItemEvent, KeyEvent
(d) WindowListener, MouseEvent
(e) All of these
33. The classes and interfaces defined in AWT are contained within the package.
(a) java.awt.* (b) java.sql.*
(c) java.io.* (d) java.int*
34. Java packages such as support the Event handling mechanism.
(a) java.util (b) java.awt
(c) java.awt.event (d) All of these
35. The general form to set a specific type of layout manager is
(a) void setLayout(LayoutManager lm)
(b) Void setLayout(LayoutManager lm)
(c) void setLayout(layoutManager lm)
(d) Void setLayout(Layoutmanager lm)
36. Some of the event listener interfaces are
(a) ActionListener, ComponentListener
(b) ContainerListener, FocusListener
(c) ItemListener, KeyListener
(d) WindowListener, MouseListener
(e) TextListener
(f) All of these
37. The AWT container is an instance of the class which holds
various components and other containers
(a) Graphics (b) Container
(c) Eventobj (d) None of these
38. A checkbox is a control that consists of a_____________.
(a) Combination of a small box
(b) A label
(c) Combination of a large box and a label
(d) Both a & b
39. Java applets are used to create applications
(a) Graphical (b) User interactive
(c) Both a & b (d) None of these
40. In Java, events are all the activities that occur between
(a) The user (b) The applications
(c) Both a & b (d) None of these
41. AWT means
(a) Abstract Window Toolkit
(b) Abstract Window Toollayout
(c) Abstract Withdraw Tools
(d) Abstract Window Title
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 7 of 29
Chapter 01 Introduction to AWT
42. Positions the components into five regions:east, west, north, south, center
(a) BorderLayout (b) CardLayout
(c) GridLayout (d) FlowLayout
43. Arranges the components horizontally
(a) BorderLayout (c) GridLayout
(b) CardLayout (d) FlowLayout
44. Arranges the componemnts into grid
(a) BorderLayout (b) CardLayout
(c) GridLayout (d) FlowLayout
45. creates a dropdown list of textual entries
(a) Choice (b) Checkbox
(c) Textbox (d) TextComponent
46. The Component class and MenuComponent class are the which represent
the GUI components.
(a) Subclasses (b) Superclasses
(c) Both a & b (d) None of these
47. The Component class is an abstract class and so its are used to create
components.
(a) Subclasses (b) Superclasses
(c) Both a & b (d) None of these
48. The AWT classes can be roughly categorized into the following groups:
(a) GUI Components (b) Layouts
(c) Event Handlers (d) All of these
49. Panel is used for components
(a) Grouping (b) Managing
(c) Deleting (d) Modifying
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 8 of 29
Chapter 01 Introduction to AWT
--------------------------------------------------------------------------------------------------------------
Total Marks-10
--------------------------------------------------------------------------------------------------------------
MCQ Question
(Total number of Question=Marks*3=10*3=30)
Note: Correct answer is marked with bold
1. The following specifies the advantages of: It is lightweight.
It supports pluggable look and feel.
It follows MVC (Model View Controller) architecture.
(a) Swing (b) AWT
(c) Both A & B (d) None of the above
2. Swing is not a part of JFC (Java Foundation Classes) that is used to create GUI
application?
(a) True (b) False
3. The Swing Component classes that are used in Encapsulates a mutually exclusive
set of buttons?
(e) AbstractButton (f) ButtonGroup
(c) JButton (d) ImageIcon
4. The Java Foundation Classes (JF(c) is a set of GUI components which simplify
the development of desktop applications?
(a) True (b) False
5. Which package is used for import the swing components?
(a) java.swing (b)java.awt
(c) javax.swing (d) All of the above
6. The String parameter to JButton constructor___________________
(a) tell which region to put the JButton in.
(b) tells the color of the JButton.
(c) tells what text will appear on JButton.
(d) tells what should happen when JButton is pressed.
7. MVC architecture is
(a) Modelling – Visual – Controller
(b) Model – View – Controller
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 9 of 29
Chapter 01 Introduction to AWT
(c) Model – Viewable – Controller
(d) Many – View – Controller
8. Which package is used for importing swing components?
(a) java.swing (b) javax.swing
(c) java.awt. (d) All of the above
9. In swing, Buttons are subclasses of which class?
(a) AbstractButton (b) JButton
(c) Button (d) JRadioButton
10. JTree class belongs to which package?
(a) java.awt (b) java.applet
(c) java.swing (d) javax.swing
11. Which component is swing represents data in row and columns?
(a) JTextArea (b) JTable
(c) JPanel (d) JtabbedPane
12. Which of the following is not constructor of JTree?
(a) JTree(TreeNode tn) (b) JTree(Vector v)
(c) JTree(int x) (d) none of the above
13. ____class used to create node in tree.
(a) TreeNode (b) DefaultMutableNode
(c) DefaultMutableTreeNode (d) Node
14. JTabbedPane class is present in which package?
(a) java.awt (b) java.swing
(c) java.awt.swing (d) javax.swing
15. What is purpose of JTree?
(a) To show data in form of parent and child nodes.
(b) To show data in list view.
(c) To show data in tabular form.
(d) To show data in menu‐bar.
16. What is the use of : Container getContentPane( )
(a) Returns Container for a JDialog.
(b) Returns a ContentPane for Menu
(c) Returns a ContentPane for Applet
(d) None of the above
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 10 of 29
17. Which of the following method is not applicable for Button in swing?
(a) setDiableIcon( ) (b) setPressedIcon( )
(c) setSelectedIcon( ) (d) setRollOverIcon( )
18. Which of the following method is used to retrieve icon of JButton?
(a) Icon getIcon( )
(b) ImageIcon getImageIcon( )
(c) ImageIcon getIcon( )
(d) ImageIcon GetImageIcon( )
19. From following list which is not Swing class?
(a) JLabel (b) JButton
(c) JImageIcon (d) JCheckBox
20. Which component provides support for two state buttons?
(a) Button, Checkbox
(b) JCheckBox,JRadioButton
(c) Button, MenuItem
(d) JCheckBox, TextField
21. How to add contents of whole vector into the JComboBox?
(a) Use the constructor of JComboBox
(b) Use method addItem( )
(c) Use method addVector( )
(d) Use method addValues( )
22. How to prevent the drop-down list of JComboBox?
(a) It is not possible
(b) We can use method preventDropMenu( ) method
(c) Directly give the value „false‟ in the constructor
(d) Use setList( ) method.
23. Which method is used to define the tabs in the tabbed pane?
(a) add( ) (b) addItem( )
(c) addPane( ) (d)addTab( )
24. The scroll bar constants for scroll pane are defined in –
(a) Scrollbar class (b) ScrollPane class
(c) ScrollPaneConstants class (d) Component class
25. Which of the following constants shows scroll bars always?
(a) HORIZONTAL_SCROLLBAR_ALWAYS
(b) HORIZONTAL_SCROLLBAR_AS_NEEDED
(c) HORIZONTAL_SCROLLBARS
(d)HORIZONTAL_ALWAYS
26. JScrollPane is an immediate sub-class of –
(a) JContainer (b) JApplet
(c) JComponent (d) ScrollPane
27. Is it possible to add array of objects to trees? How?
(a) Not possible
(b)Yes, using its one of the forms of constructor
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 11 of 29
Chapter 02 The Tour of Swing
(c) Yes, using the add( ) method
(d) Yes, using the addItem( ) method
28. Which items we can‟t directly add to JTree using its constructor?
(a) Array of objects (b) Vector
(c) Hash table (d)Arrays
29. When tree is expanded, which event is generated?
(a) ExpansionEvent (b)TreeExpansionEvent
(c) ItemEvent (d) ActionEvent
30. Which method is used to translate a mouse click on a specific point of the tree to a tree
path?
(a) translatePoint( ) (b) getLocation( )
(c) getPathForLocation( ) (d) getPath( )
31. The TreeNode is –
(a) A class (b) An interface
(c) A variable (d) Nothing
32. The TreeExpansionEvent class is defined in –
(a) java.awt package (b) javax.swing package
(c) java.awt.event package (d)javax.swing.event package
33. TreeExpansionListener interface provides following method –
(a) getExpanded( ) (b)treeExpanded( )
(c) expanded( ) (d) None of the above
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 12 of 29
Chapter 02 The Tour of Swing
--------------------------------------------------------------------------------------------------------------
Total Marks-12
--------------------------------------------------------------------------------------------------------------
MCQ Question
(Total number of Question=Marks*3=12*3=36)
1. The Following steps are required to perform:
Implement the Listener interface and overrides its methods
Register the component with the Listener
(a) Exception Handling (b) String Handling
(c) Event Handling (d) None of the above
2. In which places can put the event handling code
(a) Same class (b) Other class
(c) Annonymous class (d) All mentioned above
3. Which package provides many event classes and Listener interfaces for event
handling?
(a) java.awt (b) java.awt.Graphics
(c) java.awt.event (d) None of the above
4. To use the ActionListener interface it must be implemented by a class there are several
ways to do that find in the following?
(a) Creating a new class
(b) using the class the graphical component
(c) an anonymous inner class
(d) All mentioned above
5. The ActionListener interface is not used for handling action events?
(a) True (b) False
6. The ActionListener interface is used for handling action events, For example,
(a) JButton (b) JCheckbox
(c) JMenuItem (d) All of these
7. Which class is used for this Processing Method processActionEvent( )?
(a) Button,List,MenuItem (b) Button,Checkbox,Choice
(c) Scrollbar,Component,Button (d) None of the above
8. In Graphics class Which method is used to set the graphics current color to the
specified color?
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 13 of 29
Chapter 02 The Tour of Swing
(a) public abstract void setFont(Font font)
(b) public abstract void setColor(Color c)
(c) public abstract void drawString(String str, int x, int y)
(d) None of the above
9. Which of the following method is used to determine the type of adjustment
event?
(a) getType( ) (b) getEventType( )
(c) getAdjustmentType( ) (d) getEventObjectType( )
10.TextField generates event.
(a) ActionEvent,ItemEvent (b) ActionEvent, TextEvent
(c) ScrollEvent,TextEvent (d) ActionEvent, ScrollEvent
11.void keyTyped(KeyEvent ke) called when a key on the keyboard is .
(a) pressed and then released. (b) pressed
(c) released (d) none of the above
12.Which event is generated when the position of scrollbar is changed?
(a) KeyEvent (b) MouseEvent
(c) ItemEvent (d) AdjustmentEvent
13.The signature for the registration method for a ActionEvent should be ___.
(a) public void addActionListener(ActionEvent L)
(b) public void setAction(ActionListener L)
(c) public void setActionListener(ActionListener L)
(d) public void addActionListener(ActionListener L)
14.Which of the following component generates ActionEvent?
(a) Window (b) RadioButton
(c) ScrollBar (d) None
15._________method is used to register a keyboard event listener.
(a) KeyListener( ) (b) addKeyListener( )
(c) addKeyListenerEvent( ) (d) eventKeyboardListener( )
16. Name the method defined in EventObject class that returns the object from the event.
(a) getEvent( ) (b) getObject( )
(c) getId( ) (d) getSource( )
17. The MouseListener interface is used to make mouse handling.
(a) True (b) False
18. ActionEvent is applied on
(a) Frame (b) Checkbox, Choice, List
(c) Scrollbar (d) Button, TextField, List, Menu
19.ComponentEvent is the super class of .
(a) FocusEvent (b) MouseEvent
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 14 of 29
Chapter 02 The Tour of Swing
(c) WindowEvent (d) All of the above
20. If we close an applet window_ events will be generated.
(a) ActionEvent (b) ComponentEvent
(c) AdjustmentEvent (d) WindowEvent
21. Which of the following component generate ActionEvent?
(a) ScrollBar (b) Window
(c) RadioButton (d) None of these
22.Which Listener handles all List related Events?
(a) ItemListener (b) InputEvent
(c) SelectEvent (d) ListEvent
23. How to obtain the command name for invoking ActionEvent?
(a) getCommandName( ) (b) getActionEventCommand( )
(c) getActionCmd( ) (d) getActionCommand( )
24. ComponentEvent is the superclass of
(a) ActionEvent (b) ItemEvent
(c) TextEvent (d) All of above
25. When we need to use Checkbox or Item from the list or use a checkable Menu an is
generated.
(a) ActionEvent (b) ItemEvent
(c) MenuEvent (d) ClickEvent
26.Which of the following constant is not defined in WindowEvent class?
(a) WINDOW_ACTIVATED (b) WINDOW_CLOSED
(c) WINDOW_DEICONIFIED (d) None of these
27.Which of the following is not the method of handling window event?
(a) void windowClosed(WindowEvent we)
(b) void windowClosing(WindowEvent we)
(c) void windowAfterClosing(WindowEvent we)
(d) All of these
28.Which method is used to process mouse click?
(a) public void mouseClicked(MouseListener m)
(b) public void mouseIsClicked(MouseEvent m)
(c) public void mouseClicked(MouseEvent m)
(d) public void mouseClick(MouseEvent m)
29.Which class is used for this processing method processActionEvent( ) method?
(a) Button, List, MenuItem (b) Button,Checkbox,Choice
(c) ScrollBar, Component, Button (d) None of the above
30.Which of this package contain all the classes&methods required for event handling?
(a) java.applet (b) java.awt
(c) java.event (d) java.awt.event
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 15 of 29
Chapter 02 The Tour of Swing
31. Name the method in EvenObject class that returns the object generated from the event.
(a) getEvent( ) (b) getObject( )
(c) getId( ) (d) getSource( )
32. Which of these interfaces define a method actionPerformed()
(a) ComponentListener (b) ContainerListener
(c) ActionListener (d)InputListener
33. Button Control implements following listener interface.
(a) ItemListener (b) ActionListener
(c) FlowListener (d) Adapter
34. Clicking the closing button on the upper right corner of a frame generates a (n)‐
event.
(a) ItemEvent (b) WindowEvent
(c) MouseMotionEvent (d) ComponentEvent
35. Which of the following method must be overridden in the order to handle
KeyEvent?
(a) keyPressed(KeyEvent obj) (b) KeyReleased(KeyEvent obj)
(c) KeyTyped(KeyEvent obj) (d) All of these
36. Which of these methods can be used to know the degree of adjustment made by the user?
(a) getValue( ) (b) getAdjustmentType( )
(c) getAdjustmentValue( ) (d) getAdjustmentAmount( )
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 16 of 29
Chapter 02 The Tour of Swing
--------------------------------------------------------------------------------------------------------------
Total Marks-10
--------------------------------------------------------------------------------------------------------------
MCQ Question
(Total number of Question=Marks*3=10*3=30)
1. UDP stands for
(a) User Data Port (b) User Datagram Protocol
(c) Used Data Provider (d) User Data Protocol
2. Name the class which is used to create a port where the server will listen.
(a) Server (b) Socket
(c) ServerSocket (d) SocketServer
3. Communication using TCP protocol is and___
(a) Connection less, Iterative
(b) Collection less, concurrent
(c) Connection oriented, Iterative
(d) Connection oriented, concurrent
4. 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)
5. Which from the below use ―Middle tier‖.
(a) 3 tier (b) 4 tier
(c) n – tier (d) all of the above
6. java.net package consists of interface
(a)ContentHandlerFactory
(b) SocketImplFactory
(c) FileNameMap and URLStreamHandlerFactory
(d) All of the above
7. IPv6 uses .
(a) 4 groups of 8 bits each
(b) 4 group of 8 hexa‐decimal digits
(c) 8 groups of 4 digits each
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 17 of 29
Chapter 02 The Tour of Swing
(d) 8 groups of 4 hexa‐decimal digits each
8. Select full form of DNS.
(a) Data Network System (b) Domain Name System
(c) Domain Name Server (d) Domain Naming Service
9. 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 stream.
10. Which of these is a bundle of information passed between machines?
(a) MIME (b) Cache
(c) Datagram (d) Socket
11. Port number for FTP is
(a) 21 (b) 23
(c) 25 (d) 80
12. The class which encapsulates both the numerical IP address and the
domain name .
(a) DatagramPacket (b) DatagramSocket
(c) InetAddress (d) ServerSocket
13. 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.
14. 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
15. The constructor of URL can throw an exception called
(a) MalformedUrlException (b) UrlNotFoundException
(c) UrlException (d) UrlSourceNotFoundException
16. 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
17. 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
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 18 of 29
Chapter 02 The Tour of Swing
(d) Local IP, Local PORT, Remote IP, Remote PORT and Protocol
18. Select the method used to create URL connection.
(a) URL Connection (b) open Connection
(c) URL (d) URL Decoder
19. What value is returned by the readLine( ) method when it reach at End of File?
(a) EOF (b) null
(c) 0 (d) END
20. The class is used to create TCP server.
(a) Server (b) SocketServer
(c) ServerSocket (d) Socket
21. 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( )
22. ______method is used to retrieve file name specified in URL.
(a) getFile( ) (b) getUrl( )
(c) getFileUrl( ) (d) getLocalFile( )
23. _________is necessary to implement Datagram.
(a)DatagramPacket (b) DatagramSocket
(c) Both A & B (d) None of A & B
24. 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
25. Which of these method of DatagramPacket class is used to find the destination
address?
(a) findAddress( ) (b) getAddress( )
(c) address( ) (d) whoIs( )
26. 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
27. A server socket can connect to clients.
(a) 1 (b) 2
(c) 10 (d) multiple
28. Resolver in DNS system maps .
(a) Domain name to IP address (b) IP address to domain name
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 19 of 29
Chapter 02 The Tour of Swing
(c) Domain name to MAC address (d) MAC address to IP address
29. If a program consists of three classes, then after compilation how many class files will
be created by the compiler?
(a) one (b) three
(c) uncountable (d) zero
30. Which of the following is not a method of Security class?
(a) socketPermission( ) (b) filePermission( )
(c) dataPermission( ) (d) None of above
31. TCP does not supports Multicasting and Broadcasting because .
(a) It supports full duplex communication.
(b) It provides error control.
(c) It provides flow control
(d) It is connection oriented protocol
32. Which of the following is true about TCP protocol?
(a) is reliable and connection oriented
(b) is unreliable but connection oriented
(c) is reliable and connectionless
(d) None of these
33. Which class defines following methods? int getContentLength( )
long getDate( )
long getExpiration( )
(a) URLConnection (b) Datagram
(c) Client (d) None of these
34. Name the class which is used to create a port where the server will listen?
(a) Server (b) Socket
(c) ServerSocket (d) SocketServer
35. class Permission in java.security package is_____.
(a) static (b) abstract
(c) final (d) None of these
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 20 of 29
Chapter 02 The Tour of Swing
--------------------------------------------------------------------------------------------------------------
Total Marks-12
--------------------------------------------------------------------------------------------------------------
MCQ Question
(Total number of Question=Marks*3=12*3=36)
1. 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) db.sql
(c) pkg.sql (d) java.sql
2. 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
3. In JDBC imports all Java classes that are concern with Database
connectivity.
(a) javax.sql (b) java.mysql
(c) java.sql (d) com.sql
4. Database programming using Java throws which of the following exception?
(a) SQLException (b) ClassNotFoundException
(c) None of these (d) Both of these
5. 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
6. 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
7. Native – protocol pure Java Driver converts into the directly.
(a) JDBC calls, network protocol
(b) ODBC class, network protocol
(c) ODBC class, user calls
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 21 of 29
Chapter 02 The Tour of Swing
(d) JDBC calls, user calls
8. Choose the correct syntax for getConnection( ) method.
(a) public static Connection getConnection(String url, String password) throws
SQLException
(b) public static Connection getConnection(String name, String password) throws
SQLException
(c) public static Connection getConnection(String url, String name, String password)
throws SQLException
(d) public static Connection getConnection(String url, String name) throws
SQLException
9. SQL stands for .
(a) Structured Query Language (b) Sequential Query Language
(c) Structured Question Language (d) Sequential Question Language
10. _____is a table of data which represents a data from table.
(a) MetaData (b) ResultSetMetaData
(c) ResultSet (d) Statement
11. Public class DriverManager extends
(a) Object (b) String
(c) Connection (d) Statement
12. Which of the following method is supported by Statement interface?
(a) public boolean execute(String query)
(b) public ResultSet executeQuery(String query)
(c) public int executeUpdate(String query)
(d) All of above
13. In following statement rs is an object of_______ interface of JDBC API.
System.out.println(rs.getString(3));
(a) RowSet (b) Statement
(c) Connection (d) ResultSet
14.Which is main component of JDBC API?
(a) DriverManager (b) Driver
(c) Connection (d) All of these
15. How many steps are used to connect java application with the database using
JDBC ?
(a) 5 (b) 4
(c) 3 (d) 6
16. ODBC minimum SQL grammer contains
(a) Stored procedure (b) Data, Time and TimeStamp only
(c) create or drop View (d) Insert, update, delete only
17. Which class/interface is used for an SQL statement that is executed frequently?
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 22 of 29
Chapter 02 The Tour of Swing
(a) Statement (b) CallableStatement
(c) PreparedStatement (d) None of the above
18.What does the following code do : smt = con.createStatement( )
(a) A PreparedStatement object is created to send SQL commands to database.
(b) A Statement object is created to send SQL commands to database.
(c) A CallableStatement is created to send SQL commands to database.
(d) A Statement object is created to execute parameterized SQL commands.
19. Which kind of driver converts JDBC calls into calls on the Client API for Oracle,
Sybase, Informix, IBM DB2, or other DBMS
(a) JDBC ODBC bridge + ODBC Driver
(b) Native API partly – Java Driver
(c) JDBC – Net pure Java Driver
(d) Native Protocol Pure Java Driver
20. Which method executes an SQL statement that may return multiple results?
(a) executeUpdate( ) (b) executeQuery( )
(c) execute( ) (d) noExecute( )
21. Identify correct syntax of executeQuery( ) of Statement interface.
(a) public static ResultSet executeQuery( )
(b) public ResultSet executeQuery(String q)
(c) public void executeQuery(String q)
(d) public int executeQuery(String q)
22. Native API converts into the used by DBMS.
(a) JDBC API, Network Protocol (b) JDBC API, Native API calls
(c) JDBC API, use calls (d) JDBC API, ODBC API calls
23.Which function is used to find the column count of the particular ResultSet.
(a) getMetadata( ) (b) metadata( )
(c) getColumnCount( ) (d) getCount( )
24. The JDBC-ODBC bridge supports how many concurrent open statements per
connection?
(a) 1 (b) 0
(c) Does not support connection (d) None of these
25. Select the correct method to create CallableStatement.
(a) CallableStatement prepareCall(String sql)
(b) CallableStatementprepareCall(String sql, int resultset type, int
resultset_concurrency)
(c) CallableStatement prepareCall(String sql, int resultset_type, int
resultset_concurrency, int resultset_holdability)
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 23 of 29
Chapter 02 The Tour of Swing
(d) All of the above
26. Microsoft Access data in file format.
(a) .DAT (b) .MDB
(c) .MSSQL (d) .OBJ
27. Which of the following method is used for send SQL statements?
(a) Statement (b) CallableStatement
(c) PreparedStatement (d) Both B & C
28. DELETE statement of an SQL is executed by______
(a) execute( ) (b) executeQuery( )
(c) executeUpdate( ) (d) executeDelete( )
29. The interface to the database is handle by__________
(a) ODBC (b) JDBC
(c) JDBC & ODBC (d) APIs
30. DatabaseMetadata are retrieved through_____
(a) getDatabaseMetadata( )
(b) getMetaData( )
(c) getDBMetaData( )
(d) getDatabaseMeta( )
31. Which method is used to retrieve the ResultSet created?
(a) executeQuery( ) (b) getResultSet( )
(c) getResultSetResult( ) (d)getResult()
32.Which of the following is used generally for reading the content of the
database?
(a) DabaseData (b) DabaseData
(c) ResultSet (d) DatabaseResult
33.The syntax to create a table named ―Course‖, should begin with .
(a) create new table course (b) create table course
(c) table course create (d) new table course
34.Which of the following contains both date and time?
(a) java.io.date (c) java.util.date
(b) java.sql.date (d) java.util.dateTime
35.Which of the following is used to call stored procedure?
(a) Statement (c) CallableStatment
(b) PreparedStatement (d) CalledStatement
36.Which of the following is used to limit the number of rows returned?
(a) setMaxRows(int i) (b) setMinRows(int i)
(c) getMaxrows(int i) (d) getMinRows(int i)
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 24 of 29
Chapter 02 The Tour of Swing
--------------------------------------------------------------------------------------------------------------
Total Marks-14
--------------------------------------------------------------------------------------------------------------
MCQ Question
(Total number of Question=Marks*3=14*3=42)
1. JSP embeds in .
(a) Servlet, HTML (b) HTML, Java
(c) HTML, Servlet (d) Java, HTML
2. Which of the following is the default HttpRequest method?
(a) doGet( ) (b) doPost( )
(c) doTrace( ) (d) doPut( )
3. Which are true about tag libraries in web application?
(a) packaged in the /WEBINF directory or subdirectory of the WAR file
(b) If a tag is implemented as a tag file and packaged in /WEB‐INF/tags/ or a sub‐
directory, a TLD will be generated automatically by the web container, though,
you can provide one if you wish
(c) packaged in the /METAINF/ directory or sub directory of a tag library packaged
in a jar.
(d) All of the above.
4. Name the http method used to send resources to the server.
(a) FTP method (b) PUT method
(c) WRITE method (d) COPY method
5. Identify the proper syntax of doGet( ).
(a) void doGet(HttpResponse res,HttpRequest req) throws IOException,
ServletException
(b) void doGet(HttpRequest req,HttpResponse res) throws IOException,
ServletException
(c) void doGet(HttpResponse res) throws IOException, ServletException
(d) void doGet(HttpRequest req) throws IOException, ServletException
6. Given an HttpServletRequest request and HttpServletResponse response instances.
Which sets a cookie ―username‖ with the value ―joe‖ in a servlet?
(a) request.addCookie(new Cookie(―username‖ , ―joe));
(b) response.addCookie(new Cookie(“username” , “joe”))
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 25 of 29
Chapter 02 The Tour of Swing
(c) request.addCookie(―username‖ , ―joe);
(d) request.addCookie(―username‖ , ―joe);
7. Which JSP tag is used to transfer for processing another JSP page?
(a) <jsp:include> (b) <jsp:forward>
(c) <jsp:useBean> (d) <jsp:use:include>
8. An application wants to invalidate the session both programmatically and
declaratively.Select the best match to do this.
(a) httpRequest.getSession( ).end( )
<session config><session timeout interval> time_in_minutes </session timeout
interval></session config>
(b) httpRequest.getSession( ).invalidate( )
<session‐config><session‐timeout> time_in_minutes </session‐timeout>
</session‐config>
(c) httpRequest.getSession( ).close( )
<session‐config><session‐timeout> time_in_minutes </session timeout>
</session‐config>
(d) httpRequest.getSession( ).invalidate( )
<session config> <session duration> time_in_minutes </session‐ duration>
</session config>
9. The include( ) method in RequestDispatcher .
(a) sends a request to another resource like servlet, JSP or html.
(b) includes resources of file like servlet, JSP or html.
(c) appends the request and response objects to the current servlet.
(d) None of these
10. State true or false for following statements.
(i) JavaBeans slow‐ down software development process.
(ii) Java Servlets do not have built‐ in multithreaded feature.
(a) false, false (b) false, true
(c) true, false (d) true, true
11. _____is a small piece of information that is passed back & forth in HTTP request &
response.
(a)Servlet (b) Applet
(c) Cookie (d) Session
12. Which life cycle method is used to process a client‘s request?
(a) start( ) (b) init( )
(c) service( ) (d) destroy( )
13. A user types the URL http://www.msbte.com/result.php. Which request gets
generated?
(a) GET method (b) POST method
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 26 of 29
Chapter 02 The Tour of Swing
(c) HEAD method (d) PUT method
14. Apache Tomcat is .
(a) Servlet
(b) Java Program
(c) API
(d) Web server capable of running Java programs
15. What the getSession( ) method with ―true‖ parameter will do?
(a) The session is completed
(b) The session object is passed to another method
(c) Creates new session if, the session does not exist
(d) The session is exist
16. A JSP page consists of which tags?
(a) HTML tags (b) JSP tags
(c) Both A & B (d) None of the above
17. Life cycle of a servlet is managed by
(a) Servlet Context (b) Servlet Container
(c) Supporting protocol (d) All of the above
18. To send binary output in the response, the following method of HttpServlet
response many be used to get the appropriate Writer/Stream object.
(a) getStream( ) (b) getOutputStream( )
(c) getBianaryStream( ) (d) getWriter( )
19. ____is the first Phase of Servlet Life cycle.
(a) service( ) (b) init( )
(c) destroy( ) (d) Both B & C
20. How many copies of a JSP page can be in memory at a time?
(a) 1 (b) 2
(c) 3 (d) Unlimited
21. Which method is used to specify before any lines that used the PrintWriter?
(a) setPageType( ) (b) setContextType( )
(c) setContentType( ) (d) setResponseType( )
22. ______is used to read data from a client request.
(a) ServletResponse (b) ServletRequest
(c) Servlet (d) ServletConfig
23. The following methods belongs to the life cycle methods of the servlet.
(a) init( ) (b) service( )
(c) destroy( ) (d) All of the above
24. Java servlet
(i) is a key component of the server side java development.
(ii) is a small pluggable extension to a server that enhances functionality
(iii) runs only in windows OS
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 27 of 29
Chapter 02 The Tour of Swing
(iv) allows developers to customize any java enabled server
(a) i, ii and iii are true (b) i,iii and iv are true
(c) ii,iii and iv are true (d) i,ii and iv are true
25. Servlet lifecycle has states.
(a) Two (b) Three
(c) Four (d) Five
26. JSP life cycle includes number of phases.
(a) Two (b) Three
(c) Four (d) Five
27. How to send data in get method?
(a)using GET method in request
(b)using Requesting URL
(c)using Response URL
(d)using URL
28. JSP life cycle includes following
(a) Translation Phase (b) Compilation Phase
(c) Request handling phase (d) All of these
29. JSP stands for .
(a) Java Service Provider (b) Java Server Path
(c) Java Server Pages (d) Java Server Program
30. The authentication mechanism in the servlet specification uses a technique called ?
(a) Role Based Authentication (b) Form Based Authentication
(c) Both a & b (d) None of the above
31. Which class provides stream to read binary data such as image et(c) from the
request object?
(a) ServletInputStream (b) ServletOutputStream
(c) Both a & b (d) None of the above
32.What is the limit of data to be passed from HTML to doGet() ?
(a) 8kb (b) 1kb
(c) 4kb (d) 2kb
33.The major difference between Servlet and CGI is______
(a) Servlets are thread based and CGI is process based.
(b) Servlet executes slower than CGI.
(c) Servlet has no platform specific API whereas CGI has.
(d) All of these
34.How constructor can be used for a servlet?
(a) Initialization
(b) Constructor function
(c) Initialization and Constructor function
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 28 of 29
Chapter 02 The Tour of Swing
(d) Setup() method
35. Can servlet class declare constructor with ServletConfig object as an argument?
(a) True (b) False
36. What is the difference between servlets and applets?
i. Servlets execute on Server; Applets execute on browser
ii. Servlets have no GUI; Applet has GUI
iii. Servlets creates static web pages; Applets creates dynamic web pages
iv. Servlets can handle only a single request; Applet can handle multiple requests
(a) i, ii, iii are correct (c) i, iii are correct
(b) i, ii are correct (d) i, ii, iii, iv are correct
37. Which of the following code is used to get an attribute in a HTTP Session object in
servlets?
(a) session.getAttribute(String name)
(b) session.alterAttribute(String name)
(c) session.updateAttribute(String name)
(d) session.setAttribute(String name)
38. Which method is used to get three-letter abbreviation for locale‘s country in servlets?
(a) Request.getISO3Country() (c) Response.getISO3Country()
(b) Locale.getISO3Country() (d) Local.retrieveISO3Country()
39. Which of the following code retrieves the body of the request as binary data?
(a) DataInputStream data = new InputStream()
(b) DataInputStream data = response.getInputStream()
(c) DataInputStream data = request.getInputStream()
(d) DataInputStream data = request.fetchInputStream()
40. 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 doFilter method
(c) The destroy() method is called only once at the begining of the life cycle of a filter
(d) The destroyer() method is called after the filter has executed
41. Which of the following is true about servlets?
(a) Servlets execute within the address space of web server
(b) Servlets are platform-independent because they are written in java
(c) Servlets can use the full functionality of the Java class libraries
(d) Servlets execute within the address space of web server, platform
independent and uses the functionality of java class libraries.
42. How is the dynamic interception of requests and responses to transform the
information done?
(a) servlet container (b) servlet config
(c) servlet context (d) servlet filter
Prepared By: Prof. M.B.Patil (Department of Information Technology) Page 29 of 29