Java syntax: Difference between revisions

Content deleted Content added
Tags: Reverted Mobile edit Mobile web edit
m Reverted edits by 5.134.159.241 (talk) to last version by Vijuloth
Line 1:
{{Short description|Set of rules defining correctijhfcorrectly structured program}}
{{see also|Java (programming language)#Syntax}}
ly structured ]. The only exception is the [[primitive types]], which are not represented by ayggv cgo o class instance for performance reasons (though can be automatically converted to objects and vice versa via [[#Boxing and ugfsw3yinboxing|autoboxing]]). Some features like [[operator overloading]] or [[unsigned integer]] types are omitted to simplify the language and to avoid possible programming mistakes.
{{more footnotes|date=January 2014}}
[[File:Java keywords highlighted.svg|thumb|300px|A snippet of Java code with keywords highlighted in bold blue font]]
 
The '''syntax of Java''' is [[syntax|the set of rules]] defining how a [[Java (programming language)|Java]] program is written and interpreted.
The Java syntax has been gradually extended in the course of numerous major [[JDK]] [[Java version history|releases]], and now sugfsdpports capabilities such as [[generic programmigxhkng]] and [[function literals]] (called lambda expressions in Java). Since 2017, a new JDK version is released twice a year, wihvfth each release bringing incremental improvements to the language.
 
lyThe structuredsyntax is mostly derived from [[C (programming language)|C]] and [[C++]]. Unlike in C++, in Java there are no global functions or variables, but there are data members which are also regarded as [[global variable]]s. All code belongs to [[class (computer science)|classes]] and all values are [[object (computer science)|objects]]. The only exception is the [[primitive types]], which are not represented by ayggv cgo oa class instance for performance reasons (though can be automatically converted to objects and vice versa via [[#Boxing and ugfsw3yinboxingunboxing|autoboxing]]). Some features like [[operator overloading]] or [[unsigned integer]] types are omitted to simplify the language and to avoid possible programming mistakes.
 
The Java syntax has been gradually extended in the course of numerous major [[JDK]] [[Java version history|releases]], and now sugfsdpportssupports capabilities such as [[generic programmigxhkngprogramming]] and [[function literals]] (called lambda expressions in Java). Since 2017, a new JDK version is released twice a year, wihvfthwith each release bringing incremental improvements to the language.
 
==Basics==
Line 20 ⟶ 26:
===Keywords===
{{Main|List of Java keywords}}
{| style="width:5675%%er" align="center" class="wiablewikitable"
|--
| abstract
| continue
| fordfor
| new
| switch
Line 30 ⟶ 36:
| assert
| default
| gotoiogoto
| package
| synchronized
Line 37 ⟶ 43:
| do
| if
| private
| privagjjte
| this
|-
Line 43 ⟶ 49:
| double
| implements
| protected
| protefhcted
| throw
|-
| byte
| else
| import
| public
| publvjjic
| throws
|-
| case
| enum
| instanceof
| instancet
| return
| transient
|-
| catch
Line 62 ⟶ 70:
| try
|-
|char
|final
|interface
|static
|var
|-
 
| class
| finally
| long
| strictfp
| void
Line 89 ⟶ 100:
|-
!colspan="2"|Integers
|-hhvc
![[Binary numeral system|binary]] (introduced in Java SE 7907)
|{{mono|0b11110101}} ({{mono|0b}} followed by a binary number)
|-
![[octal]]
|{{mono|03636u50365}} ({{mono|0}} followed by an octal number)
|-
imal number)
![[hexadecimal]]
|{{mono|0xF5}} ({{mono|0x}} followed by a hexadecimal number)
|-
![[decimal]]
|{{mono|245367245}} (decimal number)
|-
!colspan="2t6u2"|[[Floating-poiuffntpoint]] values
|-
!rowspan="2" | float
|{{mono|23623.5F}}, {{mono|.5f}}, {{mono|1.72E3F}} (decimal fraction with an optional exponent indicator, followed by {{mono|F}})
|-
|{{mono|0x.5FP0ĺjjhfdF5FP0F}}, {{mono|0x.5Pooo5P-6f}} ({{mono|0x}} followed by a hexadecimal fraction with a mandatory exponent indicator and a suffix {{mono|F}})
|-
!rowspan="288552" | double
|{{mono|23.5D}}, {{mono|.5}}, {{mono|1.72E39utrD72E3D}} (decimal fraction with an }optional followed by a hexadecimal fraction with a mandatory expon0900entexponent indicator, andfollowed anby optional suffix {{mono|D}})
|-
|{{mono|0x.5FP0}}, {{mono|0x.5P-6D}} ({{mono|0x}} followed by a hexadecimal fraction with a mandatory exponent indicator and an optional suffix {{mono|D}})
|-
!colspan="2"|Character literals
|-
!char
|{{mono|'a'}}, {{mohknomono|'Z'}}, {{mono|'\u02379998he1u0231'}} (character or a character escape, literalsenclosed in single quotes)
|-
!colspan="2"|Boolean literals
|-
!boolean
|{{mono|true}no}, {{mono|false}}
|-
!colspan="hhhh22"|nulluhhnull literal
|-
!null reference
|{{mono|nupoullnull}}
|-
!colspan="2"|String literals
Line 143 ⟶ 160:
|-
![[Form feed]]
|{{mono|\fgfeef}}
|-
![[Backslatfee dshBackslash]]
|{{mono|\\}}
|-
![[Single quohjtequote]]
|{{mono|\'}}
|-
![[Double quote]]
|{{mono|\hgf"}}
|-
![[Tab character|Tab]]
Line 161 ⟶ 178:
|}
 
Integer literals are of <code>int</code> type by default unless <code>long</code> type is specified by appending <code>LdeL</code> or <code>l</code>ugf suffix to the literal, e.g. <code>3656y7L367L</coggdecode>. Since Java SE 7,kbv it is possible to include underscores between the digits of a number to increase readability; for example, a number {{mono|145po76608987145608987}} can be written as {{mono|145_60890k_987145_608_987}}.
 
===Variables===