| Terms |
Definitions |
|
public class SunRoof{}public class SexAppeal{}public class ManualTransmission{}public class Vehicle{}public class Car extends Vehicle{ private SunRoof sr;}public class Mustang extends Car{ private SexAppeal sa; private ManualTransmission mt;}True or False
|
False
|
|
can a class be synchronized?
|
no
|
|
An Interface can implement another interface. (T/F)
|
False
|
|
what can ararys hold?
|
primitives or objects
|
|
Whether you're extending Thread, or implementing Runnable, which object do you have to create all the time?
|
Thread
|
|
Methods marked "abstract" end in a semicolon rather than curly braces.Y/N?
|
Yes.(p.17)
|
|
can a sychnronized method be declared final?
|
yes
|
|
Which point is important?
|
third point on 736
|
|
What is the output of:class AddVarArgs { static void go(int x, int y) { System.out.println("int,int"); } static void go(byte... x) { System.out.println("byte..."); } public static void main(String[] args) { byte b=5; go(b,b); }}
|
int, int
|
|
If a single method is "abstract", the whole class must be declared "abstract".Y/N?
|
Yes.(p.18)
|
|
if a method has multiple params where does the var-arg have to come?
|
last
|
|
For an example on how to declare method-local inner classes look at the code on page...
|
670
|
|
Can a static synchronized method and a non-static synchornized method block each other?
|
No
|
|
What error occurs when attempting to serialize an object that has a member which is not serializable?
|
RuntimeException similar to:java.io.NotSerializableException: problemMemberVariablep. 463
|
|
Which of the following are legal declarations?1) Int[5] someArray;2) Int[] someArray[];3) Int[][] someArray[];4) Int someArray[][];5) Int someArray[5][5];
|
2,3,4 (pg. 55)
|
|
who can access public members?
|
all classes in all packagages
|
|
Which exam watch is important?
|
the one on page 672
|
|
Which code is important to look at?
|
ThreadsExample2.java and ThreadsExample2Solution.java
|
|
List the 3 types of variables allowed to be declared in an interface.
|
public, static, final
|
|
can an interface extend another interface?
|
yes, it can extend many.
|
|
Which exam watch is very important?
|
the one on page 752
|
|
What is the heap?
|
The part of memory where Java objects live, and the one and only part of memory that is in any way involved in the garbage collection process(p. 255)
|
|
public class Test { private int x = 5; Test(){}; Test(int x){ this.x = x; } public static void main (String args[]){ final Test test = new Test(); test.setX(6); System.out.println(test.getX()); test.changeX(test); System.out.println(test.getX()); }
|
6 6 (pg. 57)
|
|
Which are valid?1.) class Foo { } 2.) class Bar implements Foo { } 3.) interface Baz { }4.) interface Fi { }5.) interface Fee implements Baz { }6.) interface Zee implements Foo { }7.) interface Zoo extends Foo { }8.) interface Boo extends Fi { }
|
1,3,4,8,10,11,12 are Valid2.) cant implement a class5.) Interface cant implement an interface6.) Interface cant implement a class7.) Interface cant extend a class9.) Class cant extend multiple classes
|
|
That code is completely useless. Why?
|
because the method doesn't instantiate a method of the inner class. It can be instantiated from anywhere inside the method, but after the inner class declaration
|
|
Which point is important to look at?
|
last one on page 735
|
|
What is one option for dealing with member variable(s) that, for one reason or another, cannot be serialized?
|
Mark the variable transient.p. 465
|
|
When can a class access a protected member variable in a class in another package?
|
Only by inheritance (pg. 36)
|
|
T/F: Instance methods and variables are accessible from the constructor
|
T, but only after the super constructor has run.(Ref: p. 134)
|
|
true or false, method-local inner class object can use the local variables of the method the inner class is in
|
false. because the variables in the method are on the stack, if the method is done executing, the stack is blown. but the object created from the inner class might still be alive. A reference might be passed to some other code. If the local variable is marked final, then it's ok. Look at the top code on page 672. Variable z should be marked final if we want it to compile
|
|
What always runs just before an object is deleted by the garbage collector?
|
The finalize() method (inherited from Object)(p. 263)
|
|
T/F: The following identifier is legal:int -d;
|
False - Identifier does not start with a letter, currency char ($) or underscore.(Ref p. 5)
|
|
what does having a single abstract method mean for a class?
|
the whole class must be declared abstract
|
|
Can static method be synchronized? what about the locks?
|
yes. One lock per class to synchronize static methods
|
|
What is the use of class BufferedReader?
|
The calss is used to make lower-level Reader classes like FileReader more efficient and easier to use.p443
|
|
public class Animal implements AnimalInterface{ public abstract void speak(); public void doAnimalStuff() { } }interface AnimalInterface { void doAnimalStuff();}Will this compile?
|
No - It is illegal to have an abstract method in a class that is not explicitly declared abstract. (pg 42)
|
|
T/F: A constructor can be called by its name from another method
|
False - constructors are invoked only by the keyword new, or from another constructor using this() or super()(Ref: p. 131)
|
|
Why isn't the code in the middle of 676 compile?
|
because sizzle is not in Popcorn
|
|
What if you want to join another thread, but you only want to wait for 5 seconds until thread A is done. What do you do?
|
There is an overloaded method of join() that waits for thread a to be done, but if it takes longer than 5000 milliseconds, then stop waiting and become runnable anyway
|
|
class ArrayExample { public static void main(String[] args) { int x = -1; int y = 0; int z = 1; int[] myArray = new int[3] myArray[y] = -1; myArray[x] = 0; myArray[z] = 1; System.out.println(myArray[2][0]);} }What will the followi
|
b. Runtime exception. x is a negative number. (pg 225)
|
|
public abstract class A { private String type; public abstract void doAStuff(); public String getType() { return type; }}public abstract class B extends A { public abstract void doAStuff(); public void doBStuff() { }}public class C exten
|
class C has 3 methods - Class C implements doAStuff() and inherits both getType() and doBStuff(). (pg 43)
|
|
True or False? Creating a new Thread object will start the thread
|
false. you have to "start" the thread in order to have a new thread of execution (new call stack)
|
|
How many objects are created on the heap with the following code?int[][] tempArray = {{1,9,2,2}, {3,7}, {4,4}};
|
Four objects are created on the heap. (pg 228)
|
|
Is this legal:public int foo() { char c = 'c'; return c;}
|
Yes, you may return any value or variable to a primitive return type that may be implicitly converted to the primitive return type. (p. 128)
|
|
What does the following do, what is the output?import java.util.regex.*;Class Regit { public static void main (String... args) { String inputString = "abaaaba"; Pattern pattern = Pattern.compile(".*ab"); Matcher bacon = pattern.matcher(inputString);
|
Checks to see if a match is found at the end of the specified inputString and will print "found the bacon!" if found. There will be no output when the above code is run.m.start() returns the starting indexbacon.group().length() returns the length of the pattern found.if the inputString was "abaaabab" then when the 3rd match is found, m.start would return 6 the size of the input would be 8 and the size of the mathcing pattern would be 2.So 6 == 8-2if the inputString was "abaaab" then when the 2nd match is found, m.start would return 2 the size of the input would be 6 and the size of the mathcing pattern would be 4.So 2 == 6-4pg 489 to 499
|