Data Types in Java



There is a rich implementation of data types in the Java language, the data type specifies the size and type of types that can be stored in the identifier.

In Java, data types are classified into two categories:
  1. Primitive Data type
  2. Non-Primitive Data type
Data TypeDefault ValueDefault size
booleanfalse1 bit
char'\u0000'2 byte
byte01 byte
short02 byte
int04 byte
long0L8 byte
float0.0f4 byte
double0.0d8 byte



Identifiers in Java

The name of all the Java components is required Name, used for the classes, methods, interfaces and variables, is called identifier. The identifier must obey certain rules. These rules are:
  • All identifiers must either start with one letter (one from z or a to z) or currency letter ($) or an underscore.
  • After the first character, an identifier can be any combination of the letter.
  • A Java keyword can not be used as an identifier.
  • Identifier case sensitivity, foo and fu are two separate identifiers in Java.

What is a variable?

Variable is the name of the reserved area allocated in memory. In other words, this is a name for memory space, it is a combination of "different + enabled" which means that its value can be changed.

Java Programming language defines mainly three kind of variables.
  1. Instance variables
  2. Static Variables
  3. Local Variables
1. Instance variables - A variable which is declared inside the class but outside the method, is called frequency variable. It has not been declared as stable.
class Student
{
 String name;
 int age;
}

2. Static Variables -
 A variable declared as static is called static variable, it can not be local

class Student
{
 String name;
 int age;
 static int instituteCode=1101;
}

3. Local Variables - 
Local variables are defined in Local variables are initialized when method, constructor or block start and will end is destroyed. Local variable reside in stack.

float getDiscount(int price)
{
 float discount;
 discount=price*(20/100);
 return discount;
}
Share on Google Plus

About It E Research

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment