Advance Java MCQ Ch3
Advance Java MCQ Ch3
e-Exam Manage Questions for Advanced Java Programming (17625) for topic 3 Go Back to Subjects
Q To Fig Q Mar
Question Answer Edit Delete
No pic ure Type ks
2 TCP/IP reserves the ____________ ports for specific protocols 3 N R 1 lower 1024 Edit Delete
13 Communication using TCP protocol is __________and _________ 3 N R 1 connection-oriented, concurrent Edit Delete
16 How many bytes are required to represent an IPv4 address? 3 N R 1 4 Edit Delete
18 In the format for defining the URL what is the last part? 3 N R 1 File path Edit Delete
19 In the URL, http://www.osborne.com:80/index.htm, 80 represents 3 N R 1 Port number Edit Delete
20 In UDP send() and receive() methods belong to which class? 3 N R 1 DatagramSocket Edit Delete
21 In which class the constructors are not visible 3 N R 1 Inetaddress class Edit Delete
24 Java.net package include following classes. 3 N R 1 URLConnection, Socket, InetAddress Edit Delete
Name the class which is used to create a port where the server will
25 3 N R 1 ServerSocket Edit Delete
listen?
33 Select the proper constructor of ServerSocket class 3 N R 1 All of above Edit Delete
34 Select the proper constructor of URL class 3 N R 1 All of the above Edit Delete
38 TCP/IP sockets are used to impelement __________ connections. 3 N R 1 All of the above Edit Delete
The class which encapsulates both the numerical IP address and the
39 3 N R 1 InetAddress Edit Delete
domain name for that address.
41 The constructor which is used to create client socket is ____________. 3 N R 1 Socket(InetAddress IPAddress, int port). Edit Delete
45 The method int getPort( ) of Socket class returns____________ 3 N R 1 remote port to which this Socket object is connected. Edit Delete
The server listens for a connection request from a client using the
50 3 N R 1 Socket s = ServerSocket.accept() Edit Delete
following statement:
51 The valid sequence for URL format is ___________________ 3 N R 1 protocol, Hostname, portnumber, filepath Edit Delete
54 To create an InputStream on a Socket s, you use __________. 3 N R 1 InputStream in = s.getInputStream(); Edit Delete
56 To return an instance of InetAddress class you have to use 3 N R 1 Factory Methods of InetAddress class Edit Delete
60 UDP Protocol uses following classes for communication 3 N R 1 DatagramPacket and DatagramSocket Edit Delete
63 What does the openConnection() method of java.net.* return? 3 N R 1 Object of URLConnection class Edit Delete
64 What does URL stands for? 3 N R 1 Uniform Resource Locator Edit Delete
65 What is return type of getAddress() method of InetAddress class? 3 N R 1 byte[] Edit Delete
69 What is the optional part of URL Address 3 N R 1 Port Number Edit Delete
73 When a URL object is created __________ 3 N R 1 a connection is automatically established with that URL Edit Delete
78 Which class is used to implement datagrams with UDP protocol. 3 N R 1 DatagramSocket Edit Delete
Which class of java.net package can be used to find the host name
79 3 N R 1 The InetAddress class Edit Delete
and IP address of the client.
80 Which classes are used for connection-oriented socket programming 3 N R 1 Both A and B Edit Delete
87 Which is the correct syntax from given? 3 N R 1 byte[] getAddress() Edit Delete
89 Which method is used to know the full URL of an URL object? 3 N R 1 toExternalForm() Edit Delete
90 Which method is used to retrieve the host name associated with URL 3 N R 1 getHost() Edit Delete
91 Which method is used to return the IPAddress of local machine 3 N R 1 static InetAddress getLocalHost( ) Edit Delete
93 Which method of URL class is used to create object of URLConnection? 3 N R 1 openConnection Edit Delete
94 Which of the following are Factory Methods of InetAddress class 3 N R 1 All the Above Edit Delete
95 Which of the following class defines accept() method? 3 N R 1 ServerSocket Edit Delete
96 Which of the following constructor of InetAddress is generally used? 3 N R 1 InetAddress class does not contain any visible constructor. Edit Delete
97 Which of the following is a connection oriented protocol? 3 N R 1 TCP Edit Delete
Which of the following is mediator between real web server and client
98 3 N R 1 Proxy Edit Delete
application
99 Which of the following is not a constructor of DatagramSocket 3 N R 1 DatagramSocket(InetAddress address) Edit Delete
102 Which of the following is true about UDP? 3 N R 1 No retransmission of lost packets. Edit Delete
103 Which of the following is true for TCP ? 3 N R 1 TCP is realiable and connection oriented Edit Delete
104 Which of the following is true for UDP ? 3 N R 1 UDP is unrealiable and connection less Edit Delete
107 Which of the ServerSocket method listen client request for connection? 3 N R 1 accept() Edit Delete
108 Which of these class is necessary to implement datagrams? 3 N R 1 Both of these Edit Delete
Which of these class is used to create servers that listen for either
109 3 N R 1 ServerSockets Edit Delete
local or remote client programs?
110 Which of these class is used to encapsulate IP address and DNS? 3 N R 1 InetAddress Edit Delete
112 Which of these is a bundle of information passed between machines? 3 N R 1 Datagram Edit Delete
114 Which of these is a not a factory method of InetAddress class? 3 N R 1 static InetAddress getAllName(String hostName) Edit Delete
118 Which of these method does not belongs to DatagramPacket class 3 N R 1 getAddress() Edit Delete
122 Which of these methods is used to know the full URL of an URL object? 3 N R 1 toExternalForm() Edit Delete
Which of these methods is used to know when was the URL last
124 3 N R 1 getLastModified() Edit Delete
modified?
125 Which package is used for handling security related issue? 3 N R 1 java.security Edit Delete
126 Which socket class can send packets unreliably? 3 N R 1 java.net.DatagramSocket() Edit Delete
________ is a low level routing protocol that breaks data into smaller
131 3 N R 1 Internet protocol. Edit Delete
packets.
133 __________ is a factory method which returns an array of addresses. 3 N R 1 getAllByName. Edit Delete
151 From given list which address is called as loopback address ? 3 N U 2 127.0.0.0 Edit Delete
154 getPort() method of socket class return 3 N A 2 Returns the port number on which the socket is connected Edit Delete
Given the following lines from a Java program segment: byte[] dataOut
= new byte [512]; String userInput = "Java Programming"; dataOut =
userInput.getBytes(); Which of the following lines of code could be DatagramPacket packet = new DatagramPacket(dataOut,
157 3 N A 2 Edit Delete
used to create a new UDP datagram packet to send the data that was userInput.length, InetAddress, 9876)
provided by the user to a host identified by the InetAddress object
IPAddress?
159 Identify the valid method of URL class. 3 N U 2 All of the mentioned Edit Delete
160 Identify the valid ServerSocket constructor. 3 N U 2 public ServerSocket(int portno) Edit Delete
If you use either Telnet or FTP, which is the highest layer you are using
163 3 N U 2 Application Edit Delete
to transmit data?
In following java program fill statement showing *****. Select any one
option from given options. import java.net.*; public class InetDemo {
public static void main(String[] args) { try { InetAddress
171 ip=InetAddress.**************** System.out.println("Host Name: 3 N A 2 getByName("www.msbte.com"); Edit Delete
"+ip.getHostName()); System.out.println("IP Address:
"+ip.getHostAddress()); } catch(Exception e) { System.out.println(e); }
}}
In the following program choose the correct strings from given options
to pass in URL constructor to get an output without any exception.
import java.net.*; class URLDemo { public static void main(String
args[]) throws MalformedURLException { URL hp = new
URL("__________"); System.out.println("Protocol: " +
176 hp.getProtocol()); System.out.println("Port: " + hp.getPort()); 3 N A 2 All Edit Delete
System.out.println("Host: " + hp.getHost()); System.out.println("File: "
+ hp.getFile()); } } A. http://www.msbte.com/mainsite/index.php B.
http://www.msbte.com:80/mainsite/index.php C. www.msbte.com/ D.
www.msbte.com/mainsite/index.php
179 InputStream class is used in TCP Client-server program to 3 N U 2 Send/receive message from client to server Edit Delete
180 IPv6 uses ---------------------- 3 N U 2 Eight groups of four hexadecimal digits each Edit Delete
183 Name the components of the URL in order of their appearance 3 N U 2 Protocol,Hostname,Port Number, File Name Edit Delete
190 Select pacakge used for handling security related issues in a program 3 N U 2 java.security Edit Delete
191 Select proper method used to create the instance InetAddress class. 3 N U 2 getLocalHost(),getByName(),getAllByName() Edit Delete
194 Select the fullform of DNS 3 N U 2 Domain Name System Edit Delete
195 Select the method of DatagramPacket used to find the port number 3 N U 2 getPort() Edit Delete
196 Select the method used to create a URL Connection 3 N U 2 openConnection Edit Delete
197 Select the method which throws UnKnownHostException 3 N U 2 All of the above Edit Delete
select the proper class for creating servers that listen for either local or
198 3 N U 2 ServerSockets Edit Delete
remote client programs
199 Select the proper constructor of ServerSocket 3 N U 2 ServerSocket(int port, int maxQueue) Edit Delete
200 Select the proper constructor of the Socket class 3 N U 2 Socket(String hostName, int port) Edit Delete
201 Select the proper constructor of URL class 3 N U 2 All of above Edit Delete
202 Select the proper InetAddress factory method. 3 N U 2 static InetAddress getLocalHost() Edit Delete
204 Select the proper method to know the type of content used in the URL. 3 N U 2 getContentType() Edit Delete
Select the proper method to retrieve the host name & IP address of static InetAddress getByName(String hostName)throws
205 3 N U 2 Edit Delete
remote machine having domain name as "www.msbte.com" UnknownHostException
Select the proper method to retrieve the host name and IP Address of static InetAddress getLocalHost( )throws
206 3 N U 2 Edit Delete
local machine UnknownHostException
208 select the proper method to retrive the data from DatagramPacket 3 N U 2 getData() Edit Delete
Select the proper output for following code import java.net.*; class
DemoURL { public static void main(String args[])throws
209 3 N A 2 Port: -1 File: /downloads/index.php Edit Delete
MalformedURLException { URL hp=new
URL("http://www.msbte.com/downloads/index.php");
System.out.println("Port: "+hp.getPort()); System.out.println("File:
"+hp.getFile()); } }
213 TCP does not supports Multicasting and Broadcasting because: 3 N U 2 It is connection oriented protocol. Edit Delete
The URL connection classes are good enough for simple programs that
214 3 N U 2 HTTP Edit Delete
want to connect to ______ server to fetch content.
217 The connection establishment in TCP is called 3 N U 2 three- way handshaking Edit Delete
218 The Constructor of URL can throws an Exception called 3 N U 2 MalFormedURLException Edit Delete
The following code can be used to produce a permisson to read the file perm=new
219 3 N U 2 Edit Delete
named "abc " in the /tmp directory java.io.FilePermission("/tmp/abc","read");
The server listens for a connection request from a client using the
224 3 N U 2 Socket s = serverSocket.accept() Edit Delete
following statement:
The Socket class has how many constructors that a client uses to
225 3 N A 2 2 Edit Delete
connect to a server:
226 The User Datagram Protocol (UDP) is 3 N U 2 All of them Edit Delete
238 URL Connection is class used for_____________________. 3 N U 2 Accessing the attributes of a remote resource. Edit Delete
240 URLConnection object is retrived using following method? 3 N U 2 openConnection() Edit Delete
253 What is proper method to retrieve the host name of local machine 3 N U 2 static InetAddressgetLocalHost( )throws UnknownHostException Edit Delete
what is the out of following code if Host URL was last modified on july
18 tuesday 2013 . mport java.net.*; class networking { public static
260 void main(String[] args) throws Exception { URL obj = new 3 N A 2 Tue Jun 18 2013 Edit Delete
URL("http://www.sanfoundry.com/javamcq"); URLConnection obj1 =
obj.openConnection(); System.out.print(obj1.getLastModified); } }
264 What is the purpose of InetAddress class? 3 N U 2 To retrieve IP address of the specified host machine. Edit Delete
266 What is the use of bind() method 3 N U 2 bind a socket to a local IP address and port Edit Delete
267 What is the use of writeUTF( ) method? 3 N U 2 This method writes a string into underlying output stream Edit Delete
270 What the method getDate() of URLConnection class returns? 3 N U 2 returns time and date of response in terms of millisecond Edit Delete
272 What type of exception might be thrown by Socket class. 3 N U 2 UnknownHostException Edit Delete
when creating a client on a server port that is alerady in use client can connect to the server regardless of whehter the port is
276 3 N U 2 Edit Delete
________________ in use
277 When UnknownHostException is thrown, that indicates 3 N U 2 The IP address of a host could not be determined Edit Delete
Which class can be used to create a server socket. This object is used
281 3 N U 2 Both A & B Edit Delete
to establish communication with the clients ?
282 Which code segment listens for a socket connection? 3 N U 2 Socket socket = HttpURLConnection.open(8080); Edit Delete
285 Which Exception is thrown by DatagramSocket class constructor 3 N U 2 SocketException Edit Delete
286
Which five parameters uniquely identify a Connection ? 3 N U 2 Local IP, Remote IP, Local MAC, Remote MAC and Protocol Edit Delete
292 Which is reserved port of HTTP & FTP 3 N U 2 80 & 21 Edit Delete
295 Which method is used to obtain the Portno of client in Client Program 3 N U 2 getLocalPort() Edit Delete
296 Which method Returns the output stream of the URL connection ? 3 N U 2 getOutputStream() Edit Delete
297 Which methods are commonly used in ServerScocket class ? 3 N U 2 public Socket accept() Edit Delete
301 Which of these are correct constructor/s of URL class? 3 N U 2 All of above Edit Delete
302 Which of these class is used to encapsulate IP address and DNS? 3 N U 2 InetAddress Edit Delete
303 Which of these methods is used to know host of an URL? 3 N U 2 getHost() Edit Delete
which of this class is not related to input and output stream in terms of
304 3 N A 2 Reader Edit Delete
functioning?
311 _______ method is used to examine the address and port information 3 N U 2 getInetAddress(). Edit Delete
by the socket.
314 ___________ is a bundle of information passed between machines. 3 N U 2 Datagram Edit Delete
316 ___________ server can process multiple request at a time 3 N U 2 a concurrent Edit Delete
318 _____________ class is necessory to implements Datagram 3 N U 2 both a and b Edit Delete
326 Which client accesses the Web server by using a GET MESSAGE? 3 N U 2 HTTP Edit Delete
Program: CO5I Course: Advanced Java Programming (22517) Course Co-ordinator: Mrs.Chavan P.P.
Unit III- Event Handling
Question Bank
Sr. A
Question Option A Option B Option C Option D
No n
j
1 Which of these packages contains all the event handling interfaces? java.lang java.awt java.awt.event java.event a
vA
2 Where can the event handling code be written? Same class Other class Anonymous class All mentioned above l
l
E
3 Which of these class is super class of all the events? EventObject EventClass ActionEvent ItemEvent
v
j
Which package provides many event classes and Listener interfaces for
4 java.awt java.awt.Graphics java.awt.event None of the above a
event handling?
vC
Which of these interfaces handles the event when a component is added to
5 ComponentListener ContainerListener FocusListener InputListener o
a container?
n
A
6 Which of these interfaces define a method actionPerforme() ? ComponentListener ContainerListener ActionListener InputListener
c
C
7 Which of these interfaces define four methods? ComponentListener ContainerListener ActionListener InputListener
o
W
8 Which of these events will be generated if we close an applet's window? ActionEvent ComponentEvent AdjustmentEvent Window Event i
n
A
9 Which of these events is generated when a button is pressed ? ActionEvent KeyEvent Window Event AdjustmentEvent
c
g
Which of these methods can be used to obtain the command name for getAction
10 getCommand() getActionCommand() getActionEvent() e
invoking ActionEvent object? EventCommand()
tI
Which of these interfaces define a method
11 ComponentListener ContainerListener ActionListener ItemListener t
itemStateChanged()?
ek
12 Which of these methods will be invoked if a character is entered ? keyPressed() keyReleased() keyTyped() keyEntered() e
y
A
13 Which of these are constants defined in Window Event class? WINDOW_ACTIVATED WINDOW_CLOSED WINDOW_DEICONIFIED All of the mentioned
l
A
14 Which of these events is generated by scroll bar? ActionEvent KeyEvent Window Event AdjustmentEvent
d
U
Which of these constant value will change when the button at the end of
15 BLOCK_DECREMENT BLOCK_INCREMENT UNIT_DECREMENT UNIT_INCREMENT N
scroll bar was clicked to increase its value?
Im
16 Which of these methods is defined in MouseMotionAdapter class? mouseDragged() mousePressed() mouseReleased() mouseClicked() o
u
A
17 Which of these methods will respond when you click any button by mouse ? mouseClicked() mouseEntered() mousePressed() All of the mentioned l
l
A
18 Which of these is superclass of all Adapter classes? Applet ComponentEvent Event InputEvent
p
g
19 Which of these methods can be used to obtain the coordinates of a mouse? getPoint() getCoordinates() getMouseXY() getMouseCordinates() e
t
I
20 MouseEvent is subclass of which of these classes? ComponentEvent Containerfivent ItemEvent InputEvent
n
T
21 Which of these are integer constants of TextEvent class? TEXT_CHANGED TEXT_FORMAT_CHANGED TEXT_VALUE_CHANGED TEXT_SIZE_CHANGED
E
g
Which of these methods is used to obtain the object that generated a
22 getMethod() getWindow() getWindowEvent() getWindowObject() e
Window Event ?
tg
23 Which of these methods is used to get x coordinate of the mouse? getX() getXCoordinate() getCoordinateX() getPointX() e
t
C
24 Which of these is superclass of Window Event class? WindowEvent ComponentEvent ItemEvent InputEvent
o
K
25 Which event gets generated when the key is typed? KEY_PRESSED KEY_TYPED KEY_RELEASED None of these
E
g
What method is used to distinguish between single, double and triple mouse
26 getButton() getPoint() getClickCount() getX() e
clicks?
t
W
27 The getNewState() method belongs to __ . TextEvent Class MouseEvent Class WindowEvent Class KeyEvent Class
i
A
28 For scrollbars___________event class is used ActionEvent TextEvent AdjustmentEvent ContainerEvent
d
j
29 Which of the following is the highest class in the event-delegation model ? java.util.EventListener java.util.EventObject java.awt.AWTEvent java.awt.event.AWTEvent a
v
T
There is no way to It is impossible to have
When two or more objects are added as listeners for the same event, which The first object that was The last object that was h
30 determine which listener more than one listener for
listener is first invoked to handle the event? added as listener. added as listener. e
will be invoked first. a given event.
r
I
31 MouseEvent is subclass of which of these classes? ComponentEvent ContainerEvent ItemEvent InputEvent n
p
g
32 Which of these methods is used to get x coordinate of the mouse? getX() getXCoordinate() getCoordinateX() getPointX() e
t
B
33 In Java, events are all the actives that occur between: The user The application Both a and b None of the above
o
T
34 Which of these methods can be used to change location of an event? ChangePoint() TranslatePoint() ChangeCordinates() TranslateCordinates() r
a
A
35 Which of these events is generated by scroll bar? ActionEvent KeyEvent WindowEvent AdjustmentEvent
d
g
Which of these methods is used to obtain the object that generated a
36 getMethod() getWindow() getWindowEvent() getWindowObject() e
WindowEvent?
t
Complete the following code
public class Buttonl extends Applet implements
{ Button button=new Button("change the color");
boolean flag=true;
public void init() A
{ add(button); c
button.addActionListener(this); . t
} i
public void paint(Graphics g) o
{ if(flag) n
setBackground(Color. yellow); L
37 ActionListener ItemListener MouseListener None of these
else i
setBackground(Color.red); s
} t
public void actionPerformed(ActionEvent e) e
{ String str=e.getActionCommand(); n
if(str.equals("change the color")) e
{ flag = !flag; r
//toggle the flag values on every click of button
repaint();
}
}}
g
38 Which of these methods can be used to know which key is pressed? getKey() getModifier() getActionKey() getActionEvent() e
tW
39 Which of these events is generated when the a window is closed? TextEvent MouseEvent FocusEvent WindowEvent i
n
A
40 Which of these are integer constants of ComponentEvent class? COMPONENT_HIDDEN COMPONENT_MOVED COMPONENT_RESIZE All of the mentioned l
lF
Which of these events is generated when computer gains or losses input
41 ComponentEvent ContainerEvent FocusEvent InputEvent o
focus?
cg
Which of these methods can be used to know the degree of adjustment
42 getValue() getAdjustmentType() getAdjustmentValue() getAdjustmentAmount() e
made by the user?
tg
Which of these methods can be used to obtain the reference to
43 getContainer() getContainerCommand() getActionEvent() getContainerEvent() e
the container that generated a ContainerEvent?
gt
Which of these methods can be used to get reference to a component that
44 getComponent() getchild() getContainerComponent() getComponentChild() e
was removed from a container?
tC
Which of these events is generated when the component is added or
45 ComponentEvent ContainerEvent FocusEvent InputEvent o
removed?
n
i
t
Consider following code arid fill up the correct event listener method e
/* <applet code = "checkgroup" width = 300 height =250 > </applet> */ m
public class checkgroup extends Applet implements S
ItemListener t
{ String msg=" "; a
CheckboxGroup,.gr=new CheckboxGroupO; t
Checkbox boxl =new Checkbox("Candy" ,gr,true); e
Checkbox box2 = new Checkbox("Ice-cream" ,gr,false); C
Checkbox box3=new Checkbox(" Juice ",gr,false); h
public void init() a
{ add(boxl); n
add(box2); actionPerformed(ActionEv itemStateChanged(ItemEv textValueChanged(TextEv g
46 action(Event e,Object O)
add(box3); ent e) ent e) ent e) e
boxl.addItemListener(this); d
box2.addItemListener(this); (
box3.addItemListener(this); I
} t
public void _ e
{ repaint(); } m
public void paint(Graphics g) E
{ msg="I like "; v
msg+ =gr.getSelectedCheckbox().getLabeI(); e
g.drawString(msg,10,100); n
}} t
e
)W
47 Which of these events will be generated if we close an applet’s window? ActionEvent ComponentEvent AdjustmentEvent WindowEvent i
nC
Which of these events is generated when the size of a component is
48 ComponentEvent ContainerEvent FocusEvent InputEvent o
changed?
Cm
Which of these events is generated when the component is added or
49 ComponentEvent ContainerEvent FocusEvent InputEvent o
removed?
n