Java provides several data types to represent different kinds of values. Here are the commonly used data types in Java:
- Primitive Data Types:
byte
: 8-bit integer (-128 to 127)short
: 16-bit integer (-32,768 to 32,767)int
: 32-bit integer (-2,147,483,648 to 2,147,483,647)long
: 64-bit integer (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)float
: 32-bit floating-point numberdouble
: 64-bit floating-point numberboolean
: represents true or falsechar
: 16-bit Unicode character (0 to 65,535)
- Reference Data Types:
String
: represents a sequence of charactersArray
: represents a collection of elements of the same typeClass
: represents a class or interface typeInterface
: represents an interface typeEnum
: represents an enumeration typeObject
: represents any type of object
- Other Data Types:
BigInteger
: represents arbitrary-precision integersBigDecimal
: represents arbitrary-precision floating-point numbersDate
: represents a specific moment in timeCalendar
: provides various calendar-related operations
These are the basic data types in Java, and you can also create your own custom data types using classes and structures.