| 1 |
| 00:00:00,000 --> 00:00:03,000 |
| (piano music) |
|
|
| 2 |
| 00:00:03,000 --> 00:00:05,000 |
| -: So let's solve this problem. |
|
|
| 3 |
| 00:00:05,000 --> 00:00:07,000 |
| So we are not able to run this code, right? |
|
|
| 4 |
| 00:00:07,000 --> 00:00:07,000 |
| This is not working. |
|
|
| 5 |
| 00:00:07,000 --> 00:00:10,000 |
| We want to get hello world on the screen. |
|
|
| 6 |
| 00:00:10,000 --> 00:00:11,000 |
| It was working with J Shell |
|
|
| 7 |
| 00:00:11,000 --> 00:00:13,000 |
| because JShell says you just a parse a statement, |
|
|
| 8 |
| 00:00:13,000 --> 00:00:14,000 |
| I will work. |
|
|
| 9 |
| 00:00:14,000 --> 00:00:15,000 |
| But then when you build an application, |
|
|
| 10 |
| 00:00:15,000 --> 00:00:16,000 |
| when you run the application, |
|
|
| 11 |
| 00:00:16,000 --> 00:00:18,000 |
| how exactly it works behind the scene. |
|
|
| 12 |
| 00:00:18,000 --> 00:00:21,000 |
| Once we understand that, we can write this code. |
|
|
| 13 |
| 00:00:21,000 --> 00:00:23,000 |
| So in your machine you will be having something |
|
|
| 14 |
| 00:00:23,000 --> 00:00:25,000 |
| called JVM. |
|
|
| 15 |
| 00:00:26,000 --> 00:00:30,000 |
| Now by default, when you say Java is platform independent is |
|
|
| 16 |
| 00:00:30,000 --> 00:00:33,000 |
| because of JVM, because in your machine you will be having |
|
|
| 17 |
| 00:00:33,000 --> 00:00:35,000 |
| JVM irrespective of which OS you use. |
|
|
| 18 |
| 00:00:35,000 --> 00:00:38,000 |
| It can be Windows, Linux based OS, or Mac |
|
|
| 19 |
| 00:00:38,000 --> 00:00:40,000 |
| or whatever famous OS we have. |
|
|
| 20 |
| 00:00:40,000 --> 00:00:42,000 |
| It will have JVM installed. |
|
|
| 21 |
| 00:00:42,000 --> 00:00:45,000 |
| And of course if you have JVM, you can run Java application |
|
|
| 22 |
| 00:00:45,000 --> 00:00:48,000 |
| and if you don't have JVM, you can't run Java application. |
|
|
| 23 |
| 00:00:48,000 --> 00:00:51,000 |
| Okay, so we got JVM here, right, now what JVM says, |
|
|
| 24 |
| 00:00:51,000 --> 00:00:52,000 |
| hey, I will work. |
|
|
| 25 |
| 00:00:52,000 --> 00:00:56,000 |
| But then this one question, when you say JVM will work, |
|
|
| 26 |
| 00:00:56,000 --> 00:00:58,000 |
| but JVM works on which environment? |
|
|
| 27 |
| 00:00:58,000 --> 00:01:00,000 |
| So underlying we have your OS. |
|
|
| 28 |
| 00:01:00,000 --> 00:01:01,000 |
| So this is your OSS |
|
|
| 29 |
| 00:01:02,000 --> 00:01:06,000 |
| and then your OS is working on a hardware, right? |
|
|
| 30 |
| 00:01:06,000 --> 00:01:08,000 |
| So you'll be having an hardware, it can be a laptop, |
|
|
| 31 |
| 00:01:08,000 --> 00:01:10,000 |
| it can be a desktop, it can be a phone, doesn't matter, |
|
|
| 32 |
| 00:01:10,000 --> 00:01:12,000 |
| you have an hardware, on top of that we have an OS. |
|
|
| 33 |
| 00:01:12,000 --> 00:01:15,000 |
| On top of that we have something called JVM. |
|
|
| 34 |
| 00:01:15,000 --> 00:01:19,000 |
| Now, JVM says, okay, my job is to execute a Java code, okay. |
|
|
| 35 |
| 00:01:19,000 --> 00:01:22,000 |
| So whatever java code you create, JVM will execute that. |
|
|
| 36 |
| 00:01:22,000 --> 00:01:26,000 |
| But then JVM will not accept the code directly. |
|
|
| 37 |
| 00:01:26,000 --> 00:01:28,000 |
| See what happens is Java goes in multiple steps in Java |
|
|
| 38 |
| 00:01:28,000 --> 00:01:31,000 |
| application, when you as a programmer, |
|
|
| 39 |
| 00:01:31,000 --> 00:01:33,000 |
| so let's say you are a programmer here |
|
|
| 40 |
| 00:01:33,000 --> 00:01:34,000 |
| and when you write a code, |
|
|
| 41 |
| 00:01:34,000 --> 00:01:36,000 |
| you will not directly run write a code which will |
|
|
| 42 |
| 00:01:36,000 --> 00:01:38,000 |
| run on JVM, okay? |
|
|
| 43 |
| 00:01:38,000 --> 00:01:40,000 |
| And we don't even do that, right? |
|
|
| 44 |
| 00:01:40,000 --> 00:01:41,000 |
| We don't even write a code which directly works on the |
|
|
| 45 |
| 00:01:41,000 --> 00:01:44,000 |
| hardware and we don't even write a code which works |
|
|
| 46 |
| 00:01:44,000 --> 00:01:45,000 |
| directly on OS. |
|
|
| 47 |
| 00:01:45,000 --> 00:01:48,000 |
| Java says if you want to make it work, you have |
|
|
| 48 |
| 00:01:48,000 --> 00:01:50,000 |
| to run your code on JVM, |
|
|
| 49 |
| 00:01:50,000 --> 00:01:52,000 |
| but then JVM will not understand what you are talking about. |
|
|
| 50 |
| 00:01:52,000 --> 00:01:54,000 |
| And one more, one more thing we have talked about, right? |
|
|
| 51 |
| 00:01:54,000 --> 00:01:57,000 |
| Java is platform independent. |
|
|
| 52 |
| 00:01:57,000 --> 00:01:59,000 |
| So what does platform independence means? |
|
|
| 53 |
| 00:01:59,000 --> 00:02:01,000 |
| It simply means that you can run your application |
|
|
| 54 |
| 00:02:01,000 --> 00:02:03,000 |
| on any machine. |
|
|
| 55 |
| 00:02:03,000 --> 00:02:04,000 |
| So when you write a Java code, |
|
|
| 56 |
| 00:02:04,000 --> 00:02:06,000 |
| it will run on any machine irrespective |
|
|
| 57 |
| 00:02:06,000 --> 00:02:07,000 |
| of the hardware or the OS. |
|
|
| 58 |
| 00:02:07,000 --> 00:02:09,000 |
| But the only thing it requires is |
|
|
| 59 |
| 00:02:09,000 --> 00:02:11,000 |
| that machine need to have JVM. |
|
|
| 60 |
| 00:02:11,000 --> 00:02:13,000 |
| So irrespective of which platform I'm talking about, |
|
|
| 61 |
| 00:02:13,000 --> 00:02:16,000 |
| if it has JVM, your application becomes |
|
|
| 62 |
| 00:02:16,000 --> 00:02:17,000 |
| platform independent. |
|
|
| 63 |
| 00:02:17,000 --> 00:02:20,000 |
| But JVM itself is platform dependent, okay? |
|
|
| 64 |
| 00:02:20,000 --> 00:02:23,000 |
| So example, you can't run JVM on iOS. |
|
|
| 65 |
| 00:02:23,000 --> 00:02:27,000 |
| So we can't say Java is platform independent when JVM itself |
|
|
| 66 |
| 00:02:27,000 --> 00:02:29,000 |
| is dependent. |
|
|
| 67 |
| 00:02:29,000 --> 00:02:33,000 |
| So yes, your application is independent, JVM is not. |
|
|
| 68 |
| 00:02:33,000 --> 00:02:36,000 |
| So JVM need to be built for a particular OS. |
|
|
| 69 |
| 00:02:36,000 --> 00:02:37,000 |
| And let's say if it is windows in my, |
|
|
| 70 |
| 00:02:37,000 --> 00:02:39,000 |
| so in my machine it is Mac, |
|
|
| 71 |
| 00:02:39,000 --> 00:02:41,000 |
| but let's say if it is Windows, |
|
|
| 72 |
| 00:02:41,000 --> 00:02:43,000 |
| we have JVM available on Windows. |
|
|
| 73 |
| 00:02:43,000 --> 00:02:46,000 |
| So your JVM says, Hey, I will run your code |
|
|
| 74 |
| 00:02:46,000 --> 00:02:49,000 |
| but you have to submit me, not the Java code, |
|
|
| 75 |
| 00:02:49,000 --> 00:02:51,000 |
| but something called a byte code. |
|
|
| 76 |
| 00:02:51,000 --> 00:02:55,000 |
| So you have to convert your code into a unreadable format |
|
|
| 77 |
| 00:02:55,000 --> 00:02:57,000 |
| for a normal human being. |
|
|
| 78 |
| 00:02:57,000 --> 00:02:59,000 |
| And this is called a byte code |
|
|
| 79 |
| 00:03:00,000 --> 00:03:03,000 |
| because JVM only understands byte code. |
|
|
| 80 |
| 00:03:03,000 --> 00:03:05,000 |
| But can you write byte code? |
|
|
| 81 |
| 00:03:05,000 --> 00:03:06,000 |
| Of course not. |
|
|
| 82 |
| 00:03:06,000 --> 00:03:08,000 |
| You only understand English type of languages, right? |
|
|
| 83 |
| 00:03:08,000 --> 00:03:09,000 |
| So whatever we have return the code, |
|
|
| 84 |
| 00:03:09,000 --> 00:03:12,000 |
| we have a return system dot out dot print, |
|
|
| 85 |
| 00:03:12,000 --> 00:03:14,000 |
| it's English type language, right? |
|
|
| 86 |
| 00:03:14,000 --> 00:03:17,000 |
| So what you create is a Java code. |
|
|
| 87 |
| 00:03:17,000 --> 00:03:20,000 |
| So this is your Java file or Java code, |
|
|
| 88 |
| 00:03:20,000 --> 00:03:22,000 |
| and then you have to convert this Java code. |
|
|
| 89 |
| 00:03:22,000 --> 00:03:25,000 |
| So this is Java code, which is more of readable. |
|
|
| 90 |
| 00:03:25,000 --> 00:03:26,000 |
| This is not something which you can read. |
|
|
| 91 |
| 00:03:26,000 --> 00:03:29,000 |
| So basically you have to convert this into a Java |
|
|
| 92 |
| 00:03:29,000 --> 00:03:31,000 |
| code or byte code. |
|
|
| 93 |
| 00:03:31,000 --> 00:03:33,000 |
| So for that we have something in between here, |
|
|
| 94 |
| 00:03:33,000 --> 00:03:35,000 |
| which is called a compiler. |
|
|
| 95 |
| 00:03:35,000 --> 00:03:38,000 |
| Now since this is a Java compiler, we can call it |
|
|
| 96 |
| 00:03:38,000 --> 00:03:41,000 |
| as Java C, which is Java compiler. |
|
|
| 97 |
| 00:03:41,000 --> 00:03:44,000 |
| So basically you will write this code. |
|
|
| 98 |
| 00:03:44,000 --> 00:03:47,000 |
| So this code will be getting compiled into a byte code |
|
|
| 99 |
| 00:03:47,000 --> 00:03:51,000 |
| and that byte code goes on the JVM, it'll run. |
|
|
| 100 |
| 00:03:51,000 --> 00:03:52,000 |
| Makes sense, right? |
|
|
| 101 |
| 00:03:52,000 --> 00:03:54,000 |
| So that means when you write something it will |
|
|
| 102 |
| 00:03:54,000 --> 00:03:55,000 |
| go into byte code |
|
|
| 103 |
| 00:03:55,000 --> 00:03:57,000 |
| and then byte code will run on JVM. |
|
|
| 104 |
| 00:03:57,000 --> 00:04:00,000 |
| Now the only thing is see your project can be a big project, |
|
|
| 105 |
| 00:04:00,000 --> 00:04:01,000 |
| right, here I'm writing only one file. |
|
|
| 106 |
| 00:04:01,000 --> 00:04:02,000 |
| It can be 10 lines of code. |
|
|
| 107 |
| 00:04:02,000 --> 00:04:05,000 |
| It can ,it can be 10 files, it can be a hundred files, |
|
|
| 108 |
| 00:04:05,000 --> 00:04:06,000 |
| it can be thousand files. |
|
|
| 109 |
| 00:04:06,000 --> 00:04:10,000 |
| Out of all these files, there will be only one file |
|
|
| 110 |
| 00:04:10,000 --> 00:04:12,000 |
| with JVM will execute, okay? |
|
|
| 111 |
| 00:04:12,000 --> 00:04:14,000 |
| JVM will start with the first file |
|
|
| 112 |
| 00:04:14,000 --> 00:04:16,000 |
| and then of course that file will depend upon |
|
|
| 113 |
| 00:04:16,000 --> 00:04:18,000 |
| other files and it will execute. |
|
|
| 114 |
| 00:04:18,000 --> 00:04:22,000 |
| So JVM says you need to tell me what that file is, okay? |
|
|
| 115 |
| 00:04:22,000 --> 00:04:24,000 |
| So if you, even if you have thousand files which you want |
|
|
| 116 |
| 00:04:24,000 --> 00:04:27,000 |
| to run in your project, you have to give the first file. |
|
|
| 117 |
| 00:04:27,000 --> 00:04:30,000 |
| So in this case, what you will do is you will specify, hey, |
|
|
| 118 |
| 00:04:30,000 --> 00:04:32,000 |
| that's my first file. |
|
|
| 119 |
| 00:04:32,000 --> 00:04:34,000 |
| So when you run the code, you will specify the first file |
|
|
| 120 |
| 00:04:34,000 --> 00:04:37,000 |
| and also that file need |
|
|
| 121 |
| 00:04:37,000 --> 00:04:40,000 |
| to have something called a main method, okay? |
|
|
| 122 |
| 00:04:40,000 --> 00:04:41,000 |
| So as I, as I mentioned before, right? |
|
|
| 123 |
| 00:04:41,000 --> 00:04:45,000 |
| We have print in the same way we have main, so your file, |
|
|
| 124 |
| 00:04:45,000 --> 00:04:48,000 |
| the first file need to have a main method. |
|
|
| 125 |
| 00:04:48,000 --> 00:04:50,000 |
| So when I say first file, it is not like you have |
|
|
| 126 |
| 00:04:50,000 --> 00:04:53,000 |
| to follow a sequence, create this file, then that, |
|
|
| 127 |
| 00:04:53,000 --> 00:04:56,000 |
| that file, out of all the files in your project, |
|
|
| 128 |
| 00:04:56,000 --> 00:05:00,000 |
| the execution will start from the first file which you |
|
|
| 129 |
| 00:05:00,000 --> 00:05:01,000 |
| specify, okay? |
|
|
| 130 |
| 00:05:01,000 --> 00:05:05,000 |
| And that file need to have mean, not just mean, |
|
|
| 131 |
| 00:05:05,000 --> 00:05:08,000 |
| it is looking for a specific signature. |
|
|
| 132 |
| 00:05:08,000 --> 00:05:11,000 |
| Okay, so it has a signature, it means the entire method |
|
|
| 133 |
| 00:05:11,000 --> 00:05:13,000 |
| signature, the method name, |
|
|
| 134 |
| 00:05:13,000 --> 00:05:16,000 |
| what are the values you are parsing and all this stuff. |
|
|
| 135 |
| 00:05:16,000 --> 00:05:18,000 |
| And of course all this term you will, you will get used |
|
|
| 136 |
| 00:05:18,000 --> 00:05:19,000 |
| to in some of these sessions. |
|
|
| 137 |
| 00:05:19,000 --> 00:05:20,000 |
| Don't worry. |
|
|
| 138 |
| 00:05:20,000 --> 00:05:21,000 |
| So first you have to make sure |
|
|
| 139 |
| 00:05:21,000 --> 00:05:25,000 |
| that you provide a mean and mean has a particular signature. |
|
|
| 140 |
| 00:05:25,000 --> 00:05:27,000 |
| Again, what each word means, that we'll see later. |
|
|
| 141 |
| 00:05:27,000 --> 00:05:32,000 |
| So the signature is this, it is public static wide mean. |
|
|
| 142 |
| 00:05:32,000 --> 00:05:35,000 |
| So you have to remember, always parse this method. |
|
|
| 143 |
| 00:05:35,000 --> 00:05:36,000 |
| I know there are four words, |
|
|
| 144 |
| 00:05:36,000 --> 00:05:38,000 |
| but then this is the thing you have to remember |
|
|
| 145 |
| 00:05:38,000 --> 00:05:42,000 |
| and mean will accept some arguments, some parameters. |
|
|
| 146 |
| 00:05:42,000 --> 00:05:45,000 |
| So you have to parse string A. |
|
|
| 147 |
| 00:05:45,000 --> 00:05:47,000 |
| Now again, we'll discuss this, what this string is, |
|
|
| 148 |
| 00:05:47,000 --> 00:05:49,000 |
| what is public static void. |
|
|
| 149 |
| 00:05:49,000 --> 00:05:50,000 |
| We'll discuss that in some time, |
|
|
| 150 |
| 00:05:50,000 --> 00:05:52,000 |
| but mean is looking for the signature. |
|
|
| 151 |
| 00:05:52,000 --> 00:05:55,000 |
| So your code will not work without the signature. |
|
|
| 152 |
| 00:05:55,000 --> 00:05:57,000 |
| So remember this, so that makes sense. |
|
|
| 153 |
| 00:05:57,000 --> 00:05:58,000 |
| What are the steps you have to follow? |
|
|
| 154 |
| 00:05:58,000 --> 00:05:59,000 |
| So the first step is |
|
|
| 155 |
| 00:05:59,000 --> 00:06:03,000 |
| as a programmer you will be creating a Java file, okay? |
|
|
| 156 |
| 00:06:03,000 --> 00:06:05,000 |
| Now once your java file is ready, you will put |
|
|
| 157 |
| 00:06:05,000 --> 00:06:08,000 |
| that into compiler, then compiler will compile it. |
|
|
| 158 |
| 00:06:08,000 --> 00:06:12,000 |
| Then that code becomes a byte file, a byte code basically. |
|
|
| 159 |
| 00:06:12,000 --> 00:06:15,000 |
| Then you will take this byte code, you will run that on JVM. |
|
|
| 160 |
| 00:06:15,000 --> 00:06:18,000 |
| Now, once you, once your JVM says, okay, |
|
|
| 161 |
| 00:06:18,000 --> 00:06:19,000 |
| I'm running the code, JVM will look |
|
|
| 162 |
| 00:06:19,000 --> 00:06:21,000 |
| for this particular syntax. |
|
|
| 163 |
| 00:06:21,000 --> 00:06:23,000 |
| It should be there in your code |
|
|
| 164 |
| 00:06:23,000 --> 00:06:25,000 |
| and then you will get the output, right? |
|
|
| 165 |
| 00:06:25,000 --> 00:06:26,000 |
| Simple stuff, okay. |
|
|
| 166 |
| 00:06:26,000 --> 00:06:27,000 |
| Now there's a space in |
|
|
| 167 |
| 00:06:27,000 --> 00:06:29,000 |
| between here if you can see, this is a space I have left |
|
|
| 168 |
| 00:06:29,000 --> 00:06:31,000 |
| that space intentionally |
|
|
| 169 |
| 00:06:31,000 --> 00:06:32,000 |
| because we'll add certain things there. |
|
|
| 170 |
| 00:06:32,000 --> 00:06:35,000 |
| So at this point, just remember there's a space here, |
|
|
| 171 |
| 00:06:35,000 --> 00:06:36,000 |
| there's a box meaning here. |
|
|
| 172 |
| 00:06:36,000 --> 00:06:38,000 |
| We'll add that box in some time. |
|
|
| 173 |
| 00:06:38,000 --> 00:06:41,000 |
| Now once we have understood all those things, it's time |
|
|
| 174 |
| 00:06:41,000 --> 00:06:43,000 |
| to expand this code. |
|
|
| 175 |
| 00:06:43,000 --> 00:06:44,000 |
| Now if you remember, we have |
|
|
| 176 |
| 00:06:44,000 --> 00:06:46,000 |
| to write everything in a main, right? |
|
|
| 177 |
| 00:06:46,000 --> 00:06:50,000 |
| So this section should be a part of, |
|
|
| 178 |
| 00:06:50,000 --> 00:06:52,000 |
| remember what J will ask you for, |
|
|
| 179 |
| 00:06:52,000 --> 00:06:54,000 |
| J will ask you for mean. |
|
|
| 180 |
| 00:06:54,000 --> 00:06:56,000 |
| So we have to put that into mean. |
|
|
| 181 |
| 00:06:56,000 --> 00:06:59,000 |
| So why the syntax for mean, it's very simple, it is public, |
|
|
| 182 |
| 00:06:59,000 --> 00:07:00,000 |
| static wide mean. |
|
|
| 183 |
| 00:07:00,000 --> 00:07:03,000 |
| We have seen that, of course these words will define |
|
|
| 184 |
| 00:07:03,000 --> 00:07:04,000 |
| that words in the upcoming session. |
|
|
| 185 |
| 00:07:04,000 --> 00:07:06,000 |
| And once you understand all these terms, |
|
|
| 186 |
| 00:07:06,000 --> 00:07:08,000 |
| you are java programmer, right? |
|
|
| 187 |
| 00:07:08,000 --> 00:07:11,000 |
| And then this will say string A and that's it. |
|
|
| 188 |
| 00:07:11,000 --> 00:07:13,000 |
| This is a syntax you have to follow. |
|
|
| 189 |
| 00:07:13,000 --> 00:07:14,000 |
| Now there's one more thing. |
|
|
| 190 |
| 00:07:14,000 --> 00:07:17,000 |
| In Java, now Java is object oriented. |
|
|
| 191 |
| 00:07:17,000 --> 00:07:19,000 |
| Now what is object oriented means we'll discuss that later. |
|
|
| 192 |
| 00:07:19,000 --> 00:07:20,000 |
| But in simple terms, |
|
|
| 193 |
| 00:07:20,000 --> 00:07:24,000 |
| object oriented means everything should be an object. |
|
|
| 194 |
| 00:07:24,000 --> 00:07:26,000 |
| And to create object we need to class, okay? |
|
|
| 195 |
| 00:07:26,000 --> 00:07:27,000 |
| Again, we'll discuss all those |
|
|
| 196 |
| 00:07:27,000 --> 00:07:29,000 |
| things in the upcoming session. |
|
|
| 197 |
| 00:07:29,000 --> 00:07:31,000 |
| But a class is missing here. |
|
|
| 198 |
| 00:07:31,000 --> 00:07:34,000 |
| In fact, if you compile this code, this is what your |
|
|
| 199 |
| 00:07:34,000 --> 00:07:35,000 |
| Java say will tell you. |
|
|
| 200 |
| 00:07:35,000 --> 00:07:38,000 |
| Java say says, Hey, where is your class? |
|
|
| 201 |
| 00:07:38,000 --> 00:07:39,000 |
| Your class is missing. |
|
|
| 202 |
| 00:07:39,000 --> 00:07:40,000 |
| Okay, let's do that. |
|
|
| 203 |
| 00:07:40,000 --> 00:07:43,000 |
| So let's put that a class here and we'll give a class name. |
|
|
| 204 |
| 00:07:43,000 --> 00:07:45,000 |
| At this point we'll keep the class name and file them same. |
|
|
| 205 |
| 00:07:45,000 --> 00:07:48,000 |
| And we'll say, open bracket and close, |
|
|
| 206 |
| 00:07:48,000 --> 00:07:50,000 |
| and will give an indentation. |
|
|
| 207 |
| 00:07:50,000 --> 00:07:51,000 |
| So basically we have to follow this |
|
|
| 208 |
| 00:07:51,000 --> 00:07:53,000 |
| thing, always give a tab. |
|
|
| 209 |
| 00:07:53,000 --> 00:07:55,000 |
| So every time you open a (indiscernible), |
|
|
| 210 |
| 00:07:55,000 --> 00:07:56,000 |
| give a tab, it looks good, okay? |
|
|
| 211 |
| 00:07:56,000 --> 00:07:57,000 |
| There's no compulsion, it looks good |
|
|
| 212 |
| 00:07:57,000 --> 00:08:01,000 |
| and we love to build stuff which also runs and looks good. |
|
|
| 213 |
| 00:08:01,000 --> 00:08:02,000 |
| Okay, this looks good, right? |
|
|
| 214 |
| 00:08:02,000 --> 00:08:04,000 |
| Ignore this X and these suggestions, |
|
|
| 215 |
| 00:08:04,000 --> 00:08:06,000 |
| these are the suggestions coming from your VS code. |
|
|
| 216 |
| 00:08:06,000 --> 00:08:07,000 |
| But you know that part in fact is it |
|
|
| 217 |
| 00:08:07,000 --> 00:08:09,000 |
| because happening of this extension, |
|
|
| 218 |
| 00:08:09,000 --> 00:08:10,000 |
| let me just remove this. |
|
|
| 219 |
| 00:08:10,000 --> 00:08:11,000 |
| So let's not use that |
|
|
| 220 |
| 00:08:11,000 --> 00:08:13,000 |
| extension because it will give you a suggestion. |
|
|
| 221 |
| 00:08:13,000 --> 00:08:15,000 |
| It's good for development but not for teaching purpose. |
|
|
| 222 |
| 00:08:15,000 --> 00:08:16,000 |
| So it adds extra text there. |
|
|
| 223 |
| 00:08:16,000 --> 00:08:17,000 |
| Okay, cool. |
|
|
| 224 |
| 00:08:17,000 --> 00:08:18,000 |
| So this is how you write your code, okay? |
|
|
| 225 |
| 00:08:18,000 --> 00:08:21,000 |
| We got a class, a file name, |
|
|
| 226 |
| 00:08:21,000 --> 00:08:23,000 |
| and then public static void mean, in bracket |
|
|
| 227 |
| 00:08:23,000 --> 00:08:24,000 |
| you have to mention the parameters. |
|
|
| 228 |
| 00:08:24,000 --> 00:08:26,000 |
| Again, we'll discuss that later. |
|
|
| 229 |
| 00:08:26,000 --> 00:08:27,000 |
| And the only thing, |
|
|
| 230 |
| 00:08:27,000 --> 00:08:30,000 |
| important statement here is system.out.printHelloWorld. |
|
|
| 231 |
| 00:08:31,000 --> 00:08:33,000 |
| Okay, now let's see if this works. |
|
|
| 232 |
| 00:08:33,000 --> 00:08:35,000 |
| Let's create the screen and compile. |
|
|
| 233 |
| 00:08:35,000 --> 00:08:37,000 |
| You can see there's no error. |
|
|
| 234 |
| 00:08:37,000 --> 00:08:38,000 |
| But the moment I compiled, |
|
|
| 235 |
| 00:08:38,000 --> 00:08:39,000 |
| if you can see on the left hand side, |
|
|
| 236 |
| 00:08:39,000 --> 00:08:41,000 |
| we got this extra file. |
|
|
| 237 |
| 00:08:41,000 --> 00:08:42,000 |
| We got hello.class. |
|
|
| 238 |
| 00:08:42,000 --> 00:08:44,000 |
| Now this is your byte code. |
|
|
| 239 |
| 00:08:44,000 --> 00:08:48,000 |
| Remember we have talked about a byte code here. |
|
|
| 240 |
| 00:08:48,000 --> 00:08:50,000 |
| This is a file which got created automatically. |
|
|
| 241 |
| 00:08:50,000 --> 00:08:52,000 |
| So when you create a Java file, when you send it |
|
|
| 242 |
| 00:08:52,000 --> 00:08:55,000 |
| for the compilation, it will create the byte code, |
|
|
| 243 |
| 00:08:55,000 --> 00:09:00,000 |
| and the extension for the byte code is dot class file. |
|
|
| 244 |
| 00:09:00,000 --> 00:09:03,000 |
| The extension for java code is dot java file. |
|
|
| 245 |
| 00:09:03,000 --> 00:09:05,000 |
| And now it is compiled done. |
|
|
| 246 |
| 00:09:05,000 --> 00:09:07,000 |
| Right, now it's time to run your code. |
|
|
| 247 |
| 00:09:07,000 --> 00:09:10,000 |
| So remember when I mentioned to run, you have to use JVM, |
|
|
| 248 |
| 00:09:10,000 --> 00:09:12,000 |
| and for that you have to use a command, which is Java, |
|
|
| 249 |
| 00:09:12,000 --> 00:09:15,000 |
| and you have to mention the class name, not a file name |
|
|
| 250 |
| 00:09:15,000 --> 00:09:17,000 |
| this time, just a class name. |
|
|
| 251 |
| 00:09:17,000 --> 00:09:18,000 |
| The class name is hello. |
|
|
| 252 |
| 00:09:18,000 --> 00:09:19,000 |
| And say enter. |
|
|
| 253 |
| 00:09:19,000 --> 00:09:21,000 |
| You can see we got hello world. |
|
|
| 254 |
| 00:09:21,000 --> 00:09:22,000 |
| So yeah, that's how it works. |
|
|
| 255 |
| 00:09:22,000 --> 00:09:25,000 |
| So simple stuff, that's how we can able to complete our code |
|
|
| 256 |
| 00:09:25,000 --> 00:09:27,000 |
| and we are able to run this code. |
|
|
| 257 |
| 00:09:27,000 --> 00:09:30,000 |
| Now, if you have done until now, give round of applause |
|
|
| 258 |
| 00:09:30,000 --> 00:09:33,000 |
| or a pat on your back because you deserve it. |
|
|
| 259 |
| 00:09:33,000 --> 00:09:34,000 |
| So this makes sense, right? |
|
|
| 260 |
| 00:09:34,000 --> 00:09:35,000 |
| So there's a gap here, right? |
|
|
| 261 |
| 00:09:35,000 --> 00:09:36,000 |
| So let's remove this gap. |
|
|
| 262 |
| 00:09:36,000 --> 00:09:39,000 |
| So what we have here, so basically, you know when you, |
|
|
| 263 |
| 00:09:39,000 --> 00:09:41,000 |
| when you run your code, basically think about your cooking |
|
|
| 264 |
| 00:09:41,000 --> 00:09:42,000 |
| something in a kitchen, right? |
|
|
| 265 |
| 00:09:42,000 --> 00:09:43,000 |
| So where do we cook? |
|
|
| 266 |
| 00:09:43,000 --> 00:09:44,000 |
| Of course in a kitchen, right? |
|
|
| 267 |
| 00:09:44,000 --> 00:09:46,000 |
| Why not in a hall or in a bedroom? |
|
|
| 268 |
| 00:09:46,000 --> 00:09:48,000 |
| It's because in the kitchen to cook something, |
|
|
| 269 |
| 00:09:48,000 --> 00:09:50,000 |
| you need extra things, right? |
|
|
| 270 |
| 00:09:50,000 --> 00:09:51,000 |
| Example, if you make a bouillon, |
|
|
| 271 |
| 00:09:51,000 --> 00:09:52,000 |
| I don't know if you know the recipe, |
|
|
| 272 |
| 00:09:52,000 --> 00:09:53,000 |
| I don't know the recipe, |
|
|
| 273 |
| 00:09:53,000 --> 00:09:54,000 |
| but if you make a bouillon, |
|
|
| 274 |
| 00:09:54,000 --> 00:09:56,000 |
| you have to add extra ingredients. |
|
|
| 275 |
| 00:09:56,000 --> 00:09:58,000 |
| Now those things are kept in the shelf. |
|
|
| 276 |
| 00:09:58,000 --> 00:10:00,000 |
| So in the kitchen you'll not just have |
|
|
| 277 |
| 00:10:00,000 --> 00:10:03,000 |
| that resources which are there in the platform, |
|
|
| 278 |
| 00:10:03,000 --> 00:10:05,000 |
| but also you'll be having extra stuff. |
|
|
| 279 |
| 00:10:05,000 --> 00:10:08,000 |
| Now, the same way, if you want to run your Java application, |
|
|
| 280 |
| 00:10:08,000 --> 00:10:11,000 |
| you need extra libraries and you also need a runtime. |
|
|
| 281 |
| 00:10:11,000 --> 00:10:12,000 |
| The runtime is something which, |
|
|
| 282 |
| 00:10:12,000 --> 00:10:14,000 |
| where you can run things, right, |
|
|
| 283 |
| 00:10:14,000 --> 00:10:16,000 |
| now you can run something in a JVM. |
|
|
| 284 |
| 00:10:16,000 --> 00:10:18,000 |
| So that is part of run. |
|
|
| 285 |
| 00:10:18,000 --> 00:10:20,000 |
| But then what if you need some extra libraries? |
|
|
| 286 |
| 00:10:20,000 --> 00:10:22,000 |
| You have to, you need, you need a environment as well. |
|
|
| 287 |
| 00:10:22,000 --> 00:10:26,000 |
| So we have one more layer here, which is about your OS, |
|
|
| 288 |
| 00:10:26,000 --> 00:10:29,000 |
| which is called JRE. |
|
|
| 289 |
| 00:10:29,000 --> 00:10:32,000 |
| So when you want to run something, you use JRE to run it. |
|
|
| 290 |
| 00:10:32,000 --> 00:10:36,000 |
| Now JRE stands for Java Runtime Environment. |
|
|
| 291 |
| 00:10:36,000 --> 00:10:38,000 |
| And what is your JVMJ? |
|
|
| 292 |
| 00:10:38,000 --> 00:10:42,000 |
| JVM stands for Java Virtual Machine. |
|
|
| 293 |
| 00:10:42,000 --> 00:10:44,000 |
| Okay, so basically we have two things. |
|
|
| 294 |
| 00:10:44,000 --> 00:10:47,000 |
| We have a JVM and we have a JRE. |
|
|
| 295 |
| 00:10:47,000 --> 00:10:49,000 |
| Now JVM is a part of JRE. |
|
|
| 296 |
| 00:10:49,000 --> 00:10:51,000 |
| Now what else you'll be having inside your JVM, |
|
|
| 297 |
| 00:10:51,000 --> 00:10:53,000 |
| you will be having some libraries. |
|
|
| 298 |
| 00:10:53,000 --> 00:10:57,000 |
| So JVM with libraries is a part of JRE. |
|
|
| 299 |
| 00:10:57,000 --> 00:11:00,000 |
| So whenever you run something, it runs inside the JRE |
|
|
| 300 |
| 00:11:00,000 --> 00:11:04,000 |
| and JVM is actually responsible to run it. |
|
|
| 301 |
| 00:11:04,000 --> 00:11:06,000 |
| Okay, and by default, when you, when you want |
|
|
| 302 |
| 00:11:06,000 --> 00:11:08,000 |
| to run your application on any platform, it need |
|
|
| 303 |
| 00:11:08,000 --> 00:11:10,000 |
| to have JRE, which will have JVM. |
|
|
| 304 |
| 00:11:10,000 --> 00:11:13,000 |
| Now not every machine will have Java C. |
|
|
| 305 |
| 00:11:13,000 --> 00:11:15,000 |
| Java C is only for development purpose, right? |
|
|
| 306 |
| 00:11:15,000 --> 00:11:18,000 |
| So we can imagine this in this section. |
|
|
| 307 |
| 00:11:18,000 --> 00:11:22,000 |
| So basically we have an outer box, which is your JDK, |
|
|
| 308 |
| 00:11:22,000 --> 00:11:23,000 |
| which is used by developers. |
|
|
| 309 |
| 00:11:23,000 --> 00:11:27,000 |
| Inside, which you'll be having something called JRE. |
|
|
| 310 |
| 00:11:27,000 --> 00:11:29,000 |
| And in this you'll be having JVM. |
|
|
| 311 |
| 00:11:29,000 --> 00:11:31,000 |
| So as a developer you'll be installing JDK. |
|
|
| 312 |
| 00:11:31,000 --> 00:11:32,000 |
| JDK will have JRE. |
|
|
| 313 |
| 00:11:32,000 --> 00:11:34,000 |
| JRE will have JVM. |
|
|
| 314 |
| 00:11:34,000 --> 00:11:36,000 |
| But to run something on any other machine, |
|
|
| 315 |
| 00:11:36,000 --> 00:11:38,000 |
| let's say if you have made the application, you want |
|
|
| 316 |
| 00:11:38,000 --> 00:11:40,000 |
| to run this on your friends machine. |
|
|
| 317 |
| 00:11:40,000 --> 00:11:41,000 |
| Your friends machine will only have JRE |
|
|
| 318 |
| 00:11:41,000 --> 00:11:43,000 |
| and JVM. |
|
|
| 319 |
| 00:11:43,000 --> 00:11:45,000 |
| JDK is not required. |
|
|
| 320 |
| 00:11:45,000 --> 00:11:48,000 |
| And that's why we say Java is vora, which is write once |
|
|
| 321 |
| 00:11:48,000 --> 00:11:50,000 |
| and run anywhere, right? |
|
|
| 322 |
| 00:11:50,000 --> 00:11:52,000 |
| So you just have write on your machine, |
|
|
| 323 |
| 00:11:52,000 --> 00:11:55,000 |
| you can run it on any other machine, provided you have JRE |
|
|
| 324 |
| 00:11:55,000 --> 00:11:56,000 |
| and JVM installed. |
|
|
| 325 |
| 00:11:56,000 --> 00:11:58,000 |
| So that's how your Java works behind the scene. |
|
|
| 326 |
| 00:11:58,000 --> 00:11:59,000 |
| I hope it makes sense now |
|
|
| 327 |
| 00:11:59,000 --> 00:12:02,000 |
| and we'll write some more code in the upcoming videos. |
|
|
|
|