WEBVTT

00:00:00.050 --> 00:00:02.520
hi in this video we're going to talk

00:00:02.520 --> 00:00:06.029
about variables so what's a variable a

00:00:06.029 --> 00:00:08.309
variable is like a box with a name that

00:00:08.309 --> 00:00:10.650
can hold a value so here I have a

00:00:10.650 --> 00:00:12.870
variable called num apples with the

00:00:12.870 --> 00:00:14.910
value 5 that represents these five

00:00:14.910 --> 00:00:16.789
apples here

00:00:16.789 --> 00:00:20.640
so remember variables have a name a type

00:00:20.640 --> 00:00:25.949
and a value so in this example the name

00:00:25.949 --> 00:00:29.220
is num apples the type is int for

00:00:29.220 --> 00:00:32.820
integer and the value is 5 there's five

00:00:32.820 --> 00:00:36.180
apples so there's a few important things

00:00:36.180 --> 00:00:38.190
we can do with variables and one of them

00:00:38.190 --> 00:00:40.230
is declaring a variable so this code

00:00:40.230 --> 00:00:43.739
here int number semicolon declares the

00:00:43.739 --> 00:00:45.180
variable num Apple so what that really

00:00:45.180 --> 00:00:47.309
means is that you're saying I hereby

00:00:47.309 --> 00:00:49.559
make a box called num apples to hold an

00:00:49.559 --> 00:00:51.750
integer so it's important that you in

00:00:51.750 --> 00:00:53.699
Java you say the type of the variable

00:00:53.699 --> 00:00:58.260
when you declare it so the other

00:00:58.260 --> 00:01:00.030
important thing is initializing a

00:01:00.030 --> 00:01:02.550
variable so here with this code we're

00:01:02.550 --> 00:01:04.939
creating the variable num apples and

00:01:04.939 --> 00:01:08.070
initializing it to five so initializing

00:01:08.070 --> 00:01:09.810
both is creating the variable and

00:01:09.810 --> 00:01:13.290
setting its initial value so here you

00:01:13.290 --> 00:01:15.420
see the Box now apples has the value

00:01:15.420 --> 00:01:22.979
five and assigning to a variable lets us

00:01:22.979 --> 00:01:25.950
actually change the value in the box so

00:01:25.950 --> 00:01:28.080
here on this first line I write int

00:01:28.080 --> 00:01:31.049
number plus Eckles five that initializes

00:01:31.049 --> 00:01:36.750
the variable num apples to five and then

00:01:36.750 --> 00:01:38.939
this next line num apples equals zero

00:01:38.939 --> 00:01:41.939
that sets the value in the box equal to

00:01:41.939 --> 00:01:44.909
zero it assigns a new value to the

00:01:44.909 --> 00:01:46.649
variable and there's something really

00:01:46.649 --> 00:01:48.360
important on this line notice that I

00:01:48.360 --> 00:01:51.030
don't have the word int again you only

00:01:51.030 --> 00:01:53.250
write the word int or the type of the

00:01:53.250 --> 00:01:55.860
variable when you declare the variable

00:01:55.860 --> 00:02:00.659
for the first time so there's a few

00:02:00.659 --> 00:02:02.670
types in Java that you'll want to be

00:02:02.670 --> 00:02:04.500
aware of some of them are the primitive

00:02:04.500 --> 00:02:06.420
types and so we've already used int

00:02:06.420 --> 00:02:09.569
which is for integers double is for

00:02:09.569 --> 00:02:12.330
numbers that have decimals care is for

00:02:12.330 --> 00:02:13.840
characters like a B

00:02:13.840 --> 00:02:19.709
GED and boolean is for true/false values

00:02:19.709 --> 00:02:23.200
so for the number types the integers are

00:02:23.200 --> 00:02:25.300
whole numbers the numbers used to count

00:02:25.300 --> 00:02:26.709
you know numbers like negative three

00:02:26.709 --> 00:02:30.549
negative two negative one so here is an

00:02:30.549 --> 00:02:32.379
example of using integer int num a

00:02:32.379 --> 00:02:35.349
police file doubles they're like real

00:02:35.349 --> 00:02:37.000
numbers and they can have decimals so

00:02:37.000 --> 00:02:39.910
for example double cost equals forty

00:02:39.910 --> 00:02:45.040
point two five the boolean type

00:02:45.040 --> 00:02:47.920
represents a true/false value so boolean

00:02:47.920 --> 00:02:50.230
logged in equals false and boolean game

00:02:50.230 --> 00:02:54.489
over equals true and the care type

00:02:54.489 --> 00:02:57.099
represents a single character like care

00:02:57.099 --> 00:02:59.650
first letter equals a and care grade

00:02:59.650 --> 00:03:02.349
equals B and notice that with cares were

00:03:02.349 --> 00:03:06.780
just writing these between single quotes

00:03:06.780 --> 00:03:09.069
another type you'll want to know is

00:03:09.069 --> 00:03:10.780
called string strings are not a

00:03:10.780 --> 00:03:12.790
primitive type like the others and

00:03:12.790 --> 00:03:15.970
strings are for text so string is go

00:03:15.970 --> 00:03:18.489
between quotes and start with a capital

00:03:18.489 --> 00:03:20.950
S remember it's not a primitive type

00:03:20.950 --> 00:03:23.200
like the others so if I want to write a

00:03:23.200 --> 00:03:25.299
variable to save my name I write string

00:03:25.299 --> 00:03:27.370
name equals and then in double quotes

00:03:27.370 --> 00:03:31.389
Jeremie string question equals how are

00:03:31.389 --> 00:03:33.569
you
