| 1 |
| 00:00:00,000 |
| (calm music) |
|
|
| 2 |
| 00:00:03,000 |
| -: Okay, so we were able to run this code |
|
|
| 3 |
| 00:00:04,000 |
| and we understood something |
|
|
| 4 |
| 00:00:06,000 |
| what is happening behind the scenes, right? |
|
|
| 5 |
| 00:00:07,000 |
| So basically we know now that as a programmer, |
|
|
| 6 |
| 00:00:10,000 |
| as a Java developer, you write our Java code, |
|
|
| 7 |
| 00:00:13,000 |
| which will be having dot Java extension |
|
|
| 8 |
| 00:00:15,000 |
| and that gets compiled by Java C. |
|
|
| 9 |
| 00:00:18,000 |
| And then when you compile the code, |
|
|
| 10 |
| 00:00:20,000 |
| what you get in output is a byte code |
|
|
| 11 |
| 00:00:22,000 |
| which will be having dot class file. |
|
|
| 12 |
| 00:00:24,000 |
| And then you can run the dot class file in your JVM |
|
|
| 13 |
| 00:00:27,000 |
| and basically it's a part of JRE which will have JVM |
|
|
| 14 |
| 00:00:30,000 |
| as well as a libraries, a lot of classes. |
|
|
| 15 |
| 00:00:33,000 |
| And then everything is a part of a JRE, |
|
|
| 16 |
| 00:00:35,000 |
| that JRE you'll be installing on OS, right? |
|
|
| 17 |
| 00:00:38,000 |
| So basically you need to have a hardware, |
|
|
| 18 |
| 00:00:40,000 |
| of course you need a machine to run, right? |
|
|
| 19 |
| 00:00:42,000 |
| That machine will be having an OS |
|
|
| 20 |
| 00:00:43,000 |
| and that OS will be having JRE, which is, |
|
|
| 21 |
| 00:00:45,000 |
| which will have JVM. |
|
|
| 22 |
| 00:00:47,000 |
| But as a developer you will need one more tool, |
|
|
| 23 |
| 00:00:50,000 |
| which is JDK. |
|
|
| 24 |
| 00:00:52,000 |
| Now when you install a new JDK, |
|
|
| 25 |
| 00:00:54,000 |
| you get the updated JRE and JVM with it, okay. |
|
|
| 26 |
| 00:00:58,000 |
| So the version of JDK which we are using is JDK 17, |
|
|
| 27 |
| 00:01:02,000 |
| which is LTS, which is long-term support. |
|
|
| 28 |
| 00:01:05,000 |
| And in every new version you |
|
|
| 29 |
| 00:01:06,000 |
| get some minor extra features, right? |
|
|
| 30 |
| 00:01:09,000 |
| So even if you are watching this after 10 years |
|
|
| 31 |
| 00:01:12,000 |
| or eight years or five years, |
|
|
| 32 |
| 00:01:13,000 |
| you'll be having new version of Java. |
|
|
| 33 |
| 00:01:15,000 |
| Of course next five years you will get 10 new versions |
|
|
| 34 |
| 00:01:18,000 |
| and every new version will have minor updates, |
|
|
| 35 |
| 00:01:21,000 |
| but the base thing remains same, right? |
|
|
| 36 |
| 00:01:24,000 |
| So whatever you're learning is actually |
|
|
| 37 |
| 00:01:25,000 |
| from Java one itself. |
|
|
| 38 |
| 00:01:26,000 |
| The system.printer is same in Java 1. |
|
|
| 39 |
| 00:01:29,000 |
| So don't worry about the new updates, |
|
|
| 40 |
| 00:01:31,000 |
| the core concept will remain same. |
|
|
| 41 |
| 00:01:33,000 |
| Okay, cool. |
|
|
| 42 |
| 00:01:34,000 |
| Now once you have this thing, what next we can do? |
|
|
| 43 |
| 00:01:37,000 |
| Now think about this world, of course. |
|
|
| 44 |
| 00:01:39,000 |
| First of all, why we build software, we build software so |
|
|
| 45 |
| 00:01:42,000 |
| that we can solve a problem. |
|
|
| 46 |
| 00:01:44,000 |
| Now what problem we are trying to solve? |
|
|
| 47 |
| 00:01:45,000 |
| So basically we are trying to solve the real world problems |
|
|
| 48 |
| 00:01:51,000 |
| with the help of virtual world. |
|
|
| 49 |
| 00:01:53,000 |
| Example, you wanted to buy something. |
|
|
| 50 |
| 00:01:55,000 |
| So you got Amazon, which delivers everything at home. |
|
|
| 51 |
| 00:01:58,000 |
| So you got Amazon as online service, you wanted |
|
|
| 52 |
| 00:02:01,000 |
| to book a cab, you got Uber. |
|
|
| 53 |
| 00:02:03,000 |
| So for every problem we have a solution |
|
|
| 54 |
| 00:02:05,000 |
| in the virtual world, right? |
|
|
| 55 |
| 00:02:06,000 |
| So banking, everything is happening online. |
|
|
| 56 |
| 00:02:09,000 |
| Now when you say you are replacing the real world |
|
|
| 57 |
| 00:02:12,000 |
| with a virtual world solution, |
|
|
| 58 |
| 00:02:14,000 |
| so basically we need to work with one thing. |
|
|
| 59 |
| 00:02:16,000 |
| The most important thing now is actually data. |
|
|
| 60 |
| 00:02:19,000 |
| So basically we want to work with data. |
|
|
| 61 |
| 00:02:22,000 |
| So how will you work with data? |
|
|
| 62 |
| 00:02:23,000 |
| So basically you need data as well as processing on it. |
|
|
| 63 |
| 00:02:27,000 |
| So whatever, when you build, we build a project. |
|
|
| 64 |
| 00:02:29,000 |
| Or when you build application, |
|
|
| 65 |
| 00:02:31,000 |
| what we are doing is we are doing the processing on data. |
|
|
| 66 |
| 00:02:34,000 |
| Now this data can be coming from user |
|
|
| 67 |
| 00:02:36,000 |
| or something, so maybe you will accept the data |
|
|
| 68 |
| 00:02:38,000 |
| from the user and then you will do some work with it. |
|
|
| 69 |
| 00:02:41,000 |
| Maybe you want to store this data. |
|
|
| 70 |
| 00:02:43,000 |
| Now where exactly do we store data? |
|
|
| 71 |
| 00:02:45,000 |
| So we store data in something called database. |
|
|
| 72 |
| 00:02:48,000 |
| So we have a database here |
|
|
| 73 |
| 00:02:49,000 |
| in which you'll be showing your data. |
|
|
| 74 |
| 00:02:50,000 |
| So whatever data you're getting from the user |
|
|
| 75 |
| 00:02:52,000 |
| or from after processing. |
|
|
| 76 |
| 00:02:54,000 |
| So let's say we've got a user here, user sends us data, |
|
|
| 77 |
| 00:02:57,000 |
| we will apply a processing on that. |
|
|
| 78 |
| 00:02:58,000 |
| So we will do some work in between. |
|
|
| 79 |
| 00:03:00,000 |
| And then at the end we might store data in database. |
|
|
| 80 |
| 00:03:04,000 |
| Now this database is actually a permanent storage |
|
|
| 81 |
| 00:03:07,000 |
| or a persistent storage, which you say. |
|
|
| 82 |
| 00:03:09,000 |
| Now when you say it is permanent, |
|
|
| 83 |
| 00:03:10,000 |
| that doesn't mean you can't change it. |
|
|
| 84 |
| 00:03:12,000 |
| Of course you can, you can replace the values as well, |
|
|
| 85 |
| 00:03:14,000 |
| but then the data stays there, okay? |
|
|
| 86 |
| 00:03:16,000 |
| So if you just store it |
|
|
| 87 |
| 00:03:18,000 |
| and if even if you shut down your machine, |
|
|
| 88 |
| 00:03:20,000 |
| the data will be stored. |
|
|
| 89 |
| 00:03:21,000 |
| Example, when you copy movies |
|
|
| 90 |
| 00:03:22,000 |
| or games on your laptop, it stays there, right? |
|
|
| 91 |
| 00:03:25,000 |
| It'll get deleted when you say delete, |
|
|
| 92 |
| 00:03:27,000 |
| but the data stays there. |
|
|
| 93 |
| 00:03:28,000 |
| So this makes sense, right? |
|
|
| 94 |
| 00:03:29,000 |
| But when I say you will receive data from the user |
|
|
| 95 |
| 00:03:32,000 |
| and then you will be doing some processing on that |
|
|
| 96 |
| 00:03:34,000 |
| where you will store the data for temporary purpose. |
|
|
| 97 |
| 00:03:36,000 |
| Of course database is there for permanent storage, |
|
|
| 98 |
| 00:03:39,000 |
| but during processing you have to store your data somewhere |
|
|
| 99 |
| 00:03:42,000 |
| and that somewhere is variable. |
|
|
| 100 |
| 00:03:44,000 |
| So this is where you store your data. Now what is variable? |
|
|
| 101 |
| 00:03:47,000 |
| So imagine variable as a box |
|
|
| 102 |
| 00:03:48,000 |
| and in this box you will store your data. |
|
|
| 103 |
| 00:03:50,000 |
| Now what data you want to store? |
|
|
| 104 |
| 00:03:52,000 |
| Your data can be numeric, |
|
|
| 105 |
| 00:03:53,000 |
| it can be text, it can be image, whatever you want to store. |
|
|
| 106 |
| 00:03:56,000 |
| So you can store that data in this variable. |
|
|
| 107 |
| 00:03:58,000 |
| Now I'm not talking specific to Java in general, |
|
|
| 108 |
| 00:04:00,000 |
| when you say you want to store data, you will store |
|
|
| 109 |
| 00:04:02,000 |
| that in a box and that box will have a type to it. |
|
|
| 110 |
| 00:04:05,000 |
| It can be of type numbers, it can be of types, text |
|
|
| 111 |
| 00:04:08,000 |
| or image or video. |
|
|
| 112 |
| 00:04:09,000 |
| So here we are trying to store data, right? |
|
|
| 113 |
| 00:04:11,000 |
| So let's say I want to store the number which is 5. |
|
|
| 114 |
| 00:04:13,000 |
| So this box will have a number 5 |
|
|
| 115 |
| 00:04:15,000 |
| and it'll also have a name to it. |
|
|
| 116 |
| 00:04:16,000 |
| Maybe I can give a name. Let's say a number. |
|
|
| 117 |
| 00:04:19,000 |
| It doesn't matter what name you give, |
|
|
| 118 |
| 00:04:20,000 |
| of course there are some restrictions on names. |
|
|
| 119 |
| 00:04:23,000 |
| But num works, you can use any name in which you like. |
|
|
| 120 |
| 00:04:25,000 |
| Maybe you can create one more box here |
|
|
| 121 |
| 00:04:27,000 |
| and you want to store the number itself, |
|
|
| 122 |
| 00:04:29,000 |
| but let's say a decimal value, something like 6.5, |
|
|
| 123 |
| 00:04:31,000 |
| you can do that, okay? |
|
|
| 124 |
| 00:04:33,000 |
| And maybe you can have a different value to it, |
|
|
| 125 |
| 00:04:34,000 |
| different name to it. |
|
|
| 126 |
| 00:04:35,000 |
| Maybe you can say marks or grades. |
|
|
| 127 |
| 00:04:37,000 |
| Maybe you want to have one more box |
|
|
| 128 |
| 00:04:39,000 |
| where you want to store your name. |
|
|
| 129 |
| 00:04:41,000 |
| So I can do that, I can store my name as Navin |
|
|
| 130 |
| 00:04:43,000 |
| and it'll have a variable name. |
|
|
| 131 |
| 00:04:45,000 |
| So maybe I can say this is user. So user is Navin. |
|
|
| 132 |
| 00:04:48,000 |
| So basically what you do is you create a box |
|
|
| 133 |
| 00:04:50,000 |
| and inside the box will be having values. |
|
|
| 134 |
| 00:04:52,000 |
| Now this box are actually called variables. |
|
|
| 135 |
| 00:04:55,000 |
| So we can name this box as a variable, okay? |
|
|
| 136 |
| 00:04:59,000 |
| And so what we got till now we got |
|
|
| 137 |
| 00:05:00,000 |
| that a box will be called a variable |
|
|
| 138 |
| 00:05:03,000 |
| and you'll be having a name to it, you'll be having a value. |
|
|
| 139 |
| 00:05:06,000 |
| So name and value will be there. |
|
|
| 140 |
| 00:05:07,000 |
| Apart from that, |
|
|
| 141 |
| 00:05:09,000 |
| you know Java is actually called strongly typed language. |
|
|
| 142 |
| 00:05:13,000 |
| Now what it means is whatever variable you want to create. |
|
|
| 143 |
| 00:05:16,000 |
| So if you want to store the data, |
|
|
| 144 |
| 00:05:17,000 |
| of course Java says, "Hey, we'll accept the data," |
|
|
| 145 |
| 00:05:20,000 |
| but tell me also what kind of box you want. |
|
|
| 146 |
| 00:05:23,000 |
| A different type of data will require different box. |
|
|
| 147 |
| 00:05:25,000 |
| Okay, that makes sense. |
|
|
| 148 |
| 00:05:26,000 |
| So I will say, "Hey Java, I want to store a number. |
| |
| 149 |
| 00:05:29,000 --> 00:05:31,000 |
| So I want you to create a box |
| |
| 150 |
| 00:05:31,000 --> 00:05:33,000 |
| for me which will accept numbers." |
|
|
| 151 |
| 00:05:33,000 |
| So we can say, okay, this makes sense, number will go there. |
|
|
| 152 |
| 00:05:36,000 |
| We can also create this as a number, |
|
|
| 153 |
| 00:05:38,000 |
| but this is a text, right? |
|
|
| 154 |
| 00:05:40,000 |
| So in Java we call them as a string, right? |
|
|
| 155 |
| 00:05:42,000 |
| So text will be having a string. So this box type is string. |
|
|
| 156 |
| 00:05:46,000 |
| What about this box? |
|
|
| 157 |
| 00:05:47,000 |
| Of course we say this is a number, this is also a number, |
|
|
| 158 |
| 00:05:50,000 |
| but in number as well we have a category inside it. |
|
|
| 159 |
| 00:05:52,000 |
| So one of the category I will mention is this, we can, |
|
|
| 160 |
| 00:05:55,000 |
| if you want to store numbers, we can store |
|
|
| 161 |
| 00:05:56,000 |
| that in something called int. |
|
|
| 162 |
| 00:05:58,000 |
| Now int means integer, okay? |
|
|
| 163 |
| 00:06:00,000 |
| So we can store data in the integer format, |
|
|
| 164 |
| 00:06:01,000 |
| but we cannot store 6.5 in int because 6.5 is a real number. |
|
|
| 165 |
| 00:06:05,000 |
| So int will accept numbers, |
|
|
| 166 |
| 00:06:07,000 |
| but why is called int we not natural numbers |
|
|
| 167 |
| 00:06:10,000 |
| or whole numbers is because maybe you want |
|
|
| 168 |
| 00:06:12,000 |
| to store negative values as well. |
|
|
| 169 |
| 00:06:13,000 |
| So remember your maths concept. |
|
|
| 170 |
| 00:06:15,000 |
| So we have negative numbers to positive values. |
|
|
| 171 |
| 00:06:17,000 |
| So everything will be considered as int |
|
|
| 172 |
| 00:06:19,000 |
| so we can store minus 5 plus 5. |
|
|
| 173 |
| 00:06:21,000 |
| That's your choice. Okay, so this makes sense. |
|
|
| 174 |
| 00:06:23,000 |
| So what I will do now is if I go back to the code, |
|
|
| 175 |
| 00:06:26,000 |
| of course we want to print "Hello World", |
|
|
| 176 |
| 00:06:27,000 |
| but we have done that. |
|
|
| 177 |
| 00:06:28,000 |
| Now I want to store value so |
|
|
| 178 |
| 00:06:30,000 |
| that I can do some processing on it. |
|
|
| 179 |
| 00:06:31,000 |
| Now what kind of processing I want to do, maybe I can, |
|
|
| 180 |
| 00:06:33,000 |
| I want to add two numbers, maybe 2 plus 2 |
|
|
| 181 |
| 00:06:35,000 |
| or 5 plus 6, simple stuff, right? |
|
|
| 182 |
| 00:06:37,000 |
| But before that we'll see how do we store data? |
|
|
| 183 |
| 00:06:40,000 |
| Even if you don't store data, you can just go |
|
|
| 184 |
| 00:06:42,000 |
| inside this System.out.print, |
|
|
| 185 |
| 00:06:44,000 |
| whatever operation you want to perform, you want |
|
|
| 186 |
| 00:06:46,000 |
| to say 3 plus 5, that will work. |
|
|
| 187 |
| 00:06:48,000 |
| So you can just go back here and say compile and run. |
|
|
| 188 |
| 00:06:51,000 |
| So remember this thing every time you make a change, just |
|
|
| 189 |
| 00:06:54,000 |
| make sure that you compile it first. |
|
|
| 190 |
| 00:06:56,000 |
| So the first step is compilation and then running. |
|
|
| 191 |
| 00:06:59,000 |
| And you can see we've got the output which is 8. |
|
|
| 192 |
| 00:07:01,000 |
| Just ignore this percentage symbol as of now. |
|
|
| 193 |
| 00:07:03,000 |
| Actually there's one more thing I wanted to mention. |
|
|
| 194 |
| 00:07:06,000 |
| Whenever you print something, let's say I want |
|
|
| 195 |
| 00:07:07,000 |
| to print this number here as well. |
|
|
| 196 |
| 00:07:10,000 |
| I want to perform different options. |
|
|
| 197 |
| 00:07:11,000 |
| So you can write multiple statement |
|
|
| 198 |
| 00:07:12,000 |
| for different operation you want to perform. |
|
|
| 199 |
| 00:07:14,000 |
| So you can say 8 plus 7. |
|
|
| 200 |
| 00:07:17,000 |
| So we are doing addition here |
|
|
| 201 |
| 00:07:19,000 |
| and then addition here, let's clear the screen. |
|
|
| 202 |
| 00:07:22,000 |
| Okay, first compile, okay, that's what. |
|
|
| 203 |
| 00:07:24,000 |
| Compile run and you can see we got the value. |
|
|
| 204 |
| 00:07:28,000 |
| Now the only thing you can see is the result |
|
|
| 205 |
| 00:07:30,000 |
| are bit, they're together, right? |
|
|
| 206 |
| 00:07:32,000 |
| We want to give a space of maybe I can |
|
|
| 207 |
| 00:07:33,000 |
| print 15 on new lines. |
|
|
| 208 |
| 00:07:34,000 |
| So what you can do is instead of using print, |
|
|
| 209 |
| 00:07:36,000 |
| you can actually use something called println. |
|
|
| 210 |
| 00:07:39,000 |
| Now println means print new line. |
|
|
| 211 |
| 00:07:41,000 |
| So it'll print and it'll go on new line. |
|
|
| 212 |
| 00:07:42,000 |
| So we can do that here as well. |
|
|
| 213 |
| 00:07:44,000 |
| So just say ln, ln at the end, println, |
|
|
| 214 |
| 00:07:46,000 |
| which is print new line and now compile run |
|
|
| 215 |
| 00:07:50,000 |
| and you can see we got the value, we got 5 and 15. |
|
|
| 216 |
| 00:07:53,000 |
| So from now we'll not be using print, |
|
|
| 217 |
| 00:07:55,000 |
| we'll be using ln, println. |
|
|
| 218 |
| 00:07:57,000 |
| Okay, so again println means it'll |
|
|
| 219 |
| 00:07:59,000 |
| print, it'll go on new line. |
|
|
| 220 |
| 00:08:00,000 |
| So we got println. Now what else we can do here? |
|
|
| 221 |
| 00:08:03,000 |
| So I don't want to perform the operation here, remove that. |
|
|
| 222 |
| 00:08:07,000 |
| I want to store that value first. So how do we store? |
|
|
| 223 |
| 00:08:10,000 |
| Of course we need box, right? |
|
|
| 224 |
| 00:08:12,000 |
| So I can say num1, I can, as I mentioned, |
|
|
| 225 |
| 00:08:14,000 |
| I can use any variable name. |
|
|
| 226 |
| 00:08:15,000 |
| So let's say num1 or to start with let's say num, just |
|
|
| 227 |
| 00:08:18,000 |
| to keep it simple and then we can give a value to it. |
|
|
| 228 |
| 00:08:21,000 |
| Let's say value is 3. |
|
|
| 229 |
| 00:08:22,000 |
| So remember you have |
|
|
| 230 |
| 00:08:23,000 |
| to mention the variable name and then we have |
|
|
| 231 |
| 00:08:24,000 |
| to mention the value for it. |
|
|
| 232 |
| 00:08:26,000 |
| And at the end of course you can put a semicolon. |
|
|
| 233 |
| 00:08:29,000 |
| So we can say we got num equal to 3 |
|
|
| 234 |
| 00:08:30,000 |
| and we got a semicolon. |
|
|
| 235 |
| 00:08:32,000 |
| So in Java, after every statement you have |
|
|
| 236 |
| 00:08:34,000 |
| to give a semicolon. |
|
|
| 237 |
| 00:08:35,000 |
| You might be thinking, hey, why don't we |
|
|
| 238 |
| 00:08:37,000 |
| have a semicolon here? |
|
|
| 239 |
| 00:08:38,000 |
| It's because that is a block. |
|
|
| 240 |
| 00:08:40,000 |
| So we don't put a semicolon out at the end of a block. |
|
|
| 241 |
| 00:08:44,000 |
| The reason is it signifies that's the end. |
|
|
| 242 |
| 00:08:47,000 |
| Here, if you don't mention semicolon, |
|
|
| 243 |
| 00:08:49,000 |
| how do we define that that's the end? |
|
|
| 244 |
| 00:08:50,000 |
| So it's good to put semicolon at the end. |
|
|
| 245 |
| 00:08:53,000 |
| And anyway, Java will give you if you don't do that. |
|
|
| 246 |
| 00:08:55,000 |
| The next thing we have to do here is we have |
|
|
| 247 |
| 00:08:57,000 |
| to also mention the type, what type of num is this? |
|
|
| 248 |
| 00:09:00,000 |
| So we can say int. |
|
|
| 249 |
| 00:09:02,000 |
| Now we have to say first you have to specify the type |
|
|
| 250 |
| 00:09:04,000 |
| and then you mention the variable name. |
|
|
| 251 |
| 00:09:06,000 |
| Maybe if you have learned some other languages |
|
|
| 252 |
| 00:09:09,000 |
| where you put the type afterwards, in Java, |
|
|
| 253 |
| 00:09:11,000 |
| we first put the type |
|
|
| 254 |
| 00:09:12,000 |
| and then we put the name, then we assign the value. |
|
|
| 255 |
| 00:09:15,000 |
| Now this equal to here is called assignment operator |
|
|
| 256 |
| 00:09:18,000 |
| because you are assigning a value. |
|
|
| 257 |
| 00:09:20,000 |
| So what it'll do is it'll take the value |
|
|
| 258 |
| 00:09:22,000 |
| from the right hand side, |
|
|
| 259 |
| 00:09:24,000 |
| it'll assign the value to the left hand side, okay? |
|
|
| 260 |
| 00:09:26,000 |
| Remember this, equal to will take the value |
|
|
| 261 |
| 00:09:28,000 |
| from the right hand side, |
|
|
| 262 |
| 00:09:29,000 |
| it'll assign the value to the left hand side. |
|
|
| 263 |
| 00:09:31,000 |
| Okay, so we got a variable which is of type int. Okay? |
|
|
| 264 |
| 00:09:35,000 |
| So this is num, which is a variable |
|
|
| 265 |
| 00:09:37,000 |
| and then we can print it. |
|
|
| 266 |
| 00:09:38,000 |
| Now, let's only print the value. That's it, nothing much. |
|
|
| 267 |
| 00:09:41,000 |
| I'll just save. |
|
|
| 268 |
| 00:09:42,000 |
| Now once you click on save, you have |
|
|
| 269 |
| 00:09:43,000 |
| to compile the code and run the code |
|
|
| 270 |
| 00:09:47,000 |
| and you can see we got 3. |
|
|
| 271 |
| 00:09:48,000 |
| Okay, cool. So now can I create more variables? |
|
|
| 272 |
| 00:09:50,000 |
| We can actually, so let me just rename the value variable |
|
|
| 273 |
| 00:09:53,000 |
| from num to num1 and here as well, I'll print num1. |
|
|
| 274 |
| 00:09:57,000 |
| Okay, and then I will create one more variable, |
|
|
| 275 |
| 00:09:59,000 |
| which is num2 is equal to. |
|
|
| 276 |
| 00:10:02,000 |
| So every time you want to get a variable, |
|
|
| 277 |
| 00:10:03,000 |
| just mention the type which is int |
|
|
| 278 |
| 00:10:05,000 |
| of whatever type of variable you're creating. |
|
|
| 279 |
| 00:10:06,000 |
| At this point we are working with numbers. |
|
|
| 280 |
| 00:10:08,000 |
| So we'll say int num2 equal to. |
|
|
| 281 |
| 00:10:10,000 |
| We can assign the value, which is 5. |
|
|
| 282 |
| 00:10:11,000 |
| So we got 3 and 5. |
|
|
| 283 |
| 00:10:13,000 |
| Here, what you can do is you can actually |
|
|
| 284 |
| 00:10:15,000 |
| perform the operation here itself. |
|
|
| 285 |
| 00:10:16,000 |
| So you can say number one plus num2, that works. |
|
|
| 286 |
| 00:10:18,000 |
| So instead of adding values, we can also add the variables. |
|
|
| 287 |
| 00:10:23,000 |
| Okay, so now we are, what we're doing is we are saying num1 |
|
|
| 288 |
| 00:10:25,000 |
| plus num2 and the addition be getting printed. |
|
|
| 289 |
| 00:10:29,000 |
| Let's try. |
|
|
| 290 |
| 00:10:30,000 |
| So I can just go back here and say compile run, |
|
|
| 291 |
| 00:10:33,000 |
| and you can see we got 8. |
|
|
| 292 |
| 00:10:35,000 |
| You know what, instead of adding it |
|
|
| 293 |
| 00:10:37,000 |
| inside this, it's not a good practice. |
|
|
| 294 |
| 00:10:39,000 |
| What you can do is we can |
|
|
| 295 |
| 00:10:41,000 |
| create another variable called result. |
|
|
| 296 |
| 00:10:42,000 |
| And that's right, variables are free to use. |
|
|
| 297 |
| 00:10:45,000 |
| Of course, behind the scenes it's consuming a lot of memory, |
|
|
| 298 |
| 00:10:47,000 |
| but it's working right as of it's free as of now. |
|
|
| 299 |
| 00:10:50,000 |
| But later on we'll focus on |
|
|
| 300 |
| 00:10:52,000 |
| how can you make your code more efficient so |
|
|
| 301 |
| 00:10:54,000 |
| that it'll use less space, right? |
|
|
| 302 |
| 00:10:57,000 |
| At this point it works. So we can say num1 plus. |
|
|
| 303 |
| 00:10:59,000 |
| So whatever option you want to perform, |
|
|
| 304 |
| 00:11:01,000 |
| you can do that here. |
|
|
| 305 |
| 00:11:02,000 |
| And instead of printing doing addition here, |
|
|
| 306 |
| 00:11:05,000 |
| we can simply print result. |
|
|
| 307 |
| 00:11:07,000 |
| So what you're doing now is you are adding the value |
|
|
| 308 |
| 00:11:09,000 |
| and then you are storing that in a result |
|
|
| 309 |
| 00:11:12,000 |
| and then you are printing it. |
|
|
| 310 |
| 00:11:13,000 |
| It should work. Let's try compile run. |
|
|
| 311 |
| 00:11:17,000 |
| And you can see we got 8. So this is working. |
|
|
| 312 |
| 00:11:19,000 |
| So that's how you can create variables. |
|
|
| 313 |
| 00:11:20,000 |
| So remember this thing. |
|
|
| 314 |
| 00:11:22,000 |
| Every time you want to create a variable, |
|
|
| 315 |
| 00:11:24,000 |
| you first need a name for it, at this point is num1. |
|
|
| 316 |
| 00:11:27,000 |
| You have to also mention the type of it. |
|
|
| 317 |
| 00:11:28,000 |
| At this point, this is int |
|
|
| 318 |
| 00:11:30,000 |
| and you have to assign the value for it. |
|
|
| 319 |
| 00:11:32,000 |
| In the upcoming videos we'll talk about how can you |
|
|
| 320 |
| 00:11:34,000 |
| create a variable, which will be having a name |
|
|
| 321 |
| 00:11:37,000 |
| with a different type and different value. |
|
|
| 322 |
| 00:11:39,000 |
| Okay? So that's it from this video. |
|
|
|
|