Sun认证Java 2程序员学习指南(Exam 310-025) 第二版(影印本)

来源:互联网 发布:正规淘宝客服要交钱吗? 编辑:程序博客网 时间:2024/04/28 16:30

clip_image002[4]clip_image002

Abstract class An abstract class is a type of class that is not allowed to be instantiated. The only reason it exists is to be extended. Abstract classes contain methods and variables common to all the subclasses, but the abstract class itself is of a type that will not be used directly.

Abstract method An abstract method is a method declaration that contains no functional code. The reason for using an abstract method is to ensure that subclasses of this class will include this method. Any concrete class (that is, a class that is not abstract, and therefore capable of being instantiated) must override this method.

Access modifier An access modifier is a modifier that changes the protection of an element.

Adapter classes Adapter classes are provided to help the programmer develop classes that implement the event interfaces. Also, adapter classes are classes that implement a particular listener interface with empty methods. This means that you can subclass an adapter and then override only the methods that you are interested in.

Anonymous class You use an anonymous class when you want to create and use a class but do not want to bother with giving it a name or using it again.

Anonymous inner classes Anonymous inner classes are local inner classes that do not have a class name. Using anonymous inner classes is most effective when they are small and implement only a single or very few small methods.

API Application Programmers Interface. This term refers to a set of related classes and methods that work together to provide a particular capability.

Array Arrays are homogenous data structures implemented in Java as objects. Arrays store one or more of a specific type and provide indexed access to the store.

Automatic variables Also called method local variables. Automatic variables are variables that are declared within a method and discarded when the method has completed.

AWT The AWT is Java’s Abstract Windowing Toolkit. This is a platform independent API that provides a user interface capability.

Base class A Base class is a class that has been extended. If class d extends class b, class b is the base class of class d.

Blocked state A thread that is waiting for a resource, such as a lock, to become available is said to be in a blocked state. Blocked threads consume no processor resources.

Boolean literals Boolean literals are the source code representation for Boolean values. Boolean values can only be defined as either true or false.

BorderLayout layout manager The BorderLayout layout manager divides the container into five areas. These areas are NORTH, SOUTH, EAST, WEST, and CENTER. The name of the area indicates where the component will be placed. All directional references are relative to the top of the container, which is considered NORTH.

Call stack A call stack is a list of methods that have been called in the order in which they were called. Typically, the most recently called method (the current method) is thought of as being at the bottom of the call stack.

CardLayout layout manager The CardLayout layout manager treats each contained component as a card, with only one card being visible at any given time. Whichever component was added first will be visible first when the container is displayed.

Casting Casting is the conversion of one type to another type. Typically, casting is used to convert an object reference to either a supertype or a subtype, but casting can also be used on primitive types.

char A char is a primitive data type that holds a single character.

Character literals Character literals are represented by a single character in single quotes, such as ‘A’.

Child class See Derived class.

Class A class is the definition of a type. Classes describe an entity’s public interface. See also Base class; Derived class; Inner classes.

Class constructors Class constructors are able to call overloaded constructors both in their class and in their superclass. To call another constructor in the same class, you can place a this() in the first line of the body in the calling constructor. Placing this() in any other place will result in a compiler error.

Class members Class members are variables defined at the class level. These include both instance variables and class (static) variables.

Class methods A class method, often referred to as a static method, may be accessed directly from a class, without instantiating the class first.

Class variable See Static variable.

Collection A collection is an object used to store other objects. Collections are also commonly referred to as containers. Two common examples of collections are Hashtables and Vectors.

Collection interface The collection interface defines the public interface that is common to all collection classes.

Collections framework Three elements (interfaces, implementations, and algorithms) create what is known as the collections framework.

Command string The command string contains data about the source or cause of an event. An action event that is the result of a Button being activated contains the Button’s text. An action event that is the result of the ENTER key being pressed in a TextField component returns the entered text. Similarly, the text that represents a MenuItem or item in a list component is returned when a MenuItem or List is the source of the action event.

Comparison operators Comparison operators perform a comparison on two parameters and return a Boolean value indicating if the comparison is true. For example, the comparison 2<4 will result in true while the comparison 4==7 will result in false.

Components Components are the base class and provide functionality for defining the appearance of the widget, the response (if any) to various events, and, finally, the instructions on how to render itself. A component generates a ComponentEvent when the component’s size, position, or visibility has changed. ComponentEvents are for notification purposes only.

Conditional operators Conditional operators are used to evaluate Boolean expressions, much like if statements, except instead of executing a block of code, a conditional operator will assign a value to a variable.

Constructor A method of a class that is called when the object is created, or instantiated. Typically, constructors initialize data members and acquire whatever resources the object may require.

Container components A container component, such as Panel, generates a ContainerEvent as a result of a child component being added or removed from the container. ContainerEvents are for notification purposes only. The AWT automatically handles changes to the contents of a container component internally.

Containers Containers are specialized components that hold other components. Because containers themselves are components, you can nest containers to achieve a desired layout. In this context, containers are part of the AWT.

Continue statement The continue statement causes the current iteration of the innermost loop to cease and the next iteration of the same loop to start if the condition of the loop is met. In the case of using a continue statement with a for loop, you need to consider the effects that the continue has on the loop iterator.

Deadlock Also called deadly embrace. Threads sometimes block while waiting to get a lock. It is easy to get into a situation where one thread has a lock and wants another lock that is currently owned by another thread that wants the first lock. Deadlock is one of those problems that are difficult to cure, especially because things just stop happening and there are no friendly exception stack traces to study. They might be difficult, or even impossible, to replicate because they always depend on what many threads may be doing at a particular moment in time.

Deadly embrace See Deadlock.

Decision statement The if and switch statements are commonly referred to as decision statements. When you use decision statements in your program, you are asking the program to calculate a given expression to determine which course of action is required.

Declaration A declaration is a statement that declares a class, interface, method, package, or variable in a source file. A declaration can also initialize the variable, although for class members this is normally done in the constructor method.

Default access A class with default access needs no modifier preceding it in the declaration. Default access allows other classes within the same package to have visibility to this class.

Derived class A derived class is a class that extends another class. If class d extends class b, then class d “derives” from class b and is a derived class.

Do-while loop The do-while loop is slightly different from the while statement in that the program execution cycle will always perform the commands in the body of a do-while at least once. It does adhere to the rule that you do not need brackets around the body if it is just one line of code.

Encapsulation Encapsulation is the process of grouping methods and data together and hiding them behind a public interface. A class encapsulates methods and the data they operate on.

Event classes All event classes defined in the java.awt.event package are subclasses of java.awt.AWTEvent, which is itself a subclass of java.util.EventObject.

Event objects An event object embodies information related to a particular type of event. At a minimum, an event object contains a reference to the object that caused the event (the event source). Usually, the event object also contains other data such as mouse position or a timestamp.

Event sources An event source is a component or object that generates events. Event sources create event objects and deliver them to event listeners. An event source does not have to subclass any specific class or implement any specific interface. Additionally, an object can act as the source of multiple event types, provided that it fulfills the preceding responsibilities for each type.

Event types An event type is used to distinguish between events that share the same class but have a different purpose.

Exception Exception has two common meanings in Java. First, an Exception is an object type. Second, an exception is shorthand for “exceptional condition,” which is an occurrence that alters the normal flow of an application.

Exception handling Exception handling allows developers to easily detect errors without writing special code to test return values. Better, it lets us handle these errors in code that is nicely separated from the code that generated them and handle an entire class of errors with the same code, and it allows us to let a method defer handling its errors to a previously called method. Exception handling works by transferring execution of a program to an exception handler when an error, or exception, occurs.

Extensibility Extensibility is a term that describes a design or code that can easily be enhanced without being rewritten.

Final class The final keyword restricts a class from being extended by another class. If you try to extend a final class, the Java compiler will give an error.

Final variables The final keyword makes it impossible to reinitialize a variable once it has been declared. For primitives, this means the value may not be altered once it is initialized. For objects, the data within the object may be modified, but the reference variable may not be changed. Final variables must be initialized in the same line in which they are declared.

Finalizer Every class has a special method, called a finalizer, which is called just before an object is reclaimed by the Java VM garbage collector. The JVM calls the finalizer for you as appropriate; you never call a finalizer directly. Think of the finalizer as a friendly warning from the virtual machine. Your finalizer should perform two tasks: performing whatever cleanup is appropriate to the object, and calling the superclass finalizer. If you do not have any cleanup to perform for an object, then you’re better off not adding a finalizer to the class.

Floating-point literals Floating-point literals are defined as double by default, but if you want to specify in your code a number as float, you may attach the suffix F to the number.

Floating-point numbers Floating-point numbers are defined as a number, a decimal symbol, and more numbers representing the fraction.

FlowLayout manager This layout manager arranges components within the container from left to right. When the container runs out of room on the current row FlowLayout resumes positioning components on the next row.

FocusEvent A component generates a FocusEvent when it gains or loses keyboard focus. The event ID is set to either FOCUS_GAINED or focus lost. There are two types of focus events, permanent and temporary. Permanent focus events indicate that another component has gained the focus, whereas temporary focus events indicate that the component has lost focus temporarily due to window deactivation or scrolling.

For loop A flow control statement is used when a program needs to iterate a section of code a known number of times. There are three main parts to a for statement. They are the declaration and initialization of variables, the expression, and the incrementing or modification of variables. Each of the sections are separated by semicolons. The for loop is a remarkable tool for developers because it allows you to declare and initialize zero, one, or multiple variables inside the parenthesis after the for keyword.

Garbage collection The process by which memory requested, but no longer in use, by a Java application is reclaimed by the Java VM.

Generational garbage collectors Generational garbage collectors make the trade-off of running faster with the cost of leaving garbage lying around longer. With today’s large memory machines, this is a very reasonable trade-off to make.

GridBagLayout layout manager The GridBagLayout layout manager allows the placement of components that are aligned vertically and/or horizontally without constraining those components to be a particular size, height, or width. The GridBagLayout accomplishes this by defining a dynamic grid of cells. The constraints object passed when the component is added to the container determine how many cells the component encompasses.

GridLayout manager This layout manager arranges components in a grid within a container. Each cell in the grid is of equal dimensions. The GridLayout manager ignores the preferred size of each component and resizes them to exactly fit each cell’s dimensions. As each component is added to the container the GridLayout inserts them across each column until that row is filled and then starts at the first column of the next row.

Guarded region A section of code that is watched for errors to be handled by a particular group of handlers.

HashMap class The HashMap class is roughly equivalent to Hashtable, except that it is not synchronized for threads and it permits null values to be stored.

Heap Java manages memory in a structure called a heap. Every object that Java creates is allocated in the heap, which is created at the beginning of the application and managed automatically by Java.

Hexadecimal literals Hexadecimal numbers are constructed using 16 distinct symbols. The symbols used are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F.

Identifiers Identifiers are names that we assign to classes, methods, and variables. Java is a case-sensitive language, which means identifiers must have consistent capitalization throughout. Identifiers can have letters and numbers, but a number may not begin the identifier name. Most symbols are not allowed, but the dollar sign ($) and underscore (_) symbols are valid. See also Reference variable.

If statement If statements test an expression for a Boolean result. This is achieved by using one or more of Java’s relational operators inside the parenthesis of the statement to compare two or more variables. Also, you can simply use the reserved word true as the expression to force execution of the block of code. See also Decision statement.

Import statement Import statements allow us to refer to classes without having to use a fully qualified name for each class. Import statements do not make classes accessible; all classes in the classpath are accessible.

Inheritance Inheritance is an object-oriented concept that provides for the reuse and modification of an existing type in such a way that many types can be manipulated as a single type. In Java, inheritance is achieved with the extends keyword.

Inner classes Inner classes are a type of class and follow most of the same rules as a normal class. The main difference is an inner class is declared within the curly braces of a class or even within a method. Inner classes are also classes defined at a scope smaller than a package. See also Anonymous inner classes; Local inner classes; Member inner classes; Static inner classes.

InputEvent class An InputEvent is an abstract class that serves as the base class for MouseEvent and KeyEvent. InputEvent defines the following method to determine the time of the event.

Instance Once the class is instantiated, it becomes an object. A single object is referred to as an “instance” of the class from which it was instantiated.

Instance initializer An instance initializer (an alternative to lazy initialization) is a block of code (not a method!) that automatically runs every time you create a new instance of an object. In effect, it is an anonymous constructor. Of course, instance initializers are rather limited; because they do not have arguments, you cannot overload them, so you can have only one of these “constructors” per class.

Instance variable An instance variable is declared at object level. Instance variables may be accessed from other methods in the class, or from methods in other classes (depending on the access control). Instance variables may not be accessed from static methods, however, because a static method could be invoked when no instances of the class exist. Logically, if no instances exist, then the instance variable will also not exist, and it would be impossible to access the instance variable.

instanceof comparison operator The instanceof comparison operator is available for object variables. The purpose of this operator is to determine whether an object belongs to a given class (or any of the subclasses). This comparison may not be made on primitive types and will result in a compile-time error if it is attempted.

Interface An interface defines a group of methods, or a public interface, that must be implemented by any class that implements the interface. An interface allows an object to be treated as a type declared by the interface implemented.

Invocation events Invocation events are used to run a piece of code in the AWT event thread using the invoke() and invokeAndWait() methods. This is more of a utility than a part of the AWT event system.

Iterator An iterator provides the necessary behavior to get to each element in a collection without exposing the collection itself. In classes containing and manipulating collections, it is good practice to return an iterator instead of the collection containing the elements you want to iterate over. This shields clients from internal changes to the data structures used in your classes.

Java source file A file that contains computer instructions written in the Java programming language. A Java source file must meet strict requirements, otherwise the Java compiler will generate errors.

Java Virtual Machine (JVM) A program that interprets and executes Java byte code and that was generated by a Java compiler. The Java VM provides a variety of resources to the applications it is executing, including memory management, network access, hardware abstraction, and so on. Because it provides a consistent environment for Java applications to run in, the Java VM is the heart of the “write once run anywhere” strategy that has made Java so popular.

javac Javac is the name of the java compiler program. This Java compiler processes the source file to produce a byte code file.

java.lang package The java.lang package defines classes used by all Java programs. The package defines class wrappers for all primitive types such as Boolean, Byte, Character, Double, Float, Integer, Long, Short, and Void as well as Object, the class from which all Java classes inherit.

JVM See Java Virtual Machine.

Key pressed events Key pressed events occur for keys that do not have an associated character or that must be used in combination with other keys to form a logical character. These are keys such as function keys, up and down arrow keys, and the SHIFT key. The event types for key pressed events are KEY_PRESSED and KEY_RELEASED.

Key typed events Key typed events are higher-level than key pressed events, and only occur when a logical sequence or combination that represents a character has been completed. For example, pressing SHIFT-A results in a key typed event with the character A. The event type of a key typed event is KEY_TYPED.

KeyEvent A KeyEvent provides the following method that returns a virtual key code constant that represents the key.

Keywords Keywords are special reserved words in Java that cannot be used as identifiers for classes, methods, and variables.

Layout managers Layout managers are those classes responsible for laying out all components within a container, a process that includes sizing and positioning. A layout manager is associated with a container and a reference to that layout manager is held as a member of the container class. Layout managers are responsible for sizing and positioning components within a container. Layout managers free the developer of having to calculate positions and sizes of each component.

Local inner classes You can define inner classes within the scope of a method, or even smaller blocks within a method. We call this a local inner class. This is by far the least used form of inner classes. There are very few cases where you would ever need a named local inner class because most problems can be solved with the other types of inner classes.

Local variable A local variable is a variable declared within a method. These are also known as automatic variables. Local variables, including primitives, must be initialized before you attempt to use them (though not necessarily on the same line of code).

Low-level events In the AWT, low-level events are finer grained than semantic events and tend to occur at a higher frequency.

Mark phase The mark phase of the mark-sweep garbage collection starts with the root objects and looks at all the objects that each root object refers to. If the object is already marked as being in use, then nothing more happens. If not, then the object is marked as in use and all the objects that it refers to are considered. The algorithm repeats until all the objects that can be reached from the root objects have been marked as in use.

Mark-sweep algorithm Most Java Virtual Machines (JVMs) implement garbage collection using a variant of the mark-sweep algorithm. This algorithm gets its name from the two passes that it takes over memory. It takes the first pass to mark those objects that are no longer used, and a second pass to remove (sweep) those objects from memory. Mark-sweep starts with the assumption that some objects are always reachable.

Member inner classes Inner classes defined in an enclosing class without using the static modifier are called member inner classes. They are members of the enclosing class just like instance variables.

Members Elements of a class, including methods and variables.

Method A section of source code that performs a specific function, has a name, may be passed parameters and may return a result. Methods are found in classes only.

Method local variables See Automatic variables.

Modifier A modifier is a keyword in a class, method, or variable declaration that modifies the behavior of the element. See also Access modifier.

Modifier flags The modifier flags represent keys (such as SHIFT or ALT) that were pressed at the time of the input event.

Modular code Modular code keeps implementations isolated so that they depend on other code as little as possible. Though modular code does not affect how well your code executes, you will get many benefits by writing code this way, including the ability to easily modify, enhance, and debug the code.

Mouse Motion events Mouse Motion events are special because they are delivered using a listener interface that is different from normal Mouse events.

Narrowing The process of modifying a type. For primitives, narrowing means loss of precision, and for objects it means loss of generality.

Native methods Native indicates that a method is written in a platform-dependent language to perform a platform specific function that cannot be handled in Java. You will not need to know how to use native methods for the exam, other than knowing that native is a reserved keyword.

Notify() method The methods wait() and notify() are instance methods of an object. In the same way that every object has a lock, every object has a list of threads that are waiting for a signal related to the object. A thread gets on this list by executing the wait() method of the object. From that moment, it does not execute any further instructions until some other thread calls the notify() method of the same object.

Object Once the class is instantiated it becomes an object (sometimes referred to as an instance).

Overloaded methods Methods are overloaded when there are multiple methods in the same class with the same names but with different parameter lists.

Overridden methods Methods in the parent and subclasses with the same name, parameter list, and return type are overridden.

Package A package is an entity that groups classes together. The name of the package must reflect the directory structure used to store the classes in your package. The subdirectory begins in any directory indicated by the class path environment variable.

PaintEvent Paint events are used internally to ensure serialization of paint operations in the awt event thread. They are not intended to be used like other events.

Panel A panel is by far the simplest and most common of the AWT container classes.

Parent class A parent class is a class from which another class is derived. See also Base class.

Permanent focus events Permanent focus events indicate that another component has gained the focus.

Phantom object A phantom object is one that has been finalized, but whose memory has not yet been made available for another object.

Phantom reference Phantom references provide a means of delaying the reuse of memory occupied by an object, even if the object itself is finalized. Phantom references are a bit different from soft and weak references. First off, phantom references track memory rather than objects. Secondly, you can never actually get to the object that a phantom reference references.

Primitive literal A primitive literal is merely a source code representation of the primitive data types.

Primitives Primitives can be a fundamental instruction, operation, or statement. They must be initialized before you attempt to use them (though not necessarily on the same line of code).

Private members Private members are members of a class that cannot be accessed by any class other than the class in which it is declared.

Public access The public keyword placed in front of a class allows all classes from all packages to have access to a class.

Public members When a method or variable member is declared public, it means all other classes, regardless of the package that they belong to, can access the member (assuming the class itself is visible).

Reference The term reference is shorthand for reference variable. See Reference variable.

Reference queue The reference queue gives you a means for determining in bulk which references have changed. Reference queues give the virtual machine a mechanism for telling you that it has collected an object, or more precisely, that the reference has moved to an invalid state.

Reference variable A reference variable is an identifier that refers to a primitive type or an object (including an array). A reference variable is a name that points to a location in the computer’s memory where the object is stored. A variable declaration is used to assign a variable name to an object or primitive type. A reference variable is a name that is used in Java to reference an instance of a class.

Runtime exceptions A runtime exception is an exception that need not be handled in your program. Usually, runtime exceptions indicate a program bug. These are referred to as unchecked exceptions, since the Java compiler does not force the program to handle them.

ScrollPane ScrollPane is a container that provides optional scrollbars to gain access to that part of the container that is presently off of the viewable area. The scrollbars may be included as always on or on an as-needed basis.

Semantic events Semantic events occur as the result of a combination of low-level events. Semantic events tend to be associated with the primary purpose of the component that sources them. ActionEvent, ItemEvent, and TextEvent are the only semantic events defined in the java.awt.event package.

Shift operators Shift operators shift the bits of a number to the right or left, producing a new number. Shift operators are used on integer types only.

Soft reference A soft reference tells the runtime system that we would rather this object not be removed from memory. We do not require that the object not be removed from memory; we just would rather that it not be removed from memory.

SortedMap interface A data structure that is similar to map except the objects are stored in ascending order according to their keys. Like map, there can be no duplicate keys and the objects themselves may be duplicated. One very important difference with SortedMap objects is that the key may not be a null value.

Source file A source file is a plain text file containing your Java code. A source file may only have one public class or interface and an unlimited number of default classes or interfaces defined within it, and the filename must be the same as the public class name. See also Java source file.

Stack trace If you could print out the state of the call stack at any given time, you would produce a stack trace.

Static inner classes Static inner classes are the simplest form of inner classes. They behave much like top-level classes except that they are defined within the scope of another class, namely the enclosing class. Static inner classes have no implicit references to instances of the enclosing class and can access only static members and methods of the enclosing class. Static inner classes are often used to implement small helper classes such as iterators.

Static methods The static keyword declares a method that belongs to an entire class (as opposed to belonging to an instance). A class method may be accessed directly from a class, without instantiating the class first.

Static variable Also called a class variable. A static variable, much like a static method, may be accessed from a class directly, even though the class has not been instantiated. The value of a static variable will be the same in every instance of the class.

String literal A string literal is a source code representation of a value of a string.

String objects An object that provides string manipulation capabilities. The String class may not be subclassed.

Superclass In object technology, a high-level class that passes attributes and methods (data and processing) down the hierarchy to subclasses. A superclass is a class from which one or more other classes are derived.

Switch statement The expression in the switch statement can only evaluate to an integral primitive type that can be implicitly cast to an int. These types are byte, short, char, and int. Also, the switch can only check for an equality. This means that the other relational operators like the greater than sign are rendered unusable. See also Decision statement.

Synchronized methods The synchronized keyword indicates that a method may be accessed by only one thread at a time.

Temporary focus events Temporary focus events indicate that the component has lost focus temporarily due to window deactivation or scrolling.

Thread An independent line of execution. The same method may be used in multiple threads. As a thread executes instructions, any variables that it declares within the method (the so-called automatic variables) are stored in a private area of memory, which other threads cannot access. This allows any other thread to execute the same method on the same object at the same time without having its automatic variables unexpectedly modified.

Time-slicing A scheme for scheduling thread execution.

Transient variables The transient keyword indicates which variables are not to have their data written to an ObjectStream. You will not be required to know anything about transient for the exam, other than that it is a keyword.

Unchecked exceptions See Runtime exceptions.

Variable access Variable access refers to the ability of one class to read or alter (if it is not final) a variable in another class.

Visibility Visibility is the accessibility of methods and instance variables to other classes and packages. When implementing a class, you determine your methods’ and instance variables’ visibility keywords as public, protected, package, or default.

Visual object modeling languages Visual object modeling languages, such as the Unified Modeling Language (UML), allow designers to design and easily modify classes without having to write code first because object-oriented components are represented graphically. This allows the designer to create a map of the class relationships and helps them recognize errors before coding begins.

Volatile keyword The volatile keyword indicates that a variable may change unexpectedly.

Weak references Weak references are similar to soft references in that they allow you to refer to an object without forcing the object to remain in memory. Weak references are different from soft references, however, in that they do not request that the garbage collector attempt to keep the object in memory. Weak references are best used if you are tracking an object that someone else owns. You do not want to keep the object in memory; you just want to know if the object is still in memory.

原创粉丝点击