Java Midterm Review

Java Midterm Stuff

Java Gotchas

http://www.javaranch.com/maha/Resources/gotchas_1_.html#FALLTHRU

Java Midterm Review

http://www.cis.upenn.edu/~matuszek/cit591-2006/Pages/midterm-review.doc

Questions to ask

1. From the memory point of view, an object of class T can be treated as the set of instance variables declared in class T and superclasses of T. For almost all Java virtual machines, instance variables declared in superclasses of T are allocated in front of instance variables declared in class T itself. Please explain the benefits of such a design. (25%)

2. For a programming language with recursive calls, usually local variables are associated with
function calls(method invocations). This is the fundamental of recursive call mechanism. Please
explain the reason. (25%)

=> Every time a function is called recursively a copy of the local variables are put on the stack.

4. Program re-usage is a very crucial issue for today's software development and maintenance. For example, function call is one kind of program re-usage for many programming languages. Please list at least two kinds of program re-usage for object-oriented programming languages, and describe why they have such effects. (25%)

=> APIs (Using JAR Libraries), Inheritance (Extending a class), Using a component/subsystem (JavaBeans), Calling Web Services

Tricky stuff

int i = x = 0;
int numbersA[i++] = 42; // index = 0
// result: i = 1
int numbersB[++x] = 42; // index = 1
// result x=1
Note: Different in C

Operator Precedence

http://www.cs.princeton.edu/introcs/11precedence/

class Test {
    public static void main(String[] args) {
        int i = 2;
        int j = (i=3) * i;
        System.out.println(j);
    }
}
prints:
9

http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#4779
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License