List of Java keywords: Difference between revisions

Content deleted Content added
rewrite/add references for all keywords relating to variable/method return type declaration
rewrite/add references for all keywords relating to control-flow structures
Line 24:
:This keyword is also be used to declare that a method returns a value of type <code>byte</code>.<ref name="return" />
 
;<code id="case">[[Switch statement#Java|case]]</code>
:The <code>case</code> keyword is used to create individual cases in a [[switch statement]]; see ''<code>[[#switch|switch]]</code>''.<ref name="switch">{{cite web |title=The switch Statement |url=http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html |work=The Java Tutorials |publisher=Sun Microsystems, Inc. |date=February 14, 2008 |accessdate=2008-12-03}}</ref>
:Defines a group of statements to execute if the specified value matches the value defined by the enclosing <code>switch</code> statement.
 
;<code>[[Exception handling syntax#Java|catch]]</code>
Line 44:
:Used to resume program execution at the end of the current loop body. If followed by a label, <code>continue</code> resumes execution at the end of the enclosing labeled loop body.
 
;<code id="default">[[Switch statement#Java|default]]</code>
:The <code>default</code> can optionally be used in a [[switch statement]] to label a block of statements to be executed if no <code>case</code> matches the specified value; see ''<code>[[#switch|switch]]</code>''.<ref name="switch" />
:Defines a group of statements to begin executing if the value defined by the enclosing <code>switch</code> statement does not match any value specified by a <code>case</code> keyword in the <code>switch</code> statement.
 
;<code id="do">[[do while loop#Java|do]]</code>
:The <code>do</code> keyword is used in conjunction with <code>[[#while|while]]</code> to create a [[do-while loop]], which executes a block of statements assocated with the loop and then tests a boolean expression assocated with the <code>while</code>. If the expression evaluates to <code>true</code>, the block is executed again; this continues until the expression evaluates to <code>false</code>.<ref name="do-while">{{cite web |title=The while and do-while Statements |url=http://java.sun.com/docs/books/tutorial/java/nutsandbolts/while.html |work=The Java Tutorials |publisher=Sun Microsystems, Inc. |date=February 14, 2008 |accessdate=2008-12-03}}</ref>
:Used to declare a loop that will [[Iteration|iterate]] a block of statements. The loop's exit condition is specified with the <code>while</code> keyword. The loop will execute once before evaluating the exit condition.
 
;<code>[[Double precision|double]]</code>
Line 55:
:This keyword is also used to declare that a method returns a value of type <code>double</code>.<ref name="return" />
 
;<code id="else">[[Conditional statement|else]]</code>
:The <code>else</code> keyword is used in conjunction with <code>[[#if|if]]</code> to create an [[conditional (programming)|if-else statement]], which tests a [[boolean expression]]; if the expression evaluates to <code>true</code>, the block of statements associated with the <code>if</code> are evaluated; if it evaluates to <code>false</code>, the block of statements associated with the <code>else</code> are evaluated.<ref name="if-else">{{cite web |title=The if-then and if-then-else Statements |url=http://java.sun.com/docs/books/tutorial/java/nutsandbolts/if.html |work=The Java Tutorials |publisher=Sun Microsystems, Inc. |date=February 14, 2008 |accessdate=2008-12-03}}</ref>
:Used to define a statement or block of statements that are executed in the case that the test condition specified by the <code>if</code> keyword evaluates to false.
 
;<code>[[Enumerated type|enum]]</code> (as of J2SE 5.0)
Line 77:
 
;<code>[[for loop#Java|for]]</code>
:The <code>for</code> keyword is used to create a [[for loop]], which specifies a variable initialization, a [[boolean expression]], and an incrementation. The variable initialization is performed first, and then the boolean expression is evaluated. If the expression evaluates to <code>true</code>, the block of statements assocated with the loop are executed, and then the incrementation is performed. The boolean expression is then evaluated again; this continues until the expression evaluates to <code>false</code>.<ref name="for">{{cite web |title=The for Statement |url=http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html |work=The Java Tutorials |publisher=Sun Microsystems, Inc. |date=February 14, 2008 |accessdate=2008-12-03}}</ref>
: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.
 
:As of [[Java version history#J2SE 5.0 (September 30, 2004) (EOL)|J2SE 5.0]],{{fact}} the <code>for</code> keyword can also be used to create a so-called "[[for each loop|enhanced for loop]]", which specifies an [[array]] or {{Javadoc:SE|java/lang|Iterable}} object; each iteration of the loop executes the associated block of statements using a different element in the array or Iterable.<ref name="for" />
;<code>[[GOTO|goto]]</code> (reserved without use)
 
:This keyword is '''not used''' by current versions of the Java programming language.
;<code>[[GOTO|goto]]</code> (reserved without use)
:Although reserved as a keyword in Java, <code>goto</code> is not used and has no function.<ref name="keywords" />
 
;<code id="if">[[Conditionalif statement|if]]</code>
:UsedThe <code>if</code> keyword is used to conductcreate aan conditional[[if teststatement]], andwhich executetests a block[[boolean of statementsexpression]]; if the testexpression evaluates to <code>true.</code>, If an optionalthe block isof statements definedassociated with the <code>else</code>if statement is executed. This keyword, thencan thealso be used to create an [[conditional (programming)|if-else statement]]; see ''<code>[[#else|else]]</code>''.<ref block is executed name="if-else" the test evaluates to false./>
 
;<code>implements</code>
Line 143 ⟶ 145:
:Also used to specify a lower bound on a type parameter in Generics.
 
;<code id="switch">[[Switch statement#Java|switch]]</code>
:The <code>switch</code> keyword is used in conjunction with <code>[[#case|case]]</code> and <code>[[#default|default]]</code> to create a [[switch statement]], which evaluates a variable, matches its value to a specific <code>case</code>, and executes the block of statements associated with that <code>case</code>. If no <code>case</code> matches the value, the optional block labelled by <code>default</code> is executed, if included.<ref name="switch" />
:Used to evaluate a variable that can later be matched with a value specified by the <code>case</code> keyword in order to execute a group of statements.
 
;<code>[[Mutual exclusion|synchronized]]</code>
Line 172 ⟶ 174:
:Used in field declarations to specify that the variable is modified [[asynchronous]]ly by concurrently running threads. Methods, classes and interfaces thus cannot be declared ''volatile''.
 
;<code id="while">[[do while loop#Java|while]]</code>
:The <code>while</code> keyword is used to create a [[while loop]], which tests a [[boolean expression]] and executes the block of statements associated with the loop if the expression evaluates to <code>true</code>; this continues until the expression evaluates to <code>false</code>. This keyword can also be used to create a [[do-while loop]]; see ''<code>[[#do|do]]</code>''.<ref name="do-while" />
:Used to declare a loop that iterates a block of statements. The loop's exit condition is specified as part of the while statement. If <code>while</code> appears before the body of the loop, the exit condition is evaluated before the first iteration. If <code>while</code> appears after the loop body then the <code>do</code> keyword designates the beginning of the loop body which is executed once before evaluating the exit condition.
 
==[[Reserved word]]s for [[literal]] values==