- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Initialization, declaration and assignment terms in Java
A variable provides us with named storage that our programs can manipulate. Each variable in Java has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.
You must declare all variables before they can be used. Following is the basic form of a variable declaration − data type variable [ = value][, variable [ = value] ...] ;
Here data type is one of Java's datatypes and variable is the name of the variable. To declare more than one variable of the specified type, you can use a comma-separated list.
Following are valid examples of variable declaration and initialization in Java −
int a, b, c; // Declares three ints, a, b, and c. int a = 10, b = 10; // Example of initialization byte B = 22; // initializes a byte type variable B. double pi = 3.14159; // declares and assigns a value of PI. char a = 'a'; // the char variable a is initialized with value a
- Related Articles
- Explain the variable declaration, initialization and assignment in C language
- What is the difference between initialization and assignment of values in C#?
- Difference between Definition and Declaration in Java.
- java variable declaration
- Double brace initialization in Java
- Java Assignment Operators
- A static initialization block in Java
- Java Assignment Operator Examples
- Compound assignment operators in Java\n
- A non-static initialization block in Java
- Java variable declaration best practices
- Class declaration with one method in Java
- Reference static field after declaration in Java
- What are the assignment operators in Java?
- Interesting facts about Array assignment in Java