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?

A

Yes

22
Q

Can you instantiate an interface?

A

No

23
Q

What is the name of the .java file that an interface is written in?

A

The same as the name of the interface

24
Q

Can an interface contain constructors?

A

No

25
Q

Where does the byte code of an interface appear?

A

In a .class file

26
Q

What is the name of the directory structure containing the bytecode file of an interface?

A

The same as the name of its package

27
Q

What must all fields in an interface be declared as?

A

Static and final

28
Q

Can an interface be extended by a class?

A

No

29
Q

Can an interface extend multiple interfaces?

A

Yes

30
Q

Are methods in an interface implicitly public?

A

Yes

31
Q

What must a class do if it does not perform all the behaviors of an implemented interface?

A

Declare itself as abstract

32
Q

Can a class implement more than one interface at a time?

A

Yes

33
Q

Can a class extend more than one class?

A

No

34
Q

What are events that occur during the execution of programs that disrupt the normal flow of instructions?

A

Exceptions

35
Q

What is an exception in Java?

A

An object that wraps an occurred error event within a method

36
Q

What three things does an exception contain?

A

Info about the error including its type; the state of the program when the error occurred; possibly other custom information

37
Q

What are the three categories of exceptions?

A

Checked, unchecked, errors

38
Q

What type of exception is one which the compiler forces you to handle explicitly?

A

Checked

39
Q

What type of exception is generated by a method that must declare it that throws it?

A

Checked

40
Q

What type of exceptions are errors and RuntimeExceptions?

A

Unchecked

41
Q

What type of exception is one upon which it is assumed that the application cannot do anything to recover from it?

A

Unchecked

42
Q

What keywords are used together by a method to catch exceptions?

A

try, catch

43
Q

What keyword is used by a method to declare a checked exception it does not handle?

A

throws

44
Q

What keyword is used to postpone the handling of an unchecked exception?

A

throws

45
Q

What keyword is used to invoke an exception explicitly?

A

throw

46
Q

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?

A

finally

47
Q

What is used in Java to solve the problem of fixed size limits of arrays?

A

Collection framework

48
Q

What three things do all collection frameworks contain?

A

Interfaces, implementations (classes), algorithms.

49
Q

What interface extends Collection and declares the behavior of a collection that stores a sequence of events?

A

List

50
Q

What exception will some list methods throw if the collection cannot be modified?

A

UnsupportedOperationException

51
Q

What exception will some list methods throw when one object is incompatible with another?

A

ClassCastException

52
Q

What part of collection framework provides dynamic arrays in Java?

A

ArrayList

53
Q

What class does ArrayList inherit?

A

AbstractList

54
Q

What interface is a Collection that cannot contain duplicate elements?

A

Set

55
Q

What does the Map interface do?

A

Maps unique keys to values so they can be retrieved later