Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
The following table lists the other operators that the Java programming language supports.
Operator Description ?:
Shortcut if-else
statement[]
Used to declare arrays, create arrays, and access array elements .
Used to form qualified names (
params)
Delimits a comma-separated list of parameters (
type)
Casts (converts) a value to the specified type new
Creates a new object or a new array instanceof
Determines whether its first operand is an instance of its second operand
The?:
operator is a conditional operator that is short-hand for anif
-else
statement:Theop1 ? op2 : op3?:
operator returnsop2
ifop1
is true or returnsop3
ifop1
is false.For information about the
if
-else
statement, refer to The if/else Statements.
You use square brackets to declare arrays, to create arrays, and to access a particular element in an array. Here's an example of an array declaration:The previous code declares an array that can hold ten floating point numbers. Here's how you would access the 7th item in that array:float[] arrayOfFloats = new float[10];Note that array indices begin at 0. Arrays contains more information about arrays.arrayOfFloats[6];
The dot (.) operator accesses instance members of an object or class members of a class. You will learn more about this operator in the next lesson, Classes and Inheritance.
When declaring or calling a method, you list the method's arguments between(
and)
. You can specify an empty argument list by using()
with nothing between them. The next lesson, Classes and Inheritance, covers methods.
Casts (or "converts") a value to the specified type.
You use the new operator to create a new object or a new array. Here's an example of creating a newInteger
object from theInteger
class in thejava.lang
package:For a detailed explanation about creating objects using a statement like the previous, refer to Creating Objects in the next lesson. To learn about creating arrays, refer to Arrays.Integer anInteger = new Integer(10);
Theinstanceof
operator tests whether its first operand is an instance of its second.op1 instanceof op2op1
must be the name of an object andop2
must be the name of a class. An object is considered to be an instance of a class if that object directly or indirectly descends from that class.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.