Sullivan Market

a web based full-circle development system



My Java Tutorials - Primitive Variables


integers: byte, short, int, long
byte
Occupies 8 bits or 1 byte, which is, -128 to 127.
short
Occupies 16 bits or 2 bytes, which is, -32,768 to 32,767.
int
Occupies 32 bits or 4 bytes, which is, -2,147,483,648 to 2,147,483,647.
long
Occupies 64 bits or 8 bytes, which is, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

For Example...



public byte byteNumber = (byte)8; //note default integers are ints,
//must cast to a byte
public short shortNumber = (short)16; //note default integers are ints,
//must cast to a short
public int intNumber = 32;
public long longNumber = 64L; //note default integers are ints,
//must cast to a short
public static void Main (String[] argsIn) {

byte tempByte = byteNumber; //tempByte becomes == 8,
//byteNumber stays == 8

short tempShort = shortNumber * 2; //tempShort becomes == 32,
//shortNumber stays == 16

int tempInt = intNumber / 2; //tempInt becomes == 16,
//intNumber stays == 32

long tempLong += longNumber; //tempLong becomes == 65,
//longNumber becomes == 65
tempLong =+ longNumber; //tempLong stays == 65,
//longNumber becomes == 66

}
}

Back To Java Tutorials

©2012 SullivanMarket.com