AP Computer Science Java: Lesson 1.2b
Data Types - Abstract Data Types


Lesson 1.2b - Abstract Data Types
Purpose: To learn about abstract data types of Java and how they differ from primitive data types

Objects
When we worked with Karel J Robot, we were working with objects. An object is also an abstract data type. By abstract, it is meant that a variable of that type maintains information as well as methods that can be enacted upon it. For example, a Hurdler robot was able to keep track of where it was at and what direction it was facing and knew how to respond to commands such as jumpHurdle(); and other such pre-defined methods.

As we learn Java, we will work with many abstract data types. Some of these will be pre-defined and some we will create ourselves. For now, we will work with the abstract data type String. The String data type is capable of holding one or more characters and can be used to store words or even whole sentences. For example, suppose a program we are writing requires that we store the name of a person. A String variable will be the choice for this job. Recall that a char variable is only capable of storing a single character and cannot store an entire word.

Lastly, since a String is an abstract data type, it is actually a pre-defined class. That means that we can make method calls that perform actions with Strings like we did with robots. More on this later...

 

© DanShuster.com