Types

index
BASIC

When a variable is declared, it is declared with a particular type. The type tells what kind of values the variable can have, and what the possible operations on that type are.

There are eight primitive types in Java; these are the basic building blocks from which all other types are constructed. In addition, Java defines literally thousands of object types, and every program you write has additional programmer-defined object types of its own. Every class defines a type.

For example, int is a primitive type that can have integer values, and the operations add, subtract, multiply, divide, and several others. String is an object type supplied by Java, with operations such as length and substring. When you write a program, you might define a type (class) named Employee with operations hire, pay, and fire.