Você está na página 1de 6

Mid Term Review 2015 Winter

Exam Format

true/false and/or multiple choice questions

short-answer questions, e.g.


o define something, explain something, list things
o fill in the blank, answer a question about a diagram/screen shot
o write one or two statements to perform a certain task
o write short coding statement

1 coding problem (written, or using computer)

Topics Covered
String Processing

strings are immutable - what does this mean? how characters are stored in a string object

how string objects are created ? how string object are stored in memory

how concatenation affects a string object ? string comparison: == vs. equals()

String class methods ; Character class methods

Conversion methods used to convert various types of data to String objects

Comparing strings with .equals(), checking for null-string ("")

OOP Review

OOP - creating classes, accessor/mutator methods, constructor methods, the this


keyword, toString() and equals() methods, etc.

UML class diagram, Creating class in UML format

Creating static methods vs. non-static methods. Why client class methods are not static?

Static methods and static variable, finally, why do we need them?

Inheritance

What is inheritance, how does it work? Why use inheritance?

Terms: Parent class/child class; super class/sub class; base/derived class

how to code a child class - extends keyword

The super keyword - e.g. super.something or super()

child class "inherits" stuff from parent class; you can change (override) methods or add
methods/variables

dynamic binding - what does this mean, how does it work, effects, etc.

Simple/Single-inheritance vs. multiple-inheritance - which does Java support?

Method overriding

casting parent/child classes (assigning reference of the parent class object of a child class)

Misc. OOP Concepts

Class design - types of class relationships: composition, aggregation, inheritance;


characteristics of good program or class design, etc. (see PowerPoint from this lesson)

UML class relationship diagram, classes relationship in UML format

Object class - top of the hierarchy. What is inside Object class?

toString(), equals() - inherited from object

implicit call to toString() method e.g. System.out.println(objectVariable);

How objects and object/reference variables are stored in memory, comparing objects with
== vs. .equals()

instanceof operator

Polymorphism - what does this mean? Dynamic binding ?

Method overloading vs. method overriding - what's the difference? Examples!

Abstract Classes/Methods/Interfaces

How do you define a class/method as abstract?

What are abstract classes/methods; why do we need them?

Abstract methods
o methods with just a signature, no body
o often used in parent classes to include empty methods that only child classes will
implement

Abstract classes
o a class with at least one abstract method
o can contain attributes and methods that are implemented (have code)

Interfaces
o Why do we need them? How do define?
o How to use?
o Interface usage in GUI model

Intro to GUI
a.
b.
c.
d.

GUI Components
Layout Management. Using Layouts
Intro to Event Handling
Event Handling Practices

Primitive Data Objects

Wrapper classes - what they are, names, what they're for, etc.

The hierarchy of the wrapper classes - child/parent, Number class, etc.

Useful methods and constants e.g. MAX_VALUE/MIN_VALUE, parseXxx(), valueOf(),


xxxValue(), etc.

Wrapper Classes ? For example, Boolean class -- parseBoolean() and booleanValue()


methods and how they work

Misc.

javadoc - conventions, tags, what they're for, etc.

packages - what are they, why use them, how to create, naming conventions

Sample Questions
Coding

1. Any of programs from Home Assignments/ Practicum / Lab could be considered as


an example.

2.

Example : A class called Person is defined as follows:

public class Person


{
private String
private String
private String
private String

firstName;
lastName;
phone;
address;

public Person() {}
public Person(String firstName, String lastName, String address,
String phone) {
setFirstName(firstName);
setLastName(lastName);
setAddress(address);
setPhone(phone);
}
public void setFirstName(String name) throws IllegalArgumentException
{
if (name.equals(""))
throw new IllegalArgumentException("Invalid first
name.");
else
firstName = name;
}
public String getFirstName() { return firstName; }
public void setLastName(String name) throws IllegalArgumentException
{
if (name.equals(""))

throw new IllegalArgumentException("Invalid last

name.");
else

lastName = name;
}
public String getLastName() { return lastName; }
public void setAddress(String address) throws IllegalArgumentException
{
if (address.equals(""))
throw new IllegalArgumentException("Invalid address.");
else
this.address = address;
}
public String getAddress() { return address; }
public void setPhone(String phone) throws IllegalArgumentException
{
if (phone.equals(""))
throw new IllegalArgumentException("Invalid phone
number.");
else
this.phone = phone;
}
public String getPhone() { return phone; }
public String toString() {
return "Name: " + lastName + ", " + firstName + "\nPhone:
+ phone + "\nAddress: " + address;
}

"

Define a class called Student as a child class of Person with the following specifications:

String attributes for first name, last name, address, and phone number. These must not be
empty, or an exception is thrown.

A String attribute for student id, which is always exactly 9 digits. No letters are allowed.
If an id is invalid, an Exception with the message "Invalid student ID." is thrown.

A String attribute for program code, which is always exactly four characters. These
characters could be letters, digits, or any combination of letters and digits. If the program
code is invalid, throw an Exception with the message "Invalid program code".

A default constructor that contains no code. This allows the programmer to create an
empty object and set the values later.

A six-parameter constructor that takes the id, first name, last name, address, phone
number, and program code, and sets the values of those variables.

Accessor/mutator methods for the attributes.

An equals() method that checks to see if two student objects are equal. Two Students are
equal if they have the same student ID.

a toString() method that returns a string representation of a student in the following form
(sample values used for the data):

ID: 123456789
Name: Schmoe, Joe
Phone: 905-845-9430
Address: 100 Main St.
Program: 3220

Você também pode gostar