CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ

Java

Java Programming
Numeric variables
Assignment statements

Two of the eight primitive data types

Type Bytes Description
int 4 Integers from -2,147,483,648 to 2,147,483,647.
double 8 Numbers with decimal places that range from -1.7E308 to 1.7E308 with up to 16 significant digits.

How to declare and initialize a variable in one statement

Syntax

type variableName = value;

Examples

int scoreCounter = 1; // initialize an integer variable
double unitPrice = 14.95; // initialize a double variable

How to code assignment statements

int quantity = 0; // initialize an integer variable
int maxQuantity = 100; // initialize another integer variable

// two assignment statements

quantity = 10; // quantity is now 10
quantity = maxQuantity; // quantity is now 100

Previous | Declare and initialize | Assignment statements | Arithmetic expressions | Next