List of Java keywords: Difference between revisions

Content deleted Content added
wrap keywords in <code></code>
rewrite/add references for all keywords relating to variable/method return type declaration
Line 1:
[[Image:Java keywords highlighted.png|thumb|A snippet of Java code with keywords highlighted in blue and bold font]]
 
In the [[Java (programming language)|Java programming language]], a '''keyword''' is one of 50 [[reserved word]]s which have a predefined meaning in the language; because of this, programmers cannot use keywords as names for [[variable#Computer programming|variables]], [[method (computer science)|methods]], [[class (computer science)|classes]], or as any other [[identifier]].<ref name="keywords">{{cite web |title=Java Language Keywords |url=http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html |work=The Java Tutorials |publisher=[[Sun Microsystems, Inc.]] |year=2008 |monthdate=February 14, 2008 |accessdate=2008-12-02}}</ref> Due to their special functions in the language, most [[integrated development environment]]s for Java use [[syntax highlighting]] to display keywords in a different color for easy identification.{{fact}}
 
The following is a list of the keywords in Java, along with a brief description of their functions:<ref name="keywords" />
Line 12:
 
;<code>[[Boolean datatype#Java|boolean]]</code>
:The <code>boolean</code> keyword is used to declare a [[field (computer science)|field]] that can store a [[boolean datatype|boolean value]]; that is, either <code>true</code> or <code>false</code>.<ref name="primitive">{{cite web |title=Primitive Data Types |url=http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html |work=The Java Tutorials |publisher=Sun Microsystems, Inc. |date=February 14, 2008 |accessdate=2008-12-03}}</ref>
:Refers to an expression or [[variable#Computer Programming|variable]] that can have only a true or false value. Java provides the <code>boolean</code> type and the literal values <code>true</code> and <code>false</code>.
 
:This keyword is also be used to declare that a method returns a value of type <code>boolean</code>.<ref name="return">{{cite web |title=Returning a Value from a Method |url=http://java.sun.com/docs/books/tutorial/java/javaOO/returnvalue.html |work=The Java Tutorials |publisher=Sun Microsystems, Inc. |date=February 14, 2008 |accessdate=2008-12-03}}</ref>
 
;<code>[[Switch statement#Java|break]]</code>
Line 18 ⟶ 20:
 
;<code>[[byte]]</code>
:The <code>byte</code> keyword is used to declare a field that can store an 8-[[bit]] signed [[two's complement]] integer.<ref name="primitive" />
:An 8-[[bit]] integer. A keyword used to [[Declaration (computer science)|declare]] an expression, method return value, or variable of type byte.
 
:This keyword is also be used to declare that a method returns a value of type <code>byte</code>.<ref name="return" />
 
;<code>[[Switch statement#Java|case]]</code>
Line 27 ⟶ 31:
 
;<code>[[Character (computing)|char]]</code>
:AThe 16-bit<code>char</code> [[Unicode]]keyword character. A Java keywordis used to declare ana expression,field methodthat returncan value,store ora variable16-bit of type[[Unicode]] character.<ref name="primitive" />
 
:This keyword is also be used to declare that a method returns a value of type <code>char</code>.<ref name="return" />
 
;<code>[[Class (computer science)#Java|class]]</code>
Line 45 ⟶ 51:
 
;<code>[[Double precision|double]]</code>
:AThe 64-bit [[Floating Point|floating point value]]. A Java<code>double</code> keyword is used to declare ana expression,field methodthat returncan value,hold ora variable of type64-bit [[double- precision]] floating[[IEEE 754]] [[floating-point number]].<ref name="primitive" />
 
:This keyword is also used to declare that a method returns a value of type <code>double</code>.<ref name="return" />
 
;<code>[[Conditional statement|else]]</code>
Line 63 ⟶ 71:
:Used to define a block of statements for a block defined previously by the <code>try</code> keyword. The <code>finally</code> block is executed after execution exits the <code>try</code> block and any associated <code>catch</code> clauses regardless of whether an exception was thrown or caught, or execution left method in the middle of the <code>try</code> or <code>catch</code> blocks using the <code>return</code> keyword.
 
;<code>[[Floatingsingle pointprecision|float]]</code>
:AThe 32-bit<code>float</code> floatingkeyword point value. A Java keywordis used to declare ana expression,field methodthat returncan value,hold ora variable32-bit of[[single typeprecision]] single-precisionIEEE 754 floating -point number.<ref name="primitive" />
 
:This keyword is also used to declare that a method returns a value of type <code>float</code>.<ref name="return" />
 
;<code>[[for loop#Java|for]]</code>
:Used to define a loop that reiterates statements. The <code>for</code> loop specifies the statements to be executed, exit condition, and initialization variables for the loop. The exit condition is evaluated before the first iteration of the loop. Since J2SE 5.0, a form of the <code>for</code> loop specifies an {{Javadoc:SE|java/lang|Iterable}} object where each iteration of the loop processes one of its contained elements.
 
;<code>[[GOTO|goto]]</code> (reserved without use)</code>
:This keyword is '''not used''' by current versions of the Java programming language.
 
Line 85 ⟶ 95:
 
;<code>[[Integer (computer science)|int]]</code>
:AThe 32-bit<code>int</code> integerkeyword value. A Java keywordis used to declare ana expression,field methodthat returncan value,hold ora variable32-bit ofsigned typetwo's complement integer.<ref name="primitive" />
 
:This keyword is also used to declare that a method returns a value of type <code>int</code>.<ref name="return" />
 
;<code>[[Interface (Java)|interface]]</code>
Line 91 ⟶ 103:
 
;<code>[[long integer|long]]</code>
:AThe 64-bit<code>long</code> integerkeyword value. A Java keywordis used to declare ana expression,field methodthat returncan value,hold ora variable64-bit ofsigned typetwo's longcomplement integer.<ref name="primitive" />
 
:This keyword is also used to declare that a method returns a value of type <code>long</code>.<ref name="return" />
 
;<code>native</code>
Line 115 ⟶ 129:
 
;<code>[[short integer|short]]</code>
:AThe 16-bit<code>short</code> integerkeyword value.is Usedused to declare ana expression,field methodthat returncan value,hold ora variable16-bit ofsigned typetwo's shortcomplement integer.<ref name="primitive" />
 
:This keyword is also used to declare that a method returns a value of type <code>short</code>.<ref name="return" />
 
;<code>[[Static variable|static]]</code>
Line 149 ⟶ 165:
 
;<code>[[void return type|void]]</code>
:UsedThe in<code>void</code> methodkeyword declarationsis used to specifydeclare that thea method does not return any value.<ref name="return" <code>void</code> can also be used as a nonfunctional statement.
 
:This keyword is also used as a nonfunctional statement.{{fact}}
 
;<code>[[Volatile variable|volatile]]</code>
Line 169 ⟶ 187:
 
== References ==
;General
*{{cite [[Jamesbook Gosling|last=Gosling, |first=James]]; |authorlink=James Gosling |coauthors=[[Bill Joy|Joy, Bill]]; [[Guy Steele|Steele, Guy]]; &and [[Gilad Bracha|Bracha, GiladGillad]] ([[2005]]). |title=Java Language Specification, Third Edition.|edition=3rd |publisher=Addison-Wesley Professional. ISBN|year=2005 0-321-24678-0. [|url=http://java.sun.com/docs/books/jls/index.html online version]|accessdate=2008-12-03}}
 
;Footnotes
{{reflist|2}}
 
[[Category:Java programming language]]