15-100 Sections S-V / Fall 2008
Quiz 7 / 20 Questions / 30 Minutes
Quiz Date: Tue 11-Nov-2008
- When looking up files
on
www.cmu.edu, your browser first contacts a ____________________________
to determine that
www.cmu.edu has the IP address 128.2.10.163.
- The type “char” is both
wider and narrower than either the type _______________ or _______________.
- \b is the escape
sequence for _______________________.
- A reasonable synonym of
“deprecated” might be _______________________.
- A local variable
_____________________ an instance variable if both variables have the same
name.
- The J2ME is basically a
version of Java designed for _______________________________.
- A constant is declared
with the _________________ keyword.
- Unlike Strings,
StringBuffers are ________________________.
-
___________________________ is an example of a sequential access device.
- _____________________ occurs when Java tries to
represent a positive double value that is smaller than Double.MIN_VALUE.
- This code fails to
compile because the “+” operator converts chars to ints by ____________
conversion..
char c1 = 1;
char c2 = 2;
char c3 = c1 + c2;
- The smallest char value
is ______________ and the largest byte value is _________________.
- If a class implements
the _____________________ method in the _______________________ interface,
then collections of that class can be sorted using the built-in Arrays.sort
or Collections.sort methods.
- In the code below, “a”
is a(n) _______________ parameter and “b” is a(n) _______________ parameter.
public int foo(int a) {
int b = a – 32;
return Math.abs(b);
}
- Write a single line of
code that demonstrates all of the following, each of which must be clearly
labeled:
- Assignment
Conversion
- Method Invocation
Conversion
- Promotion
- Casting
- Give an example of each
of the following in Java’s libraries (and not your own classes):
- A static method
- An instance method
- An overloaded
method
- A static field
- The following code
demonstrates overflow. What, exactly, will it print?
SHOW YOUR WORK!
byte b1 = 67;
byte b2 = 97;
byte b3 = (byte) (b1 + b2);
System.out.println(b3);
- What will the following
code print?
int x = 3, y = 7;
while (x++ < y--)
System.out.println(--y); // note the decrement!
System.out.println(x + "," + y);
- What will the following
code print? Line up your columns carefully!
int y = 123, z = 45;
double d = 45.678;
String s = "Wahoo";
System.out.printf("123456789\n");
System.out.printf("%4d%4h\n",y,z);
System.out.printf("%+07d\n",y);
System.out.printf("%8.1f\n",d);
System.out.printf("X%-7sX\n",s);
- Write a method that
takes a variable number of Strings and returns the shortest one.
- BONUS: Assuming x and
y are ints where x=1 and y=100, what will the following print:
for (x++,--y;++x<y--;++x,y--)++x; y--; System.out.println(x+","+y);
carpe diem -
carpe diem - carpe diem - carpe diem
- carpe diem - carpe diem -
carpe diem - carpe diem - carpe
diem