Saturday, December 28, 2019

Understanding the variables in java

Understanding the variables in java


Variable


A variable is something in a program that is liable to change. A variable is a mere holder or container to hold some value and is identified by some identifier(symbolic representation).

for example

int speed=60;

We have declared a variable identified by speed, data type int, and the value assigned by "="(assignment operator), which is 60. The value assigned to a variable can be changed later in the program. The variable's identifier must be preceded by its data type. A variable must be declared before it is used in a program.


java variables



The Java programming language defines the following kinds of variables:
  • Instance Variables (Non-Static Fields) 
  • Class Variables (Static Fields)
  • Local Variables
  • Parameters

Instance Variables

Each instance of the class has its own copy of this variable. Any non-static field or attribute of a class is an instance variable. We need to create an object of the class to use the instance variable.

Class Variables

Any static variable of the class is known as the class variable. We do not need to create the objects of the class to access these variables. Read this Java tutorial for more details on the static keyword in Java. These variables belong to the class, not to the individual objects.

Local Variables

Local variables are declared and within the body of any block, method, or constructor. Their scope is limited to that particular block, method, or constructor.

Parameters

The parameters are passed between the parenthesis of the method declaration.  





Video Tutorial:-