In computer science, data is information
that is stored or processed by a computer.
While that might seem fairly abstract,
there are many data points we use in everyday life.
Your name, your age, the number of apples in your pantry,
whether your kitchen light is on or off,
these can all be considered pieces of data,
and we represent pieces of data in code using data types.
Similar to other programming languages,
Java classifies different pieces of data
with data types based on their value.
For example, there's a data type for letters and symbols,
and there are various data types for numbers.
Ultimately, a data type provides a set of possible values.
And if a piece of data is one of these values,
it is classified as that specific type.
Java separates its data types into two main categories.
One of the categories is called Primitive data types,
which consists of the most basic data types
in the Java language.
These are the most foundational.
The Boolean data type represents a true or false value.
This means the data piece
of whether the kitchen light is on or off,
could be represented as a Boolean in code.
It might have the value true,
or it might have the value false, but it can never be both.
An Int, short for integer, represents a whole number.
The number of siblings you have
could be represented in code as an Int.
You could have zero siblings, three siblings,
10 siblings, any whole number amount of siblings.
A Double represents a decimal number.
With a Double, you can represent your GPA, say 3.4 in Java.
The last Primitive type is a Char,
which is short for character.
A Char represents a single letter or symbol.
Some possible values for a Char
could be your first initial or last initial,
your favorite letter, or the hashtag symbol.
We classify these data types as Primitive types
because they are the basis and foundation
for all other data types
within the Java programming language.
Let's try using our Primitive types in Java.
We'll be creating a few pieces of data
that could represent attributes
of a given high school student.
We could represent a student's age by just writing 15.
Then we could represent a student's GPA with just 3.45.
However, we get errors.
What we've written are technically numbers
and pieces of data, but in Java,
we save data in something called a variable.
A variable is a way to label data
and reference it later in your program.
Instead of saying 15, we can create a label,
say student age, and then assign a value to it,
in this case, 15.
We still get an error here, and that's because
we need to add a data type to the variable.
We can add Int at the beginning of the line
and then a semi-colon at the end of the line
to end the statement.
And all of our errors are gone.
As you can see, a variable
has a data type, label, and value.
In this case, the data type is Int.
The label is student age, and the value is 15.
The equal sign is an assignment operator
that assigns the Int variable with the label student age,
and the value 15.
Let's create the next piece of data in Java,
a student's GPA.
We need to create another variable.
And we decided before that, that data type would be Double.
So let's write Double, and give the variable
the label student GPA,
and then we'll sign it the value 3.45,
and add a semi colon to end the statement.
Next, we'll represent a student's first initial
with the data type Char, student first initial
as the label, and give it the value K.
We'll do something similar for the student's last initial
with the data type Char, label student's last initial,
and give it the value H.
For all of these variables, you could put a different value
as long as it can still be represented
by that given data type.
For example, you couldn't put a letter or symbol
as the value of student age,
but you could put another whole number,
say 17 instead of 15.
The last piece of data we want to represent
is, has perfect attendance.
Like the other variables,
we'll write the data type, Boolean,
the label, has perfect attendance,
and then give it the value true.
You may notice that our variable names
are grayed out, that's because
although we've created a piece of data
and represented it in Java,
we don't use or reference it in our program.
One way we could reference it
is by printing out the value of the variable to the console.
We'll write System.out.println,
and instead of adding quotes
we'll just write the name of the variable.
Since student age has the value 15,
we'll print out 15 to the console.
We'll save this and then click the play button,
or you could left click and hit Run Main.main,
and we get 15 in our console.
Let's try this with the other variables.
We'll write System.out.println, student GPA,
System.out.println, student first initial,
System.out.println, the last initial,
and then the has perfect attendance.
We'll run this again, and we get 15, 3.45,
K, H, and true, as expected in the console.