2 Flashcards
(74 cards)
What is event handling in Java?
User interaction with frames involves handling events.
Give examples of user events in Java.
- Clicking a button
- Typing in a text field
- Dragging the mouse along an area in the frame
How are events handled in Java?
Events are handled through listeners.
What must a button object be associated with to program functionality?
A listener.
What is ActionListener in Java?
An interface in the java.awt.event.* library for handling button actions.
What is an inner class?
A class defined within a class, useful for accessing data within the containing class.
What is the benefit of using an inner class as a listener?
Listeners need to access frame components.
What is the first option for handling multiple buttons in Java?
Create a different listener class for each button.
What is the second option for handling multiple buttons?
Use a single listener class for all buttons with different responses.
What is the third option for handling multiple buttons?
Create an inner class that implements ActionListener with a constructor that accepts parameters.
What are compile-time errors?
Errors detected by the compiler before the program runs, preventing successful compilation.
List some causes of compile-time errors.
- 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
What are runtime errors?
Errors that occur while the program is running, causing crashes or unexpected behavior.
List some causes of runtime errors.
- Dividing by zero
- Accessing an invalid array index
- Null references
- File not found
- Illegal operations
- OutOfMemoryError
- StackOverflowError
- NoSuchMethodFoundError
- ClassNotFoundException
What is a logic error?
A mistake made by the author that is syntactically correct but leads to unexpected program behavior.
What is UML?
Unified Modeling Language, a notation system for object-oriented analysis and design.
What type of diagrams do we focus on in UML for Java applications?
Class diagrams to describe classes and their relationships.
What does a hollow arrowhead represent in UML?
Inheritance.
What does a hollow diamond denote in UML?
Aggregation.
What does a straight line represent in UML?
Bi-directional navigability.
What is the difference between aggregation and composition?
- Aggregation: parts may be independent of the whole
- Composition: parts are created and destroyed with the whole
What does cardinality specify in UML?
The number of objects that may be associated with an object of another class.
What does uni-directional navigability look like in UML?
An open arrowhead.
What is dependency in UML?
Some classes use other classes but are not related in previously discussed ways.