2 Flashcards

(74 cards)

1
Q

What is event handling in Java?

A

User interaction with frames involves handling events.

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

Give examples of user events in Java.

A
  • Clicking a button
  • Typing in a text field
  • Dragging the mouse along an area in the frame
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are events handled in Java?

A

Events are handled through listeners.

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

What must a button object be associated with to program functionality?

A

A listener.

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

What is ActionListener in Java?

A

An interface in the java.awt.event.* library for handling button actions.

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

What is an inner class?

A

A class defined within a class, useful for accessing data within the containing class.

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

What is the benefit of using an inner class as a listener?

A

Listeners need to access frame components.

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

What is the first option for handling multiple buttons in Java?

A

Create a different listener class for each button.

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

What is the second option for handling multiple buttons?

A

Use a single listener class for all buttons with different responses.

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

What is the third option for handling multiple buttons?

A

Create an inner class that implements ActionListener with a constructor that accepts parameters.

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

What are compile-time errors?

A

Errors detected by the compiler before the program runs, preventing successful compilation.

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

List some causes of compile-time errors.

A
  • Syntax errors
  • Type mismatches
  • Undefined/Not initialized variables or methods
  • Unclosed string literal
  • Missing imports
  • Missing return statements
  • Unreachable statements
  • Incorrect method signatures
  • Illegal start of expression
  • Non-static variable/method cannot be referenced from static context
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are runtime errors?

A

Errors that occur while the program is running, causing crashes or unexpected behavior.

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

List some causes of runtime errors.

A
  • Dividing by zero
  • Accessing an invalid array index
  • Null references
  • File not found
  • Illegal operations
  • OutOfMemoryError
  • StackOverflowError
  • NoSuchMethodFoundError
  • ClassNotFoundException
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a logic error?

A

A mistake made by the author that is syntactically correct but leads to unexpected program behavior.

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

What is UML?

A

Unified Modeling Language, a notation system for object-oriented analysis and design.

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

What type of diagrams do we focus on in UML for Java applications?

A

Class diagrams to describe classes and their relationships.

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

What does a hollow arrowhead represent in UML?

A

Inheritance.

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

What does a hollow diamond denote in UML?

A

Aggregation.

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

What does a straight line represent in UML?

A

Bi-directional navigability.

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

What is the difference between aggregation and composition?

A
  • Aggregation: parts may be independent of the whole
  • Composition: parts are created and destroyed with the whole
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What does cardinality specify in UML?

A

The number of objects that may be associated with an object of another class.

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

What does uni-directional navigability look like in UML?

A

An open arrowhead.

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

What is dependency in UML?

A

Some classes use other classes but are not related in previously discussed ways.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the focus of conceptual analysis in UML?
Focus on domain; mapping with code is not strict.
26
What is the visibility notation for public fields in UML?
+
27
How is a derived value indicated in UML?
/ (forward slash)
28
What is the notation for a static field in UML?
Underlined.
29
What symbol is used to denote aggregation in UML?
30
What symbol is used to denote composition in UML?
31
What does the symbol '△' represent in UML?
Inheritance.
32
What does the symbol '⟶' represent in UML?
Dependency.
33
What does the notation '1, *, 1..*' indicate in UML?
Multiplicity.
34
How do you indicate an interface in UML?
<> followed by the name of the interface.
35
What is the notation for an abstract class in UML?
Italicized class name and italicized abstract methods.
36
What does the notation 'balance: double = 0' signify?
balance is private, of type double, and initialized to zero.
37
What does the notation 'books: Book[*]' indicate?
Multiplicity of books.
38
Fill in the blank: A class that is dependent on another class in UML is represented by a _______.
◆ (filled diamond)
39
Fill in the blank: A weak ownership relationship in UML is indicated by a _______.
◇ (hollow diamond)
40
What is a compile-time error in Java?
A compile-time error is an error that occurs during the compilation of the code, preventing it from being successfully compiled.
41
What is a runtime error in Java?
A runtime error is an error that occurs while the program is executing, after successful compilation.
42
True or False: Syntax errors are a type of compile-time error.
True
43
What is an example of a common compile-time error?
Missing semicolon or mismatched parentheses.
44
What type of error occurs when trying to access an array index that is out of bounds?
Runtime error
45
In Java, what does the keyword 'extends' indicate in a class definition?
It indicates inheritance from a parent class.
46
What is UML?
UML stands for Unified Modeling Language, used for modeling software systems.
47
Fill in the blank: In UML, __________ represents a relationship where one class is a part of another class.
Composition
48
What is the difference between aggregation and composition in UML?
Aggregation represents a 'has-a' relationship with independent lifecycle, while composition is a stronger relationship where the child cannot exist without the parent.
49
True or False: In UML diagrams, a solid line with a diamond represents aggregation.
True
50
What is a dependency in UML?
A dependency indicates that one class depends on another class, usually represented with a dashed line.
51
Which error type occurs due to incorrect data types?
Compile-time error
52
True or False: An exception is a type of runtime error in Java.
True
53
What symbol is used to represent inheritance in UML?
A solid line with a closed arrowhead.
54
What is the purpose of the 'super' keyword in Java?
It is used to refer to the superclass of the current object.
55
Fill in the blank: A __________ error causes the program to crash during execution.
Runtime
56
What does it mean when a method is declared with 'throws Exception'?
It indicates that the method may throw an exception that must be handled.
57
What kind of error is caused by dividing by zero in Java?
Runtime error
58
True or False: In UML, a dashed line indicates a generalization relationship.
False
59
What is the main characteristic of a class in a composition relationship?
The child class's lifecycle is tied to the parent class.
60
Which UML relationship is represented by a line with a filled diamond?
Composition
61
What is the purpose of exception handling in Java?
To gracefully handle runtime errors and maintain normal program flow.
62
What are unchecked exceptions in Java?
Exceptions that do not need to be declared in a method's throws clause and can occur at runtime.
63
Fill in the blank: An __________ error is often related to logical mistakes in the code.
Runtime
64
What does it mean if a class is 'abstract' in Java?
It cannot be instantiated and is meant to be subclassed.
65
What keyword is used to handle exceptions in Java?
try
66
True or False: You can catch multiple exceptions in a single catch block in Java.
True
67
What does 'public class MyClass extends BaseClass' signify?
MyClass inherits from BaseClass.
68
What is the outcome of a class that has no main method in Java?
It cannot be executed as a standalone application.
69
True or False: Compile-time errors can be fixed without running the program.
True
70
In UML, how is a class that uses another class represented?
With a dashed line indicating a dependency.
71
What is the purpose of the 'catch' block in exception handling?
To handle the exception thrown by the try block.
72
Fill in the blank: __________ is a relationship where one class contains instances of another class.
Aggregation
73
What does the 'finally' block do in Java exception handling?
It executes code after the try and catch blocks, regardless of whether an exception was thrown.
74
What is the main difference between a checked exception and an unchecked exception?
Checked exceptions must be declared or handled, while unchecked exceptions do not.