2. Variables in Java

i. Variables are identifiers that is used to store the values.
ii. Identifiers means every variable declare in Standard Patterns as follows:
- variable name never start from number like int 1a=10;
- variable name never have predefine keywords like int float=10;
- variable name never have a space like int roll number=10;
- variable name never start from special symbols like @,#,!,%,^,&,* etc except of $ because $ represents a currency.
- variable name can have underscore like int roll_number=10;
- variable name should be in small letter.
- Static Variable
- Non-Static Variable
- Local Variable
1. Static Variable
- Static variable or property are the shareable property.
- Static variable or property declare inside a class and outside a method, constructor and block with the help of static keyword.
- Static property takes memory when your class loaded on JVM(Java Virtual Machine).
- Static property takes memory single time only.
- Static property takes memory inside Method Area.
- Static property always call by the help of class name.
- It is also called per class variable.
- It also has default value.
2. Non-Static Variable
- non static variables are non shareable property.
- non static variable declare inside a class and outside a method and constructor and block without static keyword.
- it takes memory when you create an object or instance.
- it takes memory depends on number of object created of same class.
- non static property takes memory inside Heap Area.
- non static property call by a reference variable.
- when you create an object using new keyword you can get reference variable.
- non-static variable is called per instance variable.
- It also has default value.
3. Local Variable
- It is also called Temporary variable.
- Local variable declare inside method ,constructor and block.
- Local variable takes memory when we call method , constructor or block where its declare.
- Local variable can be access with in a method, constructor and block only.
- Local variable takes memory inside stack.
- Each Thread has own stack and by default main method is main Thread so you need to configure from main method.
- Stack is group of FrameSet.
- Each Frameset holds a single method information.
- FrameSet is divided into three parts:
i) Local Variable Array -> Where store all the local variables.
ii)Frame Data -> It provide default error or exception messages.
iii)Operand Space -> It provide a workspace to perform some calculaton. - Local variable has no default value because java does not support garbage value.
0 Comments