Monday, 22 February 2016

Java: Variables | Variable Declaration | Different ways of initilizations

  • Variables are the basic unit of storage in a java program.variables represents a memory location which holds data.
  • A variable is defined as combination of an identifier, type and optional initializer.
  • All variables have scope and which defines visibility and lifetime.

Declaring a variable:-
  • All variables must be declared before they can be used.
  • Syntax:- type identifier[=value][,identifier[=value]…];
  • Type represents the data type of an identifier. The identifier is the name of the variable.
  • You can initialize the variable by specifying an equal sign and value comma (,) is used to separate the variables

Variable declaration for various types

Ex:-  int a,b,c;           // declares three integers a , b , c
        Int a, b, c=4, c=5;        // declares a as integer value and initialization of b ,c
Char x=’x’;   // variable x has the value ‘x’

Dynamic initialization:-

Java allows variables to be initialized dynamically using any expression valid at the time of the variable is declared.

Class Dyint
Public static void main (String args [])
Double a= 3.0, b= 4.0;
Double c = math.sqrt (a*a+b*b);   // is initialized dynamically

System.out.println (“value of c is “+c);


Post a Comment

Note: only a member of this blog may post a comment.

Find Us On Facebook

python tutorial


C Programming


Java Tutorial


Data Structures


MS Office


Database Management