Skip to content

Data Type

Essentially, a program is a collection of instructions on manipulating and storing data. For a program to work with data, it must recognize the data. This code note will cover how Java allows us to represent data we use on daily basis.

We will cover following topics:

  • What is Data Type
  • Primitive Data Type
  • Reference Data Type



› What is Data Types

It is a representation of data we use daily in Java programs. It specifies the size and types of data values supported in your code. Before you can express and work with any data in Java, it must be designed and enabled in the language.

Data types in Java comes in two forms:

  • Primitive Data Type   :    data types that comes with Java language
  • Reference Data Type :    custom data type created by developers
Java Data Type Map

Once the data type is specified in the Java language, when you use these in your code, the computer system knows how to interpret them.

When you type a number, character, or String in your Java program. Java can detect and treat them as data values.

1
2
3
4
5
6
// Look how each data is color coded as you type.
System.out.println(87);      // 87 is represented by int 
System.out.println(89.99);   // 88.99 is represented by double 
System.out.println(true);    // true is represented by boolean 
System.out.println('A');     // 'A' is represented by char 
System.out.println("hello"); // "hello" is represented by String 



› Primitive Data Type

Created by Java language engineers, Java users will be able to represent fundamental data, such as numbers, characters, and logical data. The primitive data type is built into the Java language itself.

List of Primitive Data Type:

Data Type Symbol Represents Example Data Value Data Value Range
byte Whole numbers -19, 0, 19 217  to   +128
short Whole numbers -19, 0, 19 -32768  to   +32767
int Whole numbers -19, 0, 19 -2 Billion  to  +2 billion
long Whole numbers -19L, 0L, 19L -9 QT  to   +9QT
float Decimal numbers -19.03F, 0.0F, 19.84F n/a
double Decimal numbers -19.07, 0.001, 19.76 n/a
char Single character 'A', 'a', '?', '#' n/a
boolean Single logical data true, false 2 data values only

Please note that byte, short, int, and long data types represent the same whole numbers.   The only difference between them is the storage capacity. It requires more storage in the computer to represent and hold a number 1900990 than it does for 78.



› Reference Data Type

Java language does not support data types such as Time, Pictures, and Music out of the package. Instead, the programmer must create data representations they will need in their program. This custom-made data type is known as Reference Datatype.

One example of a Reference Data Type is a String data type, which was custom-made to represent text in Java. It was created by a developer who wanted to represent text and paragraphs in a Java program.

Data Type Symbol Represents Example Data Value
String Text data such as paragraph and phrases. "Hello, Alphaleaf students! how are you?"
1
2
3
4
System.out.print("Hello!"); // "Hello!" is recognized as text data
System.out.print("");       // "" is empty text data 
System.out.print("5");      // "5" is text data, not a number
System.out.print("true");   // "true" is text data, not logical data

We will learn how to create custome Data Type of our own when we cover Object Oriented Programming.