Skip Top Navigation Bar

Introduction to Determining Data Types

A computer takes in input (data), stores it, processes it, and then outputs the new data. It's all about data. That is the source and life of any program. Consider some of the following popular programs you might be using:

Let's also consider a program that would be used to Analyze Data. The input would be data from a database. The program would store this data in a list. The program would then process the data to answer a question someone might have about the data. The output would be the answer from this analysis.

Java divides data into primitive data and reference data.

Primitive Data

Java divides data into primitive data and reference data.

Primitive data is:

Each primitive data is provided with a data type, a predefined reserved keyword that indicates what type of data is to be stored. For integer values, there are four data types: byte, short, int, and long. We will focus on using int. For real numbers, there are two data types: float and double. We will focus on using double. For boolean values the data type boolean is used. For character values the data type char is used.

Primitive vs. Reference Data

What if the data isn't a number, boolean, or character? How do we store it then? Data that doesn't fall into these categories are considered reference data. Reference data are used to represent or simulate something that is part of the real-world, like dice or calendar dates. They can also be used to group related data together. Reference data is represented with classes, which are blue prints that specify the data stored and define any behaviors or functions that are included. There are existing classes that can be used or you can create your own classes. There will be opportunities for both throughout these materials.

Some examples of reference data are:

There exists classes that can be used to represent the primitive data types as well.

Let's do some practice

For the data descriptions listed below, first determine whether a primitive data can be used or if it would require the use of a reference data type. If a primitive data type can be used, we identify which of the 4 data types would be best to use to represent the data. The 4 primitive data types are listed and described above. Some of the descriptions could be represented multiple ways, so be sure to explain your choice.

Data Description Primitve or Reference Data Type Explanation
The quantity of water bottles that are available for sale Primitive int A quantity is a number. There are only whole numbers of water bottles, so an integer is the best choice.
Whether you are paying with cash or credit card Primitive boolean Since the answer to this is either yes or no, that would be equivalent to true for yes and false for no.
Your user name Reference String Since your user name is a collection of characters, it would need to be stored in a String.
The amount of money you get paid per hour at a part-time job Primitive double Since we are using money here, we have real-number data.
The information stored about a menu item including its name, a description, and the price Reference Menu Since this data is being stored as a collection of related data, we should either create a class.
The letter grade you recieved on a test Primitive char Since this is a letter grade (A, B, C, D, F), the char type is best.
Whether you passed or failed your driving test Primitive boolean Since this is a two option situation, either you passed or you didn't, we can use a boolean type.
Your graduation date Reference LocalDate Since it is a calendar date, it is best to use the LocalDate class.
A language phrase for a language learning app Object String Since this would be more than a single character, it would need to be stored in a String.

Resources