CHAPTER 5: Introduction to Java: Objects, Methods, Classes, and Interfaces 151
Since we have already looked at data type keywords in the chapter already, at least the void
(signifying no data type used), String (text data type,) and int (Integer or whole number data), I will
go over all of the other data type keywords that are used in Java and Android here, and then we will
cover the more advanced access and non-access modifiers that are used in the Java programming
language.
It is important to note that even though using a data type keyword in front of your variable names
modifies the type of data that they are defined to contain, the more precise technical term in Java
for this data type keyword is a data type specifier keyword. These two terms are often used
interchangeably in Java; in the next section, the access control modifiers could indeed be looked at
as access control specifiers, as they are indeed specifying the level of access control by prefacing a
Java keyword in front of the Java programming construct.
Other types of data type specifier keywords used in Java (and thus in Android) include float or
floating point numbers, which have a fractional component represented by decimal notation, for
instance, 1.375, as well as boolean, which hold Boolean math “states” such as true and false. There
are other data types in Java for holding more complicated (longer) numeric representations, such as
the long and double data types, which have 64-bit accuracy and can accommodate extremely large
or extremely small numeric representations. There is also a data type that can hold one single 16-bit
Unicode character, called the char data type. The byte data type can hold one number from an 8-bit
range (256, from -128 to +127) of numeric data values, and finally the short data type can hold one
number from a 16-bit range (65,536, from -32,768 to +32,767) of numeric data values. Data types
are relatively easy to understand in comparison to access and non-access modifiers, which we will
cover next.
Java Access Modifiers: Four Levels of Access
Java has a number of modifiers that you can place before Java constructs to define what they
are and who can see them. There are two types of Java modifiers, access control modifiers and
non-access control modifiers.
In case you are wondering what I mean by access control, I’m talking about other Java
programming constructs outside of a given Java class or package being able to reference and
utilize Java assets inside of those packages.
You can apply access control modifiers to classes, methods, interfaces, constructors, and
variables, and include the public, private, and protected Java access modifier keywords. Not
using any access control keyword at all also defines a level of access control, so let’s cover all of
these concepts here in order from the most restrictive (closed) level of access control to the least
restrictive (open) level of access control.
Table 5-1 shows the four different levels of access control modifier in one place.