Vars

variables

Valid variable names:

int total;
int grade4;
int totalPer = 400;

Invalid variable names:

int 2much;

Naming styles:

int sum;
int studentCount;
int bankAccountBalance;
int level2Training;

Primative Data types:

These are the types of variables which are the foundation of all other data types. They are:

  1. Interger
  2. Floating point
  3. Character
  4. Boolean

interger types

typebitsmin valuemax valueliteral form
byte8-1281270
short16-32768327670
int32-214748364821474836470
long64-922337203685477580892233720368547758080L
byte numberOfThings = 45;
short feetInAMile = 5280;
int milesToSun = 92960000;
// note the adding of L at the end of the number
// this indicates it is a long number
long milesInALightYear = 5879000000000L;

floating point types

typebitssmallest positive valuelargest positive valueliteral form
float32$1.4 * 10^{-45}$$3.4 * 10^{38}$0.0f
double64$4.9 * 10^{-324}$$1.7 * 10^{308}$0.0 or 0.0d
float kilometersInAMarathon = 42.195f;
float absoluteZeorInCelsius = -273.15f;
double atomWithInMeters = 0.0000000001d;

character data type

char regularU = 'U';
// unicode of uppercase U with an accent
char accentedU = '\u00DA';

boolean type

boolian iLoveJava = true;

storage

Each definition of a variable gets it own allocation. When you associate a variable to an existing variable, a copy is made. There is no relation between the two. If later on, the source variable changes, the copy will remain with its original value and not be affected.

Previous
Next