Java Data types and variables

Java Data types and variables

The variables are information stored in the memory areas of internal memory system.
A variable is defined by the following characteristics: name, value, type, persistence and visibility.

Variables that are stored in the internal memory can be integers, real numbers, characters, boolean values or instances.
The internal memory is divided into two parts: stack and heap.
A variable name can not start with a number, can not contain special characters and reserved keywords.

A variable can be declared in a function or outside the function but in a class.
A variable declared within a function is local variable to that function.
A variable declared at class level is used for any function in the class.

Java variables are:

  • Primitive Data Types
  • Arrays

Primitive Data Types

Primitive data types are stored in reserved areas of the stack.
Primitive data types that can be use in Java are:

  • int
  • float
  • short
  • long
  • double
  • char
  • byte
  • boolean


An array is a collection of variables of the same data type.

Data types and variables are:

Variables members(Instance variables) of a class are declared in a class, but outside a method. Instance variables are visible to all methods of that class and other classes depending on their level of access.
Parameters methods – are visible only in the current method.
Local variables – declared in a method or a block and are visible only in the current method or block.
The parameters of exceptions.