Operators | Meaning |
a instance of b | Class text operator - The first operand must be an object reference. b is the name of a class or interface. If a is an instance of type b or a subclass of b, then true returned. If a is an instance of interface type b or a sub-interface, then true is returned. Otherwise, false is returned. |
new a(args) | Class instantiation - Create an instance of class a using constructor a(args). |
'.' | Class member access - Access a method or field of a class or object : o.f - field access for object o. o.m() - method access for object o. |
( ) | Method invocation - Parentheses after a method name invokes (i.e. calls) the code for the method, e.g. o.m(), o.m(x,y) |
(a) | Object cast - Treat an object as the type of class or interface a: a a1=(a)a2; Treat a2 as an instance of class or interface a. |
+ | String concatenation - This binary operator will concatenate one string to another. E.g. String str1 = "abc"; String str2 = "def"; String str3 = str1 + str2; results in str3 holding "abcdef". For mixed operands, if either a or b in (a + b) is a string, concatenation to a string will occur. Primitives will be converted to strings and the toString() methods of objects will be called. (This is the only case of operator overloading in Java.) The equivalence operator "+=" will also perform string concatenation. |
[ ] | Array element access - In Java, arrays are classes. However, the bracket operators work essentially the same as in the C/C++. To access a given element of an array, place the number of the element as an int value (long values cannot be used in Java arrays) into the brackets, e.g. float a = b[3]; int n = 5; char c=c[n]; where b is a float array and c is a char array. |