Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Java syntax
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Operators== Operators in Java are similar to those in [[C++]]. However, there is no <code>delete</code> operator due to [[Garbage collection (computer science)|garbage collection]] mechanisms in Java, and there are no operations on [[Pointer (computer programming)|pointers]] since Java does not support them. Another difference is that Java has an unsigned right shift operator (<code>>>></code>), while C's right shift operator's signedness is type-dependent. Operators in Java cannot be [[Operator overloading|overloaded]]. {| class="wikitable" |- ! style="text-align: center" | Precedence ! style="text-align: center" | Operator ! style="text-align: center" | Description ! style="text-align: center" | Associativity |- ! rowspan=3| 1 | style="border-bottom-style: none; border-top-style: none" | <code>()</code> | style="border-bottom-style: none; border-top-style: none" | Method invocation | style="vertical-align: center" rowspan="4" | Left-to-right |- | style="border-bottom-style: none; border-top-style: none" | <code>[]</code> | style="border-bottom-style: none; border-top-style: none" | Array access |- | style="border-bottom-style: none; border-top-style: none" | <code>.</code> | style="border-bottom-style: none; border-top-style: none" | Class member selection |- ! 2 | style="border-bottom-style: none" | <code>++</code> <code>--</code> | style="border-bottom-style: none" | Postfix increment and decrement<ref>{{Cite web|title = Operators (The Javaβ’ Tutorials > Learning the Java Language > Language Basics)|url = http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html|website = docs.oracle.com|access-date = June 16, 2015|publisher = Oracle and/or its affiliates|archive-date = June 24, 2015|archive-url = https://web.archive.org/web/20150624161036/http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html|url-status = live}}</ref> |- ! rowspan=5| 3 | style="border-bottom-style: none" | <code>++</code> <code>--</code> | style="border-bottom-style: none" | Prefix increment and decrement | style="vertical-align: center" rowspan="5" | Right-to-left |- | style="border-bottom-style: none; border-top-style: none" | <code>+</code> <code>-</code> | style="border-bottom-style: none; border-top-style: none" | Unary plus and minus |- | style="border-bottom-style: none; border-top-style: none" | <code>!</code> <code>~</code> | style="border-bottom-style: none; border-top-style: none" | Logical NOT and bitwise NOT |- | style="border-bottom-style: none; border-top-style: none" | <code>(''type'') val</code> | style="border-bottom-style: none; border-top-style: none" | Type cast |- | style="border-top-style: none" | <code>new</code> | style="border-top-style: none" | Class instance or array creation |- ! 4 | <code>*</code> <code>/</code> <code>%</code> | Multiplication, division, and modulus (remainder) | style="vertical-align: center" rowspan="13" | Left-to-right |- ! rowspan=2| 5 | style="border-bottom-style: none;" | <code>+</code> <code>-</code> | style="border-bottom-style: none;" | Addition and subtraction |- | style="border-top-style: none" | <code>+</code> | style="border-top-style: none" | String concatenation |- ! 6 | <code><<</code> <code>>></code> <code>>>></code> | [[Bitwise operation|Bitwise]] left shift, signed right shift and unsigned right shift |- ! rowspan=3| 7 | style="border-bottom-style: none;" | <code><</code> <code><=</code> | style="border-bottom-style: none;" | [[Relational operator|Relational]] "less than" and "less than or equal to" |- | style="border-bottom-style: none; border-top-style: none" | <code>></code> <code>>=</code> | style="border-bottom-style: none; border-top-style: none" | Relational "greater than" and "greater than or equal to" |- | style="border-top-style: none" | <code>instanceof</code> | style="border-top-style: none" | Type comparison |- ! 8 | <code>==</code> <code>!=</code> | Relational "equal to" and "not equal to" |- ! 9 | <code>&</code> | Bitwise and logical AND |- ! 10 | <code>^</code> | Bitwise and logical XOR (exclusive or) |- ! 11 | <code><nowiki>|</nowiki></code> | Bitwise and logical OR (inclusive or) |- ! 12 | <code>&&</code> | Logical conditional-AND |- ! 13 | <code><nowiki>||</nowiki></code> | Logical conditional-OR |- ! 14 | <code>''c'' ? ''t'' : ''f''</code> | [[Ternary operator|Ternary]] conditional (see [[?:]]) | style="vertical-align: center" rowspan="6" | Right-to-left |- ! rowspan=5| 15 | style="border-bottom-style: none" | <code>=</code> | style="border-bottom-style: none" | Simple assignment |- | style="border-bottom-style: none; border-top-style: none" | <code>+=</code> <code>-=</code> | style="border-bottom-style: none; border-top-style: none" | Assignment by sum and difference |- | style="border-bottom-style: none; border-top-style: none" | <code>*=</code> <code>/=</code> <code>%=</code> | style="border-bottom-style: none; border-top-style: none" | Assignment by product, quotient, and remainder |- | style="border-bottom-style: none; border-top-style: none" | <code><<=</code> <code>>>=</code> <code>>>>=</code> | style="border-bottom-style: none; border-top-style: none" | Assignment by bitwise left shift, signed right shift and unsigned right shift |- | style="border-top-style: none" | <code>&=</code> <code>^=</code> <code><nowiki>|</nowiki>=</code> | style="border-top-style: none" | Assignment by bitwise AND, XOR, and OR |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)