1
00:00:00,510 --> 00:00:03,510
In this lecture, I'm going to talk about object references.

2
00:00:03,870 --> 00:00:06,180
This topic is divided into four parts.

3
00:00:06,360 --> 00:00:10,140
First, I will tell you what object references are.

4
00:00:10,320 --> 00:00:13,740
Second, what makes them different from primitives?

5
00:00:13,950 --> 00:00:18,120
Third, what basic built in object references Java has.

6
00:00:18,600 --> 00:00:22,890
And last, we will have a code in part about how we can use them.

7
00:00:24,300 --> 00:00:32,640
What object reference means, let me explain this, so object is an instance of a class, it is stored

8
00:00:32,640 --> 00:00:41,040
somewhere in the memory and reference is used to point to that memory location where that object is

9
00:00:41,040 --> 00:00:41,620
stored.

10
00:00:42,120 --> 00:00:43,470
You don't have to handle it.

11
00:00:43,740 --> 00:00:48,900
Jabot will do it for you and uses the variable name to get the object.

12
00:00:49,770 --> 00:00:52,710
To visualize this, you can see a class here.

13
00:00:53,100 --> 00:01:00,120
It is like a blueprint, a scheme, a plan for something like a car, a dodge challenger in our case.

14
00:01:00,630 --> 00:01:05,460
But it can be a movie, an RPG character or something else.

15
00:01:05,850 --> 00:01:09,810
So an object can be created based on that blueprint.

16
00:01:11,050 --> 00:01:18,340
Sticking to our example, we have a Dodge challenger because here it had a lot of attributes, like

17
00:01:18,340 --> 00:01:21,870
a number of seats, horsepower or is damaged.

18
00:01:22,390 --> 00:01:28,140
When you create an object, you can add value to all those attributes.

19
00:01:28,480 --> 00:01:37,300
You can have a dodge with three ninety two horsepower or another one with seven hundred and seven horsepower.

20
00:01:37,930 --> 00:01:41,770
But you can create many other objects with different attributes.

21
00:01:42,220 --> 00:01:47,380
You can create almost unlimited amount of objects out of a class.

22
00:01:47,890 --> 00:01:52,660
When you create an object, it is almost the same as with the primitives.

23
00:01:52,840 --> 00:01:56,230
So instead of data type, we use class name.

24
00:01:56,500 --> 00:02:06,790
Then variable name equals a value or the new keyword and the class name parentheses that where you can

25
00:02:06,790 --> 00:02:11,110
add some parameters to the class and a semicolon.

26
00:02:11,770 --> 00:02:17,080
As you can see, I used uppercase as a starter letter in case of class name.

27
00:02:17,260 --> 00:02:22,810
It is not forced by Java, but it is highly recommended, so it's almost a must.

28
00:02:23,000 --> 00:02:30,730
So as I mentioned, you can add parameters in the parentheses and based on that an object will be created.

29
00:02:31,660 --> 00:02:39,470
I will give you more details on this later in the classes lecture, so just to stick to the Dodge Challenger.

30
00:02:39,820 --> 00:02:47,650
We can create a class Dodge Challenger with all the attributes we coded in the previous lecture to create

31
00:02:47,650 --> 00:02:51,640
an object of deduction and your class, you have to do the following.

32
00:02:52,030 --> 00:03:01,000
The Challenger Red Dot challenger equals new Dodge challenger, and in the parentheses you add red and

33
00:03:01,000 --> 00:03:01,800
a semicolon.

34
00:03:02,230 --> 00:03:05,260
So it's going to create a dodge challenger.

35
00:03:06,220 --> 00:03:13,890
And the color of that car is going to be red, so based on this, you can create a green one as well.

36
00:03:13,900 --> 00:03:15,490
So don't change a green dot.

37
00:03:15,490 --> 00:03:17,980
Chinja, new dodge challenger green.

38
00:03:18,370 --> 00:03:21,700
So as you can see, the class name starts with uppercase.

39
00:03:22,180 --> 00:03:28,870
The variable name starts with a lowercase as in case of the primitives or any other variables.

40
00:03:29,080 --> 00:03:29,290
Right.

41
00:03:29,360 --> 00:03:33,860
Then it was a little bit of taste of classes and objects.

42
00:03:34,270 --> 00:03:36,940
Let's see what makes them different from primitives.

43
00:03:37,630 --> 00:03:40,410
The biggest difference is that they have functionality.

44
00:03:40,690 --> 00:03:49,420
So when we wanted to print something out, we used that printer and function and we put the text and

45
00:03:49,420 --> 00:03:52,120
the variables between the parentheses.

46
00:03:52,750 --> 00:03:59,680
In case of the challenger, we can create functionalities like honk and it would print something on

47
00:03:59,680 --> 00:04:07,150
the screen or get color, which would return the color of the car, or we can have it get a description

48
00:04:07,180 --> 00:04:10,350
or turn left or get horsepower.

49
00:04:10,480 --> 00:04:12,910
But the options are almost unlimited.

50
00:04:13,480 --> 00:04:19,990
What you have to keep in mind for now is that you can call these functions when you create an object

51
00:04:20,290 --> 00:04:28,270
and put a dot at the end of the variable name and you can use those functions that are available for

52
00:04:28,270 --> 00:04:29,080
that class.

53
00:04:29,110 --> 00:04:35,140
So, as I said, more on this later to let's see what built in data types Java has.

54
00:04:35,380 --> 00:04:41,980
They are pretty easy because every primitive has its object version with a little name change.

55
00:04:41,980 --> 00:04:50,590
So byte short integer instead of end long float, double boolean and character instead of char.

56
00:04:50,590 --> 00:04:53,220
The values you can store in them is the same.

57
00:04:53,260 --> 00:04:55,090
We also have a new one here.

58
00:04:55,330 --> 00:05:02,590
String String is for storing texts like Red Green Dot Chinja or sentence's.

59
00:05:02,590 --> 00:05:09,550
As I mentioned before, objects have useful functions in case of string to uppercase, to lowercase

60
00:05:09,550 --> 00:05:16,230
or equals that can be used to compare two strings or is empty or is blank.

61
00:05:16,270 --> 00:05:21,310
These functions are very good and used quite regularly, but be careful.

62
00:05:21,310 --> 00:05:23,050
The last two are not the same.

63
00:05:23,230 --> 00:05:28,180
Besides these, there are many other functions that can be used for strings.

64
00:05:28,300 --> 00:05:31,560
So to define a string variable, you have to do the following.

65
00:05:31,960 --> 00:05:40,690
So first the class name string, then car type is the variable name equals in parentheses.

66
00:05:40,690 --> 00:05:46,600
The text we would like to assign to car type variable name, then the semicolon.

67
00:05:46,750 --> 00:05:49,330
It's almost the same like with the primitives.

68
00:05:49,840 --> 00:05:52,000
Well string is a big topic.

69
00:05:52,360 --> 00:05:59,920
There will be a few other lectures to cover that we are going to do some coding exercise with it, but

70
00:05:59,920 --> 00:06:02,160
we will get back to it a bit later.

71
00:06:02,170 --> 00:06:10,090
OK, I know this lecture has a lot of more on this later part, but I wanted to give you some insight

72
00:06:10,090 --> 00:06:12,130
to those Java concepts.

73
00:06:12,130 --> 00:06:19,540
I think it is better to give some explanation now instead of not telling you anything or having a separate

74
00:06:19,540 --> 00:06:24,940
lecture with a ton of information moving back to object references.

75
00:06:24,940 --> 00:06:31,450
I think the best way we can see how they work, what they are, is to use them in the code.

76
00:06:31,630 --> 00:06:33,790
So let's get back to intelligent.
