O'Reilly logo

Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition by Rolf W. Rasmussen, Khalid A. Mughal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.4. Simple Assignment Operator =

The assignment statement has the following syntax:

<variable> = <expression>

which can be read as “the destination, <variable>, gets the value of the source, <expression>”. The previous value of the destination variable is overwritten by the assignment operator =.

The destination <variable> and the source <expression> must be type compatible. The destination variable must also have been declared. Since variables can store either primitive data values or object references, <expression> evaluates to either a primitive data value or an object reference.

Assigning Primitive Values

The following examples illustrate assignment of primitive values:

 int j, k; j = 10; // j gets the value 10. j = 5; // j gets the value ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required