Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,390 --> 00:00:03,150
We can use the car type to store a single character.
2
00:00:04,750 --> 00:00:09,130
So in this lesson, you're going to use the card type two story single character and you're also going
3
00:00:09,130 --> 00:00:11,170
to learn when to use car versus drink.
4
00:00:14,250 --> 00:00:19,620
First, I'll need you to make a new class by yourself inside Section two workspace, make a new file
5
00:00:19,620 --> 00:00:24,390
named form Java and the form class must have the main method.
6
00:00:33,710 --> 00:00:40,400
CA is short for a character, as I mentioned earlier, a car variable can only store one character like
7
00:00:40,400 --> 00:00:47,480
A, B or C, and so to define a car variable, you need to write the variable type car, the variable
8
00:00:47,480 --> 00:00:49,370
name, which in this case is gender.
9
00:00:50,000 --> 00:00:53,390
And the character value, which is wrapped in single quotes.
10
00:00:54,140 --> 00:00:56,240
Pay close attention to the single quotes.
11
00:00:56,630 --> 00:00:58,780
Single quotes are for car values.
12
00:00:59,300 --> 00:01:01,280
Don't confuse them with double quotes.
13
00:01:01,760 --> 00:01:04,060
Double quotes are for string values.
14
00:01:04,580 --> 00:01:06,160
Remember that for your next quiz.
15
00:01:07,390 --> 00:01:07,820
All right.
16
00:01:07,820 --> 00:01:16,670
So inside your code, make a car variable named a gender car gender and set it equal to f so single
17
00:01:16,670 --> 00:01:23,720
quotes for a character value and f now print it system dot out.
18
00:01:24,650 --> 00:01:27,620
Dot print line gender.
19
00:01:33,810 --> 00:01:35,370
We're going to compile our code.
20
00:01:39,540 --> 00:01:40,740
And run it.
21
00:01:46,770 --> 00:01:52,980
And that's it, there's really nothing else to a car variable, it can only store one character and
22
00:01:52,980 --> 00:01:58,470
one character, only the gender variable stores the character F, which we then printed.
23
00:02:01,350 --> 00:02:04,770
You can join a string value with a car value using the plus symbol.
24
00:02:05,670 --> 00:02:10,740
So far, using the plus symbol, you connected a number to a string and as a result, the number blended
25
00:02:10,740 --> 00:02:11,470
into the string.
26
00:02:11,490 --> 00:02:15,660
If you remember in the last lesson and you can do the same thing with characters.
27
00:02:17,720 --> 00:02:26,120
This involves a string, the plus icon and a character, and as a result, the character blends into
28
00:02:26,120 --> 00:02:28,760
the string, forming a more complete sentence.
29
00:02:29,740 --> 00:02:36,430
We can apply this in our code, so instead of just printing boring old F will print the string gender.
30
00:02:38,450 --> 00:02:42,650
Leave some white space and connect the string to your character value.
31
00:02:45,310 --> 00:02:52,060
All right, compile the code using job C form dot Java and run it Java form.
32
00:02:53,160 --> 00:02:57,570
Sweet Java embeds the character inside the string and prints it.
33
00:03:01,280 --> 00:03:03,730
You might be asking, why not always use string?
34
00:03:04,040 --> 00:03:07,310
What's the point of a car variable if it can only store one character?
35
00:03:08,150 --> 00:03:12,610
If you actually try to store more than one character inside a car variable, Java would throw an error.
36
00:03:13,340 --> 00:03:13,880
Try it out.
37
00:03:13,910 --> 00:03:20,570
I'm going to try to store car name is equal to and in single code.
38
00:03:20,570 --> 00:03:23,240
Since we're using a car, we'll have to put Jenah.
39
00:03:24,620 --> 00:03:32,480
I already see that there's an Arab let's compile the code anyway, Gervasi form Java and attempting
40
00:03:32,480 --> 00:03:35,920
to compile the code tells me there's an error in line four of my code.
41
00:03:36,950 --> 00:03:42,800
So what I'm going to do actually is store all of these values into string variables, change both types
42
00:03:42,800 --> 00:03:43,390
to string.
43
00:03:43,970 --> 00:03:46,970
And you remember that string values are enclosed in double quotes.
44
00:03:56,650 --> 00:03:58,120
All right, we're going to print the name.
45
00:04:00,530 --> 00:04:02,960
System dart out.
46
00:04:04,600 --> 00:04:05,380
Print line.
47
00:04:07,240 --> 00:04:08,030
Name.
48
00:04:09,390 --> 00:04:15,600
Colon leaf, some white space and connect the string to the string value inside named.
49
00:04:18,730 --> 00:04:20,589
All right, Kapalua code.
50
00:04:23,770 --> 00:04:25,920
Run it and everything works out.
51
00:04:27,040 --> 00:04:28,780
So string is more flexible.
52
00:04:28,810 --> 00:04:30,130
Why not always use it?
53
00:04:30,730 --> 00:04:33,090
The answer is memory and performance.
54
00:04:33,820 --> 00:04:35,380
Don't let these two words frighten you.
55
00:04:35,380 --> 00:04:37,870
Just know this in terms of memory.
56
00:04:37,870 --> 00:04:46,210
Card takes up less memory in terms of performance cars faster car is a primitive data type where a string
57
00:04:46,210 --> 00:04:47,170
is an object.
58
00:04:47,680 --> 00:04:49,330
We'll talk more about objects later.
59
00:04:49,330 --> 00:04:54,310
But for now, when it's possible to use car use car, especially when you're OK, it's really big.
60
00:04:54,340 --> 00:04:58,630
These types of considerations can really make a difference in how well your app performs.
61
00:04:59,580 --> 00:05:03,780
Smack our code will say CA gender is equal to F instead.
62
00:05:06,660 --> 00:05:12,630
We can narrow this down to one rule and it's simple, really use car to store a single character and
63
00:05:12,630 --> 00:05:14,670
you string to store a larger text.
64
00:05:18,950 --> 00:05:24,800
In this lesson, you used a car variable to story single character, a car variable can only store one
65
00:05:24,800 --> 00:05:25,330
character.
66
00:05:26,360 --> 00:05:29,060
You can also join a string value with a car value.
67
00:05:31,930 --> 00:05:37,930
And finally, you learn to use car to store single characters and use string to store text.
6404
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.