2 Flashcards

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
Q

What is the focus of conceptual analysis in UML?

A

Focus on domain; mapping with code is not strict.

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

What is the visibility notation for public fields in UML?

A

+

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

How is a derived value indicated in UML?

A

/ (forward slash)

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

What is the notation for a static field in UML?

A

Underlined.

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

What symbol is used to denote aggregation in UML?

A

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

What symbol is used to denote composition in UML?

31
Q

What does the symbol ‘△’ represent in UML?

A

Inheritance.

32
Q

What does the symbol ‘⟶’ represent in UML?

A

Dependency.

33
Q

What does the notation ‘1, , 1..’ indicate in UML?

A

Multiplicity.

34
Q

How do you indicate an interface in UML?

A

«interface» followed by the name of the interface.

35
Q

What is the notation for an abstract class in UML?

A

Italicized class name and italicized abstract methods.

36
Q

What does the notation ‘balance: double = 0’ signify?

A

balance is private, of type double, and initialized to zero.

37
Q

What does the notation ‘books: Book[*]’ indicate?

A

Multiplicity of books.

38
Q

Fill in the blank: A class that is dependent on another class in UML is represented by a _______.

A

◆ (filled diamond)

39
Q

Fill in the blank: A weak ownership relationship in UML is indicated by a _______.

A

◇ (hollow diamond)

40
Q

What is a compile-time error in Java?

A

A compile-time error is an error that occurs during the compilation of the code, preventing it from being successfully compiled.

41
Q

What is a runtime error in Java?

A

A runtime error is an error that occurs while the program is executing, after successful compilation.

42
Q

True or False: Syntax errors are a type of compile-time error.

43
Q

What is an example of a common compile-time error?

A

Missing semicolon or mismatched parentheses.

44
Q

What type of error occurs when trying to access an array index that is out of bounds?

A

Runtime error

45
Q

In Java, what does the keyword ‘extends’ indicate in a class definition?

A

It indicates inheritance from a parent class.

46
Q

What is UML?

A

UML stands for Unified Modeling Language, used for modeling software systems.

47
Q

Fill in the blank: In UML, __________ represents a relationship where one class is a part of another class.

A

Composition

48
Q

What is the difference between aggregation and composition in UML?

A

Aggregation represents a ‘has-a’ relationship with independent lifecycle, while composition is a stronger relationship where the child cannot exist without the parent.

49
Q

True or False: In UML diagrams, a solid line with a diamond represents aggregation.

50
Q

What is a dependency in UML?

A

A dependency indicates that one class depends on another class, usually represented with a dashed line.

51
Q

Which error type occurs due to incorrect data types?

A

Compile-time error

52
Q

True or False: An exception is a type of runtime error in Java.

53
Q

What symbol is used to represent inheritance in UML?

A

A solid line with a closed arrowhead.

54
Q

What is the purpose of the ‘super’ keyword in Java?

A

It is used to refer to the superclass of the current object.

55
Q

Fill in the blank: A __________ error causes the program to crash during execution.

56
Q

What does it mean when a method is declared with ‘throws Exception’?

A

It indicates that the method may throw an exception that must be handled.

57
Q

What kind of error is caused by dividing by zero in Java?

A

Runtime error

58
Q

True or False: In UML, a dashed line indicates a generalization relationship.

59
Q

What is the main characteristic of a class in a composition relationship?

A

The child class’s lifecycle is tied to the parent class.

60
Q

Which UML relationship is represented by a line with a filled diamond?

A

Composition

61
Q

What is the purpose of exception handling in Java?

A

To gracefully handle runtime errors and maintain normal program flow.

62
Q

What are unchecked exceptions in Java?

A

Exceptions that do not need to be declared in a method’s throws clause and can occur at runtime.

63
Q

Fill in the blank: An __________ error is often related to logical mistakes in the code.

64
Q

What does it mean if a class is ‘abstract’ in Java?

A

It cannot be instantiated and is meant to be subclassed.

65
Q

What keyword is used to handle exceptions in Java?

66
Q

True or False: You can catch multiple exceptions in a single catch block in Java.

67
Q

What does ‘public class MyClass extends BaseClass’ signify?

A

MyClass inherits from BaseClass.

68
Q

What is the outcome of a class that has no main method in Java?

A

It cannot be executed as a standalone application.

69
Q

True or False: Compile-time errors can be fixed without running the program.

70
Q

In UML, how is a class that uses another class represented?

A

With a dashed line indicating a dependency.

71
Q

What is the purpose of the ‘catch’ block in exception handling?

A

To handle the exception thrown by the try block.

72
Q

Fill in the blank: __________ is a relationship where one class contains instances of another class.

A

Aggregation

73
Q

What does the ‘finally’ block do in Java exception handling?

A

It executes code after the try and catch blocks, regardless of whether an exception was thrown.

74
Q

What is the main difference between a checked exception and an unchecked exception?

A

Checked exceptions must be declared or handled, while unchecked exceptions do not.