JAVA Theory
Variables
A variable is a name which is associated with a value that can be changed. It is a name of memory location.
Declare a variable in java:
Syntax |
---|
data_type variable_name = value ; Ex: int a =10; |
Types of variables:
Local variables:
A variable that is declared within a method, constructor or block is called local variable.
Instance variables:
A variable proclaimed inside the class outside any block, constructor or method is called instance variable.
Static/Class variables:
Static variables also known as Class variables are declared with the static keyword in a class.
Syntax |
---|
class skill
{
int a = 10;// instance variable static int m = 50;//static variable void method() { int c = 20;// local variable } } |
Data Types in javaData types specifies the type of values that can be stored in the variable. There are two types of data types in java.
Primitive data typesThere are 8 primitive data type: interger types:* byte * short* int * long floating-point types:*float *doubleboolean data type whose values are either true or false. char data type values are 16-bit Unicode character. [boolean --- size(1 bit) ] |