Data Types - Java, Kotlin

Java & Kotlin Data Types Overview

1. Integer Data Types Learn more →

Data TypeJavaKotlinSizeMin ValueMax ValueDescription
BytebyteByte8 bits-128127 Stores very small whole numbers. Saves memory in large arrays.
ShortshortShort16 bits-32,76832,767 Stores small integers larger than Byte but smaller than Int.
IntintInt32 bits-231231-1 Most commonly used for whole numbers.
LonglongLong64 bits-263263-1 Used to store very large whole numbers.

2. Floating-Point Data Types Learn more →

Data TypeJavaKotlinSizePrecisionDescription
FloatfloatFloat32 bits6–7 digits Stores decimal numbers with single precision. Requires 'F' suffix in Kotlin.
DoubledoubleDouble64 bits15–16 digits Stores decimal numbers with double precision. Default for decimals.

3. Character Data Type Learn more →

Data TypeJavaKotlinSizeDescription
CharactercharChar16 bits Stores a single Unicode character (letters, digits, symbols).

4. Boolean Data Type Learn more →

Data TypeJavaKotlinDescription
BooleanbooleanBoolean Stores true/false values. Used in conditions.

5. String Data Type Learn more →

FeatureJavaKotlinDescription
StringStringString Stores a sequence of characters (text). Strings are immutable.
Null SafetyNoYes Kotlin prevents null unless explicitly allowed using '?'.

6. Array Data Type Learn more →

FeatureJavaKotlinDescription
Array Typeint[], String[]IntArray, Array<String> Used to store multiple values of the same type.

7. Kotlin Special Data Types Learn more →

Data TypeDescription
AnyRoot type of all non-null types (like Object in Java).
UnitRepresents no meaningful return value (like void).
NothingRepresents no value; used for functions that never return.
Nullable (?)Allows variables to safely hold null values.

Java vs Kotlin – Key Differences

AspectJavaKotlin
Primitive TypesYesNo (handled internally)
Null SafetyNoYes
Type ConversionImplicitExplicit
Code SafetyLowerHigher

Conclusion: Kotlin enhances Java data types with null safety, concise syntax, and modern features while remaining fully JVM compatible.

Comments

Popular posts from this blog

Integer Data Types in Java and Kotlin (Byte, Short, Int, Long) with Examples

Floating Point Data Types in Java and Kotlin (Float vs Double) Explained