Primitive number data types

Introduction to Java

Jim White

Java Developer

Primitive types

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

Introduction to Java

Numerical primitive types

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

Introduction to Java

Primitives for whole numbers - int

int stores whole numbers up to two million

Introduction to Java

long, short, and byte

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

Introduction to Java

int is the primitive of choice

int is used most of the time

Introduction to Java

double

double allows up to 16 decimal places

Introduction to Java

float

float stores up to 7 decimal places

Introduction to Java

double is the primitive for decimal numbers

double is used more often

Introduction to Java

Declaring primitives - int

defining int intEx = 123456

Introduction to Java

Declaring primitives - int, double, short, byte

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

Introduction to Java

Declaring primitives - float and long

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

Introduction to 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
Introduction to Java

Let's practice!

Introduction to Java

Preparing Video For Download...