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 object data.

Primitive Data

Primitive data is:

Numbers are broken into two categories:

Why are there all these data types to represent integers and real numbers?

Each of these data types have a different storage capacity. This can be important if you have storage concerns.

Primitive vs. Object 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 objects. Objects either represent things in the real-world or group related data together. They are represented in one of two ways:

Some examples of object data are:

Let's do some practice

For the data descriptions listed below, we first determine whether it is primitive data or object data. If it is primitive data, we identify which of the 8 data types would be best to use to represent the data. The 8 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 Object 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 it is going to be an integer. A short could also be used, since it is a reasonably larger number to have in inventory. The int type is a common type to use for integers.
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. A case could be made for this being a String for cash or credit card
Your user name Object 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. This data is best represented in a float or a double. You will often see double being used for real-numbers.
The information stored about a menu item including its name, a description, and the price Object Menu Since this data is being stored as a collection of related data, we should either create a class or a record.
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. You could also use a String.
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. Other types could also be used, such as char if it was represented as a p for passed or f for failed. You might also choose to use the String type and use the words passed or failed.
Your graduation date Object LocalDate Since it is a calendar date, it is best to use the LocalDate class.
Your dessert selection from the choices: brownie, cookie, or cake Object String Since the dessert selections are word a String would work best. You could also choose to number the choices 1 for brownie, 2 for cookie, and 3 for cake. In this case, you would want to use a int or other integer type. Another option would be to have each choice be assigned a letter, so A for brownie, B for cookie, and C for cake. In this case, you would want to use a char or String.
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