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:
- Primitive Data type
- Non-Primitive Data type
Data Type | Default Value | Default size |
---|---|---|
boolean | false | 1 bit |
char | '\u0000' | 2 byte |
byte | 0 | 1 byte |
short | 0 | 2 byte |
int | 0 | 4 byte |
long | 0L | 8 byte |
float | 0.0f | 4 byte |
double | 0.0d | 8 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.
- Instance variables
- Static Variables
- 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;
}
class Student
{
String name;
int age;
static int instituteCode=1101;
}
float getDiscount(int price)
{
float discount;
discount=price*(20/100);
return discount;
}
0 comments:
Post a Comment