Java syntax: Difference between revisions

Content deleted Content added
m Reverting possible vandalism by 197.138.0.200 to version by Jarble. Report False Positive? Thanks, ClueBot NG. (3874883) (Bot)
m Replaced outdated html codes with wikicodes.
Line 101:
|-
![[Binary numeral system|binary]] (introduced in Java SE 7)
|<tt>{{mono|0b11110101</tt>}} (<tt>{{mono|0b</tt>}} followed by a binary number)
|-
![[octal]]
|<tt>{{mono|0365</tt>}} (<tt>{{mono|0</tt>}} followed by an octal number)
|-
![[hexadecimal]]
|<tt>{{mono|0xF5</tt>}} (<tt>{{mono|0x</tt>}} followed by a hexadecimal number)
|-
![[decimal]]
|<tt>{{mono|245</tt>}} (decimal number)
|-
!colspan="2"|[[Floating-point]] values
|-
!rowspan="2" | float
|<tt>{{mono|23.5F</tt>}}, <tt>{{mono|.5f</tt>}}, <tt>{{mono|1.72E3F</tt>}} (decimal fraction with an optional exponent indicator, followed by <tt>{{mono|F</tt>}})
|-
|<tt>{{mono|0x.5FP0F</tt>}}, <tt>{{mono|0x.5P-6f</tt>}} (<tt>{{mono|0x</tt>}} followed by a hexadecimal fraction with a mandatory exponent indicator and a suffix <tt>{{mono|F</tt>}})
|-
!rowspan="2" | double
|<tt>{{mono|23.5D</tt>}}, <tt>{{mono|.5</tt>}}, <tt>{{mono|1.72E3D</tt>}} (decimal fraction with an optional exponent indicator, followed by optional <tt>{{mono|D</tt>}})
|-
|<tt>{{mono|0x.5FP0</tt>}}, <tt>{{mono|0x.5P-6D</tt>}} (<tt>{{mono|0x</tt>}} followed by a hexadecimal fraction with a mandatory exponent indicator and an optional suffix <tt>{{mono|D</tt>}})
|-
!colspan="2"|Character literals
|-
!char
|<tt>{{mono|'a'</tt>}}, <tt>{{mono|'Z'</tt>}}, <tt>{{mono|'\u0231'</tt>}} (character or a character escape, enclosed in single quotes)
|-
!colspan="2"|Boolean literals
|-
!boolean
|<tt>{{mono|true</tt>}}, <tt>{{mono|false</tt>}}
|-
!colspan="2"|null literal
|-
!null reference
|<tt>{{mono|null</tt>}}
|-
!colspan="2"|String literals
|-
!String
|<tt>{{mono|"Hello, World"</tt>}} (sequence of characters and character escapes enclosed in double quotes)
|-
!colspan="2"|Characters escapes in strings
|-
![[Unicode]] character
|<tt>{{mono|\u3876</tt>}} (<tt>{{mono|\u</tt>}} followed by the hexadecimal unicode code point up to U+FFFF)
|-
![[Octal]] escape
|<tt>{{mono|\352</tt>}} (octal number not exceeding 377, preceded by backslash)
|-
![[Line feed]]
|{{mono|\n}}
|<tt>\n</tt>
|-
![[Carriage return]]
|{{mono|\r}}
|<tt>\r</tt>
|-
![[Form feed]]
|{{mono|\f}}
|<tt>\f</tt>
|-
![[Backslash]]
|{{mono|\\}}
|<tt>\\</tt>
|-
![[Single quote]]
|{{mono|\'}}
|<tt>\'</tt>
|-
![[Double quote]]
|{{mono|\"}}
|<tt>\"</tt>
|-
![[Tab character|Tab]]
|{{mono|\t}}
|<tt>\t</tt>
|-
![[Backspace]]
|{{mono|\b}}
|<tt>\b</tt>
|}
 
Integer literals are of <code>int</code> type by default unless <code>long</code> type is specified by appending <code>L</code> or <code>l</code> suffix to the literal, e.g. <code>367L</code>. Since Java SE 7, it is possible to include underscores between the digits of a number to increase readability; for example, a number <tt>{{mono|145608987</tt>}} can be written as <tt>{{mono|145_608_987</tt>}}.
 
===Variables===
Line 206:
===Code blocks===
 
The separators <tt>{</tt>{mono|{}} and <tt>{{mono|}}}</tt> signify a code block and a new scope. Class members and the body of a method are examples of what can live inside these braces in various contexts.
 
Inside of method bodies, braces may be used to create new scopes, as follows:
Line 278:
</syntaxhighlight>
 
Classes with the <code>public</code> modifier must be placed in the files with the same name and <tt>{{mono|java</tt>}} extension and put into nested folders corresponding to the package name. The above class <code>myapplication.mylibrary.MyClass</code> will have the following path: <code>myapplication/mylibrary/MyClass.java</code>.
 
===Import declaration===