Midterm Review - Computer Science | CS 161, Exams of Computer Science

Material Type: Exam; Class: INTRODUCTION TO COMPUTER SCIENCE I; Subject: Computer Science; University: Oregon State University; Term: Fall 2005;

Typology: Exams

Pre 2010

Uploaded on 08/30/2009

koofers-user-0d2
koofers-user-0d2 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Midterm Review
What is bytecode?
What is the Java Virtual Machine?
Where does execution start in a Java application?
Is Java case sensitive?
Legal names of Java identifiers
Class names (identifiers) start with a ____________.
Method names (identifiers) start with a ____________.
Object names (identifiers) start with a ________________.
Java constants are declared with the keyword ___________ and their names do not use
______________.
Primitive types: How many are there? What are they? Are they objects?
Variable declaration statements
Variable declarations that also initialize
Variable assignment - Which of the following will compile? If not--WHY? Consider each
statement in the indented list as directly following the given 3 lines.
int x = 9, y = 4, z;
float fl = 6.5;
double dbl = 6.5;
ox = y + 1;
ox = y + 1.;
ox = fl;
ox = y * fl;
ofl = x;
ofl = x + 1.;
ofl = x + 1.0
ofl = dbl + x;
ofl = dbl + z;
odbl = x + y;
Order of operations - Which operations have precedence?
List the order of the operations in the following expressions.
o(x + y) / z * 4;
o(int)a + x / b;
oa * (9 - b * c)
Visibility modifiers: public vs. private
Static variables and methods
oName a static method in the Java API
oHow would you call that method?
oCan a static method refer to non-static instance variables? Why or why not?
oWhat is the difference between an instance variable that is declared to be static
and another instance variable that is not static?
Floating point numbers in conditionals
float x=4.32f, y=100f;
if ( x*y == 432 ) System.out.println( "good" );
oWill the above line print out good? Try it!
pf3
pf4

Partial preview of the text

Download Midterm Review - Computer Science | CS 161 and more Exams Computer Science in PDF only on Docsity!

Midterm Review

 What is bytecode?  What is the Java Virtual Machine?  Where does execution start in a Java application?  Is Java case sensitive?  Legal names of Java identifiers  Class names (identifiers) start with a ____________.  Method names (identifiers) start with a ____________.  Object names (identifiers) start with a ________________.  Java constants are declared with the keyword ___________ and their names do not use ______________.  Primitive types: How many are there? What are they? Are they objects?  Variable declaration statements  Variable declarations that also initialize  Variable assignment - Which of the following will compile? If not--WHY? Consider each statement in the indented list as directly following the given 3 lines. int x = 9, y = 4, z; float fl = 6.5; double dbl = 6.5; o x = y + 1; o x = y + 1.; o x = fl; o x = y * fl; o fl = x; o fl = x + 1.; o fl = x + 1. o fl = dbl + x; o fl = dbl + z; o dbl = x + y;  Order of operations - Which operations have precedence? List the order of the operations in the following expressions. o (x + y) / z * 4; o (int)a + x / b; o a * (9 - b * c)  Visibility modifiers: public vs. private  Static variables and methods o Name a static method in the Java API o How would you call that method? o Can a static method refer to non-static instance variables? Why or why not? o What is the difference between an instance variable that is declared to be static and another instance variable that is not static?  Floating point numbers in conditionals float x=4.32f, y=100f; if ( x*y == 432 ) System.out.println( "good" ); o Will the above line print out good? Try it!

o What is a good way to compare floating point numbers in if statements?  Integer division vs. floating point division Evaluate the following expressions: int x = 9, y = 10; double z = 4; o x / y o x / y + z o x * z / y o x / y > 0 o z / y > 0  Type casting int pennies; int howManyNickels = 6, howManyDimes = 14; float NICKEL_WORTH=0.05, DIME_WORTH=0.1; // The next line won't compile. Why? Fix this line with type casting so that it calculates the value in pennies. pennies = howManyNickels * NICKEL_WORTH * 100 + howManyDimes * DIME_WORTH * 100;  Strings o equality testing - How should you compare Strings for equality? o concatenation  Conditional operators You might be asked to evaluate boolean expressions with the following o and o or o not  Conditionals: o if/else - Make sure you can tell which if and else goes with.  Loops: o for o while o do-while o nested What is printed out with the following nested loop: for (int a=2, b=10; a<6; a++) { while ( b++ % a != 0 ) { System.out.println("b="+b + " a=" + a); } } How about this one: int x=0; do { for(int a=0; a<3; a++) x += a; }while (x < 10); System.out.println("x ended up at " +x);  Fancy stuff o increment++ o ++increment

 how would you write a setter method associated with the instance variable int score o overloading  String Class o String str = "Oregon State University";  String s = _________________________________; // set s = the word State in str using the substring method.  String myString = ______________________________; // concatenate "I attend " with str  char c = _________________________; // set c equal to the g in str using the charAt method  int len = ___________________________; set len equal to the length of str (use a method)  Math Class o Math.round o Math.sqrt o Math.pow  The modern way to read input (since Java 1.5) is by using the ____________ class.  deMorgan's theorem

  1. Flip the gate (change && to ||, or change || to &&)
  2. Invert the whole thing (add! to the whole thing)
  3. Invert each component (add! to each component) Example: !( !var1 && var2 ) = var1 || !var