Core Java Flashcards

1
Q

If a variable is declared as private, where may thevariable be accessed?

A

A private variable may only be accessed within the class in which it is declared.

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

What is an object’s lock and which object’s havelocks?

A

An object’s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object’s lock. All objects and classes have locks. A class’s lock is acquired on the class’s Class object.

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

What is the Dictionary Class?

A

The Dictionary class provides the capability to store key-value pairs.

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

How are the elements of a BorderLayout organized?

A

NEWS Centre

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

What is the % operator?

A

Modulous division

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

When can an object reference be cast to an interfacereference?

A

When the object implements the instance to be referenced

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

What is the difference between a Window and aFrame?

A

The Frame class extends Window to define a main application window that can have a menu bar.

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

Which class is extended by all other classes?

A

The Object class is extended by all other classes.

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

Can an object be garbage collected while it is stillreachable?

A

No only while unreachable

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

Is the ternary operator written x : y ? z or x ? y : z ?

A

X?y:z

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

What is the difference between the Font andFontMetrics classes?

A

The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.

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

How is rounding performed under integer division?

A

The fractional part of the result is truncated.

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

What happens when a thread cannot acquire a lockon an object?

A

enters waiting state

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

What is the difference between the Reader/Writerclass hierarchy and the InputStream/OutputStream classhierarchy?

A

The Reader/Writer class hierarchy is character-oriented, and the InputStream/ OutputStream class hierarchy is byte-oriented.

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

What classes of exceptions may be caught by a catchclause?

A

A catch clause can catch any exception that may be assigned to the Throwable type.

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

If a class is declared without any access modifiers,where may the class be accessed?

A

A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.

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

Q117. What is the SimpleTimeZone class?

A

The SimpleTimeZone class provides support for a Gregorian calendar.

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

What is the Map interface?

A

The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.

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

Does a class inherit the constructors of itssuperclass?

A

nope

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

For which statements does it make sense to use alabel?

A

statements that can enclose a break or continue statement.

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

What is the purpose of the System class?

A

access to system resources

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

Which TextComponent method is used to set aTextComponent to the read-only state?

A

setEditable()

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

How are the elements of a CardLayout organized?

A

The elements of a CardLayout are stacked, one on top of the other, like a deck of cards.

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

Is &&= a valid Java operator?

A

nope

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

Name the eight primitive Java types?

A

you know this

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

Which class should you use to obtain designinformation about an object?

A

The Class class

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

What is the relationship between clipping andrepainting?

A

When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting.

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

Is “abc” a primitive value?

A

nope. String obj.

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

What is the relationship between an event-listenerinterface and an event-adapter class?

A

An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.

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

What restrictions are placed on the values of eachcase of a switch statement?

A

During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.

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

What modifiers may be used with an interfacedeclaration?

A

public or abstract

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

Is a class a subclass of itself?

A

yep

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

What is the highest-level event class of the eventdelegationmodel?

A

java.util.EventObject

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

What event results from the clicking of a button?

A

Action Event

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

How can a GUI component handle its own events?

A

A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.

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

What is the difference between a while statementand a do statement?

A

A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.

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

How are the elements of a GridBagLayout organized?

A

The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.

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

What advantage do Java’s layout managers provideover traditional windowing systems?

A

Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java’s layout managers aren’t tied to absolute sizing and positioning, they are able to accomodate platform-specific differences among windowing systems

39
Q

What is the Collection interface?

A

The Collection interface provides support for the implementation of a mathematical bag – an unordered collection of objects that may contain duplicates.

40
Q

What modifiers can be used with a local inner class?

A

final or abstract

41
Q

What is the difference between the paint() andrepaint() methods?

A

The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

42
Q

What is the purpose of the File class?

A

The File class is used to create objects that provide access to the files and directories of a local file system.

43
Q

Can an exception be rethrown?

A

yep

44
Q

Which Math method is used to calculate the absolutevalue of a number?

A

The abs() method is used to calculate absolute values.

45
Q

When does the compiler supply a default constructorfor a class?

A

The compiler supplies a default constructor for a class if no other constructors are provided.

46
Q

When is the finally clause of a try-catch-finallystatement executed?

A

The finally clause of the try-catch-finally statement is always executed unless the thread of execution terminates or an exception occurs within the execution of the finally clause.

47
Q

Which class is the immediate superclass of theContainer class?

A

component

48
Q

If a method is declared as protected, where may themethod be accessed?

A

A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

49
Q

How can the Checkbox class be used to create a radiobutton?

A

By associating Checkbox objects with a CheckboxGroup.

50
Q

Which non-Unicode letter characters may be used asthe first character of an identifier?

A

_ and $

51
Q

What restrictions are placed on method overloading?

A

not same name, return types and arguments.

52
Q

What happens when you invoke a thread’s interruptmethod while it is sleeping or waiting?

A

When a task’s interrupt() method is executed, the task enters the ready state. The next time the task enters the running state, an InterruptedException is thrown.

53
Q

What is casting?

A

There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.

54
Q

What is the return type of a program’s main()method?

A

A program’s main() method has a void return type.

55
Q

Name four Container classes.

A

Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane

56
Q

What class of exceptions are generated by the Javarun-time system?

A

The Java runtime system generates RuntimeException and Error exceptions.

57
Q

What class allows you to read objects directly from astream?

A

The ObjectInputStream class supports the reading of objects from input streams.

58
Q

What is the difference between a field variable and alocal variable?

A

A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.

59
Q

Under what conditions is an object’s finalize()method invoked by the garbage collector?

A

The garbage collector invokes an object’s finalize() method when it detects that the object has become unreachable.

60
Q

How are this() and super() used with constructors?

A

this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

61
Q

What is the relationship between a method’s throwsclause and the exceptions that can be thrown during the method’s execution?

A

A method’s throws clause must declare any checked exceptions that are not caught within the body of the method.

62
Q

How is it possible for two String objects withidentical values not to be equal under the == operator?

A

The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory.

63
Q

Why are the methods of the Math class static?

A

So they can be invoked as if they are a mathematical code library.

64
Q

What Checkbox method allows you to tell if aCheckbox is checked?

A

getState()

65
Q

What state is a thread in when it is executing?

A

An executing thread is in the running state.

66
Q

What are the legal operands of the instanceofoperator?

A

The left operand is an object reference or null value and the right operand is a class, interface, or array type.

67
Q

How are the elements of a GridLayout organized?

A

The elements of a Grid layout are of equal size and are laid out using the squares of a grid.

68
Q

What an I/O filter?

A

An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.

69
Q

If an object is garbage collected, can it becomereachable again?

A

Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.

70
Q

What is the Set interface?

A

no duplicates

71
Q

What classes of exceptions may be thrown by a throwstatement?

A

A throw statement may throw any expression that may be assigned to the Throwable type.

72
Q

What are E and PI?

A

E is the base of the natural logarithm and PI is mathematical value pi.

73
Q

Are true and false keywords?

A

nope

74
Q

What is a void return type?

A

A void return type indicates that a method does not return a value.

75
Q

What is the difference between the File andRandomAccessFile classes?

A

The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.

76
Q

What happens when you add a double value to aString?

A

The result is a String object.

77
Q

What is your platform’s default character encoding?

A

windows c1252

78
Q

Which package is always imported by default?

A

java.lang package

79
Q

What interface must an object implement before itcan be written to a stream as an object?

A

Serializable or Externalizable interface

80
Q

How are this and super used?

A

this is used to refer to the current object instance. super is used to refer to the variables and methods of the superclass of the current object instance.

81
Q

What is the purpose of garbage collection?

A

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources may be reclaimed and reused.

82
Q

What interface is extended by AWT event listeners?

A

All AWT event listeners extend the java.util.EventListener interface.

83
Q

What restrictions are placed on method overriding?

A

• Overridden methods must have the same name, argument list, and return type.

84
Q

How can a dead thread be restarted?

A

nope

85
Q

What happens if an exception is not caught?

A

An uncaught exception results in the uncaughtException() method of the thread’s
ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown.

86
Q

What is a layout manager?

A

A layout manager is an object that is used to organize components in a container.

87
Q

Which arithmetic operations can result in thethrowing of an ArithmeticException?

A

Integer / and % can result in the throwing of an ArithmeticException.

88
Q

What are three ways in which a thread can enter thewaiting state?

A

by invoking its sleep() method
by blocking on I/O
by unsuccessfully attempting to acquire an object’s lock, by invoking an object’s wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.

89
Q

Can an abstract class be final?

A

An abstract class may not be declared as final.

90
Q

What happens if a try-catch-finally statement doesnot have a catch clause to handle an exception that is
thrown within the body of the try statement?

A

The exception propagates up to the next higher level try-catch statement (if any) or results in the program’s termination.

91
Q

What is numeric promotion?

A

Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.

92
Q

What is the difference between a Scrollbar and aScrollPane?

A

A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling.

93
Q

What is the difference between a public and a nonpublicclass?

A

A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.