DAY : 16 Explanation of variables

Difference between Local variable and Global Variable Variables are classified into Global variables and Local variables based on their scope. The main difference between Global and local variables is that global variables can be accessed globally in the entire program, whereas local variables can be accessed only within the function or block in which they are defined. Local Variable : Method {} Global Variable : Class {} Global Variables If you don't initialize global variables, they take default values of declared type. For example, If global variable is int type and it is not initialized explicitly, it will take default value of int type i.e 0. Default values 1.Byte, Short, Int, Long - 0 2.Float, Double - 0.0 3.Boolean - False 4.Char- " 5.String - Null How to find variables in Java? We can access instance variables through object references, and static variables can be accessed directly using the class name. Some Recap topic are 1.Variables 2.Data types 3.Statically programming types language are 1.Primitive types 2.Non primitive types Primitive 8 types - Byte, Short, Int, Long,Float, Double,Boolean,Char. Non primitive types- String. 4.Variables: 1.Global Variables- Are having the Initial values 2.Local Variables-Are having the non Initial values

Apr 7, 2025 - 01:56
 0
DAY : 16 Explanation of variables

Difference between Local variable and Global Variable

Variables are classified into Global variables and Local variables based on their scope. The main difference between Global and local variables is that global variables can be accessed globally in the entire program, whereas local variables can be accessed only within the function or block in which they are defined.

  1. Local Variable : Method {}
  2. Global Variable : Class {}

Global Variables

If you don't initialize global variables, they take default values of declared type. For example, If global variable is int type and it is not initialized explicitly, it will take default value of int type i.e 0.

Default values
1.Byte, Short, Int, Long - 0
2.Float, Double - 0.0
3.Boolean - False
4.Char- "
5.String - Null

How to find variables in Java?

We can access instance variables through object references, and static variables can be accessed directly using the class name.

Some Recap topic are
1.Variables
2.Data types
3.Statically programming types language are
1.Primitive types
2.Non primitive types
Primitive 8 types - Byte, Short, Int, Long,Float, Double,Boolean,Char.
Non primitive types- String.
4.Variables:
1.Global Variables- Are having the Initial values
2.Local Variables-Are having the non Initial values