Primitive number data types

Introduzione a Java

Jim White

Java Developer

Primitive types

Table summarizing primitive types - byte, short, int, long, float, double, char, and boolean

Introduzione a Java

Numerical primitive types

byte, short, int, long, float, and double all highlighted as the focus for this video

Introduzione a Java

Primitives for whole numbers - int

int stores whole numbers up to two million

Introduzione a Java

long, short, and byte

Table summarizing long (up to a quintillion), short (up to 30000), and byte (up to 128)

Introduzione a Java

int is the primitive of choice

int is used most of the time

Introduzione a Java

double

double allows up to 16 decimal places

Introduzione a Java

float

float stores up to 7 decimal places

Introduzione a Java

double is the primitive for decimal numbers

double is used more often

Introduzione a Java

Declaring primitives - int

defining int intEx = 123456

Introduzione a Java

Declaring primitives - int, double, short, byte

Defining double, short, and byte variables in the same way

Introduzione a Java

Declaring primitives - float and long

Syntax for float and long requires a F/f or L/l at the end

Introduzione a Java

Numerical primitives in action

class PrintlnAsCalculator {
  public static void main(String[] args) {

    int x = 60000;
    byte y = 1;
    short z = 300;
    long w = 20000000L;

    System.out.println(x + y + z + w);
  } 
}
20060301
class PrintlnAsCalculator {
  public static void main(String[] args) {

    double pi = 3.1415926535;
    float half = 0.5F;

    System.out.println(pi + half);
  }
}

$$

3.6415926535
Introduzione a Java

Let's practice!

Introduzione a Java

Preparing Video For Download...