Tutorials for Java ,Core java ,Advance java ,oracle ,HTML, CSS, JavaScript, Java and other programming language tutorial Learn Java tutorial for beginners with examples in eclipse online. Java tutorial point for core java, servlet, jsp, struts, spring, for learning web technologies online. Content includes tutorials and references relating to HTML, CSS, JavaScript, PHP, AngularJS, SQL, Bootstrap, Node.js, and jQuery this is a website like w3school tutorialspoint etc

Search This Blog

About

Header Ads

Thursday, 31 May 2018

Assignment Operators

0 comments

Assignment Operators

The java assignment operator statement has the following syntax:

<variable> = <expression>

If the value already exists in the variable it is overwritten by the assignment operator (=).

Ex:
public class AssignmentOperatorsDemo {
public AssignmentOperatorsDemo( ) {

// Assigning Primitive Values

 int j, k;

 j = 10; // j gets the value 10.

 j = 5; // j gets the value 5. Previous value is overwritten.

 k = j; // k gets the value 5.

 System.out.println("j is : "+j);

 System.out.println("k is : "+k);

// Assigning References

 Integer i1 = new Integer("1");

 Integer i2 = new Integer("2");

 System.out.println("i1 is : "+i1);

 System.out.println("i2 is : "+i2);

 i1 = i2;

 System.out.println("i1 is : "+i1);

 System.out.println("i2 is : "+i2);

// Multiple Assignments
 k = j = 10; // (k = (j = 10))

 System.out.println("j is : "+j);

 System.out.println("k is : "+k);
 }
 public static void main(String args[]){
 new AssignmentOperatorsDemo();
 }
}

Assignment Operators

x operation= y
is equivalent to
x = x operation y

x and y must be numeric or char types except for "=", which allows x and y also to be object references.
In this case, x must be of the same type of class or interface as y. If mixed floating-point and integer
types, the rules for mixed types in expressions apply.

=
Assignment operator.
 x = y;
y is evaluated and x set to this value.
The value of x is then returned.


No comments:

Post a Comment