Final Exam - Introduction to Computer Science: Java B | CSE 8B, Exams of Computer Science

Material Type: Exam; Class: Intro/Computer Science: Java B; Subject: Computer Science & Engineering; University: University of California - San Diego; Term: Winter 2004;

Typology: Exams

Pre 2010

Uploaded on 03/28/2010

koofers-user-l5b
koofers-user-l5b 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Page 1 (43) _____________ CSE 8B Name ________________________
Page 2 (37) _____________ Final
Page 3 (28) _____________ cs8f ________
Page 4 (26) _____________ Winter 2004
Std. I/II I (24) _____________ Signature _________________________
Total (158) _____________ [Total points = 150 + 8 points built-in Extra Credit] Student ID _____________________
This test is to be taken by yourself with closed books, closed notes, no calculators, your own cheat sheet.
1) What gets printed if the program is run with the following command? Be sure to include the "—NEXT—" line. (25 pts)
java F1 123456 STOP
public class F1 {
public static void main( String[] args ) {
F1 ref = new F1();
for ( int i = 0; i < args.length; ++i ) {
System.out.println( args[i] );
ref.recurse( new StringBuffer(args[i]), 0, args[i].length() -1 );
System.out.println( "--NEXT--" );
}
}
public void recurse( StringBuffer a, int b, int c ) {
if ( b < c )
{
recurse( a, b+1, c-1 );
char tmp = a.charAt( b );
a.setCharAt( b, a.charAt( c ) );
a.setCharAt( c, tmp );
System.out.println( a );
}
}
}
2) Write a public static method named avgGTorEqToX () that returns a double and takes 2 parameters named nums of type int[]
and x of type int that determines average of the values in nums array that are greater than or equal to the second parameter x. (18 pts)
For example, given the following declarations: int[] a = { 25, 10, 5, 27, 15, 33, 35, 22, 55, 48 };
int n = 22;
Calling Foo.avgGTorEqToX( a, n ); would return the value 35.0
public class Foo {
}
pf3
pf4
pf5

Partial preview of the text

Download Final Exam - Introduction to Computer Science: Java B | CSE 8B and more Exams Computer Science in PDF only on Docsity!

Page 1 (43) _____________ CSE 8B Name ________________________

Page 2 (37) _____________ Final

Page 3 (28) _____________ cs8f ________

Page 4 (26) _____________ Winter 2004

Std. I/II I (24) _____________ Signature _________________________

Total (158) _____________ [Total points = 150 + 8 points built-in Extra Credit] Student ID _____________________

This test is to be taken by yourself with closed books, closed notes, no calculators, your own cheat sheet.

1) What gets printed if the program is run with the following command? Be sure to include the "—NEXT—" line. (25 pts) java F1 123456 STOP

public class F1 { public static void main( String[] args ) { F1 ref = new F1();

for ( int i = 0; i < args.length; ++i ) { System.out.println( args[i] ); ref.recurse( new StringBuffer(args[i]), 0, args[i].length() -1 ); System.out.println( "--NEXT--" ); } }

public void recurse( StringBuffer a, int b, int c ) {

if ( b < c ) { recurse( a, b+1, c-1 );

char tmp = a.charAt( b ); a.setCharAt( b, a.charAt( c ) ); a.setCharAt( c, tmp );

System.out.println( a ); } } }

2) Write a public static method named avgGTorEqToX () that returns a double and takes 2 parameters named nums of type int[] and x of type int that determines average of the values in nums array that are greater than or equal to the second parameter x. (18 pts)

For example, given the following declarations: int[] a = { 25, 10, 5, 27, 15, 33, 35, 22, 55, 48 }; int n = 22;

Calling Foo.avgGTorEqToX( a, n ); would return the value 35. public class Foo {

3) Fill in the blanks with the corresponding number. Words/numbers may be used more than once. (37 pts)

Composition provides ___________ relationship where inheritance provides ___________ relationship.

By definition, a Java application will always have a(n) ___________. To run an application, you use the command ___________.

A(n) ___________ variable is defined outside any method and exists only in individual objects.

The three main features/tenets of Object Oriented Programming are ___________, ___________, and ___________.

Java supports single inheritance of ___________. It does this using the keyword ___________.

The class (not-so-secret) password is ___________. To denote a constant in Java, the keyword ___________ is used.

When assigning a variable of type double to a variable of type int, Java requires you to use a ______________ on the double variable.

You use ___________ to get the number of elements in an array. You use ___________ to get the number of chars in an String.

A(n) _________ can contain only public abstract methods and public static final constants. One of the main distinguishing features

between a(n) __________ definition and a method definition is that the method definition has a(n) ___________.

Java supports multiple inheritance of ___________. It does this using the keyword ___________.

When performing exception handling, you put code in a(n) ___________ block that may throw an exception. Then a series of one

or more ___________ blocks listing exception types from ___________ specific to ___________ specific. The optional

___________ block is always executed. The ___________ is thrown if we try to call Long.ParseLong( "123.abc" );

___________ and ___________ variables are stored in a ___________ which is allocated on the ___________ every time a method

is called and deallocated when the method returns.

To check for exact type equivalence, use __________ on two objects and check if the resulting references are the same.

The ___________ reference is passed as a hidden parameter to every ___________ method and ___________.

___________ is a same class constructor call. The body of the default constructor supplied by the compiler is ___________.

Methods in the same class that have the same name but differ in the types of their parameters are ___________ methods.

5) Indicate whether each of the following is (26 pts) [1 point each] Runtime Storage

A) Class Definition K) Inner class definition B) Static variable/constant definition L) Static variable/constant access 1) Local var - Stack Frame C) Static method definition M) Static method call/invocation 2) Class Area D) Constructor definition N) Constructor call/invocation 3) Param - Stack Frame E) Instance variable/constant definition O) Instance variable/constant access 4) Object in Heap F) Instance method definition P) Instance method call/invocation G) Local variable/constant definition Q) Local variable/constant access H) Parameter definition R) Parameter access I) Interface S) Inheritance of interface J) Superclass T) Inheritance of implementation U) Overloaded method/constructor

public class Foo extends JApplet { ________ ________ ________ Foo extends JApplet

public static boolean raw; ________ ________ raw raw

private int boff = 12; ________ ________ boff boff

public static void main( String[] args ) { ________ ________ ________ main() args args

Foo burger; ________ ________ burger burger

burger = new Foo(); ________ ________ ________ ... burger new Foo() where burger } is pointing

public Foo Foo( boolean raw ) { ________ ________ ________ Foo() raw raw

Foo.main( "CSE" ); ________ Foo.main()

raw = true; ________ raw

return this;

}

public Foo() { ________ Foo()

Foo( raw ); ________ ________ ... Foo() raw }

private class Fry implements ActionListener { ________ ________ ________ Fry implements ActionListener ... } }

Terms

1 ActionListener 2 ArrayIndexOutOfBoundsException 3 BorderLayout 4 BufferedReader 5 Class 6 Class.forName(str).newInstance() 7 ClassCastException 8 CloneNotSupportedException 9 Cloneable 10 Exception 11 FlowLayout 12 Fubar 13 Graphics 14 IOException 15 JApplet 16 JButton 17 JComponent 18 JLabel 19 JPanel 20 JTextField 21 NumberFormatException 22 Object 23 ParseLongException 24 abstract 25 accessor/get 26 actionPerformed 27 applet 28 appletviewer 29 application 30 array 31 cast 32 catch 33 checked 34 class 35 class area 36 component 37 composition 38 concrete/fully defined 39 constructor 40 container 41 default 42 dynamic 43 encapsulation 44 equals() 45 exception 46 extends 47 final 48 finally 49 getClass() 50 has-a 51 hashCode() 52 heap 53 immutable 54 implementation 55 implements 56 import 57 inheritance 58 inner class 59 instance 60 instanceof

61 interface 62 is-a 63 java 64 java.awt 65 java.awt.event 66 java.io 67 java.lang 68 javac 69 javax.swing 70 layout manager 71 least 72 length 73 length() 74 local 75 main() 76 method 77 most 78 mutator/set 79 new 80 non-static 81 outer class 82 overflowed 83 overloaded 84 overridden 85 overwritten 86 package 87 package access 88 paint() 89 parameters 90 polymorphism 91 primitive 92 private 93 protected 94 public 95 readLine() 96 recursion 97 reference 98 return type 99 slackers 100 snafu 101 stack/runtime stack 102 stack frame 103 static 104 subclass 105 super 106 super() 107 superclass 108 this 109 this() 110 throw 111 throws 112 toString() 113 try 114 unchecked 115 void 116 wrapper class 117 Hot Dog 118 Top Dog 119 Snoop Dogg 120 Big Dog