Data Types

The following table lists the primitive types in Rust and their equivalent in Java:

RustJavaJava Wrapper ClassNote
boolbooleanBoolean
charcharCharacterSee note 1.
i8byteByte
i16shortShort
i32intIntegerSee note 2.
i64longLong
i128
isizeSee note 3.
u8
u16
u32
u64
u128
usizeSee note 3.
f32floatFloat
f64doubleDouble
()voidVoidSee note 4.

Notes:

  1. char in Rust and Character in JVM have different definitions. In Rust, a char is 4 bytes wide that is a Unicode scalar value, but in the Java Platform, a Character is 2 bytes wide (16-bit fixed-width) and stores the character using the UTF-16 encoding. For more information, see the Rust char documentation.

  2. Unlike Java (and like C/C++/C#), Rust makes a distinction between signed and unsigned integer types. While all integral types in Java represent signed numbers, Rust provides both signed (e.g. i32) and unsigned (e.g. u32) integer types.

  3. Rust also provides the isize and usize types that depend on the architecture of the machine your program is running on: 64 bits if you're on a 64-bit architecture and 32 bits if you're on a 32-bit architecture.

  4. While a unit () (an empty tuple) in Rust is an expressible value, the closest cousin in Java would be void to represent nothing.

See also: