Sunteți pe pagina 1din 2

Keywords

Keywords are identifiers like public, static and class that have a special meaning inside Java source code and outside of comments and Strings. Four keywords are used in Hello World, public, static, void and class. Keywords are reserved for their intended use and cannot be used by the programmer for variable or method names. There are fifty reserved keywords in Java 1.1, 51 in Java 1.2, 52 in Java 1.4, and 54 in Java 5. The forty-eight that are actually used in are listed below. Don't worry if the purposes of the keywords seem a little opaque at this point. They will all be explained in much greater detail later.

Keywords Used in Java 1.1


Keyword
boolean byte char double float short void int long while for do switch break continue case default if else try catch finally class abstract

Purpose declares a boolean variable or return type declares a byte variable or return type declares a character variable or return type declares a double variable or return type declares a floating point variable or return type declares a short integer variable or return type declare that a method does not return a value declares an integer variable or return type declares a long integer variable or return type begins a while loop begins a for loop begins a do while loop tests for the truth of various possible cases prematurely exits a loop prematurely return to the beginning of a loop one case in a switch statement default action for a switch statement execute statements if the condition is true signals the code to be executed if an if statement is not true attempt an operation that may throw an exception handle an exception declares a block of code guaranteed to be executed signals the beginning of a class definition declares that a class or method is abstract

specifies the class which this class is a subclass of declares that a class may not be subclassed or that a field or method may final not be overridden implements declares that this class implements the given interface import permit access to a class or group of classes in a package instanceof tests whether an object is an instanceof a class interface signals the beginning of an interface definition native declares that a method is implemented in native code new allocates a new object package defines the package in which this source code file belongs private declares a method or member variable to be private protected declares a class, method or member variable to be protected public declares a class, method or member variable to be public return returns a value from a method static declares that a field or a method belongs to a class rather than an object super a reference to the parent of the current object synchronized Indicates that a section of code is not thread-safe this a reference to the current object throw throw an exception throws declares the exceptions thrown by a method transient This field should not be serialized volatile Warns the compiler that a variable changes asynchronously
extends

Two other keywords, const and goto, are reserved by Java but are not actually implemented. This allows compilers to produce better error messages if these common C++ keywords are improperly used in a Java program. Java 1.2 adds the strictfp keyword to declare that a method or class must be run with exact IEEE 754 semantics. Java 1.4 adds the assert keyword to specify assertions. Java 5 adds assert and enum. and false appear to be missing from this list. In fact, they are not keywords but rather boolean literals. You still can't use them as a variable name though.
true

Previous | Next | Top | Cafe au Lait


Copyright 1997, 2000, 2002, 2005 Elliotte Rusty Harold elharo@metalab.unc.edu Last Modified February 2, 2005

S-ar putea să vă placă și