0% found this document useful (0 votes)
905 views11 pages

MCQ Exam (TCLD)

The three main parts of a GUI program are GUI components, event listeners, and application code. The Graphics object represents the area that an applet or component can draw on. Common GUI components include frames, buttons, text fields, etc. Events like mouse clicks or button presses generate events that can be handled by listener methods. The layout manager determines where components are placed in a container like a frame.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
905 views11 pages

MCQ Exam (TCLD)

The three main parts of a GUI program are GUI components, event listeners, and application code. The Graphics object represents the area that an applet or component can draw on. Common GUI components include frames, buttons, text fields, etc. Events like mouse clicks or button presses generate events that can be handled by listener methods. The layout manager determines where components are placed in a container like a frame.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

What is a Graphics object?

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

What method must a button listener implement?


1 actionMethod().
2 buttonAction().
3 eventAction().
4 actionPerformed().
Ans:4.

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.

What method changes the color of a content pane?


1 setBackground()
2 setBackgroundColor()
3 setForegroundColor()
4 setColor()
Ans:1

How should a command string be compared with a literal string?


1 equals()
2=
3 equalsIgnoreCase()
4 ==
Ans:1

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

The three software parts of a GUI program are:


1 Windows, Buttons, Mice
2 Frames, Code, Events
3 GUI Components, Event Listeners, Application Code
4 GUI Components, Graphics, Code
Ans:3

When is the paint() method of a frame object called?


1 The Java system calls it once when the program starts.
2 The main() method calls it once when the program starts.
3 The user calls it to display the frame.
4 The Java system calls it every time it decides to display the frame.
Ans:4.

From what immediate base class is JTextField derived?


1 JText
2 JComponent
3 JTextComponent
4 JField
Ans:3

When the user clicks on a button, what is generated?


1 A Button object.
2 A Container
3 An Event.
4 A Listener.
Ans:3

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 are correct event handling methods?


1 MousePressed(MouseClick e){}
2 mousePressed(MouseEvent e){}
3 functionKey(KeyPress k){}
4 componentAdded(ContainerEvent e){}
Ans:2,4

The size of a frame on the screen is measured in:


1 nits
2 dots
3 inches
4 pixels
Ans:4

What is the name for a method that responds to events?


1 An application method.
2 A snoop method.
3 A container method.
4 A listener method.
Ans:4

The fundamental classes for GUI programming are contained in the:


1 Java Enhancement Toolkit
2 Abstract Windowing Toolkit
3 Graphics Event Toolkit
4 GUI toolkit
Ans:2
Which of the following statements are true?
1 The collection interface contains a method called enumerator
2 The iterator method returns an instance of the Vector class
3 The Set interface is designed for unique elements
4 At the root of the collection hierarchy is a class called Collection
Ans:3

How do you indicate where a component will be positioned using Flowlayout?


1 North, South,East,West
2 Assign a row/column grid reference
3 Do nothing; the FlowLayout will position the component
4 Pass a X/Y percentage parameter to the add method
Ans:3

Why does an applet have no main() method?


1 The paint() method is like the main method for an applet.
2 The browser acts as the main. The applet provides methods for the browser.
3 Programs that do graphics don't need a main.
4 Only simple programs need a main.
Ans:2

What is the role of the Graphics object?


1 It contains a list of commands from the browser to your applet.
2 It can be omitted, but is sometimes used for file i/o.
3 It represents the area the applet can draw in and provides drawing methods.
4 It represents the entire screen of the computer monitor.
Ans:3

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)

Which of the following draws a circle with a radius of 50 at X=10, Y=20?


1 graph.drawCircle( 50, 50, 10, 20 );
2 graph.drawCircle( 50 );
3 graph.drawOval( 50, 50 );
4 graph.drawOval( 10, 20, 50, 50 ); (X-axes, Y-axes, radius, radius)
Ans:4

What must be imported to get class Applet


1 java.awt.*
2 java.java
3 java.applet.Applet
4 java.util
Ans:3

What must be imported to get most graphics components?


1 java.*
2 java.util.*
3 java.Graphics
4 java.awt.*
Ans:4

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.

Can two or more applets appear on the same web page?


1 No, applets can't appear on web pages.
2 Yes, but there must be <applet> and </applet> for each one.
3 Yes, put them all between <applet> and </applet>
4 No, only one per page.
Ans:2

The syntax of drawstring() method is…………….


1 void drawstring(String x,int x)
2 void drawstring(String s)
3 void drawstring(intx,inty,string s)
4 void drawstring(String s,intx,int y)
Ans:4

The syntax of paint()method is…………….


1 public void paint(Graphics g)
2 public void paint(String s)
3 public void paint(Graphics g,String s)
4 public void paint()
Ans:1.

The constructor for Font class is…………….


1 Font(String name,int style)
2 Font(String name, int style, int size)
3 Font(String name)
4 Font(String name,int size)
Ans:2 Font myFont = new Font(“Serif”, Font.ITALIC, 12);

To display text in the applet status bar………method is used.


1 showStatus()
2 drawStatusBar()
3 drawStatus()
4 showStatusBar()
Ans:1

Which of the following is an optional attribute of applet tag?


1 Code
2 Name
3 Height
4 Width
Ans:2

Which method is called first by an applet?


1 run()
2 init()
3 paint()
4 start()
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 default priority of a newly created thread?


1 MAX_PRIORITY (which is defined as 10 in the Thread class.)
2 A thread inherits the priority of its parent thread.
3 NORM_PRIORITY (which is defined as 5 in the Thread class.)
4 MIN_PRIORITY (which is defined as 1 in the Thread class.)
Ans:2
Thread.MIN_PRIORITY = 1
Thread.NORM_PRIORITY = 5
Thread.MAX_PRIORITY = 10

The class Hashtable is used to implement which collection interface.


Select the one correct answer:
1 SortedSet
2 List
3 Map
4 Set
Ans:3

Which of the following statements are true?


Select the two correct answers:
1 The notify() and notifyAll() methods can be used to signal and move waiting threads to ready-to-run state.
2 The wait(), notify(), and notifyAll() methods must be executed in synchronized code.
3 The Thread class is an abstract class.
4 The wait method defined in the Thread class, can be used to convert a thread from Running state to Waiting
state.
Ans:1,2

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

Which most closely matches a description of a Java Map?


1 A class for containing unique array elements
2 A vector of arrays for a 2D geographic representation
3 A class for containing unique vector elements
4 An interface that ensures that implementing classes cannot contain duplicate keys
Ans:4
Note: Because Set and Map both are not allow duplicate values.

How does the set collection deal with duplicate elements?


1 Duplicate values will cause an error at compile time
2 An exception is thrown if you attempt to add an element with a duplicate value
3 The add method returns false if you attempt to add an element with a duplicate value
4 A set may contain elements that return duplicate values from a call to the equals method
Ans:3

What can cause a thread to stop executing?


1 A call to the thread's stop method.
2 Another thread is given a higher priority
3 The program exits via a call to System.exit(0);
4 A call to the halt method of the Thread class?
Ans:1,2,3

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 are methods of the Thread class?


1 go()
2 stop()
3 yield()
4 sleep(long msec)
Ans:4,2,3

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

Which of the following are methods of the Collection interface?


1 isEmpty
2 iterator
3 setText
4 toArray
Ans:1,2, 4
Note: add(), remove(), size(), isEmpty(), contains(), iterator().

SortedMap is a/an?
1 Class
2 Interface
3 Method
4 Abstract Class
Ans:2

How can you prevent a member variable from becoming serialized?


1 You cannot.
2 By marking it transient
3 By marking it volatile
4 By marking it private
Ans:2

What can cause a thread to become non-runnable?


1 Calling the notifyAll method on an object.
2 Calling the notify method on an object.
3 Exiting from a synchronized block
4 Calling the wait method on an object.
Ans:4

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);

A Vector object acts like:


1 An array of primitive values.
2 An array of primitive values or of object references.
3 An array of references to objects of a particlar class.
4 An array of references to objects of class Object.
Ans:4

Which of the following opens the file "myData.stuff" for Input?


1 FileInputStreamfis = new FileInputStream( new BufferedInputStream( "myData.stuff") )
2 FileInputStreamfis = new FileInputStream( "myData.stuff", true)
3 FileInputStreamfis = new FileInputStream( "myData.stuff")
4 DataInputStream dis = new DataInputStream( "myData.stuff" )
Ans:2
Note:
FileInputStream infile = new FileInputStream("myfile.dat");
FileOutputStream outfile = new FileOutputStream("results.dat");

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

What package holds the File class?


1 java.file
2 java.io
3 java.lang
4 java.util
Ans:2

What method of File is used to test if a file or directory exists?


1 list()
2 isFile()
3 exists()
4 isDirectory()
Ans:3
Note: java.io.File.exists()

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 File method creates a new disk directory?


1 dir()
2 mkdir()
3 list()
4 makeDirectory()
Ans:2

In the following, what is the directory separator character?


C:\MyFiles\Programs\Examples\someFile.txt
1.
2:
3\
4/
Ans:3

How many bits per character does a Java program use?


1 16
24
3 32
48
Ans:1

What does the flush() method of a stream do?


1 It ensures that all pending output operations are completed.
2 It erases all the data in the file.
3 It summons the garbage collector.
4 It initializes the output methods.
Ans:1

What data type does readLine() return?


1 String
2 int
3 char
4 byte[]
Ans:1

What class does readLine() belong to?


1 InputStreamReader
2 BufferedReader
3 FileReader
4 Reader
Ans:2

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 is the DataInputStream method that reads an int value?


1 ReadInt( )
2 readInt()
3 read()
4 ReadInteger()
Ans:2

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

How does the set collection deal with duplicate elements?


1 A set may contain elements that return duplicate values from a call to the equals method
2 The add method returns false if you attempt to add an element with a duplicate value
3 Duplicate values will cause an error at compile time
4 An exception is thrown if you attempt to add an element with a duplicate value
Ans:2

What can cause a thread to stop executing?


1 Another thread is given a higher priority
2 A call to the thread's stop method.
3 A call to the halt method of the Thread class?
4 The program exits via a call to System.exit(0);
Ans:1,2,4

Which of the following are methods of the Thread class?


1 sleep(long msec)
2 yield()
3 stop()
4 go()
Ans:1,2,3

Which of the following are methods of the Collection interface?


1 setText
2 iterator
3 toArray
4 isEmpty
Ans:2,3,4
Note: add(), remove(), size(), isEmpty(), contains(), iterator(). We found toArray() method from google search.
How can you prevent a member variable from becoming serialized?
1 By marking it volatile
2 By marking it private
3 By marking it transient
4 You can not.
Ans:3

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.

Basic graphing methods:

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)

You might also like