Term
What can valid identifiers begin with? |
|
Definition
Letter, underscore or currently symbol. |
|
|
Term
What is the maximum length of an identifier. |
|
Definition
|
|
Term
JavaBeans must be named using _______ and depending on the methods purpose must start with ___, ___, __, ___, or ______. |
|
Definition
JavaBeans must be named using camelCase and depending on the methods purpose must start with get, set, is, add, or remove. |
|
|
Term
How many public classes can a source file have? |
|
Definition
|
|
Term
How many package statements are allowed and where must they be? |
|
Definition
Only one is allowed and it must be the first statement in the file. |
|
|
Term
Where must the import statement go? |
|
Definition
At the begining of the file AFTER the package statement (if present) otherwise it must be the first statement in the file. |
|
|
Term
How many public classes can be in a source file? |
|
Definition
|
|
Term
True/False there can be only one top level class. |
|
Definition
False, you can have many top level classes, but only one Public class. |
|
|
Term
True/False When a thread is sleeping it releases its locks. |
|
Definition
False, Locks are only released on wait() |
|
|
Term
What access modifiers can interfaces have for declarations? |
|
Definition
|
|
Term
Will This Compile?
interface Arachnid{ void bite();}
public class BlackWidow implements Arachnid{
void bite();}
|
|
Definition
No, the interfaces are declared as public whether they say so or not. The class then changes it to default (package) access. It will not compile. |
|
|
Term
What is the output?
int k=8;
int s=0;
for(int i=5;i>2;i--){
s=k-i;
break;
}
System.out.println(s);
|
|
Definition
S would be 3.
It's easy to think that S might be 4 instead abut the postfix operator doesnt occur until AFTER the code block has executed. |
|
|
Term
What is the result of compilation?
class Fuel{
static int getFuel(){return 23}
}
class Gas extends Fuel{
public static void main(String[] args){
System.out.println(super.getFuel());
}
}
|
|
Definition
Compilation fails.
Only instance methods can be overridden. Calls to super only apply to overridden methods. |
|
|
Term
Will this compile?
List<Number> numbers = new ArrayList<Integer>(); |
|
Definition
No, Interger is a subtype of Number. |
|
|
Term
Will this compile?
List<JButton> numbers = new ArrayList<JButton>(); |
|
Definition
|
|
Term
What will extends Animal> accept?
1. Animal
2. Dog
3. Mammal
4. Cat |
|
Definition
Animal, Dog, Cat
Since Mammal does not extend from Animal and is a supertype of Animal it will fail type checking. |
|
|
Term
What will super Dog> accept?
1. Animal
2. Dog
3. Mammal
4. Cat |
|
Definition
Animal, Mammal, Dog
Since Cat is not a supertpe of Dog it will fail type checking. |
|
|
Term
Will this compile?
1) List> list = new ArrayList();
|
|
Definition
|
|
Term
Will this compile?
2) List extends Animal> aList = new ArrayList();
|
|
Definition
|
|
Term
Will this compile?
3) List> foo = new ArrayList extends Animal>(); |
|
Definition
No. Problem: you cannot use wildcard notation in the object creation. So the new ArrayList extends Animal>() will not compile. |
|
|
Term
Will this compile?
4) List extends Dog> cList = new ArrayList(); |
|
Definition
No
Problem: You cannot assign an Integer list to a reference that takes only a Dog (including any subtypes of Dog, of course). |
|
|
Term
Will this compile?
5) List super Dog> bList = new ArrayList();
|
|
Definition
|
|
Term
Will this compile?
6) List super Animal> dList = new ArrayList();
|
|
Definition
No
Problem: You cannot assign a Dog to super Animal>. The Dog is too "low"
in the class hierarchy. Only or |
|
|
Term
Will this compile?
public class NumberHolder extends number>{} |
|
Definition
No.
The ? will not work for generic class and method declarations. |
|
|
Term
Will this compile?
public static extends T> List backwards(List input) |
|
Definition
No.
You cant use wildcards in the type variable declaration. |
|
|
Term
Will this compile?
public static super T> List backwards(List input) |
|
Definition
No
You can not use wildcards in the type variable declaration. |
|
|
Term
Will this compile?
public static List backwards(List extends T> input) |
|
Definition
Yes.
You can define the type passed to a declaration with the ? wildcard parameter. |
|
|
Term
Is this statement true?
If the equals() method returns true, the hashCode() comparison == might return false. |
|
Definition
No, This is a negation of the hashCode() and equals() contract. (Objective 6.2)
x.equals(y) == true then x.hasCode() == y.hashCode() (REQUIRED) |
|
|
Term
Is this statement true?
If the hashCode() comparison != returns true, the equals() method might return true. |
|
Definition
No, This is a negation of the hashCode() and equals() contract. (Objective 6.2)
x.hasCode() != y.hashCode() then x.equals(y) == false (REQUIRED) |
|
|
Term
Is this statement true?
If the equals() method returns false, the hashCode() comparison == might return true. |
|
Definition
|
|
Term
Is this statement True?
If the hashCode() comparison == returns true, the equals() method might return true. |
|
Definition
|
|
Term
What is the result?
String s="Pod";
s.substring(1,7);
s.insert(0,"i");
System.out.println(s);
|
|
Definition
Compilation fails. Strings do not have an insert method. |
|
|
Term
The HashMap uses what methods for inserting and retreiving data? |
|
Definition
put(K key, V value) and get(Object key) |
|
|
Term
The LinkedList uses what methods for inserting and retreving data? |
|
Definition
add(E o) Appends the specified element to the end of this list
add(int index, E element) Inserts the specified element at the specified position in this list.
get(int index) |
|
|
Term
Will this compile?
short [][]b = new short[4][4];
short b3=8;
b[1][0]=b3;
|
|
Definition
Yes
A short fits into the arra element directly. |
|
|
Term
Will this compile?
short [][]b = new short[4][4];
short b2[][][][] = new short[2][3][2][2];
b2[1][1][0][1]=b1[1][0];
|
|
Definition
Yes because your assigning a value from the 2 dimension b1 to the single demsion item in b2. |
|
|
Term
What is the result?
int x=0;
for(int y=2;y>0;y--){
x++;
}
System.out.println(x+y);
|
|
Definition
Compillation fails.
y is out of scope. |
|
|
Term
What is the result?
int x=2;
int y;
for(y=2;y>0;y--){
x++;
}
System.out.println(x+y);
|
|
Definition
|
|
Term
Scope1.java Contains:
class ForNext{
public static void main(String arg[]){
int y; for(y=2;y>0;y--){System.out.println(x+y);}
}
What happens when you run it with "java Scope1" |
|
Definition
Exception in thread "main" java.lang.NoClassDefFoundError: Scope1
This is because the compiler creates a ForNext.class |
|
|
Term
Will this compile?
throw new RuntimeException(); |
|
Definition
yes, you can throw a new RuntimeException(); |
|
|
Term
What calls will request the Garbage Collector to run? |
|
Definition
System.gc() and Runtime.getRuntime().gc() |
|
|
Term
What is the result?
class crap{
public void static main(String[] args){poo();}
static void poo(){System.out.println("hi");
{System.out.println("bye");}
} |
|
Definition
Just "Hi"
The {} init block is never called because the constructor was never called. The static method doesnt require the constructor. |
|
|
Term
What is the result?
class myNum{
public void static main(String[] x){
int i;
System.out.printlin(go(i));
}
int go(int z){return ++z;}
}
|
|
Definition
Compilation fails.
go (instance method) is being called from a static method |
|
|
Term
True or False
protected is less restrictive that default |
|
Definition
|
|
Term
True/False
Protected member can be accessed by a subclass regardless of the package it's in. |
|
Definition
|
|
Term
What are the access levels for a class in order from less restrictive to most restrictive? |
|
Definition
Public Protected Default Private |
|
|
Term
Which of the following can be used in a switch or case statement?
byte char int short long double |
|
Definition
|
|
Term
In regex what does \w search for |
|
Definition
Word characters (Digits, letters or seperators) |
|
|
Term
What is the ^ operator for? |
|
Definition
|
|