Data types are one of the most fundamental blocks of a Java Program. Java, being an Object oriented language requires all the basic units of a program to be an object.

Data types are used to define / describe an object. For example, most physical objects in the real world can be defined using a set of characteristics. For example, A car can be defined using a host of characteristics like make, model, color, dimensions. These characteristics become the data types for the class Car.

Similarly, the non physical components can also be objectified, for example an Account can be defined using characteristics like ID, Name, Type etc which will become its data types.

class Car {
   Model model;
   Make make;
   String color;

Boolean Types

Variables of type boolean can have any of the two Boolean literal values true and false. The expressions that result in a Boolean type are used in the context of decision making. Several operators combine boolean values, including operators for boolean AND, boolean OR, and boolean negation (these are &&, ||, and !, respectively), as well as comparison operators that produce a boolean result.

boolean state = true; //Initialize the variable state with the value true.


Note: Java does not support bool to integer conversions. Boolean types cannot be cast to primitive types and vice versa

Side Note: The boolean type is named after the mathematician, George Boole, who invented Boolean algebra.


Explicit data values that appear in the program are called literals. Literals are used to represent fixed values or constants. Each literal is also of a particular type and can be used anywhere a value of its type is allowed. Integer Literals have int type, floating point literals have double type etc. If the type of the literal is not specified, java assigns the most feasible type to it by default. If the type has to be explicitly assigned add appropriate suffixes to the literal. 25, for example, is an integer literal of type int.