0% found this document useful (0 votes)
79 views

Advanced Java Programming (AJP) MCQs

The document contains 62 multiple choice questions about Java programming concepts including GUI components, events, networking, and more. Some key points covered are: - TextArea's immediate super class is TextComponent. AWT stands for Abstract Window Toolkit. ActionEvents are generated when a button is pressed. - Common networking classes include ServerSocket, Socket, and InetAddress. TCP/IP protocols like TCP and UDP are used to establish connections. - GUI components include labels, buttons, text fields, checkboxes and more. Events like actionEvents and focusEvents are used to detect user interactions. - Layout managers like BorderLayout and FlowLayout are used to position components. Methods like setText() and get

Uploaded by

Rambo Gaming
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Advanced Java Programming (AJP) MCQs

The document contains 62 multiple choice questions about Java programming concepts including GUI components, events, networking, and more. Some key points covered are: - TextArea's immediate super class is TextComponent. AWT stands for Abstract Window Toolkit. ActionEvents are generated when a button is pressed. - Common networking classes include ServerSocket, Socket, and InetAddress. TCP/IP protocols like TCP and UDP are used to establish connections. - GUI components include labels, buttons, text fields, checkboxes and more. Events like actionEvents and focusEvents are used to detect user interactions. - Layout managers like BorderLayout and FlowLayout are used to position components. Methods like setText() and get

Uploaded by

Rambo Gaming
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 17

1.

The immediate super class of TextArea is…


a) TextField
b) TextBox
c) TextComponent
d) Component
Answer: c
2. AWT Stands for what ?
a) Advanced Web Technology
b) Abstraction ToolKit
c) Abstract Window ToolKit
d) Abstract Windowing ToolKit
Answer: c

3. Consider the following program and identify the missing statement.


class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL netAddress= new URL("http://www.sun.com:/index.html");
System.out.println("Protocol
:"+netAddress.getProtocol()); System.out.println("Port :"+netAddress.getPort());
System.out.println("Host
:"+netAddress.getHost()); System.out.println("File :"+netAddress.getFile());
}
}
a) Missing semicolon
b) Missing package statement
c) Missing initialization
d) None of the above
Answer: b

4. 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
Answer: d

5) Who invented Java Programming ?


a) Guido van Rossum
b) James Gosling
c) Dennis Ritchie
d) Bjarne Stroustrup
Answer: b

6. Which class can be used to represent the Checkbox with a textual label that can
appear in a menu ?
A) MenuBar
B) MenuItem
C) CheckboxMenuItem
D) Menu
Answer: c

7. What is the return type of getText( ) method of JButton class ?


A) void
B) String
C) Character array
D) There is no such method
Answer: b
8. Which of the following is constructor for Frame class?
a) Frame()
b) Frame(String s, int how)
c) Frame(int l , int b)
d) Frame(int l, int b, String s)
Answer: a

9. In swing MVC architecture, c stands for:


A) Controller
B) Container
C) Class
D) None of this
Answer: a

10. Dimension class sets which of the following values?


a) length and breadth
b) length and width
c) length and height
d) width and height
Answer: d

11. add() method is defined by which class?


a) Component
b) Container
c) Applet
d) Frame
Answer: b

12. Action event is generated when…


a) Label is dragged
b) Button is pressed
c) Mouse is dragged
d) Window is opened
Answer: b

13. Multiple selections are allowed in…


Menu
B. CheckboxGroup
C. List
D. Choice
Answer: d

14. Which event is handled on Button component?


a) AdjustmentEvent
b) FocusEvent
c)KeyEvent
d)ActionEvent
Answer: d

15. Which of the following is a passive component?


a) Label
b) Button
c) Checkbox
d) Scrollbar
Answer: a

16. BorderLayout does not support this value of alignment…


A. BorderLayout.WEST
b) BorderLayout.EAST
c) BorderLayout.NORTH
d) BorderLayout.MIDDLE
Answer: d

17. 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.
Answer: c

18. What is default block-increment of Scrollbar?


a) 10
b) 5
c) 1
d)We can not use block increment in scrollbars.
Answer: d

19. What is API?


a) Application Programming Interchange
b) Application Programming Interaction
c) Application Programming Interface
d) None of these
Answer: c

20. The setSize( ) method is defined by this class…


a) Applet
b)Component
c)Frame
d)Panel
Answer: c

21. Which class encapsulates a blank window upon which we can draw?
a) Applet
b)Canvas
c)Window
d)Frame
Answer: b

22. Action event is generated when…


a) Label is dragged
b) Button is pressed
c) Mouse is dragged
d) Window is opened
Answer: b

23. At the root of Java event hierarchy, which class is located?


a) AWTEvent
b) Event
c) EventObject
d) Events
Answer: c

24. How to remove the event listener?


a) Using removeListener() method.
b)Using removeTypeListener() method.
c) Using removeEvent( ) method.
d)It is not possible to remove the event listener.
Answer: b

25. 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)
Answer: a

26. BorderLayout does not support this value of alignment…


a) BorderLayout.WEST
b) BorderLayout.EAST
c)BorderLayout.NORTH
d) BorderLayout.MIDDLE
Answer: d

27. FlowLayout does not support this value of alignment…


a) FlowLayout.LEFT
b) FlowLayout.CENTER
c) FlowLayout.RIGHT
d) FlowLayout.BASELINE
Answer: d

28. Which method is used to append the text at the end of TextArea?
a) append( )
b) add( )
c) appendAt( )
d) addAt( )
Answer: a

29. The various controls supported by AWT are.


a) Labels, push buttons
b) Checkboxes, choice list
c) Scroll bars, text fields, text area
d) All the above
Answer: d

30. Which of the following is a passive component?


a) Label
b) Button
c) Checkbox
d) Scrollbar
Answer: a

31. What are the types of DialogBox?


a) Modal
b) Modal and ModeLess
c) LOAD and SAVE
d) None
Answer: b

32.Label(String s, int how) does what?


a) Sets the string and alignment of Label b) Sets the string and alignment of
caption of a Label
c) Sets the string and integer value 10
d) Sets the string and integer value 0
Answer: b

33. Which methods are commonly used in Server Socket class?


a) Public Output Stream get Output Stream ()
b) Public Socket accept ()
c) Public synchronized void close ()
d) None of the mentioned
Answer: b

34. What is the default alignment value for Label?


a) Label.RIGHT(2)
b) Label.CENTER(1)
c) Label.LEFT(0)
d) None
Answer: c

35. How can the Checkbox class be used to create a radio button?
a) By associating Checkbox objects with a CheckboxGroup.
b) using RadioButton class of AWT
c) using the RoundButton class
d) None
Answer: a

36. Which constructor of Datagram Socket class is used to create a


datagram socket and binds it with the given Port Number?
a) Datagram Socket(int port)
b) Datagram Socket(int port, Int Address address)
c) Datagram Socket()
d) None of the mentioned
Answer: b

37. What is the default visibility of a Frame Window?


a) True
b) False
c) No such restriction
d) None
Answer: b

38. The client in socket programming must know which information?


a) IP address of Server
b) Port number
c) Both IP address of Server & Port number
d) None of the mentioned
Answer: c

39. Which method is used for setting caption of a Button?


a) setText(String s)
b) setText(String s, int how)
c) setLabel(String s)
d) setLabel(String s, int how)
Answer: a

40. The URL Connection class can be used to read and write data to
the specified resource referred by the URL
a) True
b) False
Answer: a

41. Which of the following constructor creates a TextField with 5 columns width?
a) TextField()
b) TextField(5)
c) TextField(5,5)
d) Both a and b
Answer: d

42. Datagram is basically an information but there is no guarantee of


its content, arrival or arrival time.
a) True
b) False
Answer: a

43. How to give editing facility to TextField?


a) setEditable(true)
b) setEditable (false)
c) setEnable (true)
d) setEnable (false)
Answer: a

44. TCP, FTP, Telnet, SMTP, POP etc. are examples of?
a) Socket
b) IP Address
c) Protocol
d) MAC Address
Answer: c

45. How to give password field effect to the TextField?


a) setChar(char c)
b) setEchoChar(char c)
c) setEcho(char c)
d) setCharacter(char c)
Answer: b

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


a) Socket
b) IP Address
c) Protocol
d) MAC Address
Answer: b

47. How would you set the color of a graphics context called g to cyan?
a) g.setColor(Color.cyan);
b) g.setCurrentColor(cyan);c
c) g.setColor("Color.cyan");
d) g.setColor("cyan’);
Answer: a

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


a) Socket
b) IP Address
c) Protocol
d) MAC Address
Answer: c

49. In Int Address class which method returns the host name of the
IP Address?
a) Public String get Hostname()
b) Public String getHostAddress()
c) Public static IntAddress get Localhost()
d) None of the mentioned
Answer: a
50. Which of the following is a passive component?
a) Label
b) Button
c) Checkbox
d) Scrollbar
Answer: a

51. Give the abbrevation of BSD.


a. Berkeley Software Distribution
b. Berkeley Socket Distribution
c. Berkeley System Distribution
d. None of the above
Answer a

52. Label(String s, int how) does what?


a) Sets the string and alignment of Label b) Sets the string and alignment of
caption of a Label
c) Sets the string and integer value 10
d) Sets the string and integer value 0
Answer: b

53. 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
Answer: c

54. What is the default alignment value for Label?


a) Label.RIGHT(2)
b) Label.CENTER(1)
c) Label.LEFT(0)
d) None
Answer: c

55. The URLConnection class can be used to read and write


data to the specified resource referred by the URL
a) True
b) False
Answer: a

56. What is the default visibility of a Frame Window?


a) True
b) False
c) No such restriction
d) None
Answer: b

57. Datagram is basically an information but there is no


guarantee of its content, arrival or arrival time.
a. True
b. False
Answer: a

58. Which method is used for setting caption of a Button?


a) setText(String s)
b) setText(String s, int how)
c) setLabel(String s)
d) setLabel(String s, int how)
Answer: a

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


a) Socket
b) IP Address
c) Protocol
d) MAC Address
Answer: b

60. Which of the following constructor creates a TextField with 5 columns width?
a) TextField()
b) TextField(5)
c) TextField(5,5)
d) Both a and b
Answer: d

61. Which steps occur when establishing a TCP connection


between two computers using sockets?
a) The server instantiates a ServerSocket object, denoting which
port number communication is to occur on
b) The server invokes the accept() method of the ServerSocket
class. This method waits until a client connects to the server on
the given port
c) After the server is waiting, a client instantiates a Socket object,
specifying the server name and port number to connect to
d) All of the above
Answer: d

62. How to give editing facility to TextField?


a) setEditable(true)
b) setEditable (false)
c) setEnable (true)
d) setEnable (false)
Answer: a

63. In InetAddress class which method 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
Answer: a

64. How to give password field effect to the TextField?


a) setChar(char c)
b) setEchoChar(char c)
c) setEcho(char c)
d) setCharacter(char c)
Answer: b

65. Which type of Statement can execute parameterized queries?


a) PreparedStatement
b) ParameterizedStatement
c) ParameterizedStatement and CallableStatement
d) All kinds of Statements (i.e. which implement a sub interface of Statement)
Answer: a

66. How to create TextArea with 2 rows and 3 columns?


a) TextArea(3,2)
b) TextArea(2,3)
c) TextArea(2)
d) TextArea(3)
Answer: b

67. Which type of driver converts JDBC calls into the network protocol used
by the database management system directly?
a) Type 1 driver
b) Type 2 driver
c) Type 3 driver
d) Type 4 driver
Answer: d

68. How to replace a Text from TextArea?


a) replace()
b) replaceText()
c) replaceRange()
d) replaceAll()
Answer: c

69. Which type of driver provides JDBC access via one or more ODBC
drivers?
a) Type 1 driver
b) Type 2 driver
c) Type 3 driver
d) Type 4 driver
Answer: a

70. How to create a List with 3 visible number of rows?


a) List()
b) List(3)
c) List(3,true)
d) List(3,3)
Answer: b

71. Which packages contain the JDBC classes?


a) java.jdbc and javax.jdbc
b) java.jdbc and java.jdbc.sql
c) java.sql and javax.sql
d) java.rdb and javax.rdb
Answer: c

72. Which constructor is used to give multiple mode selection facility to List?
a) List()
b) List(3)
c) List(3,true)
d) List(3,false)
Answer: c

73. 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
Answer: d

74. Which method is used to add elements in Choice?


a) add()
b) addItem()
c) add(String s,2)
d) Both a and c
Answer: a

75. How do you know in your Java program that a SQL warning is
generated as a result of executing a SQL statement in the database?
a) You must catch the checked SQLException which is thrown by the method which
executes the statement
b) You must catch the unchecked SQLWarningException which is thrown by the method
which executes the statement
c) You must invoke the getWarnings() method on the Statement object (or a sub
interface thereof)
d) You must query the ResultSet object about possible warnings generated by the
database
Answer: c

76. Which of the following constructor creates a Scrollbar with Vertical


Orientation ?
a) Scrollbar(4)
b) Scrollbar(1)
c) Scrollbar()
d) Scrollbar(0)
Answer: c

77.How can you execute DML statements (i.e. insert, delete, update) in the
database?
a) By making use of the InsertStatement, DeleteStatement or UpdateStatement classes
b) By invoking the execute(…) or executeUpdate(…) method of a normal Statement
object or a sub-interface object thereof
c) By invoking the executeInsert(…), executeDelete(…) or executeUpdate(…) methods
of
the DataModificationStatement object
d) By making use of the execute(…) statement of the DataModificationStatement
object
Answer: b

78. Which of the following component handles multiple events?


a) List
b) Choice
c) Scrollbar
d) TextArea
Answer: a

79. How can you retrieve information from a ResultSet?


a) By invoking the method get(…, String type) on the ResultSet, where type is the
database type
b) By invoking the method get(…, Type type) on the ResultSet, where Type is an
object
which represents a database type
c) By invoking the method getValue(…), and cast the result to the desired Java
type.
d) By invoking the special getter methods on the ResultSet: getString(…),
getBoolean
(…), getClob(…),…
Answer: d

80. The setLayout() method is defined by which class?


a) Applet
b) Container
c) Component
d) Frame
Answer: b

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


a) Datagram Socket
b) Datagram Packet
c) Both Datagram Socket & Datagram Packet
d) None of the mentioned
Answer: c
82. Which of the following class defines accept() method?
a)Server
b)ServerSocket
c) Socket
d)ClientSocket
Answer: b

83. In which cryptography the public and private key are used?
a) Symmetric key cryptography b)Asymmetric key cryptography
c)both a and b
d) None of the above
Answer: b

84. Which constructor is used to create ServerSocket connected to port no 1254 and
maxq length as 50.
a) ServerSocket(1254)
b)ServerSocket()
c)ServerSockect(50)
d)None of the above
Answer: a

85. A technique that creates a subletting effect; one server answers ARP requests
for multiple hosts?
a) Proxy Server
b)Proxy firewall
c)Proxy ARP
d)None of the above
Answer: a

86. Which client accesses the Web server by using a GET MESSAGE?
a) HTTP
b) FTP
c) SMTP
d) IMTP
Answer: a

87. Which is the connectionless protocol?


a) TCP
b) UDP
c) IP
d) HTTP
Answer: b

88. What is the port number of HTTP?


a) 80
b) 23
c) 47
d) 92
Answer: a

89. Which protocol that web browsers and servers use to transfer hypertext pages
and images?
a) TCP/IP
b) UDP
c) HTTP
d) SMTP
Answer: c

90. Originally, all Internet addresses consisted of ____ bit values.


a) 32
b) 16
c) 24
d) 8
Answer: a

91. What is the full form of DNS?


a) Domain Naming System
b) Domain Naming Service
c) Domain Naming Software
d) Domain Naming Security
Answer: a

92. What is URL?


a) Unicast Resource Location
b) Uniform Research Launcher
c) Universal Research Locator
d) Uniform Resource Locator
Answer: d

93. Which class is used to encapsulate both the numerical IP address and the domain
name for that address?
a) InetAddress
b) SocketAddress
c) IPAdress
d) DNSSockets
Answer: a

94. Which of the following constructor of InetAddress is generally used?


a) InetAddress()
b) InetAddress(int port)
c) InetAddress(URL url)
d) There is no any visible constructor for InetAddress
Answer: d
95. Factory method of InetAddress class throws which of the following exception?
a) MalFormedURLException
b) UnknownHostException
c) URLException
d) MalFormedURLIOException
Answer: b

96. What type of the value that getAllByName( ) returns?


a) InetAddress[ ]
b) InetAddress
c) URL[ ]
d) URL
Answer: a
97. Which of these is a protocol for breaking and sending packets to an address
across a network?
a) TCIP/IP
b) DNS
c) Socket
d) Proxy Server
Answer: a

98. In a web application, running in a webserver, who is responsible for creating


request and
response object,
a) Web server
b) Servlet
c) Container
d) Client
Answer: c

99. Find Errors


import java.sql.*;
class Test{
public static void main(String ar[])throws Exception
{
Class.forName(""sun.jdbc.odbc.JdbcOdbcDriver"");
System.out.println(""Drivers Loaded"");
Connection c=DriverManager.getConnection(url);
} }
a) url is not displayed
b) Connection object is created
c) url is displayed
d) No error
Answer: a

100. Find Errors


import java.sql.*;
class Test{
public static void main(String ar[])throws Exception
{
String url=""jdbc:odbc:mydsn"";
Connection c=DriverManager.getConnection(url);
} }
a) Drivers are not loaded
b) Drivers are loaded
c) Connection is created
d) Connection is not created
Answer: a

101. How can we create Radio buttons?


a) Using ButtonGroup class
b) Using JCheckboxGroup class
c) Using JRadioButton class
d)Using JButton class
Answer: c

102. How to make the group of Radio buttons?


a)Using ButtonGroup class
b) Using JButtonGroup class
c) Using JRadioButton
d) Using AbstractButton class
Answer: a
103. 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( )
Answer: a

104.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.
Answer: a

105.When JCheckBox is clicked the _____ event is generated.


a)ItemEvent
b) ActionEvent
c) TextEvent
d) MouseEvent
Answer: a
106. A JSP page consists of which tags?
a) HTML tags
b) JSP tags
c) Both A & B
d) None of the above
Answer: c

107. In JSP how many ways are there to perform exception handling?
a) 3
b) 2
c) 4
d) 5
Answer: b

108. Which packages does a JSP API consist of?


a) javax.servlet.jsp
b) java.servlet
c) javax.servlet.jsp.tagext
d) Both a and c
Answer: d

109. What is not true of a Java bean?


a) There are no public instance variables. b) All persistent values are accessed
using getxxx and setxxx
methods.
c) It may have many constructors as necessary.
d)) All of the above are true of a Java bean.
Answer: c

110. A JSP is transformed into


a) java applet
b) java servlet
c) both a and b
d) none of the above
Answer: a
111. What programming language(s) or scripting language(s) does Java Server Pages
(JSP) support?
a) VBScript only
b) JavaScript only
c) Java only
d) All of the above
Answer: c

112. What servlet processor was developed by Apache Foundation and Sun?
a) Apache Tomcat
b) Apache web server
c) Sun servlet processor
d) None of the above
Answer: a

113. What is invoked via HTTP on the Web server computer when it responds to
requests from a user's Web
browser?
a) A java Application
b) A java servlet
c) A java Applet
d) all of the above
Answer: b

114. How many copies of a JSP page can be in memory at a time?


a) 1
b) 2
c) 3
d) 4
Answer: a

115. How does Tomcat execute a JSP?


a) As CGI Script
b) As an independent process
c) By one of the Tomcat’s Thread
d) None of the above
Answer: c

116. The Java __________ specification defines an application programming interface


for communication
between the Web server and the application program.
a) Servlet
b) Server
c) Program
d) Randomize
Answer: a

117. The doGet() method in the example extracts values of the parameter’s type and
number by using
__________
a) request.getParameter()
b) request.setParameter()
c) responce.getParameter()
d) responce.getAttribute()
Answer: b

118. A deployment descriptor describes


a) web component response settings
b) web component settings
c) web component request objects
d) All of the above
Answer: b

119. Dynamic interception of requests and responses to transform the information is


done by
a) servlet container
b) servlet config
c) servlet context
d) servlet filter
Answer: d

120. The life cycle of a servlet is managed by


a) servlet context
b) servlet container
c) the supporting protocol
d) All of the above
Answer: b

121. What is the limit of data to be passed from HTML when doGet() method is used?
a) 4K
b) 8K
c) 2K
d) 1K
Answer: c

122. The getSession() method with 'true' as its parameter [ getSession(true) ] it


will return the appropriate
session object when
a) the session is completed
b) the session object is passed to another method
c) the session does not
exists
d) the session is existing
Answer: d

123. What's the difference between servlets and applets?


1) Servlets executes on Servers, where as Applets executes on Browser
2) Servlets have no GUI, where
as an Applet has GUI
3) Servlets creates static web pages, where as Applets creates dynamic web pages
4) Servlets can handle only a single request, where as Applet can handle multiple
requests
a) 1,2,3 are correct
b) 1,2 are correct
c) 1,3 are correct
d) All are correct
Answer: b

124. Which method is used to specify before any lines that uses the PrintWriter?
a) setPageType()
b) setContextType()
c) setContentType()
d) setResponseType()
Answer: c

125. JSP stands for __ ?


a) Java Service Page
b) Java Servlet Page
c) Java Server Page
d) None of the above
Answer: c

126. What is a Hidden Comment in JSP?


a) <%-- --%>
b) <%-- %>
c) <%- -%>
d) <%!-- -->
Answer: a

127. What is a Expression in JSP?


a) <%= %>
b) <%-- %>
c) <% %>
d) None of the above
Answer: a

128. What is a Declaration in jsp?


a) <%= %>
b) <%! %>
c) <% %>
d) None of the above
Answer: b

You might also like