Final Exam Information Possible Final Exam Short Answer Items
A Java applet is a Java program that is executed using a Web browser. Usually, the bytecode form of the Java applet is pulled across the Internet from another computer and executed locally. A Java application is a Java program that can stand alone. It does not require a Web browser in order to execute.
High-level languages allow a programmer to express a series of program instructions in English-like terms that are relatively easy to read and use. However, in order to execute, a program must be expressed in a particular computer's machine language, which consists of a series of bits basically unreadable by humans. A high-level language program must be translated into machine language before it can be run.Java bytecode is a low-level representation of a Java source code program. The Java compiler translates the source code into bytecode, which can then be executed using the Java interpreter. The bytecode might be transported across the Web prior to being executed by a Java interpreter that is part of a Web browser.
A variable is a place to store a value. It is the name we give to a memory location. When we refer to the variable name, we are referencing the value stored at the corresponding memory location.
+ operator.
The + operator can be used for arithmetic
addition and for string concatenation.
A Java constant is declared like a variable, except the final
modifier is used. The value of a constant cannot be changed, unlike a
variable whose value can be changed as needed.
Operator precedence determines how an expression gets evaluated. It is a set of rules that establishes which operators get evaluated first and how operators within the same precedence level evaluate.
An infinite loop is a repetition statement that never terminates. Specifically, the body of the loop never causes the condition to become false.
A class is a blueprint of an object. It defines the variables (instance variables, that is) and methods that will be a part of every object that is instantiated from it. But a class reserves no memory space for instance variables. Each object has its own data space, and therefore its own state.
Constructors are special methods in an object that are used to initialize the object when it is instantiated. A constructor has the same name as its class, and it does not return a value.
An actual parameter is the value or variable sent to a method when it is invoked. A formal parameter is the corresponding variable in the definition of the method; it takes on the value of the actual parameter so that it can be used inside the method.
An explicit return statement can be used
to define the value that is returned from a method. The
type of the return value must match the type specified
in the method definition.
Overloaded methods are distinguished by having their own signature, which includes the number, order, and type of the parameters. The return type is not part of the distinguishing signature.
public method
A public method is called a service
method for an object because it can be invoked by the client
of an object and defines a service that the object provides.
private method
A private method is called a support method. It
cannot be invoked from outside the object and is used to support
the activities of other methods in the class.
public variable
A public variable is a variable that can be directly
accessed and modified by the client. This explicitly violates the
concept of encapsulation and therefore should be avoided.
static variable
A static variable is also called a class variable
because there is only copy of it for all objects of the class,
unlike instance variables for which there is a separate copy
for each instantiated object.
static method
A static method is also called a class method
because it can be invoked through the class name, without
explicitly creating an object of that class.
break and
continue statements?
Abreakstatement will terminate the execution of the body of the switch or loop. Acontinuestatement begins the next iteration of the loop in which it is contained.
Whenever a reference is made to a particular array element, the
index operator ensures that the value of the index is greater than
or equal to zero and less than the size of the array. If it is not
within the valid range, an ArrayIndexOutOfBounds
exception is thrown.
An array of objects holds references to the object type specified as the array element. The array of object references and the element objects are instantiated separately.
Vector
as opposed to an array? What are the disadvantages?
AVectorobject can dynamically grow and shrink as needed. A disadvantage of theVectorclass is that it copies a significant amount of data in order to insert and delete elements, and this process is inefficient.
The Java coordinate system is used to reference any drawing surface. The top-left corner represents coordinate (0, 0). The x axis increases to the right and the y axis increases down.
A child class is derived from a parent class using inheritance. The methods and variables of the parent class automatically become a part of the child class, subject to the rules of the visibility modifiers used to declare them.
Because a new class can be derived from an existing one, the characteristics of the parent class can be reused without the error-prone process of copying and modifying code.
A child class may prefer its own definition of a method in favor of the definition provided for it by its parent. In this case, the child overrides the parent's definition with its own.
super reference important to a
child class?
The super reference can be used to call the
parent's constructor, which cannot be invoked directly by name.
Any derivation in a class hierarchy should represent an is-a relationship. That is, the child is a more specific version of the parent. If this relationship does not hold, then inheritance is used improperly.
Polymorphism is the ability for a reference of one class to refer to an object of another. In Java, a reference to a parent class can be used to refer to an object of the child class.
When a child class overrides the definition of a parent's method, two versions of that method exist. If a polymorphic reference is used to invoke the method, the specific version of the method that gets invoked is determined by the type of the object being referred to, not by the type of the reference variable.
A class can be instantiated; an abstract class cannot. Abstract classes often contain abstract methods that do not have implementations.
A class can be instantiated; an interface cannot. A class implements an interface by giving a definition for each method defined in the interface.
An abstract class may have some methods defined. An interface contains no defined methods. Neither can be instantiated. A class can implement many interfaces, but can only be derived from a single abstract class.
An interface is used to define a common set of methods and constants for classes that are often contained in different class hierarchies.
A package is a language construct used for grouping classes with interdependent or similar characteristics. A package can be imported into a program as a unit.
A window is not attached to another container while a panel must be. The user can move a window from one point to another on the screen.
An event is a situation that arises in software, often in response to a user action such as a mouse button click. A program can be written to process and respond to particular events.
A container is a Java component that can contain other components. It is used to organize and display a graphical user interface.
A layout manager controls the format and relative positions of the components in a GUI. Each Java container is governed by a layout manager.
The order in which you put components in containers defines a component hierarchy. Careful planning of the component hierarchy can facilitate high-quality GUI development.
Label instead of a
TextField?
ALabelcannot be modified by the user by typing over it, whereas the contents of aTextFieldcan be modified if it is made editable. If you don't want the user to change a value, you don't even want to hint that there may be a possibility. Using aTextFieldcould give the user the wrong idea.
There are three elements: the GUI with its components presented in a particular manner, the listeners that are ready to respond to events, and the rest of the program code that handles the rest of the processing for your particular application.
There are many GUI components because there are many ways to interact with a system. Some components are particularly well suited to certain types of interactions. It is the challenge of the interface developer to design the user interface for maximum ease and functionality.
Left as an exercise to the reader...
Recursion is the act of defining something in terms of itself. Recursive programming allows a method to call itself, solving a smaller version of the problem each time, until the terminating condition is reached.
See problem 39.
Infinite recursion has no terminating condition or one that is improperly specified. The recursive path is followed forever. In a recursive program, infinite recursion will often result in an error that indicates that available memory has been exhausted.
A base case is always required to terminate recursion and begin the process of returning through the calling hierarchy. Without the base case, infinte recursion would result.
Recursion is not necessary. Every recursive algorithm can be written in an iterative manner. However, many problem solutions are much more elegant and straightforward when written recursively.
Avoid recursion when the iterative solution is simpler and more easily understood. Recursion has the overhead of multiple method calls and is sometimes (altough very rarely) not entirely intuitive.