EXAM Flashcards
An interface is a class that includes:
Abstract public methods and constant values
Interfaces hold values by default how?
Public, static, final
What are the two main uses of interfaces in Java?
1) Implementing a common function throughout many classes
2) Simulate multiple inheritance
What keyword is used when a class uses an interface?
implements
If a method has a code block in an interface, what keyword is used?
default
Do you have to override a default method from an interface?
No
What kind of inheritance does Java use?
Single inheritance
Can you instantiate an object of an interface class?
No
What is a functional interface?
An interface with only one abstract method
What is an exception?
An object that signals an error
What is a major benefit of using exceptions for errors?
Separates the code for errors from the code while running smoothly
Why should exceptions only be used for unusual or catastrophic events?
Exceptions involve a lot of overhead, potentially reducing performance dramatically.
What does a catch block use as a parameter?
An exception object
What are the 4 categories of exceptions?
1) Code or Data Errors
2) Standard Method Exceptions
3) Throwing your own exceptions
4) Java errors
What are all exceptions a subclass of?
Throwable
What are the 2 subclasses of Throwable?
1) Error
2) Exception
Unchecked exceptions are from which class?
The Runtime Class (Error class too)
What are some common runtime exceptions?
ArithmeticException, IndexOutOfBounds, NullPointer
What are the 2 ways to deal with checked exceptions?
1) Confess using “throws” keyword in header
2) try-catch blocks
What block of code is always executed regardless of exceptions?
finally block
What is important to remember when writing multiple catch blocks?
Order matters. The most abstract (least specific) should be at the bottom.
What are 3 useful methods held in Throwable class?
getMessage()
printStackTrace()
printStackTrace(printStream e)
When defining your own exception class, what class must be a superclass?
Throwable
What is the best class to extend your own exception classes from?
Exception
What kind of programs are GUIs?
Event-Driven Programs
What is meant by “heavyweight” when referirng to GUI?
Depend heavily on OS
What did Swing improve upon from the original Java AWT GUI components?
Lightweight (less OS involvement), more powerful
What is AWT?
Abstract Windows Toolkit
What is a container object?
An object to hold other GUI components
What are 3 examples of container objects?
1) Window
2) Frame
3) Panel
How do you set a JFrame’s position in the middle?
setLocationRelativeTo(null);
Which container comes with a title?
JFrame
What should be the final method in your boilerplate code?
setVisible(true)
What is the most common layout manager?
FlowLayout
What is the default layout manager for JFrame?
BorderLayout
What is the Event Delegation Model?
The responsibility for handling events is given to an object other than the one that produced the event
What is an event?
An object created when a user interacts with something, like a button in a GUI
What kind of event does a JButton create?
ActionEvent
What is the mother of all classes in JavaFX?
Application Class
What is the top level container class in JavaFX?
Stage Class
Which class in JavaFX is analogous to a JFrame in Swing?
Stage class
Which sub-container typically gets added to a stage container?
Scene
What method provides the Stage object?
launch()
What code is needed in main to start a GUI in JavaFX?
launch()
What are individual elements like TextFields and Buttons called in JavaFX?
Nodes
What is a node without a child called?
Terminal node (or leaves)
What is a scene graph?
The collection of all the nodes
What is a root node?
The top-level node
What are the 3 life-cycle methods provided by the application class?
- init()
- start()
- stop()
What method is analogous to the JFrame constructor method in JavaFx?
start(Stage primaryStage)
What are the two types of MouseEvent listeners?
- MouseListener
2. MouseMotionListener
What are 3 different kinds of event objects?
ActionEvent, ChangeEvent, ItemEvent