Java Flashcards

1
Q

What keyword would be used to refer to the current class instance variable, in order to resolve ambiguity between instance variables & parameters?

A

this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why might the this keyword be used to invoke the current class constructor?

A

To reuse the constructor i.e. for constructor chaining

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The new operator is followed by a call to a ____, which initializes a new object.

A

Class constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The super keyword can be used to refer to a parent class instance variable if what is true?

A

The parent class and child class have the same fields

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When should the super keyword be used to invoke a parent class method?

A

If the child class contains the same method as the parent class i.e if the method is being overwritten

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What four things can the static keyword be applied with?

A

Variables, methods, blocks, nested classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Where can the final keyword be initialized?

A

In the constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What string handling method returns a character at a specified index?

A

char charAt(int index)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What string handling method compares the current string to another object?

A

int compareTo(Object o)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What string handling method concatenates the specified string to the end of the current string?

A

String concat(String str)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What string handling method compares the current string to the specified object?

A

boolean equals(Object anObject)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What string handling method compares the current string to another string while ignoring case considerations?

A

boolean equalsIgnoreCase(String anotherString)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What in Java is a group of similar types of classes & interfaces?

A

Package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the three advantages of packages?

A

Categorizing classes & interfaces; providing access protection; removing naming collision

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the three ways to access a package from other packages?

A

import package.*; import package.classname; using the fully qualified name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If the import package.* syntax is used, then which of the following three will not be accessible? Classes, interfaces, subpackages

A

Subpackages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

If the import package.classname syntax is used, what is the only part of the package that will be accessible?

A

Declared class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When is the fully qualified name of a package generally used?

A

Two packages have the same class name / To prevent class name collision

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the ordering sequence of a Java program?

A

Package > import > class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a reference type in Java that is similar to class and is a collection of abstract methods?

A

Interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Besides abstract methods, what 3 or 4 things may an interface also contain?

A

Constants, default or static methods, nested types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

All the methods of an interface implemented by a class need to be defined in the class, unless what is true?

A

The class is abstract

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Can an interface contain any number of methods?

22
Q

Can you instantiate an interface?

23
What is the name of the .java file that an interface is written in?
The same as the name of the interface
24
Can an interface contain constructors?
No
25
Where does the byte code of an interface appear?
In a .class file
26
What is the name of the directory structure containing the bytecode file of an interface?
The same as the name of its package
27
What must all fields in an interface be declared as?
Static and final
28
Can an interface be extended by a class?
No
29
Can an interface extend multiple interfaces?
Yes
30
Are methods in an interface implicitly public?
Yes
31
What must a class do if it does not perform all the behaviors of an implemented interface?
Declare itself as abstract
32
Can a class implement more than one interface at a time?
Yes
33
Can a class extend more than one class?
No
34
What are events that occur during the execution of programs that disrupt the normal flow of instructions?
Exceptions
35
What is an exception in Java?
An object that wraps an occurred error event within a method
36
What three things does an exception contain?
Info about the error including its type; the state of the program when the error occurred; possibly other custom information
37
What are the three categories of exceptions?
Checked, unchecked, errors
38
What type of exception is one which the compiler forces you to handle explicitly?
Checked
39
What type of exception is generated by a method that must declare it that throws it?
Checked
40
What type of exceptions are errors and RuntimeExceptions?
Unchecked
41
What type of exception is one upon which it is assumed that the application cannot do anything to recover from it?
Unchecked
42
What keywords are used together by a method to catch exceptions?
try, catch
43
What keyword is used by a method to declare a checked exception it does not handle?
throws
44
What keyword is used to postpone the handling of an unchecked exception?
throws
45
What keyword is used to invoke an exception explicitly?
throw
46
What code block keyword is used to run any cleanup-type statements that the programmer wants to excecute, regardless of any exceptions occurring in the preceding try & catch blocks?
finally
47
What is used in Java to solve the problem of fixed size limits of arrays?
Collection framework
48
What three things do all collection frameworks contain?
Interfaces, implementations (classes), algorithms.
49
What interface extends Collection and declares the behavior of a collection that stores a sequence of events?
List
50
What exception will some list methods throw if the collection cannot be modified?
UnsupportedOperationException
51
What exception will some list methods throw when one object is incompatible with another?
ClassCastException
52
What part of collection framework provides dynamic arrays in Java?
ArrayList
53
What class does ArrayList inherit?
AbstractList
54
What interface is a Collection that cannot contain duplicate elements?
Set
55
What does the Map interface do?
Maps unique keys to values so they can be retrieved later