290W Exam 2 Solutions
Spring '99


 

Java
====

(1) When a Java applet is compiled, what is the result? (a) Java Development Kit (b) Java Virtual Machine (c) Java ByteCode (d) Machine Language (c)

(2) When javac tells you that you are using a "deprecated method", what does this mean? (a) a method that still works, but may not be available in future versions (b) a method that no longer works (c) a method that will work in a future version, but is not available yet (d) a method that does not exist (a)

(3) You are looking at a file of Java code that contains the line public class Overbyte extends Applet What should be the file name of the file you are looking at? (a) Overbyte.java (b) Overbyte.class (c) overbyte.java (d) Applet.java (a)

(4) <APPLET CODEBASE="__________" CODE="__________" WIDTH=200 HEIGHT=200> What goes in the two blanks above (in order) if the Java applet is called Spin.class and it is in a sub-directory called appls? (a) Spin, appls (b) appls, Spin.applet (c) appls, Spin (d Java, appls/Spin (c)

(5) What does ALIGN=RIGHT mean when used as an attribute for the APPLET tag? (a) all labels and text will be right-justified inside the applet (b) all buttons will appear in the applet along the right border (c) layout in the applet works from right to left (instead of left to right) (d) the same thing it means when used with the IMG tag (d)

(6) What does the following statement mean? import java.awt.*; (a) import all the classes in the java.awt package (b) import the class named java.awt.* (c) import the class named java.awt (d) do NOT import any classes from the java.awt package (a)

(7) public class Overbyte extends Applet What does "extends Applet" mean? (a) class Overbyte cannot use any Applet methods (b) class Overbyte is a specific applet and can use all Applet methods (c) Applet is a class, Overbyte is a function (d) class Overbyte should be imported from the java.applet package (b)

(8) In the Graphics method drawString (String, int, int) how are the last two parameters used? (a) as the x and y locations in the applet to begin to "draw" the string (b) as the minimum and maximum length of the string (c) as the beginning and ending character positions in the string to "draw" on the applet (d) as the sizes of type fonts to be used to "draw" the string on the applet (a)

(9) Which of the following creates a Font object that represents a plain 12-point Courier font? (a) Font standard = new Font ("Courier", Font.BOLD, 12); (b) Font standard = new Font ("Courier", PLAIN, 12); (c) Font standard = new Font ("Courier", Font.PLAIN, 12); (d) Font standard = new Font (Font.Courier, Font.PLAIN, Font.12); (c)

(10) Which of the following sets the background color of the entire applet to white? (a) setBackground (Color.white); (b) setBackground ("white"); (c) Background = "white"; (d) setColor (white); (a)

(11) Which of the following makes the text in TextField fillin appear in blue? (a) setForeground (Color.blue); (b) fillin = Color.blue; (c) fillin.setForeground ("blue"); (d) fillin.setForeground (Color.blue); (d)

(12) Which of the following is most likely to be the name of a method (function) that changes the label on a button? (a) Setlabel (b) setLabel (c) label (d) 4aNewLabel (b)

(13) Why do we say that the operator + is "overloaded"? (a) It can mean either addition or concatenation. (b) It can be used to add several items, as in x + y + z + w. (c) When two items are added, the result may be too large to fit in the desired variable. (d) It can be used to concatenate several items, as in "CS" + "290W" + "happens". (a)

(14) Suppose that visit is an integer variable currently equal to 656. What will the following label say? add(new Label("You are visitor " + (visit++))); (a) You are visitor (visit++) (b) You are visitor 656 (c) You are visitor 657 (d) You are visitor (657) (b)

(15) How will the applet look as a result of? for (x=0; x<10; x=x+1) { g.drawString("hello",25+10*x,25+15*x); } (a) The string "hello" will appear on 10 lines like stair steps. (b) The string "hello" will appear on 10 lines with each one directly beneath the one above. (c) The string "hello" will appear on the same line 10 times. (d) The string "hello" will appear only once at location 125, 175. (a)

(16) Which best describes the use of quotes in Java? (a) Single and double quotes may be used interchangeably for characters and strings. (b) Double quotes are used for characters and strings. Single quotes may NOT be used in Java. (c) Double quotes are used for characters; single quotes for strings. (d) Single quotes are used for characters; double quotes for strings. (d)

(17) Which of the following allows you to use moniker[0]... moniker[9] as Label objects? (a) Label moniker [10]; (b) Label [] moniker; (c) Label [10] moniker; (d) Label [] moniker = new Label[10]; (d)

(18) Which best describes the relationship between character arrays and Strings in Java? (a) An array of characters is NOT a String. (b) An array of characters is the SAME as a String. (c) An array of characters CANNOT be converted into a String. (d) A String CANNOT be converted into an array of characters. (a)

(19) What is... String singer = new String ("Sarah McLachlan"); ...equivalent to? (a) singer.concat("Sarah McLachlan"); (b) singer = "Sarah McLachlan"; (c) String singer = new String (); (d) String singer = "Sarah McLachlan"; (d)

(20) How would you compare the String composer to singer above to determine if composer also has the character string "Sarah McLachlan"in it? (a) composer.concat(singer) (b) composer=singer (c) composer==singer (d) composer.equals(singer) (d)

(21) String group = new String (" Goo Goo Dolls "); String fixGroup = new String (); fixGroup = group.trim(); What is fixGroup? (a) "GooGooDolls" (b) "Goo Goo Dolls" (c) "Goo Goo Dolls" (d) " Goo Goo Dolls" (c)

(22) <PARAM NAME="subject" VALUE="Pharmacy"> Which of the following stores the character string "Pharmacy" in the String object study? (a) String study = new String ("subject"); (b) String study = new String (getParameter ("subject")); (c) String study = new String (getParameter ("Pharmacy")); (d) getParameter ("subject"); (b)

(23) What is the default Layout Manager? (a) BorderLayout (b) FlowLayout (c) GridLayout (d) PanelLayout (b)

(24) How does the FlowLayout Layout Manager arrange components by default? (a) in columns top-to-bottom and left-to-right (b) in rows left-to-right and top-to-bottom (c) into corners of the applet or panel (d) into equal size rectangles (b)

(25) What are the five window sections called in BorderLayout? (a) Top, Bottom, Left, Right, Middle (b) North, South, East, West, Center (c) Up, Down, East, West, Middle (d) Panel1, Panel2, Panel3, Panel4, Panel5 (b)

(26) Which of the following signifies that you want to have a window with equal-sized rectangles of 4 rows and 3 columns? (a) setLayout(new BorderLayout(4, 3)); (b) setLayout(new RectangleLayout(4, 3)); (c) setLayout(new GridLayout(4, 3)); (d) setLayout(new PanelLayout(4, 3)); (c)

(27) In an applet you have created a button via Button stop = new Button ("quit"); In the public boolean action method, how do you check to see if this button has been clicked? (a) if (e.target=="quit") (b) if (e.target==Button) (c) if (e.target==quit) (d) if (e.target==stop) (d)

(28) Why does every if block in the public boolean action method end with the line return true; (a) to indicate that the action method has NOT handled this event (b) to indicate that the action method has handled this event (c) to indicate that the Boolean expression in the if statement really was true or you could not have gotten to this statement (d) to indicate that some other event handler must do more in order to completely handle this event (b)

(29) Which of the following is the ONLY correct statement about Layout Managers, Applets, and Panels? (a) All panels in an applet and the applet itself MUST use different Layout Managers. (b) All panels in an applet and the applet itself MUST use the same Layout Manager. (c) All panels in an applet and the applet itself MAY use different Layout Managers. (d) All panels in an applet MUST use the same Layout Manager, but the applet itself MAY use a different Layout Manager. (c)

(30) Which of the following adds the Panel neon = new Panel(); to the applet? (a) neon.add (Panel); (b) neon.add (b1); (c) add (Panel); (d) add (neon); (d)

(31) Button revise = new Button ("modify"); Which of the following gets the character string "modify" from Button revise and puts it in String harump? (a) harump.getLabel(revise); (b) harump.getLabel(); (c) harump = revise.getLabel(); (d) revise.getLabel(); (c)

(32) Button revise = new Button ("modify"); Which of the following makes the string "modify" appear in yellow letters on Button revise? (a) setForeground(Color.yellow); (b) revise.setBackground(Color.yellow); (c) revise.setForeground(Color.yellow); (d) Button revise = new Button ("yellow"); (c)

(33) Label result = new Label(); String whichDay = new String ("Monday"); Which of the following puts the string "Monday" in the Label result? (a) setText(whichDay); (b) result = "Monday"; (c) result.getText("Monday"); (d) result.setText(whichDay); (d)

(34) Which method is used for both TextArea and TextField objects to specify whether they are editable or not? (a) setText (b) setEditable (c) setChangeable (d) setBoolean (b)

(35) TextField zipCode = new TextField ("47907", 5); What does TextField zipCode look like when the applet is loaded? (a) It is a blank 5-character TextField that will return "47907" as a result of zipCode.getText() if it is not ever changed. (b) It is a TextField with the character string "47907" in it andspace for 5 more characters such as "47907-1398". (c) It is a 5-character TextField with the character string "47907" in it. (d) Trick Question: There is no 2-parameter constructor function for TextFields! (c)

(36) Checkbox burger = new Checkbox ("cheeseburger", food, false); Checkbox fries = new Checkbox ("french fries", food, false); Checkbox shake = new Checkbox ("chocolate shake", food, false); What does the second parameter (food) in all the statements above mean? (a) All three are Checkboxes. (b) All three Checkboxes are part of the same CheckboxGroup. (c) All three Checkboxes will have the same label -- food. (d) All three Checkboxes can be checked simultaneously. (b)

(37) Which method can be used with Choice or List objects to return the index number of the selected item? (a) getSelectedIndex (b) getItem (c) getNumber (d) select (a)

(38) Which of the following creates a new Color object with RGB 135,206, 250? (a) Color skyBlue = new Color (135, 206, 250); (b) Color skyBlue = new Color (135.206.250); (c) Color skyBlue = (135, 206, 250); (d) new Color (Color.skyBlue); (a)

(39) Which of the following is true if ANY button is clicked? (a) (e.target == bestBuy) (b) (e.target == Button) (c) (e.target instanceOf Button) (d) (e.target isAny Button) (c)

(40) What event is detected when the mouse moves into the applet window? (a) Event.MOUSE_ENTER (b) Event.MOUSE_MOVE (c) Event.MOUSE_DOWN (d) Event.MOUSE_ARRIVE (a)

(41) Which of the following will place an image named motor on the applet with the upper left corner of the image at location x,y? (a) motor = g.drawImage (x, y); (b) motor.drawImage (x, y, this); (c) g.drawImage (motor, x, y, this); (d) g.paintImage (motor, x, y, this); (c)

(42) Which of the following will draw a square from 5,5 to 25,25? (a) g.drawSquare (5,5,20); (b) g.drawSquare (5,5,25,25); (c) g.drawRect (5,5,25,25); (d) g.drawRect (5,5,20,20); (d)

(43) For any "fill" method (like fillRect, fillRoundRect, fillOval), what method determines the "fill" color? (a) setFill (b) setColor (c) setForeground (d) setBackground (b)

(44) What method can be used to draw an octagon (8-sided figure)? (a) drawRect (b) drawOctagon (c) drawPolygon (d) drawSides (c)

(45) What class does Java have to support concurrency? (a) Task (b) Thread (c) Concur (d) Multi (b)

(46) What method is used to pause a thread momentarily? (a) stop (b) pause (c) suspend (d) resume (c)

(47) Which of the following will cause a thread to do nothing at all for 5 seconds? (a) rest(5); (b) suspend(5000); (c) sleep(5); (d) sleep(5000); (d)

(48) Which of the following says that class ClockTime is a subclass of the Thread class? (a) class ClockTime extends Applet (b) class ClockTime extends Thread (c) class Thread extends ClockTime (d) subclass ClockTime (b)

(49) Which of the following creates an object of class ClockTime and puts it into execution? (a) start ClockTime watch; (b) watch.start(); (c) ClockTime watch; (d) ClockTime watch; watch.start(); (d)

(50) Which of the following is the ONLY correct statement about multiple threads? (a) All threads may be suspended and resumed independently. (b) All threads must be suspended simultaneously. (c) All threads must be resumed simultaneously. (d) Trick Question: Multiple threads are NOT allowed in a Java program! (a)


Any questions or comments please send mail to Becky Koutsis. Last updated on April 1, 1999
Back to the exams page.
Return to homepage of CS 290W -
Advanced World-Wide Web