Java Keywords And Data Types


Java Keywords:

● There are 49 reserved keywords currently defined in the Java language.
● These keywords, combined with the syntax of the operators and separators, form the definition of the Java language. 
● These keywords cannot be used as names for a variable,class, or method.

Java Keywords
abstract continue goto package synchronized
assert default if private this
Boolean do implements protected throw
break double import public throws
byte else instanceof return transient
case extends int short try
catch final interface static void
char finally long strictfp volatile
class float super while while
const for switch switch

Data Types:

 ● Java is safe and robustness because of data Types.
 ● in C/C++ you can assign a floating-point value to an integer. In Java we cannot assign a floating-point value to an integer.
 ● Java defines eight types of data: byte, short, int, long, char, float, double, and Boolean. These can be put in four groups as follows.

Integers:- 
 ● This group includes byte, short, int, and long, which are for whole valued signed numbers.

byte:  The smallest integer type is byte. This is a signed 8-bit type that has a range from –128 to 127. Variables of type byte are especially useful when you’re working with a stream of data from a network or file.
Byte variables are declared by use of the byte keyword.
For example:
byte a = 50, b = -50;
a and b default value is 0.

short: short is a signed 16-bit type. It has a range from –32,768 to 32,767.This . A short is 2 times smaller than an int.
Short variables are declared by use of the short keyword.
For example, declares two short variables called a and b:
short a = 105000 ,b = -150000;
a and b default value is 0

Int: The most commonly used integer type is int. It is a signed 32-bit type that has a range from –2,147,483,648 to 2,147,483,647. Int are commonly used to control loops and to index arrays.
Int variables are declared by use of the int keyword.
For example, declares two int variables called a and b:
int a = 10500 ,b = -150000;
a and b default value is 0

long: long is a signed 64-bit It has a range from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. This type it useful when big numbers are needed.
Long variables are declared by use of the long keyword.
For example, declares two long variables called a and b:
long a = 100000L ,b= 100000L;
a and b default value is 0

Floating-point numbers :-
 ● This group includes float and double, which represent numbers with fractional precision. Floating-point numbers, also known as real numbers, are used when evaluating expressions that require fractional precision.
float: The type float specifies a single-precision value that uses 32 bits of storage. Variables of type float are useful when you need a fractional component, but don’t require a large degree of precision.
For example, declares two float variables called a and b:
float b = 245.5f, c = 14.5f;
a and b default value is 0.0f.

double: Double precision, as denoted by the double keyword, uses 64 bits to store a value.
All transcendental math functions, such as sin( ), cos( ), and sqrt( ), return double values.
For example, declares two double variables called a and b:
double a = 1234.5 , b =  234.5;
a and b default value is 0.0d.

Characters:-
 ● This group includes char, which represents symbols in a character set, like letters and numbers.

char: char data type is a single 16-bit Unicode character. The range of a char is 0 to 65,536. The standard set of characters known as ASCII still ranges from 0 to 127. char minimum value is '\u0000' or 0 and maximum value is '\uffff' or 65,535.
Example: char a = ‘A’;
Booleans:- 
 ● This group includes boolean, which is a special type for representing true/false values.

boolean: is logical values. It represent one bit of information.
Example: boolean a = true;
Default value of a is false.