---
title: "What is the difference between Assignment and Initialization?"  
description: "What is the difference between Assignment and Initialization?"  
author: "Pushpendra Singh"  
published: 2010-10-25  
updated: 2023-05-03  
canonical: https://www.mindstick.com/interview/160/what-is-the-difference-between-assignment-and-initialization  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# What is the difference between Assignment and Initialization?

```
Assignment can be done as many times as desired where as initialization can be done only once.for exampleinitialize the value:int i;i=0;Assignmenti=i i;
```

## Answers

### Answer by Aryan Kumar

In programming, both assignment and initialization are ways to give a value to a variable or object property, but they have different meanings.

Assignment is the process of giving a new value to an existing variable or object property. It does not create a new variable or property, but simply replaces the existing value with a new one. Assignment can be used to change the value of a variable or object property multiple times throughout the program.

Initialization, on the other hand, is the process of giving an initial value to a variable or object property when it is first created. Initialization sets the value of the variable or property at the beginning of the program and is only done once. Initialization is typically done when a variable or property is declared, either with an explicit value or with a default value.

Here is an example that illustrates the difference between assignment and initialization:

```java
int x; // declaration
x = 5; // assignment
int y = 10; // declaration and initialization
```

In this example, **x** is declared as an integer variable, but it does not have an initial value. The first line is a declaration, but not an initialization. The second line is an assignment, which gives the variable **x** a value of 5.

In contrast, **y** is declared as an integer variable and initialized with a value of 10 in the same statement. This is a declaration and initialization in one step.

In summary, assignment is the process of giving a new value to an existing variable or object property, while initialization is the process of giving an initial value to a variable or object property when it is first created.

### Answer by Amit Singh

```
Assignment can be done as many times as desired where as initialization can be done only once.for exampleinitialize the value:int i;i=0;Assignmenti=i i;
```


---

Original Source: https://www.mindstick.com/interview/160/what-is-the-difference-between-assignment-and-initialization

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
