Skip to main content
OCA Java Programmer 1Z0-803

JAVA Differentiate between Primitive and Reference Variables

By November 3, 2013September 12th, 2022No Comments

Welcome to TheUrbanPenguin and the series of free tutorials we have running to prepare you for the OCA exam 1ZO-803, the Java 7 SE Programmer 1 certification from Oracle. Each tutorial will step you through a specific objective of one of the 8 topics from the exam. In this tutorial we look at the wonderful world of Variables and what they can point to. Variables in Java can be native from the, if you like: raw elements that Java has. Technically we would refer to these as  Primitive Data Types. Java has 8 Primitive data types which we list for you below in the following bulleted list:

  • boolean
  • byte
  • short
  • int
  • long
  • float
  • double
  • char

Using the following examples we can see variables declared, initiated and used from Primitives:

int count = 1;
 if (count < 10) {
 system.out.println(count);
 }
byte noWheels;
 noWheels = 4;
 system.out.println("There are " + noWheels + " wheels on this vehicle");

Of course, in an Object Oriented system we can access variables in other objects. These would be Reference variables even though they may be made up from Primitive types as they are in another class we just name a reference to the Object and Field.

int count;
 count = Car.noWheels;

The video takes you through a demo.