Home   |   About   |   Terms   |   Contact    
Read & Learn
 

Difference between the Initialization and the Assignment in Java?

Java

☯ All Java Articles     ☯ All Articles


A new product.






Popular Google Pages:




This article is regarding What is the difference between the Initialization and the Assignment Statement in Java?
Last updated on: .



◕ What is the difference between the Initialization and the Assignment in Java?

■ Initialization causes a variable to have the value that you specify when it is created.

Example:
int flower = 786;
This is the Initialization of the variable flower.

Why Initialization is important in Java?

■ On the other hand an assignment involves copying data from one place to another in memory.
In normal practice, we have to declare and initialize variables before using them in the assignment statement.

Example:
a = b + c ;

Here the values of the variables b & c are added and final result is stored in the variable a.

The equal sign ' = ' is called the Assignment Operator.



Please note:

a = b = c = 123;
What is the above statement? An Initialization or an Assignment statement?

Ans:- This is an assignment statement.
Because the compiler allocates some memory to store the constant 123 as type int in the variable c.
The value in c is extracted and copied to b. Then again the value in b is copied to a.



Related Java articles:
What is Java? Where we can apply Java?
Why Java is a Machine Independent Program? What is Machine Independent Program?
Root Directory of Java
How to Compile and run a Java Program?
What is .class file in Java?
What is variable in a program?
What is identifier in Java?
Integer data types in Java?
What is Primitive Types in Java?
How to declare constant variables in Java?
Why should we declare the initial value of a variable in Java?
Use of Underscores to write an integer in Java





Popular Google Pages:





Top of the page

Amazon & Flipkart Special Products

   


Top of the page