#VARIABLES and TYPES# - Study24x7
Social learning Network

Welcome Back

Get a free Account today !

or

Forgot password?

By Registering, you agree to our Privacy Policy and Terms of use.

#VARIABLES and TYPES#

study24x7
COMPUTER PROGRAMMING 2020 Published on 10 June 2020

Variables and types


A variable is a data name that is used to store the data value. Constant variable cannot be changed during the execution of a program.

A variable is a symbol or name that stands for a value. It is a value that can change. A variable can take different values during the execution. It can be choose by the programmer in many ways.

Example 1:

c = a + b

This is an example of programming expression.

a, b and c are variables.


Example 2:

  1. Average
  2. Total
  3. Count_1
  4. Class_strength


In every program, variable has its own:

·Name (Identifier)

·Data Type

·Size

·Value


Variable consists of letters, digits and the underscore (_) character. It has following conditions:

1 Uppercase and lower case is significant.

 For example: The variable Average is not the same as average or AVERAGE

2 They must begin with a letter.

3 It should not be a keyword.

4 White space is not allowed.


Example of valid variable names is:


SUM1                                   ph_value                                            Mumbai

John                                     Value                                                   distance


Example of variable names


Variable Name
Valid?
Remarks

First_tag
Valid

Price$
Not valid
Dollar sign is not valid
Average weight
Not valid
Blank space is not allowed
Int_type
Valid
Keyword may be the part of a name


Variables can represent numeric values, characters, character strings, or memory addresses.


Types of Variables in JAVA


Types of Variables


Local Variables                                      Instance Variables                        Static Variables



·Local variable- A variable that is declared inside the method that is called local variable.


·Instance variable- A variable that declared the inside the class but outside the method that is called instance variable.


·Static variable-A static Variable is a special type of the variable that is shared by all objects from a class. Static variable are used to keep track of global information such as number of objects from a class


Example1:-

class Simple

{  

public static void main(String[] args)

{  

int a=10;  

int b=10;  

int c=a+b;  

System.out.println(c);  

}

}  



Example2:-


class A

{  

int data=50; //instance variable  

static int m=100; //static variable  

void method()

{  

int n=90;//local variable  

}  

}//end of class




Keep visit to learn the What are the data types and how many types of it?


For more information you can visit this page


COMPUTER PROGRAMMING 2020

 



study24x7
Write a comment...