Home   |   About   |   Terms   |   Contact    
Read & Learn
 

Why should we declare the initial value of a variable in Java?

Java

☯ All Java Articles     ☯ All Articles


A new product.






Popular Google Pages:




This article is regarding Why should we declare the initial value of a variable in Java?
Last updated on: .



◕ Why should we declare the initial value of a variable in Java?

It is a very good practice to always initialize our variables when we declare them.
If we declare the initial value of a variable in Java then we can avoid so many problems as shown bellow.

- 1) The variable cannot take a junk value left over from when the memory was last used.

- 2) Sometimes if we try to use a variable in a calculation that has not had a value assigned to it, then our program does not compile.
It causes a problem and takes lot time to debug.

- 3) Sometimes the compiler cannot determine whether or not a variable has been initialized before it is used if we don't initialize it.
This shows an error again and again while running the program.



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