Midterm 1 Information

 

Time:  Tuesday, 2/24, 5-7pm  (unless you’ve contacted me about a conflict)

Place:  145 Birge

Bring:  Your student ID and some pencils

 

What’s the exam format?

 

See the “Practice Exam” on the Exams page of the main CS 302 website.  It’s a smaller version of what you’ll see on Tuesday, with some examples of the different types of questions.  Read the questions carefully, because details matter.

 

How can you prepare?

 

            The true-false and multiple choice questions focus on Java terminology and facts from chapters 1-4, and on understanding small pieces of code.  The written section may require you to do some object-oriented design and to write small pieces of code, as in short methods and small classes.  Expect questions related to any assignments and class examples you’ve seen so far, and about all the term definitions and Java rules that we talked about in class.  Here are some suggestions for studying:

 

 

Terminology:

 

application

source file

bytecode

machine code

compilation error

run-time error

import statement

comment

class

instantiable class

main class

object

instance

constructor

self-referencing pointer

garbage collection

dot notation

sending a message

method call

instance method

class method

method header

visibility

return type

return value

argument

parameter

pass-by-value

method composition

accessor

mutator

overloaded method

instance data member

class data member

class integrity

variable

constant

literal constant

identifier

reserved word

local variable

variable scope

analysis phase

design phase

coding phase

testing phase

operation phase

class declaration

method declaration

variable declaration

primitive type

reference type

aliasing

initialization

assignment

expression

statement

operator

operand

binary operator

unary operator

integer division

mod operator

operator precedence

concatenation

casting

numeric promotion

assignment conversion

wrapper class

standard input

standard output

escape character

code duplication

 

 

Review Questions:

 

1)     Which of the following are valid identifiers?  

 

·        myVar2

·        Bus Stop

·        TAX_RATE

·        3rd

·       $val

 

2)     Evaluate the following expressions:

 

·        (double)(5/2)

·        12 / 3.0

·       2 * (1 + (3/4) / 2) * (-2 – 6 % 3)

 

3)     Fill in the method so that it calculates and returns the value of  (sin(2x))4 . Suppose that it’s inside a class called Trig.  How would you call this method?

 

public static double evaluate(double x) {

 

 

 

}

 

 

 

4)     Write an instance method called product which takes two int parameters, returns their product as a double, and can be called only from within its own class.  Suppose this method is in a class called Calc.  How would you call it?

 

 

 

 

 

 

5)     In a class declaration, why are data members declared outside of any method?

 

 

 

 

6)     Fill in the following constructor so that it initializes two data members with the names age and name:

 

public Person (int age, String name) {

 

 

 

 

}

 

7)     Where do local variables exist?  How do you decide whether to make something a data member or a local variable?

 

 

 

 

 

 

8)     An example of a class constant is Math.PI.  What must its declaration look like inside the Math class?  Why did they choose not to make it an instance variable?

 

 

 

 

 

 

9)     What methods are allowed to access the following kinds of data?

 

·       instance data

·       static data

·       private data

·       public data

 

10)  How do you force a conversion from one numeric type to another?  What about from a String to a number?

 

 

 

 

 

 

11)  One example of an expression is “(2+2)”, and its type will be int.  A method call can also be an expression; how can you tell what its type will be?

 

 

 

12)  If a method takes a parameter of type float, which of the following would be okay to pass as an argument to that method? 

 

·       5

·       2.4

·       10L

·       6.02f