Month End Sale: Get Extra 10% OFF on Job-oriented Training! Offer Ending in
D
H
M
S
Get Now

Variables in Java

Level : Beginner
Mentor: Shailendra Chauhan
Duration : 00:02:00

Variables in Java

In Java, a variable with a data type denotes a memory location that stores a value throughout program execution and is specified using primitive data types such as byte, short, int, long, float, double, char, or boolean.

Types of Variables

There are three types of Variables:

  1. Local
  2. Instance
  3. Class/Static

Local Variables

Local variables are those that are declared within the method's body. It is generated when a block is inserted into the storage, and it calls and destroys the block immediately after exiting the function.

Instance Variables

Declared within the class but not within the method body itself. An instance variable is produced when an object class is generated and destroyed when the same object class is destroyed.

Class/Static Variables

Static variables are those that are declared to be static. It is created to begin the program's execution and then destroyed automatically once the execution is complete.

Declaration of Variables

To declare the variable programmers, need to focus on two things:

  1. datatype: It denotes the types of Data that are going to be stored.
  2. data_name: A particular name of that variable

Variable Initialization

For initializing the variable there are 3 major components, are

  1. datatype: It defines what type of data is going to be stored in a variable
  2. variable_name: Particular name of the variable
  3. value: Initially stored value in the variable


Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this