# Primitive Data Types

Let's go into the details of some of the primitive data types.

We'll cover the following

As we discussed briefly in the previous lesson, primitive data types are the most basic types of data in Java. Primitive variables directly store primitive values. In the context of the AP Computer Science exam, we will look into three primitive data types: int, double, and boolean. All of these types are constructed using a binary notation (i.e., base $2$ digits: $0$ and $1$). However, the representation of each varies.

## int type in Java

We use the int type variable to represent integers. The size of an int type variable is $4$ bytes, or $32$ bits. You can assign both positive and negative integer values to such a variable. It uses twoâ€™s complement representation. Letâ€™s briefly take a look at this representation.

You may recall the binary representation of numbers from school but feel free to take a look at this recapBinaryNotation.

You can represent any positive integer in binary notation, but what about the negative integers? Thatâ€™s where twoâ€™s complement comes in handy.

Note: To get information about 2â€™s complement, check out this shot.

Because of twoâ€™s complement representation, the int can take values from the range of $-2,147,483,648$ to $2,147,483,647$.

ðŸ“Œ Note: For integers of larger magnitude, Java has the data type, long. It has a size of 8 bytes, or 64 bits, and its range is $-9,223,372,036,854,775,808$ to $9,223,372,036,854,775,807$.

### Use cases

The int data type can be used whenever you need to represent a discrete number. For example:

• To represent scores in different games
• To represent dates and time in seconds
• To keep count of various events

### Syntax

In Java, you can declare an int type variable and assign it a value in the following manner:

Get hands-on with 1200+ tech skills courses.