(1) CS 290W -- EXAM II

CS290w EXAM II
Saturday, December 19, 1998



(1) Why is the statement
import java.lang.*
not necessary in a Java program?

(a) Because java.lang.* is completely contained in java.awt.*
(b) Java goes and gets the appropriate packages depending upon the objects and methods you use
(c) Because this package is automatically imported into every Java program
(d) Trick Question: import java.lang.* must appear if you want to use something from that package
(c)

(2) Suppose that press is a Button and mutate is a String that is currently "Press here for more details". Which statement below will put that label on the press Button?

(a) setLabel(mutate);
(b) press.setLabel();
(c) mutate.setLabel(press);
(d) press.setLabel(mutate);
(d)

(3) String whatsit = new String();
TextArea reason =
new TextArea ("Why are you asking for this information?",10,30);
reason.setText("Please be honest");
whatsit = reason.getText();
After these lines of Java, what is in whatsit?

(a) "Please be honest"
(b) "Why are you asking for this information?"
(c) 10
(d) "Why are yo"
(a)

(4) Which of the following puts into the integer variable amount the
integer represented by the character string keyedin?

(a) amount = Integer.parseInt(keyedin);
(b) amount = keyedin;
(c) keyedin = Integer.parseInt(amount);
(d) Integer.parseInt(keyedin);
(a)

(5) What does the setEditable method for TextArea and TextField objects do?

(a) specifies whether creators of the applet (that is, you) can change the displayed text
(b) specifies what portion of the TextArea or TextField can be edited
(c) specifies whether the information is to be displayed in a TextArea/TextField or in a Label
(d) specifies whether users of the applet can change the displayed text
(d)

(6) How do you create something exactly like a set of Radio buttons in a Java applet?

(a) use a CheckboxGroup object
(b) use several Checkbox objects that have all been constructed using new Checkbox("....",null,false)
(c) use a Radio object
(d) use a Choice object
(a)

(7) Choice breakfast = new Choice();
Which of the following adds "Bacon and Eggs" as a choice?

(a) Choice breakfast = new Choice("Bacon and Eggs");
(b) addItem("Bacon and Eggs");
(c) breakfast = "Bacon and Eggs";
(d) breakfast.addItem("Bacon and Eggs");
(d)

(8) For both a Choice object and a List object, what does the getSelectedItem method tell you?

(a) the character string for the selected item
(b) the index number for the selected item
(c) the character string for any item (based on the parameter)
(d) the index number for any item (based on the parameter)
(a)

(9) TextField inside...;
TextField outside...;
...
inside.setBackground(outside.getBackground());
What does the statement above do?

(a) changes the background color of TextField inside to be the same as the background color of TextField outside
(b) changes the background color of TextField outside to be the same as the background color of TextField inside
(c) changes the background colors of both TextField inside and TextField outside
(d) gets an error message during compilation snce the setBackground method must have a parameter which is a Color
(a)

(10) Suppose that you want to search in three different data files (F1,F2, F3) for a particular item. How can you do that using concurrency?

(a) Start thread t1 and let it search F1. If the item is not found,then start thread t2 and let it search F2. If the item is not found, then start thread t3 and let it search F3.
(b) Simultaneously start three different threads (t1, t2, t3) each searching in one of the files.
(c) Randomly search one of the files F1, F2, F3. If the item is not found, then again randomly search one of the files F1, F2, F3, etc. until the item is found.
(d) Start a Thread thrd that searches F1, then searches F2, and then searches F3, but which stops when it finds the item.
(b)

(11) What Java class is used to support concurrency?

(a) Thread
(b) Concur
(c) Task
(d) Runnable
(a)

(12) Suppose that a class contains the line
Thread account;
Which of the following statements appearing in the applet's start()
method connects the thread to the applet?

(a) Thread = new Thread(this);
(b) account = new Thread(this);
(c) Thread account;
(d) account = new Thread(Applet);
(b)

(13) Which of the following statements best describes Java's URL class.

(a) A character string may be used in a URL constructor to make a URL object.
(b) A URL object is just a character string.
(c) A URL object can only be created by visiting a Web page and then placing the URL of that Web page in the URL object via the getDocumentBase() method.
(d) Trick Question: Java has no URL class!

(a)

(14) What is "exception handling"?

(a) When an improper situation (like division by zero) occurs, it can only be handled by Java's built-in runtime facilities.
(b) The Thread account receives the command account.stop().
(c) The writer of the Java program includes the action(Event,Object)method.
(d) The writer of the Java program decides what to do in improper situations (like division by zero).
(d)

(15) How is exception handling done in Java?

(a) do {something} catch (exception)
(b) while (boolean expression) {statements} catch (exception)
(c) try {something} catch (exception)
(d) try {something} handle (exception)
(c)

(16) Why would you use
while (true)
in a Java method?
(a) to set up a loop that will run as long as the variable true is not zero
(b) to set up a loop that will "never" run
(c) to set up a loop that will run "forever"
(d) Trick Question: This is illegal in Java.
(c)

(17) Why is the repaint() method useful?
(a) It simply calls paint().
(b) It erases anything previously painted and then calls paint().
(c) It erases anything previously painted and leaves the applet blank.
(d) It shifts the x,y coordinates by one and then calls paint() leading to a thicker line.
(b)

(18) Which of the following puts a thread to sleep for a minute?

(a) Thread.toSleep() = 1;
(b) Thread.sleep(60000);
(c) toSleep(60);
(d) sleep(1);
(b)

(19) Which best describes multiple threads?

(a) Multiple threads may each be doing different things.
(b) Multiple threads must all have the same run() code, so they must do exactly the same thing.
(c) All threads must be stopped simultaneously.
(d) All threads must sleep simultaneously.
(a)

(20) Button up = new Button ("up");
Button down = new Button ("down");
Button left = new Button ("left");
Button right = new Button ("right");
Which of the following will be true if any of the four buttons above are clicked?

(a) if (event.target == Button)
(b) if (event.target instanceof Button)
(c) if (event.target instanceof up, down, left, right)
(d) if (event.target == up, down, left, right)
(b)

(21) There are four buttons on an applet. But, the action method only tells what to do if one of the first three are clicked. What will happen if the fourth button is clicked?
(a) nothing
(b) error message in the status line
(c) one of the other buttons' code in the action method will be used
(d) This cannot happen. Java requires that there be code in the action method for all buttons in the applet.
(a)

(22) What does the following handleEvent statement monitor??
if (event.id == Event.MOUSE_UP)

(a) if the mouse button has been pressed
(b) if the mouse has been lifted off the mouse pad
(c) if the mouse has been moved out of the applet
(d) if the mouse button has been released
(d)

(23) A Web page with an applet has the URL http://www.xircon.com/fantasy.html. What URLs will result from running the two methods getDocumentBase() andgetCodeBase() respectively?

(a) http://www.xircon.com, http://www.xircon.com/fantasy.html
(b) http://www.xircon.com/fantasy.html, http://www.xircon.com
(c) http://www.xircon.com, fantasy.html
(d) fantasy.html, http://www.xircon.com
(b)

(24) Java has a Graphics method draw3DRect() for drawing 3-dimensional rectangles. What is the Graphics method that both draws and "fills in" 3-dimensional rectangles?

(a) fill3DRect()
(b) draw3DRect(fill)
(c) 3DRect()
(d) drawAndFill3DRect()
(a)

(25) What Java Graphics method is used to draw a circle?

(a) drawCircle()
(b) drawOval()
(c) circle()
(d) drawRound()
(b)

(26) In Java __________ generally begin with an uppercase letter;__________ generally begin with a lowercase letter.
(a) objects; classes
(b) classes; variables, objects, and methods
(c) objects; variables
(d) classes, objects, and methods; variables
(b)

(27) int x=5;
y=4*(x++);
What value do x and y now have?

(a) 6, 24
(b) 5, 20
(c) 6, 20
(d) 5, 24
(c)

(28) If a continue statement is reached in a loop, what does this mean to do?

(a) Terminate this loop.
(b) Go ahead and execute the rest of the loop this time, but then terminate the loop.
(c) Skip the rest of the loop this time, but go through the loop again if conditions are met for proceeding.
(d) Terminate this program.
(c)
Perl
====

(29) Which best describes Perl?

(a) Perl is compiled into byte code.
(b) Perl is compiled into machine language.
(c) Perl programs can only be run by Web servers.
(d) Perl is interpreted at run time.
(d)

(30) Why are Perl programs generally run as applications, not applets?

(a) because Perl scripts are interpreted.
(b) because Web browsers don't have Perl interpreters.
(c) because Perl scripts must be compiled before they can be used.
(d) Trick Question: Perl programs are generally run as applets, not applications!
(b)

(31) Which of the following files is most likely a Perl script that is NOT a cgi application?

(a) findauthor.notcgi
(b) findauthor.perl
(c) findauthor.class
(d) findauthor.pl
(d)

(32) Which of the following is the most important file permission for the Perl script described in the previous question?

(a) readable by the user
(b) world-readable
(c) executable by the user
(d) writeable by the user
(c)

(33) What does the line #!/usr/local/bin/perl at the top of a Perl program do?

(a) nothing, it is just a comment
(b) just tells the operating system that this is a Perl script
(c) tells the operating system that the Perl interpreter is in directory /usr/local/bin
(d) tells the operating system to get any special files (like cgi-lib.pl) from directory /usr/local/bin/perl
(c)

(34) Which best characterizes the main function in Perl?

(a) It must be the first function in the Perl program.
(b) There is no main function required.
(c) It must be the last function in the Perl program.
(d) It must be named start().
(b)

(35) Which of the following would tell you that a Perl variable is a character string?

(a) $sAnimorph
(b) string Animorph
(c) char Animorph[50]
(d) $Animorph
(a)

(36) Which of the following concatenates two strings in Perl?

(a) $sBase+$sAssignment
(b) $sBase,$sAssignment
(c) $sBase.$sAssignment
(d) $sBase cat $sAssignment
(c)

(37) $sReason = "My dog ate it";
chop($sReason);
What will now be in $sReason?

(a) "Mydogateit"
(b) "My dog ate i"
(c) "My dog ate"
(d) "dog ate it"
(b)

(38) Which of the following correctly checks to see if $sBase and $sAssignment are the same character string?

(a) if ($sBase == $sAssignment)
(b) if ($sBase eq $sAssignment)
(c) if ($sBase = $sAssignment)
(d) if ($sBase equiv $sAssignment)
(b)

(39) Which of the following correctly sets $iFlag to 0 if there are less than 100 students, to 1 if there are 100 or more but less than 500, and does not change $iFlag otherwise?

(a) if ($iNum < 100) {$iFlag=0;}
elsif ($iNum < 500) {$iFlag=1;}
(b) if ($iNum < 100) {$iFlag=0;}
else {$iFlag=1;}
(c) if ($iNum < 100) {$iFlag=0;}
elsif ($iNum >= 100) {$iFlag=1;}
(d) if ($iNum < 100) {$iFlag=0;}
elsif ($iNum < 500) {$iFlag=1;}
else {$iFlag=2;}
(a)

(40) Which of the following is equivalent to...?
if ($fSpeed > 62.5)
(a) unless ($fSpeed < 62.5)
(b) unless ($fSpeed <= 62.5)
(c) if ($fSpeed <= 62.5)
(d) unless ($fSpeed > 62.5)
(b)

(41) $sButter = "Land-o-Lakes";
print "My favorite butter is $sButter. Do you like it? \n";
What will be printed?
(a) My favorite butter is Land-o-Lakes. Do you like it?
(b) My favorite butter is $sButter. Do you like it?
(c) My favorite butter is Land-o-Lakes.
(d) My favorite butter is
(a)

(42) @aiWidth = (200, 255, 146, 307, 199, 312);
Which of the following prints the single number 146?
(a) print "@aiWidth[2] \n";
(b) print "@aiWidth \n";
(c) print "$aiWidth \n";
(d) print "$aiWidth[2] \n";
(d)

(43) @aiWidth = (200, 255, 146, 307, 199, 312);
$iBunch = @aiWidth;
What is $iBunch?
(a) 5
(b) 6
(c) (200, 255, 146, 307, 199, 312)
(d) 200
(b)

(44) @aiWidth = (200, 255, 146, 307, 199, 312);
$iFinal = $#aiWidth;
What is $iFinal?
(a) 5
(b) 6
(c) (200, 255, 146, 307, 199, 312)
(d) 200
(a)

(45) @aiWidth = (200, 255, 146, 307, 199, 312);
$#aiWidth = 3;
What is @aiWidth?
(a) 5
(b) 6
(c) (200, 255, 146)
(d) (200, 255, 146, 307);
(d)

(46) @aiWidth = (200, 255, 146, 307, 199, 312);
Which of the following loops uses each of the @aiWidth values in
consecutive order?
(a) foreach @aiWidth ($iWide) {...}
(b) for $iWide (@aiWidth) {...}
(c) useach $iWide (@aiWidth) {...}
(d) foreach $iWide (@aiWidth) {...}
(d)

(47) What keyword declares a function in Perl?
(a) func
(b) sub
(c) subrtn
(d) &
(b)

(48) How can a value be returned from a Perl function?
(a) Put the value on the last line of the function followed by a
semi-colon
(b) return (value);
(c) Both (a) and (b)
(d) Put it into $_[0]
(c)

(49) &fPrime (48);
The Prime function computes all prime factors of the input parameter.
Which of the following statements in the Prime function loads the
input parameter into $iNumber?
(a) $iNumber = $_[0];
(b) $iNumber = $_[1];
(c) load ($iNumber);
(d) $_[0] = $iNumber;
(a)

(50) What does Perl's index (string, string) function do?
(a) Copies part of a string to another string by specifying beginning
position and length.
(b) Copies parts of a string into an array of strings.
(c) Copies the end of a string to another string by specifying
beginning position.
(d) Finds an occurence of one string within another.
(d)

(51) What does Perl's substr (string, int, int) function do?
(a) Copies part of a string to another string by specifying beginning
position and length.
(b) Copies parts of a string into an array of strings.
(c) Copies the end of a string to another string by specifying
beginning position.
(d) Finds an occurence of one string within another.
(a)

(52) What does Perl's substr (string, int) function do?
(a) Copies part of a string to another string by specifying beginning
position and length.
(b) Copies parts of a string into an array of strings.
(c) Copies the end of a string to another string by specifying
beginning position.
(d) Finds an occurence of one string within another.
(c)

(53) What does Perl's split (regexp, string) function do?
(a) Copies part of a string to another string by specifying beginning position and length.
(b) Copies parts of a string into an array of strings.
(c) Copies the end of a string to another string by specifying beginning position.
(d) Finds an occurence of one string within another.
(b)

(54) What will the statement
tr/0-3/r-u/;
do to the character string in $_?
(a) Change all occurences of 0 to r, and 3 to u
(b) Change all occurences of r, s, t, u to 0-3
(c) Change all occurences of 0 to r, 1 to s, 2 to t, and 3 to u
(d) Change all occurences of r to 0, s to 1, t to 2, and u to 3
(c)

(55) What will the statement
tr/0-9//d;
do to the character string in $_?
(a) Change all occurences of 0-9 to d
(b) Count the number of digits 0-9, but leave the string unchanged
(c) Change all occurences of 0-9 to a blank character
(d) Delete all digits 0-9
(d)

(56) $sEmailAddress = "elton\@biology.purdue.edu";
Which of the following will evaluate to true?
(a) if ($sEmailAddress =~ /BIO/)
(b) if ($sEmailAddress =~ /biological/)
(c) if ($sEmailAddress == /BIO/)
(d) if ($sEmailAddress =~ /BIO/i)
(d)

(57) Which of the following opens a file for writing so that any previous information in the file is over-written?
(a) open (SRCHFOR, "srchterms.txt");
(b) open (SRCHFOR, "<srchterms.txt");
(c) open (SRCHFOR, ">srchterms.txt");
(d) open (SRCHFOR, ">>srchterms.txt");
(c)

(58) Which of the following writes information into the file in the previous question?
(a) print SRCHFOR "$sSrchtext $iEndtag \n");
(b) print "$sSrchtext $iEndtag \n");
(c) print srchterms.txt "$sSrchtext $iEndtag \n");
(d) print ">srchterms.txt $sSrchtext $iEndtag \n");
(a)

(59) Which best characterizes a Perl script that is to be used as a
Web cgi application in your career account?
(a) Must be in a cgi-bin directory.
(b) Must have the suffix .pl.
(c) Must have the suffix .cgi.
(d) Must be in a cgi-bin directory and have the suffix .cgi.
(c)

(60) Which file permission is best for a data file that is to be both
read and written by a cgi application?
(a) Readable but not executable (rwxr--r--)
(b) Executable but not readable (rwx--x--x)
(c) Readable and executable (rwxr-xr-x)
(d) Readable and writeable (rwxrw-rw-)
(d)

(61) What does the environmental variable HTTP_REFERER usually report?
(a) the URL of the cgi script
(b) the browser the user is using
(c) the last page visited by the browser
(d) the IP address operating system the remote machine making the request
(c)

(62)%asExec = ("pr", "William Clinton", "vp", "Albert Gore",
"ag", "Janet Reno");
Which of the following references the string "Albert Gore"?
(a) $asExec{vp}
(b) $asExec[vp]
(c) $asExec[1]
(d) $asExec(vp)
(a)

(63) If METHOD=POST is used in the FORM tag, how is data sent to the Perl cgi program?
(a) in the environmental variable QUERY_STRING
(b) in a file with the handle POST
(c) in a file with the handle FORM
(d) in standard input <STDIN>
(d)

(64) What character is sent in place of a blank in data gathered from a FORM?
(a) &
(b) +
(c) %
(d) /
(b)

(65) Suppose that you have available the parsing program cgi-lib.pl.
What function must you call in order to access FORM data?
(a) cgi-lib
(b) $in
(c) ReadParse
(d) Oraperl
(c)

(66) Suppose that you have available the parsing program cgi-lib.pl.
How do you access the string in the TEXT field named reason?
(a) $in{'TEXT'}
(b) $in{'string'}
(c) $in{'FORM.reason'}
(d) $in{'reason'}
(d)

(67) In a Perl cgi script that contains <INPUT TYPE=RADIO ... > which attribute is returned for the radio button that is selected?
(a) NAME
(b) SELECTED
(c) CGI
(d) VALUE
(d)

(68) Suppose that a FORM contains
<SELECT NAME=meat SIZE=1>
<OPTION>Fish</OPTION>
<OPTION>Poultry</OPTION>
<OPTION>Beef</OPTION>
<OPTION>Pork</OPTION>
</SELECT>
Further suppose that the item "Beef" is selected. What string will the Perl cgi script receive?
(a) "2"
(b) "3"
(c) "meatBeef"
(d) "Beef"
(d)

(69) Which of the following tells Oraperl the location of the Oracle client software?
(a) ORACLE_HOME = "/opt/oracle/product/8.0.4";
(b) use Oraperl;
(c) $ENV{"ORACLE_HOME"} = "/opt/oracle/product/8.0.4";
(d) use Oraperl at /opt/oracle/product/8.0.4;
(c)

(70) Which two Oracle functions RETURN handles that are used by other Oracle functions in order to retrieve data from a database?
(a) ora_login, ora_fetch
(b) ora_open, ora_fetch
(c) ora_login, ora_open
(d) ora_open, ora_close
(c)

(71) In which Oracle function do you include the SQL SELECT statement
to specify which data you want to retrieve?
(a) ora_fetch
(b) ora_select
(c) ora_open
(d) ora_sql
(c)

(72) Which Oracle function returns data from the table a row at a time?
(a) ora_return
(b) ora_open
(c) ora_fetch
(d) ora_retrieve
(c)

(73) What SQL statement will return all data items for voters who live in zip code 47906?
(a) SELECT * FROM voters WHERE zip = 47906
(b) SELECT name, address, voter_number FROM voters WHERE zip = 47906
(c) SELECT * FROM voters
(d) SELECT zip FROM voters WHERE zip = 47906
(a)

(74) What SQL statement will return all data items for voters born between 1970 and 1980?
(a) SELECT * FROM voters WHERE birthyear <= 1980
(b) SELECT * FROM voters WHERE birthyear >= 1970 AND birthyear <= 1980
(c) SELECT * FROM voters WHERE birthyear >= 1970
(d) SELECT birthyear FROM voters
(b)

(75) What SQL statement will return all data items for voters who live on any street with "Cherry" in the street name (like Cherry Lane, Cherry Hill Road, Red Cherry Drive)?
(a) SELECT * FROM voters WHERE street = 'Cherry'
(b) SELECT * FROM voters WHERE street LIKE '%Cherry%'
(c) SELECT * FROM voters WHERE street LIKE 'Cherry'
(d) SELECT * FROM voters WHERE street CONTAINS 'Cherry'
(b)

 

 

 


Back to the exams page.
Return to homepage of CS 290W -
Advanced World-Wide Web