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

Java-Programming (Set 3)

This document contains a set of multiple choice questions about Java programming topics including multithreading, exceptions, garbage collection, inheritance, interfaces, packages and more. The questions cover fundamental and advanced concepts in Java.

Uploaded by

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

Java-Programming (Set 3)

This document contains a set of multiple choice questions about Java programming topics including multithreading, exceptions, garbage collection, inheritance, interfaces, packages and more. The questions cover fundamental and advanced concepts in Java.

Uploaded by

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

Java Programming

3 of 7 sets

201. What is multithreaded programming?


A. It’s a process in which two different processes run simultaneously.
B. Its a process in which two or more parts of same process run simultaneously.
C. Its a process in which many different process are able to access same information.
D. Its a process in which a single process can access information from many sources.
Answer:B

202. Which of these are types of multitasking?


A. Process based multitasking
B. Thread based multitasking
o m
C. Both a & b
. c
D. None of the mentioned
te
Answer:D a
q M
c
203. Which of these packages contain all the Java’s built in exceptions?
A. java.io
B. java.util
M
C. java.lang
D. java.net
Answer:C

204. Thread priority in Java is?


A. Integer
B. Float
C. Double
D. Long
Answer:A

205. What will happen if two thread of same priority are called to be processed
simultaneously?
A. Any one will be executed first lexographically
B. Both of them will be executed simultaneously
C. None of them will be executed
D. It is dependent on the operating system.
Answer:D

206. Which of these statements is incorrect?


A. By multithreading CPU’s idle time is minimized, and we can take maximum use of it.
B. By multitasking CPU’s idle time is minimized, and we can take maximum use of it.
C. Two thread in Java can have same priority
D. A thread can exist only in two states, running and blocked.
Answer:D

207. Which method executes only once


A. start() method
B. init() method
C. stop() method
D. destroy() method
Answer:B

208. Thread class is available in


A. java.io package
B. java.lang package
C. java.awt package
D. java.util package
Answer:B

209. Minimum threads in a program are


A. 1
B. 2
C. 5
D. Many
Answer:A

210. Interfaces helps in which type of inheritance


A. Multiple inheritance

View all MCQ's at McqMate.com


B. Multilevel inheritance
C. Hierarchical inheritance
D. None of above
Answer:A

211. Which of these values is returned by read () method is end of file (EOF) is
encountered?
A. 0
B. 1
C. -1
D. Null
Answer:C

212. Which of these exception is thrown by close () and read () methods?


A. IOException
B. FileException
C. FileNotFoundException
D. FileInputOutputException
Answer:A

213. Which exception is thrown by the read ( ) method of input stream class?
A. Exception
B. ClassNotFoundException
C. read Exception
D. IOException
Answer:D

214. What garbage collection in the context of java?


A. The operating system periodically deletes all of the java files available on the system.
B. Any package imported in a program and not used in automatically deleted.
C. When all references to an object are gone, the memory used by the object is automatically
reclaim
Answer:C

215. In order for a source code file, containing the public class test, to successfully
compile, which of the following must be true?

View all MCQ's at McqMate.com


A. It must have a package statement
B. It must be named test.java
C. It must import java.lang
D. It must declare a public class named test.
Answer:B

216. Which of the following are true about the Error and Exception classes?
A. Both classes extend throwable
B. The error class is final and exception class is not.
C. The Exception class is final and the Error is not.
D. Both classes implement Throwable
Answer:A

217. Which of the following are true?


A. The void class extends the class class
B. The float class extends double class
C. The system class extends the runtime class
D. The integer class extends the number class
Answer:D

218. How do you create a Reader object from an InputStream object?


A. Use the static createReader() method of InputStream class
B. Use the static createReader() method of Reader class
C. Create an InputStreamReader object passing the InputStream object and an argument to the
InputStreamReader constructor.
D. Create an OutputStreamReader object, passing the InputStream object as an argument to the
OutputStreamReader constructor.
Answer:C

219. Which of the following is true?


A. The event inheritance model has replaced the event delegation model
B. The event inheritance model is more efficient than event delegation model
C. The event delegation model uses event listeners to define the methods of event handling
classes.
D. The event delegation model uses the handleEvent() method to support event handling.

View all MCQ's at McqMate.com


Answer:C

220. Which of the following is the highest class in the event delegation model?
A. java.util.EventListner
B. java.util.EventObject
C. java.util.AWTEvent
D. java.util.event.AWTEvent
Answer:B

221. When two or more objects are added as listeners for the same event, which
listener is first invoked to handle the event?
A. The first object that was added as listner.
B. The last object that was added as listner
C. There is no way to determine which listener will be invoked first.
D. It is impossible to have more than one listener for a given event.
Answer:C

222. Suppose that you want to have an object eh handle the TextEvent of TextArea
object t. How should you add eh as the event handler for?
A. t.addTextListener(eh);
B. eh.addTextListner(t);
C. addTextListner(eh.t);
D. addTextListner(t,eh);
Answer:D

223. Which is true about an anonymous inner class?


A. It can extend exactly one class and implement exactly one interface.
B. It can extend exactly one class and can implement multiple interfaces.
C. It can extend exactly one class or implement exactly one interface.
D. It can implement multiple interfaces regardless of whether it also extends a class.
Answer:C

224. Which is true about a method-local inner class?


A. It must be marked final.
B. It can be marked abstract.
C. It can be marked public.

View all MCQ's at McqMate.com


D. It can be marked static.
Answer:B

225. Which statement is true about a static nested class?


A. You must have a reference to an instance of the enclosing class in order to instantiate it.
B. It does not have access to nonstatic members of the enclosing class.
C. It's variables and methods must be static.
D. It must extend the enclosing class.
Answer:B

226. Which of these is correct way of inheriting class A by class B?


A. class B + class A {}
B. class B inherits class A {}
C. class B extends A {}
D. class B extends class A {}
Answer:C

227. Which of the following are true about interfaces.


A. Methods declared in interfaces are implicitly private.
B. Variables declared in interfaces are implicitly public, static, and final.
C. An interface contains any number of method definitions.
D. The keyword implements indicate that an interface inherits from another.
Answer:B

228. Which of the following is correct way of implementing an interface salary by


class manager?
A. class Manager extends salary {}
B. class Manager implements salary {}
C. class Manager imports salary {}
D. None of the mentioned.
Answer:B

229. Which of the following is incorrect statement about packages?


A. Package defines a namespace in which classes are stored.
B. A package can contain other package within it.
C. Java uses file system directories to store packages.

View all MCQ's at McqMate.com


D. A package can be renamed without renaming the directory in which the classes are stored.
Answer:D

230. Which exception is thrown by read() method?


A. IOException
B. InterruptedException
C. SystemException
D. SystemInputException
Answer:A

231. Which method in Thread class is used to check weather a thread is still
running?
A. isAlive()
B. Join()
C. isRunning()
D. Alive()
Answer:A

232. Which of these class contains the methods print() & println()?
A. System
B. System.out
C. BufferedOutputStream
D. PrintStream
Answer:D

233. To design a general-purpose search method, searchList, to search a list, which


of the following must be parameters of the method searchList? (i) The array
containing the list. (ii) The length of the list. (iii) The search item. (iv) A boolean
variable indicating whether the search is successful.
A. (i) and (ii)
B. (i), (ii), and (iii)
C. (ii), (iii), and (iv)
D. (i), (ii), (iii), and (iv)
Answer:B

View all MCQ's at McqMate.com


234. Consider the following list.list = {24, 20, 10, 75, 70, 18, 60, 35} Suppose that list
is sorted using the selection sort algorithm as discussed in the book. What is the
resulting list after two passes of the sorting phase, that is, after two iteration of the
outer for loop?
A. list = {10, 18, 24, 20, 75, 70, 60, 35}
B. list = {10, 18, 20, 24, 75, 70, 60, 35}
C. list = {10, 18, 24, 75, 70, 20, 60, 35}
D. None of these
Answer:C

235. Which method would you most likely use to add an element to an end of a
vector?
A. insertElementAt
B. addElement
C. copyInto
D. lastElement
Answer:B

236. In which package is the class Vector located?


A. java.io
B. java.lang
C. java.util
D. java.text
Answer:C

237. An abstract method ____.


A. is any method in the abstract class
B. cannot be inherited
C. has no body
D. is found in a subclass and overrides methods in a super-class using the reserved word
abstract
Answer:C

238. The classes Reader and Writer are derived from the class _________.
A. Streams
B. Inputs

View all MCQ's at McqMate.com


C. Outputs
D. Object
Answer:D

239. The method toString() is a public member of the class _____________.


A. Object
B. String
C. Writer
D. Output
Answer:A

240. For the interface WindowListener that contains more than one method, Java
provides the class ____.
A. MouseAdapter
B. WindowAdapter
C. KeyListener
D. KeyAdapter
Answer:B

241. If a negative value is used for an array index, ____.


A. a NumberFormatException is thrown
B. the program terminates immediately
C. the last index of the array is automatically accessed instead
D. an IndexOutOfBoundsException is thrown
Answer:D

242. Consider the following list. int[] intList = {35, 12, 27, 18, 45, 16, 38}; What is
the minimum number of comparisons that have to be made to find 18 using a
sequential search on intList?
A. 1
B. 2
C. 3
D. 4
Answer:D

View all MCQ's at McqMate.com


243. Which of these packages contains all the classes and methods required for
even handling in Java?
A. java.applet
B. java.awt
C. java.event
D. java.awt.event
Answer:D

244. What is an event in delegation event model used by Java programming


language?
A. An event is an object that describes a state change in a source.
B. An event is an object that describes a state change in processing.
C. An event is an object that describes any change by the user and system.
D. An event is a class used for defining object, to create events.
Answer:A

245. Which of these methods are used to register a keyboard event listener?
A. KeyListener()
B. addKistener()
C. addKeyListener()
D. eventKeyboardListener()
Answer:C

246. Which of these methods are used to register a mouse motion listener?
A. addMouse()
B. addMouseListener()
C. addMouseMotionListner()
D. eventMouseMotionListener()
Answer:C

247. What is a listener in context to event handling?


A. A listener is a variable that is notified when an event occurs.
B. A listener is a object that is notified when an event occurs.
C. A listener is a method that is notified when an event occurs.
D. None of the mentioned

View all MCQ's at McqMate.com


Answer:B

248. Which command disassembles a class file


A. javaamd
B. javacmd
C. java
D. javap
Answer:D

249. JDBC stands for:


A. Java Database Connectivity
B. Java Database Components
C. Java Database Control
D. None of the above is correct.
Answer:A

250. Which of the following statements is false as far as different type of statements
is concern in JDBC?
A. Regular Statement
B. Prepared Statement
C. Callable Statement
D. Interim Statement
Answer:D

251. Which statement is static and synchronized in JDBC API?


A. executeQuery()
B. executeUpdate()
C. getConnection()
D. prepareCall()
Answer:C

252. Which driver is efficient and always preferable for using JDBC applications?
A. Type – 4
B. Type – 1
C. Type – 3
D. Type – 2

View all MCQ's at McqMate.com


Answer:A

253. Which one of the following does not extends java.awt.Component


A. CheckBox
B. Canvas
C. CheckbocGroup
D. Label
Answer:C

254. What is default layout manager for panels and applets?


A. Flowlayout
B. Gridlayout
C. BorderLayout
D. none
Answer:A

255. java.awt.Component class method getLocation() returns Point (containg x and


y cordinate).What does this x and y specify
A. Specify the postion of components lower-left component in the coordinate space of the
component's parent.
B. Specify the postion of components upper-left component in the coordinate space of the
component's parent.
C. Specify the postion of components upper-left component in the coordinate space of the screen.
D. none
Answer:B

256. Which of the following methods finds the maximum number of connections
that a specific driver can obtain?
A. Database.getMaxConnections
B. Connection.getMaxConnection
C. DatabaseMetaData.getMaxConnections
D. ResultSetMetaData.getMaxConnections
Answer:C

257. What is the disadvantage of Type-4 Native-Protocol Driver?


A. At client side, a separate driver is needed for each database.

View all MCQ's at McqMate.com


B. Type-4 driver is entirely written in Java
C. The driver converts JDBC calls into vendor-specific database protocol
D. It does not support to read MySQL data.
Answer:A

258. What is the preferred way to handle an object's events in Java 2?


A. Override the object's handleEvent( ) method.
B. Add one or more event listeners to handle the events
C. Have the object override its process Event ( ) methods.
D. Have the object override its dispatch Event ( ) methods.
Answer:B

259. Which component method is used to access a component's immediate


container?
A. getVisible()
B. getImmediate()
C. getParent()
D. getContainer()
Answer:C

260. Which of the following creates a List with 5 visible items and multiple
selections enabled?
A. new List(5, true)
B. new List(true, 5)
C. new List(5, false)
D. new List(false, 5)
Answer:A

261. An Applet has its Layout Manager set to the default of FlowLayout. What
code would be the correct to change to another Layout Manager?
A. setLayoutManager(new GridLayout());
B. setLayout(new GridLayout(2,2));
C. setGridLayout(2,2);
D. setBorderLayout();
Answer:B

View all MCQ's at McqMate.com


262. How do you change the current layout manager for a container?
A. Use the setLayout method.
B. Once created you cannot change the current layout manager of a component
C. Use the setLayoutManager meth
Answer:A

263. Which of the following methods can be used to draw the outline of a square
within a JAVA.awt.Component object?
A. drawLine()
B. fillRect()
C. drawPolygon()
D. drawPolygon()
Answer:A

264. State true or false (i) JPanel is a class included in awt package (ii) Anonymous
classes are mostly used for event handling (iii) Names of anonymous classes must
be unique (iv) JOptionPane is an inner class
A. i-false, ii-false, iii-true, iv-true
B. i-true, ii-false, iii-true, iv-false
C. i-false, ii-true, iii-false, iv-false
D. i-true, ii-true, iii-false, iv-true
Answer:C

265. State true or false (i) Java RMI supports distributed objects written entirely in
java (ii) Java RMI makes use of stubs and skeleton (iii) In Java RMI an object
registers itself with a media server (iv) IDL is interface declaration language
A. True, True, False, False
B. False, True, True, True
C. True, False, True, False
D. True, True, True, True
Answer:A

266. Match the following


(a) Datagram Socket (i) UDP connection
(b) URL (ii) provides a necessary framework of debugging java programs
(c) java.net (iii) makes it possible to communicate over a network with java
programs

View all MCQ's at McqMate.com


(d) sun.tools.debug (iv) is a java object that represents WWW address
A. a-i, b-iv, c-iii, d-ii
B. a-i, b-iv, c-ii, d-iii
C. a-ii, b-iii, c-i, d-iv
D. a-ii, b-i, c-iii, d-iv
Answer:A

267. State true or false (i) public can only be assigned to class (ii) protected protects
a statement (iii) protected method is never accessible outside the package (iv)
friendly variable may be accessible outside class
A. True, True, False, True
B. False, False, False, True
C. False, True, False, False
D. True, False, False, False
Answer:A

268. Which refers to a channel through which data flow from the source to the
destination:
A. String
B. Character
C. Stream
D. Buffer
Answer:C

269. The ________ method help in clearing the contents of the buffer:
A. flush()
B. clear()
C. rub()
D. vanish()
Answer:C

270. Which of these methods can be used to output a string in an applet?


A. display()
B. print()
C. drawString()
D. transient()

View all MCQ's at McqMate.com


Answer:C

271. Which of these methods are used to register a MouseMotionListener?


A. addMouse()
B. addMouseListener()
C. addMouseMotionListner()
D. eventMouseMotionListener()
Answer:C

272. What is a listener in context to event handling?


A. A listener is a variable that is notified when an event occurs.
B. A listener is an interface that is notified when an event occurs.
C. A listener is a method that is notified when an event occurs.
D. None of the mentioned
Answer:B

273. Which of these events will be generated if scroll bar is manipulated?


A. ActionEvent
B. ComponentEvent
C. AdjustmentEvent
D. WindowEvent
Answer:D

274. Which of these events will be generated if we close a Frame window?


A. ActionEvent
B. ComponentEvent
C. AdjustmentEvent
D. WindowEvent
Answer:D

275. Which of these methods in KeyEvent class can be used to know which key is
pressed?
A. getKeyCode()
B. getModifier()
C. getActionKey()
D. getActionEvent()

View all MCQ's at McqMate.com


Answer:A

276. The default layout manager of an Applet is


A. Flowlayout
B. Gridlayout
C. BorderLayout
D. BoxLayout
Answer:A

277. The processes that participate in supporting remote method invocation are
A. Client
B. Server
C. Object Registry
D. All of the above
Answer:D

278. Through the design mode of a builder tool, we use ___ or ____ to customize
the bean.
A. Property sheet
B. Bean customizer
C. Either (a) or (c)
D. None of the above
Answer:C

279. Swing is a ___________ framework


A. connection-based
B. component-based
C. platform-based
D. None of the above
Answer:B

280. How many kinds of classes can be used in Java RMI?


A. One
B. Two
C. Three
D. Four

View all MCQ's at McqMate.com


Answer:B

281. Which method is used to enable an event for a particular object?


A. enableEvent()
B. enable()
C. enableObject()
D. enableEvents()
Answer:D

282. How would you detect a keypress in a JComboBox?


A. Add a KeyListener to the JComboBox
B. Add a KeyListener to the JComboBox’s editor component
C. Either (a) or (b)
D. None of the above
Answer:B

283. Which Swing methods are thread-safe?


A. repaint()
B. revalidate()
C. invalidate()
D. all of the above
Answer:D

284. Which of the following is not true?


A. The Frame class extends Window
B. The CheckboxMenuItem class extends the MenuItem class
C. JComponent is a subclass of Container
D. None of the above
Answer:D

285. What is the correct way to write a JavaScript array?


A. var txt = new Array:1=("tim")2=("kim")3=("jim")
B. var txt = new Array(1:"tim",2:"kim",3:"jim")
C. var txt = new Array="tim","kim","jim")
D. var txt = new Array("tim","kim","jim")

View all MCQ's at McqMate.com


Answer:D

286. What is the correct JavaScript syntax to insert a comment that has more than
one line?
A. <!--This comment has more than one line-->
B. /*This comment has more than one line*/
C. //This comment has more than one line//
D. <//This comment has more than one line//>
Answer:B

287. What is Remote method invocation (RMI)?


A. RMI allows us to invoke a method of java object that executes on another machine.
B. RMI allows us to invoke a method of java object that executes on another Thread in
multithreaded programming.
C. RMI allows us to invoke a method of java object that executes parallely in same machine.
D. None of the mentioned
Answer:A

288. Which of this package is used for remote method invocation?


A. java.applet
B. java.rmi
C. java.lang.rmi
D. java.lang.reflect
Answer:B

289. Which of these methods are member of Remote class?


A. checkIP()
B. addLocation()
C. AddServer()
D. None of the mentioned
Answer:D

290. Which of these Exceptions is thrown by remote method?


A. RemoteException
B. InputOutputException
C. RemoteAccessException

View all MCQ's at McqMate.com


D. RemoteInputOutputException
Answer:A

291. Which of this class is used for creating a client for server-client operations?
A. serverClientjava
B. Client.java
C. AddClient.java
D. ServerClient.java
Answer:C

292. Which of this package is used for all the text related modifications?
A. java.text
B. java.awt
C. java.lang.text
D. java.text.mofify
Answer:A

293. Which of this package contains classes and interfaces for networking?
A. java.io
B. java.util
C. java.net
D. java.network
Answer:C

294. Which of these is superclass of ContainerEvent class?


A. WindowEvent
B. ComponentEvent
C. ItemEvent
D. InputEvent
Answer:B

295. Which of these events is generated when the size os an event is changed?
A. ComponentEvent
B. ContainerEvent
C. FocusEvent

View all MCQ's at McqMate.com


D. InputEvent
Answer:A

296. Which of these methods can be used to obtain the reference to the container
that generated a ContainerEvent?
A. getContainer()
B. getContainerCommand()
C. getActionEvent()
D. getContainerEvent()
Answer:D

297. To locate a remote object with a name t at port 7000 on host


panda.armstrong.edu, use
A. Remote remoteObj = Name.lookup("rmi://panda.armstrong.edu:7000/t");
B. Remote remoteObj = Name.lookup("//panda.armstrong.edu:7000/t");
C. Remote remoteObj = Name.lookup("http://panda.armstrong.edu:7000/t");
D. Remote remoteObj = Naming.lookup("rmi://panda.armstrong.edu:7000/t");
Answer:D

298. ____________ is a subinterface of java.rmi.Remote that defines the methods


for the server object.
A. Server stub
B. Server implementation
C. Server object interface
D. RMI Registry
Answer:C

299. Each remote object has a unique name identified by an URL with the protocol
rmi as follows:
A. http://host:port/name
B. //host:port/name
C. http://host/name
D. rmi://host:port/name
Answer:B

300. __________ provides the naming services for the server to register the object
and for the client to locate the object.

View all MCQ's at McqMate.com


A. Server stub
B. RMI Registry
C. Server implementation
D. Server Skeleton
Answer:B

View all MCQ's at McqMate.com

You might also like