There are majorly two types of languages. First one is Statically typed language where each variable and expression type is already known at compile time.Once a variable is declared to be of a certain data type, it cannot hold values of other data types.Example: C,C++, Java. Other, Dynamically typed languages: These languages can receive different data types over the time. Ruby, Python
Java is statically typed and also a strongly typed language because in Java, each type of data (such as integer, character, hexadecimal, packed decimal, and so forth) is predefined as part of the programming language and all constants or variables defined for a given program must be described with one of the data types.
Java has two categories of data:
  • Primitive
  • Non Primitive
Primitive :-
Primitive means “very basic”. In Java, primitive datatype refer to basic (self-explanatory, you know it’s an integer when you declare an int) datatype such as int, char, short, byte, float, long, double etc.
boolean: boolean data type represents only one bit of information either true or false . Values of type boolean are not converted implicitly or explicitly (with casts) to any other type. But the programmer can easily write conversion code.
byte: The byte data type is an 8-bit signed two’s complement integer. The byte data type is useful for saving memory in large arrays.
short: The short data type is a 16-bit signed two’s complement integer. Similar to byte, use a short to save memory in large arrays, in situations where the memory savings actually matters.
int : It is a 32-bit signed two’s complement integer.
long: The long data type is a 64-bit two’s complement integer.
float: The float data type is a single-precision 32-bit IEEE 754 floating point. Use a float (instead of double) if you need to save memory in large arrays of floating point numbers.
double: The double data type is a double-precision 64-bit IEEE 754 floating point. For decimal values, this data type is generally the default choice.
char : The char data type is a single 16-bit Unicode character. A char is a single character.

Non Primitive :-
Non primitive datatypes are those which uses primitive datatype as base like array, enum, class etc.

Ranges of Primitive Data Type :-

1

Reserved Words/Keywords :-
Any programming language reserves some words to represent functionalities defined by that language. These words are called reserved words.

2

Variables :-
A variable is the name given to a memory location. It is the basic unit of storage in a program.
  • The value stored in a variable can be changed during program execution.
  • A variable is only a name given to a memory location, all the operations done on the variable effects that memory location.
  • In Java, all the variables must be declared before use.
How to declare variables?
We can declare variables in java as follows:

int age = 24;
Syntax = datatype variableName = value;
datatype: Type of data that can be stored in this variable.
variableName: Name given to the variable.
value: It is the initial value stored in the variable.

Types of variables
There are three types of variables in Java:
  • Local Variables
  • Instance Variables
  • Static Variables
Local Variables: A variable defined within a block or method or constructor is called local variable.
  • These variable are created when the block in entered or the function is called and destroyed after exiting from the block or when the call returns from the function.
  • The scope of these variables exists only within the block in which the variable is declared. i.e. we can access these variable only within that block.
Instance Variables: Instance variables are non-static variables and are declared in a class outside any method, constructor or block.
  • As instance variables are declared in a class, these variables are created when an object of the class is created and destroyed when the object is destroyed.
  • Unlike local variables, we may use access specifiers for instance variables. If we do not specify any access specifier then the default access specifier will be used.
Static Variables: Static variables are also known as Class variables.
  • These variables are declared similarly as instance variables, the difference is that static variables are declared using the static keyword within a class outside any method constructor or block.
  • Unlike instance variables, we can only have one copy of a static variable per class irrespective of how many objects we create.
  • Static variables are created at start of program execution and destroyed automatically when execution ends.
Instance variable Vs Static variable
  • Each object will have its own copy of instance variable whereas We can only have one copy of a static variable per class irrespective of how many objects we create.
  • Changes made in an instance variable using one object will not be reflected in other objects as each object has its own copy of instance variable. In case of static, changes will be reflected in other objects as static variables are common to all object of a class.
  • We can access instance variables through object references and Static Variables can be accessed directly using class name.