2 Flashcards
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.
What is the focus of conceptual analysis in UML?
Focus on domain; mapping with code is not strict.
What is the visibility notation for public fields in UML?
+
How is a derived value indicated in UML?
/ (forward slash)
What is the notation for a static field in UML?
Underlined.
What symbol is used to denote aggregation in UML?
◇
What symbol is used to denote composition in UML?
◆
What does the symbol ‘△’ represent in UML?
Inheritance.
What does the symbol ‘⟶’ represent in UML?
Dependency.
What does the notation ‘1, , 1..’ indicate in UML?
Multiplicity.
How do you indicate an interface in UML?
«interface» followed by the name of the interface.
What is the notation for an abstract class in UML?
Italicized class name and italicized abstract methods.
What does the notation ‘balance: double = 0’ signify?
balance is private, of type double, and initialized to zero.
What does the notation ‘books: Book[*]’ indicate?
Multiplicity of books.
Fill in the blank: A class that is dependent on another class in UML is represented by a _______.
◆ (filled diamond)
Fill in the blank: A weak ownership relationship in UML is indicated by a _______.
◇ (hollow diamond)
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.
What is a runtime error in Java?
A runtime error is an error that occurs while the program is executing, after successful compilation.
True or False: Syntax errors are a type of compile-time error.
True
What is an example of a common compile-time error?
Missing semicolon or mismatched parentheses.
What type of error occurs when trying to access an array index that is out of bounds?
Runtime error
In Java, what does the keyword ‘extends’ indicate in a class definition?
It indicates inheritance from a parent class.
What is UML?
UML stands for Unified Modeling Language, used for modeling software systems.
Fill in the blank: In UML, __________ represents a relationship where one class is a part of another class.
Composition
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.
True or False: In UML diagrams, a solid line with a diamond represents aggregation.
True
What is a dependency in UML?
A dependency indicates that one class depends on another class, usually represented with a dashed line.
Which error type occurs due to incorrect data types?
Compile-time error
True or False: An exception is a type of runtime error in Java.
True
What symbol is used to represent inheritance in UML?
A solid line with a closed arrowhead.
What is the purpose of the ‘super’ keyword in Java?
It is used to refer to the superclass of the current object.
Fill in the blank: A __________ error causes the program to crash during execution.
Runtime
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.
What kind of error is caused by dividing by zero in Java?
Runtime error
True or False: In UML, a dashed line indicates a generalization relationship.
False
What is the main characteristic of a class in a composition relationship?
The child class’s lifecycle is tied to the parent class.
Which UML relationship is represented by a line with a filled diamond?
Composition
What is the purpose of exception handling in Java?
To gracefully handle runtime errors and maintain normal program flow.
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.
Fill in the blank: An __________ error is often related to logical mistakes in the code.
Runtime
What does it mean if a class is ‘abstract’ in Java?
It cannot be instantiated and is meant to be subclassed.
What keyword is used to handle exceptions in Java?
try
True or False: You can catch multiple exceptions in a single catch block in Java.
True
What does ‘public class MyClass extends BaseClass’ signify?
MyClass inherits from BaseClass.
What is the outcome of a class that has no main method in Java?
It cannot be executed as a standalone application.
True or False: Compile-time errors can be fixed without running the program.
True
In UML, how is a class that uses another class represented?
With a dashed line indicating a dependency.
What is the purpose of the ‘catch’ block in exception handling?
To handle the exception thrown by the try block.
Fill in the blank: __________ is a relationship where one class contains instances of another class.
Aggregation
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.
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.