General Topics:
Use the list of questions below as a guide when studying for Exam 1. It is by no means a comprehensive list of questions. Also, these are not the exact questions that will be on the exam. The form of the questions on the exam may also be different from those found here.
You are responsible for all material presented in the lectures for the General Topics listed above. You are also responsible for all material covered in lab and the concepts taught by any programming assignments.
Answering the applicable “self-test” questions in each chapter of the recommended text (by Savitch) is also a good way to review. The answers to the self-test questions are found at the end of each chapter.
for
loop, a variable can be declared at the
same time it is initialized, as in for (int i = 0; i
< 42; i++)
.
boolean
data type.nextInt()
and next()
when performing
user input. How is this problem addressed?
for
loop control statement? (e.g. for (int i = 0; i < size;
i++)
).
String aString = "the quick brown fox
jumped over the lazy dog";
write syntactically correct Java
code to
anotherString
as a copy of aString
.
sentence
in which each string is initialized to
“I love Java”.
Dog
is a user-defined class with one instance
variable: String name;
. Be sure to differentiate
between stack memory and heap memory.
Dog[] dogs = new Dog[5]; dogs[0] = new Dog("Fido"); dogs[1] = new Dog("Lassie"); dogs[2] = new Dog("Ralph");
==
cannot be used to test the equality of objects in Java.
=
cannot be used
to assign one object to another in Java.
Define the following terms:
class, object, method, reference variable, primitive type, instance variable, public method, public instance variable, private method, private instance variable, constructor, copy constructor, method overrloading, class invariant, visibility modifier, instance, instantiation, class scope, mutator, accessor, method signature, immutable class/object, privacy leak
public class Aquarium { private int volume; private int numFish; private int temperature; private boolean clean; public Aquarium() { // code intentionally missing } public Aquarium(int volume, int numFish, int temp) { // code intentionally missing } public void cleanAquarium() { clean = true; } public int getTemperature() { return temperature; } public int getVolume() { return volume; } public int getNumFish() { return fish; } public void setTemperature(int temperature) { this.temperature = temperature; } }
getTemperature()
method?
clean
?
public class Point { private int x, y; public Point(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } public void move(int deltaX, int deltaY) { x += deltax; y += deltaY; } } public class Circle { private Point center; private int radius; public Circle(Point p, int radius) { center = p; this.radius = radius; } public Point getCenter() { /* code missing */ } public int getRadius() { return radius; } public void alter(Point newCenter) { /* code missing */ } public void alter(int radius) { this.radius = radius; } }and the declarations
Point point = new Point(3, 6); Circle circle1 = new Circle(point, 5); Circle circle2 = new Circle(new Point (1, 2), 3);
alter(Point
newCenter)
method.
alter()
methods in the context of composition.
getCenter()
method.
circle2
's center.
circle2
and
circle1
have the same center.
Point p = point;
Point p2 = new Point(3, 5);
Circle c = new Circle();
System.out.println(circle1.getX());
circle1 = circle2;
toString
method that formats
the Point as ( x, y )
.