Quick Summary of Working with Java Operators

By John Paul Mueller

Operators are an essential part of Java application development. They do precisely as their name implies — they operate on the value contained within a primitive type or object in some way.

Assigning data to a variable will store the information while the Java application runs. You can use arithmetic operators to modify the data value using various types of math. Here are the key points you need to remember when working with operators:

  • Most applications use simple assignments to initialize variables.

  • You must initialize a variable before you can modify it using a combined assignment operator.

  • Combined assignment operators perform an operation on the variable by using a value to the right of the operator as input, and they then store the result in the variable.

  • When performing math-related tasks, you must consider the order in which the values appear and the operations performed on them.

  • Incrementing and decrementing are often used to keep track of the count of something.

  • Negation produces the negative value of a number, while a bitwise Not produces the reversal of the bits within the number.

  • A Boolean Not turns a true value into a false value, and vice versa.

  • Use the new operator to create as many instances of an object as required by an application.

  • Casting makes it possible to turn one variable type into another.

  • Casting incorrectly can have serious side effects that could make the output of your application unusable.

  • Relational and conditional evaluation operators make it possible to determine the truth value of an expression.

  • It’s possible that more than one relational operator will be true for a given expression.

  • At least one relational operator will provide an output of true for a given expression.

  • Determining the type of a variable can help you overcome issues with improper casting.

  • The conditional evaluation operator is one of the few ternary operators provided by Java.

  • Java always executes operations defined by operators with a higher precedence first.

  • The associativity of an operator determines whether Java works with the right side or the left side first.

And here is the tech talk you should know in order to work with operators in Java:

  • associativity: The order in which Java performs binary operations.

  • binary operator: An operator that requires two operands to function. The addition operation, as specified by the + operator, is an example of a binary operator.

  • bitwise: The act of modifying a value one bit at a time, rather than acting on the value as a whole.

  • class: A blueprint written in code for creating objects. A class can include methods, properties, and events. The class defines specific ways to manipulate data in a safe manner.

  • grouping: The act of using parentheses to show the preferred order of completing math tasks, rather than relying on the default order.

  • negation: The act of setting a value to its negative equivalent. This means that a positive value becomes a negative value, and a negative value becomes positive. A value of 2 becomes –2, and a value of –2 becomes 2.

  • object: An instance of a class created using the new operator.

  • operand: The variable or constant used with an operator to produce a result from an operation. For example, when looking at A + B, A and B are both operands, + is the operator, and addition is the operation.

  • operator: A special symbol or symbol set that performs a predefined task with a value within a variable — either a primitive type or an object. In some cases, operators change the value, but in others they simply perform a comparison and provide the result as output.

  • precedence: The order in which Java interacts with operators when an equation or expression contains more than one operator. For example, Java always performs multiplication before it performs addition. Most of the rules of precedence are the same as those used by mathematicians.

  • ternary operator: An operator that requires three operands to function. For example, the conditional operator requires three operands: the conditional expression, a true output, and a false output.

  • unary operator: An operator that performs an operation on a single operand. For example, B++ is an example of a unary operator where B is the operand and ++ is the operator for an increment operation.