Data Type
A data type specifies the type of data that a variable can store such as integer, floating, character, etc. There are two data types available in Java −
-
Primitive Data Types
-
Reference/Object Data Types
Primitive Data Types
There are eight primitive datatypes supported by Java. Primitive datatypes are predefined by the language and named by a keyword. Let us now look into the eight primitive data types in detail.
byte
-
Example: byte a = 100, byte b = -50
short
-
Short data type is a 16-bit signed two’s complement integer
-
Example: short s = 10000, short r = -20000
int
-
Int data type is a 32-bit signed two’s complement integer.
-
Example: int a = 100000, int b = -200000
long
-
Long data type is a 64-bit signed two’s complement integer
-
Example: long a = 100000L, long b = -200000L
float
-
Example: float f1 = 234.5f
double
-
Example: double d1 = 123.4
boolean
-
boolean data type represents one bit of information
-
Example: boolean one = true
char
-
Example: char letterA = ‘A’
Reference/Object data types
Reference/Object data types, simply known as reference types or object types, are data types in programming languages that allow you to work with objects and references to those objects. Unlike primitive data types, which store the actual data, reference types store memory addresses or references to the location where the actual data (the object) is stored in memory.
Example:
Calculate obj = new calc(60,80);
Here, the value is passed through object using reference data types in other methods.
Identifiers in Java
Identifiers in Java are symbolic names used for identification. They can be a class
name, variable name, method name, package name, constant name, and more. However, In Java, There are some reserved words that can not be used as an identifier.
public class Kalokalam
{
public static void main(String[] args)
{
System.out.println("Hello Kalokalam");
}
}
From the above example, we have the following Java identifiers:
1. HelloKalokalam (Class name)
2. main (main method)
3. String (Predefined Class name)
4. args (String variables)
5. System (Predefined class)
6. out (Variable name)
7. println (method)
Rules for Identifiers in Java
There are some rules and conventions for declaring the identifiers in Java. If the identifiers are not properly declared, we may get a compile-time error. Following are some rules and conventions for declaring identifiers:
-
A valid identifier must have characters [A-Z] or [a-z] or numbers [0-9], and
underscore(_) or a dollar sign ($). for example, @java is not a valid identifier
because it contains a special character which is @. -
There should not be any space in an identifier. For example, java lang is an
invalid identifier. -
An identifier should not contain a number at the starting. For example,
123java is an invalid identifier. -
An identifier should be of length 4-15 letters only. However, there is no
limit on its length. But, it is good to follow the standard conventions. -
We can’t use the Java reserved keywords as an identifier such as int, float,
double, char, etc. For example, int double is an invalid identifier in Java. -
An identifier should not be any query language keywords such as SELECT, FROM, COUNT, DELETE, etc.