1
00:00:00,450 --> 00:00:05,210
Hi Everyone interesting story all I want to talk about this story in class in Java.

2
00:00:05,430 --> 00:00:08,560
So first of all we need to create a Java project.

3
00:00:08,700 --> 00:00:13,830
So we need to click on File New and then click on Java project.

4
00:00:13,830 --> 00:00:14,470
OK.

5
00:00:14,610 --> 00:00:16,800
So for the project name just type in here.

6
00:00:16,890 --> 00:00:18,960
A strange class.

7
00:00:19,590 --> 00:00:20,280
OK.

8
00:00:20,490 --> 00:00:25,200
And then click on finish and then if we need a main class for our project.

9
00:00:25,260 --> 00:00:32,100
So just click on this as our See folder and then click on File New and then click on class.

10
00:00:32,160 --> 00:00:40,110
So for the class name just type in here made and for the package name we need a reverse domain here.

11
00:00:40,110 --> 00:00:49,050
So just type in here com that your name dot project name is three in class.

12
00:00:49,590 --> 00:00:50,260
OK.

13
00:00:51,340 --> 00:00:58,600
And for the modifiers to publish and here make sure that you check this check box here that says public

14
00:00:58,810 --> 00:01:00,460
static void main effect.

15
00:01:00,470 --> 00:01:01,020
OK.

16
00:01:01,240 --> 00:01:03,080
And then click on finish.

17
00:01:03,100 --> 00:01:07,150
So as you can see here our main class is now created.

18
00:01:07,150 --> 00:01:14,140
So just delete this comment here and then I double click on this main Java tab here in order to make

19
00:01:14,140 --> 00:01:16,380
this a little area wider.

20
00:01:16,870 --> 00:01:19,810
So as you can see here my editor area is now much wider.

21
00:01:19,900 --> 00:01:23,980
So now I want to talk about a predefined class in Java called string.

22
00:01:24,040 --> 00:01:30,930
Ok so what is strange strange is nothing but a sequence of characters.

23
00:01:30,940 --> 00:01:36,940
For example hello is a string of five characters in Java programming language.

24
00:01:36,940 --> 00:01:45,520
Strange is an immutable object which means it is constant and can not be changed once we actually created

25
00:01:45,760 --> 00:01:46,930
that object.

26
00:01:46,930 --> 00:01:51,160
OK first of all in order to create our screened there are two ways.

27
00:01:51,190 --> 00:01:56,680
The first way is string literal and the second way is using the new keyboard.

28
00:01:56,680 --> 00:02:05,320
OK so the first way is strangely the road in Java strings can be created by assigning a string literal

29
00:02:05,470 --> 00:02:06,960
to a string instance.

30
00:02:07,050 --> 00:02:11,000
OK so now let me show you some real examples about strings.

31
00:02:11,020 --> 00:02:11,540
OK.

32
00:02:11,830 --> 00:02:18,460
So first of all in order to create a string object first we need to refer to the name of our string

33
00:02:18,460 --> 00:02:21,500
class as strange as you can see here.

34
00:02:21,670 --> 00:02:28,830
And then if we need to give our object a name for example my first strange.

35
00:02:29,190 --> 00:02:29,910
OK.

36
00:02:29,950 --> 00:02:36,700
And then we need to put in an assignment operator here and then we need to actually assign a string

37
00:02:36,700 --> 00:02:38,640
literal to our string object.

38
00:02:38,650 --> 00:02:39,240
OK.

39
00:02:39,340 --> 00:02:43,670
So I just need to put in here to double quotes and insert the double quotes.

40
00:02:43,670 --> 00:02:46,140
I can just typing Hello.

41
00:02:46,490 --> 00:02:47,240
OK.

42
00:02:47,260 --> 00:02:51,100
And then I need to put in a semi-colon at the end of my statement.

43
00:02:51,100 --> 00:02:59,770
So now as you can see I created a string object called my first string and I assigned this string literal

44
00:02:59,920 --> 00:03:01,140
to our string object.

45
00:03:01,150 --> 00:03:01,760
OK.

46
00:03:01,960 --> 00:03:09,300
So in order to actually create String objects we need to actually put use these double quotes and inside

47
00:03:09,310 --> 00:03:10,360
the double quotes.

48
00:03:10,510 --> 00:03:12,950
We can just put our string literals.

49
00:03:13,150 --> 00:03:18,180
So remember that string object is nothing but a sequence of characters.

50
00:03:18,220 --> 00:03:25,000
OK so now if I want to output the value of this string object to the console I just need to type in

51
00:03:25,000 --> 00:03:29,090
here system that out that princeling.

52
00:03:29,770 --> 00:03:35,680
And then inside the prentices I can just refer to the name of my object my first strange and then I

53
00:03:35,680 --> 00:03:38,940
need to put in a semi-colon at the end of my statement.

54
00:03:38,950 --> 00:03:42,170
So now if I run my project let's see what happens.

55
00:03:42,700 --> 00:03:45,490
As you can see this value is now output to the console.

56
00:03:45,490 --> 00:03:45,990
Hello.

57
00:03:46,080 --> 00:03:46,610
OK.

58
00:03:46,720 --> 00:03:50,160
So this value is the value of this string object.

59
00:03:50,170 --> 00:03:56,260
OK so now let me actually create another string object.

60
00:03:56,260 --> 00:04:01,200
So again I need to refer to the name of my class as strange.

61
00:04:01,420 --> 00:04:02,070
OK.

62
00:04:02,200 --> 00:04:05,010
And then I need to give my object a name.

63
00:04:05,020 --> 00:04:08,120
My second string.

64
00:04:08,320 --> 00:04:09,000
OK.

65
00:04:09,220 --> 00:04:15,600
And then I need to put in an assignment operator here and then I put in double quotes and then inside

66
00:04:15,600 --> 00:04:24,340
the double quotes again I type in Hello OK and then I need to put in a semi-colon at the end of my statement.

67
00:04:24,400 --> 00:04:30,520
And now if you want to output the value of my second string object to the concert I just need to type

68
00:04:30,520 --> 00:04:37,660
in here system that out that print learned and it inside the parenthesis I can just refer to the name

69
00:04:37,660 --> 00:04:40,940
of my object my second string object.

70
00:04:40,990 --> 00:04:44,150
And then I need to put in a semicolon at the end of my statements.

71
00:04:44,170 --> 00:04:47,360
So as you can see here now this value is output to the console.

72
00:04:47,650 --> 00:04:55,930
And as I said earlier in the section this for example this my second string doesn't hold this hello.

73
00:04:55,990 --> 00:04:57,100
Object here.

74
00:04:57,270 --> 00:05:04,760
This my second string only actually contains the address of this object in memory.

75
00:05:04,810 --> 00:05:09,920
OK so this is how our objects are actually saved in memory.

76
00:05:10,120 --> 00:05:16,360
But for primitive data types for example our primitive data types like int and for example the name

77
00:05:16,360 --> 00:05:17,980
of my value is a.

78
00:05:18,010 --> 00:05:19,800
And then I can assign a value to my value.

79
00:05:19,820 --> 00:05:26,080
But here is a valuable actually holds this number free wheeling it.

80
00:05:26,110 --> 00:05:26,510
OK.

81
00:05:26,560 --> 00:05:32,720
But this my second string actually contains the address of this hello object in memory.

82
00:05:32,740 --> 00:05:33,090
OK.

83
00:05:33,090 --> 00:05:38,600
In other words this my second string is actually a pointer to this.

84
00:05:38,620 --> 00:05:39,370
Hello.

85
00:05:39,430 --> 00:05:41,470
Object in memory.

86
00:05:41,470 --> 00:05:48,300
Ok so now let me actually show you another important point about objects in memory.

87
00:05:48,310 --> 00:05:52,500
So as you can see here I have 10 string objects here.

88
00:05:52,500 --> 00:05:53,030
OK.

89
00:05:53,170 --> 00:06:00,860
So now as you can see here I assigned the same value to all of these 10 String instances.

90
00:06:00,880 --> 00:06:01,390
OK.

91
00:06:01,390 --> 00:06:08,920
So as you can see here for example for my first string instance I assigned the word hello to my first

92
00:06:09,040 --> 00:06:09,940
string instance.

93
00:06:09,940 --> 00:06:10,700
OK.

94
00:06:10,990 --> 00:06:15,940
Or for example for my second string instance I assigned the word Hello.

95
00:06:16,240 --> 00:06:16,540
OK.

96
00:06:16,540 --> 00:06:26,580
And for all of my 10 string instances here I assigned the same word hello to all of these string instances.

97
00:06:26,580 --> 00:06:29,480
How this object is actually saved in memory.

98
00:06:29,480 --> 00:06:37,720
So because we actually have 10 strange instances here with this same value the compiler is only actually

99
00:06:37,720 --> 00:06:41,040
create one object which as you can see here divorce.

100
00:06:41,050 --> 00:06:41,580
Hello.

101
00:06:41,740 --> 00:06:49,000
And it's going to actually assign the address of this object in memory to all of these 10 string instances.

102
00:06:49,000 --> 00:06:49,460
OK.

103
00:06:49,600 --> 00:06:57,020
So for example my first string instance actually holds the address of the hello object in memory or

104
00:06:57,100 --> 00:07:03,430
my second string instance actually holds the address of the hello object in memory.

105
00:07:03,550 --> 00:07:09,040
Or in other words these string instances actually point to the hello object in memory.

106
00:07:09,040 --> 00:07:09,510
OK.

107
00:07:09,640 --> 00:07:14,210
So that's it that's how actually the objects are actually saved in memory.

108
00:07:14,380 --> 00:07:18,180
When you actually create String objects by using string literals.

109
00:07:18,240 --> 00:07:25,660
OK but if you actually for example change the value of one of these string instances to another value

110
00:07:25,690 --> 00:07:31,660
that string instance going to actually hold another address for that specific object.

111
00:07:31,690 --> 00:07:39,340
OK but if you have actually the same value for your string instances the compiler is going to actually

112
00:07:39,340 --> 00:07:47,530
create only one object and that is going to actually hold the address of that object to those string

113
00:07:47,560 --> 00:07:48,520
instances.

114
00:07:48,520 --> 00:07:53,110
So now let me actually show you some real examples in order to make this concept more meaningful for

115
00:07:53,110 --> 00:07:53,300
you.

116
00:07:53,340 --> 00:08:01,960
OK so now if you go back inside the eclipse as you can see here these two objects this my first string

117
00:08:02,020 --> 00:08:06,520
object and this my second string object have actually the same value.

118
00:08:06,530 --> 00:08:13,210
OK so the compiler is going to actually create only one object and then it's going to actually hold

119
00:08:13,210 --> 00:08:15,990
the address of that object inside.

120
00:08:16,150 --> 00:08:18,100
Inside of these string instances.

121
00:08:18,100 --> 00:08:18,480
OK.

122
00:08:18,520 --> 00:08:26,070
So now if I for example change the value of my first string object to another value of i need to refer

123
00:08:26,120 --> 00:08:27,470
to the name of our object.

124
00:08:27,490 --> 00:08:34,990
My first strange and that I need to put in an assignment operator here and then I actually change the

125
00:08:34,990 --> 00:08:37,270
value hello to HI.

126
00:08:37,330 --> 00:08:38,060
Okay.

127
00:08:38,170 --> 00:08:41,000
And then I need to put in a semi-colon at the end of my statement.

128
00:08:41,200 --> 00:08:47,560
So as you can see here now if I want to output the value of the first string object to the console I

129
00:08:47,560 --> 00:08:53,070
just need to type in here system that out that princeling and it inside the parenthesis.

130
00:08:53,080 --> 00:08:59,140
I can just refer to the name of my object my first strange and then I need to put in a semicolon at

131
00:08:59,140 --> 00:09:00,570
the end of my statement.

132
00:09:00,580 --> 00:09:04,480
So now if I had on my project as you can see this value is now output to the console.

133
00:09:04,480 --> 00:09:12,550
OK so now the address of this object is actually is actually reading this my first string object.

134
00:09:12,550 --> 00:09:17,930
OK this object is inside another place is in the memory.

135
00:09:18,340 --> 00:09:22,110
And that address is inside of this my first string instance.

136
00:09:22,120 --> 00:09:22,530
OK.

137
00:09:22,540 --> 00:09:28,210
It's my first string instance actually holds the address of this object inside the memory.

138
00:09:28,330 --> 00:09:33,370
And this my second string object actually holds the address of this object.

139
00:09:33,370 --> 00:09:34,310
Hello.

140
00:09:34,420 --> 00:09:35,620
Inside the memory.

141
00:09:35,620 --> 00:09:36,260
OK.

142
00:09:36,490 --> 00:09:41,420
So now if you want to output the value of the second string object to the console.

143
00:09:41,500 --> 00:09:42,550
Let's see what happens.

144
00:09:42,580 --> 00:09:49,210
System that out that prints learn and then inside the parenthesis I can just refer to the name of my

145
00:09:49,510 --> 00:09:52,020
my second string object.

146
00:09:52,060 --> 00:09:55,300
And then I need to put in a semi-colon at the end of my statement.

147
00:09:55,330 --> 00:09:59,020
So as you can see this value Halo is now outputted with the consular kit.

