Numeric Types Overview

The integer types store numbers without decimal places.

byte data type

The byte data type store values in the range from -128 to 127, which is 27-2^{7} to 27 2^{7}. You would use the byte data type if you know your number would be within the range of -128 to 127. It saves memory in large arrays.

byte maximumUsersPerGroup = 120;

short data type

The short data types stores values in the range from -32768 to 32767, which is 215-2^{15} to 215 2^{15}.

short maximumMessageLength = 5000;

int data type

The int data type store values in the range from 231 -2^{31} to 231 2^{31}

int currentUsersOnline = 9300;

long data type

It stores values in the range from 263 -2^{63} to 263 2^{63} . An integer literal is of type long if it ends with the letter L or l.

long bigNumberWithoutDecimal = 68719476736;

Optionally you can prefix it with the letter L or l. Try to avoid using the lowercase l as it can be mistaken with the value 1.

long maximumCharacters = 140L;

char data type

The char data type can contain a single unicode character enclosed in single quotes(''). Its represented internally as a number.

char correctAnserOption = 'A';
//Using an int number
char atSign = 64;

results matching ""

    No results matching ""