MCQ Exam (TCLD)
MCQ Exam (TCLD)
1 The Graphics object represents the part of the Frame that you can draw on.
2 The Graphics object represents the entire monitor.
3 The Graphics object represents the whole Frame.
4 The Graphics object represents the graphics board.
Ans:1
In Java, what do you call an area on the screen that has nice borders and various buttons along the top border?
1 A box.
2 A window.
3 A screen.
4 A frame
Ans:4.
How can the user be prevented from entering text into a text field?
1 By using setVisible( false )
2 By using setEditable( false )
3 By using setEditable( true )
4 By using setNotEditable()
Ans:2
What type of object determines where GUI components go in the content pane?
1 The layout manager.
2 The layabout programmer.
3 The frame hanger.
4 The layer organizer.
Ans:1
Which of the following puts "Hello" starting at X=20 Y=50? Assume that graph holds a Graphics object reference.
1 graph.drawString( 20, 50, "Hello" );
2 drawString( "Hello", 20, 50 );
3 graph.drawString( "Hello", 20, 50 );
4 graph.println( "Hello" );
Ans:3 drawstring(String str, int x, int y)
What method call is used to draw a line from X=20, Y=30 to X=70, Y=50
1 gr.drawLine( 20, 30, 70, 50 );
2 gr.drawLine( (20, 30), (70, 50) );
3 gr.drawLine( 20, 70, 30, 50 );
4 gr.drawLine( 20, 30, 50, 70 );
Ans:1 drawLine(int x1, int y1, int x2, int y2)
What method of your applet is called by the browser when it wishes to display it on the monitor?
1 setColor()
2 setBackground()
3 drawLine()
4 paint()
Ans:4
Can the source code for your applet be compiled by the usual javac compiler?
1 Yes---if you are going to run it from the DOS prompt.
2 Yes---an applet is just another class as far as the compiler is concerned.
3 No---because applets have no main()
4 No---the web browser compiles the code.
Ans:2.
Core Java
What should be done to invoke the run() method on a thread for an object derived from the Thread class?
Select the one correct answer.
1 The start() method should be directly invoked on the Object.
2 The init() method should be directly invoked on the Object.
3 The run() method should be directly invoked on the Object.
4 The creation of the object using the new operator would create a new thread and invoke its run() method.
Ans:1
Note: The start() method invokes the run() method when the thread is ready to execute.
What is the name of the Collection interface used to represent elements in a sequence (in a particular order)?
Select the one correct answer.
1 Map
2 Set
3 List
4 Collection
Ans:3
Note: The Comparable interface imparts natural ordering to classes that implement it. It can also be used to
override natural ordering.
If the elements have a natural order, TreeSet uses the natural order.
Which of these classes implement the Collection interface SortedMap. Select the one correct answer?
1 TreeMap
2 Hashtable
3 HashMap
4 TreeSet
Ans:1
The start() method invokes the run() method when the thread is ready to execute.
1 Output of first0, first1, second0, second1
2 Compile time error
3 Output of first0, second0, first0, second1
4 Runtime error
Ans:1
Under what circumstances might you use the yield method of the Thread class?
1 To call from the currently running thread with a parameter designating which thread should be allowed to run
2 To call from the currently running thread to allow another thread of the same or higher priority to run
3 To allow a thread of higher priority to run
4 To call on a waiting thread to allow it to run
Ans:2
Note: Use the method Thread.yield() to give other runnable threads a chance to execute.
Which of the following methods are members of the Vector class and allow you to input a new element?
1 addItem
2 append
3 addElement
4 insert
Ans:3
SortedMap is a/an?
1 Class
2 Interface
3 Method
4 Abstract Class
Ans:2
Declare and construct a Vector with 20 initial slots and an increment size of 5.
1 Vector v = new Vector(20)
2 Vector v(20) = new Vector(5)
3 Vector v = new Vector(20, 5)
4 Vector[] v = new Vector(20,5)
Ans:3 Vector v = new Vector(initial size, increment);
Which of the following best describes the use of the synchronized keyword?
1 Ensures only one thread at a time may access a method or object
2 Allows two process to run in parallel but to communicate with each other
3 Ensures that two or more Threads will start and end at the same time
4 Ensures that two or more processes will start and end at the same time
Ans:1
A program uses the FileWriter constructor with the string "newFile.txt". What happens if "newFile.txt" already
exists?
1 The constructor returns null.
2 The program exits.
3 The existing file is erased and replace with a new, empty one.
4 An exception is thrown.
Ans:3
What abstract data type is the ancestor of all streams that output byte-oriented data?
1 OutputStream
2 BinaryOutputStream
3 ByteStream
4 ByteOutputStream
Ans:1
What happens when the constructor for FileInputStream fails to open a file for reading?
1 It returns null.
2 It throws a DataFormatException.
3 It throws aArrayIndexOutOfBoundsException.
4 It throws a FileNotFoundException.
Ans:4
Which of the following statements are true. Select the two correct answers.
1 The wait method defined in the Thread class, can be used to convert a thread from Running state to Waiting
state.
2 The Thread class is an abstract class.
3 The notify() and notifyAll() methods can be used to signal and move waiting threads to ready-to-run state.
4 The wait(), notify(), and notifyAll() methods must be executed in synchronized code.
Ans:3,4
Which of these classes implement the Collection interface SortedMap. Select the one correct answer?
1 Hashtable
2 HashMap
3 TreeSet
4 TreeMap
Ans:4
What is the name of the printed output of a program that shows the byte-by-byte contents of a binary file?
1 Pattern Listing
2 Binary Refuse
3 Hex Dump
4 Charmed Display
Ans:3 Hex Dump = Hexadecimal.
Line:
drawLine(int x1, int y1, int x2, int y2)
Rectangle:
drawRect(int x, int y, int width, int length)
Oval/Circle:
drawOval(int x, int y, int width, int length)
drawCircle(int x, int y, int radius, int radius)
Arc:
drawArc(int x, int y, int width, int length, int startAngle, int arctAngle)
Polygon:
drawPolygon(int x[], int y[], int n)
String (text):
drawstring(String str, int x, int y)