Java Fundamentals  «Prev  Next»
Lesson 10Using Java Compound Assignment Operators
Objective Examine Compound Assignment operators in Java.

Java Compound Assignment Operators

Boolean operators

Java also supports a number of Boolean, string, and assignment operators.
Boolean operators are used to perform logical comparisons, and always result in one of two values: true or false. Following are the most commonly used Boolean operators:
1) Boolean Operators1 2) Boolean Operators2 3) Boolean Operators3 4) Boolean Operators4 5) Boolean Operators5 6) Boolean Operators6

Program 1 Program 2 Program 3 Program 4 Program 5 Program 6
  1. AND: Compares two values and returns true if they are both true
  2. OR: Compares two values and returns true if either of the values are true
  3. Negation: Flips the state of a value
  4. Equal-to: Compares two values for equality
  5. Not-equal-to: Compares two values for inequality
Compound Assignment Operator

String operators

There is only one string operator, the concatenation operator (+), which appends a string onto another string. Following is an example of using the concatenation operator:
String nickname = "tough guy";
String message = "Hey there, " + nickname + "!";

The nickname string is effectively placed in the middle of a sentence. This code acts somewhat like a form letter in that you provide a sentence and then plug a name into it.

Assignment operators

Assignment operators all perform some type of operation that results in a value being stored in a variable. The following link contains the most commonly used assignment operators:

prime Application - Exercise

In this exercise, You will create a command-line application to determine whether a number is prime.
prime Application - Exercise