Non-Primitive Data Types in Java

Non-Primitive Data Types in Java
Coming up next: Reference Data Types in Java

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
Your next lesson will play in 10 seconds
  • 0:04 Primitive Versus Non-Primitive
  • 1:48 Class Data Types
  • 2:19 Interface Data Types
  • 2:38 Array Data Types
  • 3:19 Lesson Summary
Add to Add to Add to

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Log in or Sign up


Recommended Lessons and Courses for You

Lesson Transcript
Instructor: Martin Gibbs

Martin has 16 years experience in Human Resources Information Systems and has a PhD in Information Technology Management. He is an adjunct professor of computer science and computer programming.

Like life forms, non-primitive data types in Java are more sophisticated than their primitive brethren. This lesson covers the non-primitive types, also called reference types. Code examples are provided to show their use and functionality.

Primitive Versus Non-Primitive

The primitive data types include byte, int, long, short, float, double, and char. They are part of the core of Java and you don't need anything special to use them. For example, the following declares a long variable for a partNumber:

Java primitive data declaration

A data type that is primitive, such as the long variable, actually stores the value. If we give a value to the partNumber value, for example 4030023, that is what Java stores.

Non-primitive, or reference data types, are the more sophisticated members of the data type family. They don't store the value, but store a reference to that value. Instead of partNumber 4030023, Java keeps the reference, also called address, to that value, not the value itself.

Reference types can be a class, interface, or array variable. Remember that a class is a set of plans for a given object. There are thousands of tree objects, but the parent set of plans would belong in the tree class. Variables can exist inside the tree class, such as height or tree type. These are reference variables.

An array is a single object that contains multiple values of the same type. We could have declared our integer for partNumbers as an array to hold a given number of partNumbers in a single object.

The diagram you're looking at on your screen illustrates an example of primitive variables versus a reference variable. Notice how the values are stored in the primitive variables but the non-primitive or reference variable points to an address in memory.

Java non-primitive diagram

Now let's take a closer look at each type of reference data type, starting with the class.

Class Data Types

Let's say we declare a new class called Product:

Java class definition

In order to create a new non-primitive or reference variable for this class, we have to create a new instance of the Product class. The new keyword is used to create an object. Look at the following example where we'll be creating a new Product called car wax.

The Java code is as follows:

Java class variable

So now we have a variable of carWax: But it's really an instance of the Product class, and not a set value like the primitive variables.

Interface Data Types

An interface is like a dashboard or control panel for a class. It has the buttons, but the function is elsewhere. We won't go into detail on implementing interfaces since the focus is on the interface as a non-primitive, or reference, data type.

Java non-primitive interface

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create An Account