Java Applications Final(100)

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

False

A catch clause that uses a parameter variable of the Exception type is capable of catching any exception that extends the Error class.(T/F)

True

A class must implement the Serializable interface in order for objects of the class to be serialized. (T/F)

Container

A container is simply a component that holds other components

Content Pane

A content pane is a container that is part of every JFrame object. You cannot see the content pane and it does not have a border, but any component that is to be displayed in a JFrame must be added to its content pane.

Default Method

A default method is an interface method that has a body.

Functional Interface

A functional interface is an interface that has one abstract method. You can use a special type of expression, known as a lambda expression, to create an object that implements a functional interface.

GUI

A graphical window or a system of graphical windows that is presented by an application for interaction with the user. In addition to accepting input from the keyboard, GUIs typically accept input from a mouse as well.

Layout Manager

A layout manager is an object that governs the positions and sizes of components in a container. The layout manager automatically repositions and, in some cases, resizes the components when the container is resized. (JPanel panel = new JPanel(); panel.setLayout(new BorderLayout());)

overloading

A method in a subclass having the same name as a method in the superclass but a different signature is an example of

overriding

A method in a subclass that has the same signature as a method in the superclass is an example of

Panel

A panel is also a container that can hold GUI components. Unlike JFrame objects, panels cannot be displayed by themselves; however, they are commonly used to hold and organize collections of related components. With Swing, you create panels with the JPanel class

private

A subclass does not have access to these superclass members

Overriding

A subclass may have a method with the same signature as a superclass method. In such a case, the subclass method overrides the superclass method. Also In order for overriding to occur, the subclass method must have the same signature as the superclass method

Inheritance Chain

A superclass can also inherit from another class.

Polymorphism

A superclass reference variable can reference objects of a subclass. In Java, a reference variable is this because it can reference objects of types different from its own, as long as those types are subclasses of its type.

Abstract Class UML

Abstract classes are drawn like regular classes in UML, except the name of the class and the names of abstract methods are shown in italics.

overridden

Abstract methods must be

ButtonGroup

Adding radio button components to this type of object creates a mutually exclusive relationship between them.

Object

All classes directly or indirectly inherit from this class.

Throwable

All exception classes inherit from this class.

checked exceptions

All exceptions that do not inherit from the Error class or the RuntimeException class are __________.

False

All methods in an abstract class must also be declared abstract. T/F

Inheritance

Allows a new class to extend an existing class. The new class inherits the members of the class it extends.

Differences

Although overloaded methods have the same name, they have different signatures. When a method overrides another method, however, they both have the same signature. Also: When a subclass overloads a superclass method, both methods may be called with a subclass object. However, when a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object.

Abstract Class

An abstract class is not instantiated, but other classes extend it. An abstract method has no body and must be overridden in a subclass. Ex: AccessSpecifier abstract ReturnType MethodName(ParameterList);

True

An abstract class is not instantiated, but serves as a superclass for other classes. T/F

Inner class

An inner class is a class that is defined inside another class. An anonymous inner class is an inner class that has no name. An anonymous inner class must implement an interface, or extend another class.

Interface

An interface specifies behavior for a class. An interface cannot be instantiated. Instead, it is implemented by other classes. When a class implements an interface, the class must override the methods that are specified by the interface. All interfaced methods are public.

exception

An object that is generated as the result of an error or an unexpected event.

GridLayout

Arranges components in a grid with rows and columns

BorderLayout

Arranges components in five regions: north, south, east, west, and center; this is the default layout manager for a JFrame object's content pane

FlowLayout

Arranges components in rows; this is the default layout manager for JPanel objects

True

Beginning in Java 7, multi-catch can reduce a lot of duplicated code in a try statement that needs to catch multiple exceptions, but perform the same operation for each one. (T/F)

True

Check boxes may be grouped in a ButtonGroup, like radio buttons are. (True or False)

center

Components in this/these regions of a BorderLayout manager are resized both horizontally and vertically so they fill up the entire region.

north and south

Components in this/these regions of a BorderLayout manager are resized horizontally so they fill up the entire region.

east and west

Components in this/these regions of a BorderLayout manager are resized vertically so they fill up the entire region.

True

Every class has a toString method and an equals method inherited from the Object class. T/F

True

Every class is either directly or indirectly derived from the Object class. T/F

final and static

Fields in an interface are

IOException

FileNotFoundException inherits from

Outputstream

FileOutputStream - allows you to open a file for writing binary data. It provides only basic functionality for writing bytes to the file. DataOutputStream - allows you to write data of any primitive type or String objects to a binary file. Cannot directly access a file. It is used in conjunction with a FileOutputStream object that has a connection to a file. FileOutputStream fstream = new FileOutputStream("MyInfo.dat"); DataOutputStream outputFile = new DataOutputStream(fstream);

Superclass

General Class of the Program

center

If a container is governed by a BorderLayout manager and you add a component to it, but you do not pass the second argument specifying the region, this is the region in which the component will be added.

False

If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method. T/F

True

If the class SerializedClass contains references to objects of other classes as fields, those classes must also implement the Serializable interface in order to be serialized. (T/F)

False

If two methods in the same class have the same name but different signatures, the second overrides the first. T/F

Package Access

If you do not provide an access specifier for a class member, the class member is given package access by default.

default exception handler

If your code does not handle an exception when it is thrown. The default exception handler prints an error message and crashes the program.

default exception handler

If your code does not handle an exception when it is thrown, it is dealt with by this.

RadioButtons

Implements ActionListener

CheckBoxes

Implements ItemListener

Frame

In GUI terminology, a container that can be displayed as a window is known as a frame. A frame appears as a basic window that has a border around it, a title bar, and a set of buttons for minimizing, maximizing, and closing the window. In a Swing application, you create a frame object from the JFrame class.

Interface in UML

In a UML diagram, an interface is drawn like a class, except the interface name and the method names are italicized, and the <<interface>> tag is shown above the interface name. The relationship between a class and an interface is known as a realization relationship (the class realizes the interfaces). You show a realization relationship in a UML diagram by connecting a class and an interface with a dashed line that has an open arrowhead at one end. The arrowhead points to the interface.

first

In a subclass constructor, a call to the superclass constructor must appear

False

In an inheritance relationship, the subclass constructor always executes before the superclass constructor. T/F

Inheritance Relationship

In an inheritance relationship, the subclass inherits members from the superclass, not the other way around. This means it is not possible for a superclass to call a subclass's method.

Superclass Constructor

In an inheritance relationship, the superclass constructor always executes before the subclass constructor. If a superclass has either (a) a default constructor or (b) a no-arg constructor that was written into the class, then that constructor will be automatically called just before a subclass constructor executes.

superclass

In an inheritance relationship, this is the general class.

subclass

In an inheritance relationship, this is the specialized class.

True

In versions of Java prior to Java 7, each catch clause can handle only one type of exception. (T/F)

False

Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class. T/F

True

It is not possible for a superclass to call a subclass's method. T/F

Dynamic Binding

Java performs dynamic binding or late binding when a variable contains a polymorphic reference. This means that the Java Virtual Machine determines at runtime which method to call, depending on the type of object that the variable references. So, it is the object's type that determines which method is called, not the variable's type.

Background and Foreground

Many of the Swing component classes have methods named setBackground and setForeground. You call these methods to change a component's color. The background color is the color of the component itself, and the foreground color is the color of text that might be displayed on the component. The argument that you pass to the setBackground and setForeground methods is a color code. (EX: Color.BLACK)

Hiearchy

Object Throwable Exception RuntimeException IllegalArgumentException NumberFormatException

PrintWriter

One of the classes that can be used to create a text file and write data to it. EX: PrintWriter output = new PrintWriter("Test.txt"); output.println("Testing to write to this file"); output.close();

Tier

Presentation Tier, Logic tier, Data Tier

Private

Private members of the superclass cannot be accessed by the subclass, so technically speaking, they are not inherited. Only methods in the superclass can access them.

True

Private members of the superclass cannot be accessed by the subclass. T/F

Limitations

Programmers are limited in what they can do with the AWT classes, however. the AWT classes communicate with another layer of software, known as the peer classes, which directs the underlying operating system to draw its own built-in components. Each version of Java that is developed for a particular operating system has its own set of peer classes. Although this means that Java programs have a look that is consistent with other applications on the same system, it also leads to some problems. - One problem for example is that not all operating systems offer the same set of GUI components -Another problem is in the behavior of components across various operating systems. -A third problem is that programmers cannot easily customize the AWT components.

Event Driven

Programs that operate in a GUI environment must be event-driven An event is an action that takes place within a program, such as the clicking of a button.

Protected

Protected members of a class may be accessed by methods in a subclass, and by methods in the same package as the class. Protected class members may be denoted in a UML diagram with the # symbol.

Class Header

Public Class (SubClass) Extends (SuperClass)

Scanner

Reading data from a file is similar to reading data from the console. A Scanner object can be used to read data from a text file. EX: public class ReadFile { public static void main(String[] args) throws IOException { File file = new File("Test.txt"); Scanner inputFile = new Scanner(file); while (inputFile.hasNext()) { System.out.println(inputFile.nextLine()); } inputFile.close(); } }

Inputstream

Reads Data from a binary file FileInputStream fstream = new FileInputStream("Numbers.dat"); DataInputStream inputFile = new DataInputStream(fstream);

Subclass

Specialized class. Extended version of Superclass. Inherits fields and methods from Superclass without any of them having to be rewritten. New Fields and methods may also be added to this class

AWT

The Abstract Windowing Toolkit (AWT). The AWT allows programmers to create applications and applets that interact with the user via windows and other GUI components.

Graphics

The Graphics class includes the methods for drawing shapes.Each GUI component has an associated Graphics object. To be able to draw on any GUI component the program must get a reference to the component's Graphics object. To achieve this, you have to override either the paint method or the paintComponent method of the GUI component. If it is a frame or an applet that you are trying to draw on, paint method must be overridden, if it is any type of JComponent such as a JPanel, paintComponent must be overridden.

Object

The Java API has a class named Object, which all other classes directly or indirectly inherit from. Two of the most useful methods are the toString and equals methods which comes from the Object Class.

True

The ability to display splash screens was introduced in Java 6.

True

The call stack is an internal list of all the methods that are currently executing. (T/F)

event source

The component that generated the event object

rows

The data that are stored in a table are organized in

columns

The datum that is stored in a row is divided into

super

The following is an explicit call to the superclass's default constructor

Hiearchy

The more general classes are toward the top of the family tree and the more specialized classes are toward the bottom.

NumberFormatException

The numeric wrapper classes "parse" methods all throw an exception of this type.

Guidelines

The super statement that calls the superclass constructor may be written only in the subclass's constructor. You cannot call the superclass constructor from any other method. • The super statement that calls the superclass constructor must be the first statement in the subclass's constructor. This is because the superclass's constructor must execute before the code in the subclass's constructor executes. • If a subclass constructor does not explicitly call a superclass constructor, Java will automatically call the superclass's default constructor, or no-arg constructor.

Constructor Issues

The superclass constructor always executes before the subclass constructor. • You can write a super statement that calls a superclass constructor, but only in the subclass's constructor. You cannot call the superclass constructor from any other method. • If a super statement that calls a superclass constructor appears in a subclass constructor, it must be the first statement. • If a subclass constructor does not explicitly call a superclass constructor, Java will automatically call super() just before the code in the subclass's constructor executes. • If a superclass does not have a default constructor and does not have a no-arg constructor, then a class that inherits from it must call one of the constructors that the superclass does have.

False

The throw statement informs the compiler that a method throws one or more exception. (T/F)

False

The throws clause causes an exception to be thrown. (T/F)

Requirement

There is a special requirement that all event listener classes must meet: They must implement an interface.

instanceof

There is an operator in Java named instanceof that you can use to determine whether an object is an instance of a particular class. EX: refVar instanceof ClassName

unchecked exceptions

These are exceptions that inherit from the Error class or the RuntimeException class.

Superclass Constructor 1

These are not inherited as their purpose is to construct objects of the superclass.

Swing

These components have a consistent look and predictable behavior on any operating system

protected

These superclass members are accessible to subclasses and classes in the same package.

DROP

This SQL statement is used to delete an entire table.

INSERT

This SQL statement is used to insert rows into a table

DELETE

This SQL statement is used to remove rows from a table

WHERE

This clause allows you to specify a search criteria with the SELECT statement.

ResultSet

This contains the results of an SQL SELECT statement

throws clause

This informs the compiler of the exceptions that could get thrown from a method.

Flowlayout

This is a JPanel object's default layout manager.

JDBC Driver

This is a Java class that is designed to communicate with a specific DBMS

primary key

This is a column that holds a unique value for each row and can be used to identify specific rows.

exception handler

This is a section of code that gracefully responds to exceptions

Database URL

This is a string listing the protocol that should be used to access a database, the name of the database, and potentially other items.

call stack

This is an internal list of all the methods that are currently executing.

None

This is the default alignment of a FlowLayout manager.

Borderlayout

This is the default layout manager for a JFrame object's content pane.

Content Pane

This is the part of a JFrame object that holds the components that have been added to the JFrame object.

Serialization

This is the process of converting an object to a series of bytes that represent the object's data.

SQL

This is the standard language for working with database management systems.

JDBC

This is the technology that makes it possible for a Java application to communicate with a DBMS

extends

This key word indicates that a class inherits from another class.

super

This key word refers to an object's superclass.

Super

This key word refers to an object's superclass. You can use the super key word to call a superclass constructor.

getMessage

This method can be used to retrieve the error message from an exception object.

printStackTrace

This method may be called from any exception object, and it shows the chain of methods that were called when the exception was thrown.

instanceof

This operator can be used to determine whether a reference variable references an object of a particular class

SELECT

This type of SQL statement is used to retrieve rows from a table

Swing

To remedy these problems, Swing was introduced with the release of Java 2. Swing is a library of classes that do not replace the AWT, but provide an improved alternative for creating GUI applications and applets. Very few of the Swing classes rely on an underlying system of peer classes. Instead, Swing draws most of its own components on the screen. This means that Swing components can have a consistent look and predictable behavior on any operating system.

False

True or False: The FlowLayout manager does not allow the programmer to align components.

False

True or False: A GUI program automatically stops executing when the end of the main method is reached.

False

True or False: A class may only implement one interface.

True

True or False: A common technique for writing an event listener class is to write it as a private inner class inside the class that creates the GUI.

False

True or False: A component placed in a GridLayout manager's cell will not be resized to fill up any extra space in the cell

True

True or False: A panel cannot be displayed by itself.

False

True or False: A subclass reference variable can reference an object of the superclass.

False

True or False: A superclass has a member with package access. A class that is outside the superclass's package but inherits from the superclass can access the member.

True

True or False: A superclass reference variable can reference an object of a subclass that extends the superclass.

False

True or False: All operating systems offer the same set of GUI components.

False

True or False: An object of a superclass can access members declared in a subclass.

True

True or False: By default all members of an interface are public.

True

True or False: Constructors are not inherited.

False

True or False: Default layout manager for a JPanel is the BorderLayout

False

True or False: IOException serves as a superclass for exceptions that are related to programming errors, such as an out-of-bounds array subscript.

False

True or False: If a subclass constructor does not explicitly call a superclass constructor, Java will not call any of the superclass's constructors.

True

True or False: In a subclass, a call to the superclass constructor can only be written in the subclass constructor.

True

True or False: Not including polymorphic references, a try statement may have only one catch clause for each specific type of exception.

True

True or False: Some of the common GUI components are buttons, labels, text fields, check boxes, and radio buttons

False

True or False: Suppose you add the same button three times into a container, there will be three buttons

True

True or False: The ActionEvent argument that is passed to an action listener's actionPerformed method is the event object that was generated in response to an event.

True

True or False: The System.exit method will end the application.

True

True or False: The superclass constructor always executes before the subclass constructor.

False

True or False: The throws clause causes an exception to be thrown.

True

True or False: The visible property of a JButton object is true by default.

True

True or False: When a class contains an abstract method, the class cannot be instantiated

False

True or False: When a method is declared with the final modifier, it must be overridden in a subclass.

False

True or False: When an exception is thrown by code inside a try block, all of the statements in the try block are always executed.

True

True or False: When an exception is thrown, the JVM searches the try statement's catch clauses from top to bottom and passes control of the program to the first catch clause with a parameter that is compatible with the exception.

False

True or False: When in the same try statement you are handling multiple exceptions and some of the exceptions are related to each other through inheritance, you should handle the more general exception classes before the more specialized exception classes.

True

True or False: You are not required to catch exceptions that inherit from the RuntimeException class.

True

True or False: You can place a panel inside a region governed by a BorderLayout manager.

True

True or False: You can place multiple components inside a BorderLayout region.

True

True or False: You can place multiple components inside a GridLayout cell.

True

True or False: You can place multiple components inside a container governed by a FlowLayout manager

True

True or False: You can write a class that extends the JPanel class.

False

True or False: You cannot have more than one catch clause per try statement.

GridLayout

What layout manager should you use so that every component occupies the same size?

Contract

When a class implements an interface, it is agreeing to provide all of the methods that are specified by the interface. It is often said that an interface is like a "contract," and when a class implements an interface it must adhere to the contract.

Final

When a method is declared with the final modifier, it cannot be overridden in a subclass. If a subclass attempts to override a final method, the compiler generates an error. This technique can be used to make sure that a particular superclass method is used by subclasses and not a modified version of it.

False

When a splash screen is displayed, the application does not load and execute until the user clicks the splash screen image with the mouse. (True or False)

True

When a subclass extends a superclass, the public members of the superclass become public members of the subclass. T/F

Thrown

When an exception is generated, it is said to have been ____________

True

When an exception is thrown by a method that is executing under several layers of method calls, a stack trace indicates the method executing when an exception occurred and all of the methods that were called in order to execute that method. (T/F)

False

When an interface variable references an object, you can use the interface variable to call any and all of the methods in the class implementing the interface. T/F

True

When an object is serialized, it is converted into a series of bytes that contain the object's data. (T/F)

True

When deserializing an object using the readObject method, you must cast the return value to the desired class type. (T/F)

True

When the code in a try block may throw more than one type of exception, you need to write a catch clause for each type of exception that could potentially be thrown. (T/F)

FlowLayout

Which layout does not resize a button in the container it controls?

JFrame

With Swing, you use this class to create a frame.

dynamic

With this type of binding, the Java Virtual Machine determines at runtime which method to call, depending on the type of the object that a variable references.

try block

You can think of this code as being "protected" because the application will not halt if it throws an exception.

Throwing Exceptions

You can write code that throws one of the standard Java exceptions, or an instance of a custom exception class that you have designed.

False

You must use the statement import java.swing.*; in order to use the ItemListener interface. (True or False)

Inheritance in UML

You show inheritance in a UML diagram by connecting two classes with a line that has an open arrowhead at one end. The arrowhead points to the superclass.

BorderFactory

You use this class to create Border objects.

throw

You use this statement to throw an exception manually.

is a relationship

a relationship that exists between objects, it means that the specialized object has all of the characteristics of the general object, plus additional characteristics that make it special. Ex: allows you to extend the capabilities of a class by creating another class that is a specialized version of it.

exception handler

a section of code that gracefully responds to exceptions when they are thrown.

RuntimeException

a superclass for exceptions that result from programming errors, such as an out-of-bounds array subscript.

IOException

a superclass for exceptions that are related to input and output operations

Event listener

an object that automatically executes one of its methods when a specific event occurs. If you wish for an application to perform an operation when a particular event occurs, you must create an event listener object that responds when that event takes place.

LIKE

can be used to search for a substring

event object

contains information about the event

finally

one or more statements that are always executed after the try block has executed and after any catch blocks have executed if an exception was thrown.

Components

present data to the user and/or allow interaction with the application. (EX: buttons, labels, text fields, check boxes, and radio buttons)

exception handling

process of intercepting and responding to exceptions

database management system

software that manages large collections of data.

Abstract Methods and Classes

• Abstract methods and abstract classes are defined with the abstract key word. • Abstract methods have no body, and their header must end with a semicolon. • An abstract method must be overridden in a subclass. • When a class contains an abstract method, it cannot be instantiated. It must serve as a superclass. • An abstract class cannot be instantiated. It must serve as a superclass.


Kaugnay na mga set ng pag-aaral

Test 4: Chapters 6,7,8 (Macro Economics)

View Set

Act cH4 + subject verb agreement

View Set

Care & Prevention of Athletic Injury Quiz 2

View Set

Genetics Chapter 1: Overview of Genetics

View Set