AP Computer Science Java: Lesson 1.2a
Data Types - Primitive Data Types


Lesson 1.2a - Primitive Data Types
Purpose: To learn about simple data types of Java and how they are handled in memory

Data Storage
Programs need to be able to store data. Since there are different types of data with different storage needs, Java has to be able to address this fact. We will begin with what are called primitive (or simple) data types. Primitive data types are simply used for storage and do not have methods associated with them. Below are the simple data types we will use in this course.

Numeric Data Types
Type What it stores Storage Requirements Range
int
whole numbers
4 bytes
-2,147,483,648 to +2,147,483,647
double
decimal numbers
8 bytes
-1.7977+E308 to +1.7977+E308

 

Non-Numeric Data Types
Type What it stores Examples
char
single characters
'C', 'k', '$', '8'
boolean
logical values
true, false


Important So when a variable is declared of a given type, it is capable of storing a value as described in the above tables. It may not accurately store values of other types. For example, if a double is stored in an int variable, it will lose the decimal part of the number. So choose data types wisely and handle them with care.

 

© DanShuster.com