(piano music)
-: Now once we have our setup done, it's time
to write our first code.
That's right.
So finally we are going
to run our first Java code here.
Now for that we have to open our editor.
So of course in the last video we have discussed
that we are going to use VS code.
So let's open VS code here.
So I will say code.
Okay, so our VS code is all set to write our first code.
You can see it, it will give you a welcome screen
when you do it and then it will ask the preference,
do you want a light color, dark color, dark, high contrast
or light high contrast.
I would say go for dark because it's good for development.
It will not strain your eyes at least.
So let's close this.
Get started and this is how your VS code will look like.
Okay, simple stuff.
Right now what we'll do is first of all
where you will get your folder.
So you will see your folders on the left hand side.
So this is where you will get your project,
all the files which you want to work with.
So you'll be having that here.
Now of course in the upcoming tutorials,
we'll be using a different IDE
and I want you to get used
to different IDs when you work with.
So on the left hand side we can see we have an explorer here
and then we, if you want
to search something, we have it here.
If you want to add some extensions, which we are going
to do later, we will add certain extensions to work with.
At this point, we don't need any extension,
so just keep it blank.
I mean, no need, no need to install anything here.
In my machine I already have something
on some other accounts,
but on this account I don't think so.
Anyway.
And then if you want to run
and debug it, you debug, you will find the option here.
Now why do we run of, of course we know what
to, why to run, right?
But why do we debug the application?
Yeah, we'll see that later.
At this point,
let's open our files of explorer here.
And this is where I want to create my first project.
Now, how do we create a project?
Now project will be a very broad term at this point.
What we are going to do is we will create some files
and of course when you merge these files
and libraries, you create a project.
At this point we do, we are not working
with any external libraries.
At this point,
we are just going for a simple files, okay?
Hello world, right?
So for that
what we'll do is we'll click on open folder
because all these files will be part
of one particular folder.
So we'll click on Open Folder
and it'll give you certain options
where you want to save this.
So I will save this in my desktop itself.
In fact, on my desktop I want to create one more folder.
So I will say open folder again, inside desktop I will,
I want to create a folder here.
We'll say, this is, I will have a short name,
we'll say, Course, Create and Open.
So you can see we got our course folder here.
What I will do is I will zoom in in inside my VS code so
that you can see everything properly.
And again, the recommendation would be
to watch this on a bigger screen so
that you know you can actually
understand each and every line.
Because in mobile, sometime you will be seeing a font size
and a small font.
I don't want to see this page every time I open my VS codes,
so I will just uncheck this and click on close here
and let's create our first file.
And this is where you are going
to write our first code, right?
So we have already seen how do we install JDK, how do we
check the version on the terminal?
Can you do that in this?
So VS code itself has a terminal here, so you don't have
to open the external terminal.
Of course if you're using Windows,
you'll be having an option of command prompt.
But let's click on terminal here
and you can see we have an option
of terminal, click on this one.
This is where you can enter your commands.
Whatever commands you have.
The same command we'll write here.
So we'll say Java version
and you can see I have Java 17 in this machine
and Java 18 is already released.
But then Java 17 is the LTS version.
So when you say LTS, it means long-term support, right?
So we'll use that and we'll also check if my
Java C is working.
You can see Java C is also there.
Now Java C basically stands
for Java compile as we discussed before.
So we need both.
We need Java to run the application, we need Java C
to compile the code, right?
Okay, cool.
So we got the number as well,
I will just minimize this a bit.
Okay, so now let's create our first file.
So what we are going to do is we'll click on this particular
file here and we'll name this as hello.java.
Now there is something you have to remember,
whenever you create a Java project, you have to make sure
that you give an extension or Java files.
Basically you have to give an extension with dot Java.
Now different languages have different extension.
When you talk about C, we say dot C,
when you say C plus plus language, we say dot CPP.
When you say Java script, we use dot JS.
In the same way,
in Java we say.java, simple stuff, right?
So you've got our file here.
Now VS code will give you some suggestions.
We'll ask you to install some extensions for Java
and we'll click on recommendation.
Okay, it is asking us extension pack for Java,
which will help us,
it will give you some options and extra stuff.
Again, this is just an advantage which you get from VS
code, again, not required.
If you don't want to install this extension,
I think I should go for it.
We also have intelli code for AI assistance.
But yeah, we'll stick to this extension.
Again, in your machine, you don't have
to install this, there's no compulsion.
You can still write your Java code,
but maybe it will give you some
suggestions and stuff in between.
Let's see, let's close this and let's write our code.
So extension will be installing behind the scene.
You don't have to worry about it.
So basically how do we write our Java code?
It's very simple actually.
First of all, the question is
what do you wanna do in this code?
Do you want to create a game
or do you want to build a rocket which will go to mass?
I'll not be doing those extra stuff.
What I will do now is I will create a very simple file which
will print hello world.
I know, that's how you start a programming language, right?
It is irrespective of which language you're learning,
the first thing you do is you print hello world.
So here I want to print hello world.
Now how do we do that?
See if you, in case if you are coming from other languages,
let's say Python, right?
So what you do is if you want
to print hello world in Python, you can write only one line
and maybe Java is not that famous
for simplicity at the start.
Of course when you build a bigger project,
Java is much more structured compared to the languages.
But then to start with, it's not that easy.
So just bear with me.
So what we are gonna do now is
if you want to just experiment
with Java, if you want to play some, if you want
to test some code or stuff,
we have an option which was introduced in Java nine.
So basically you can write your code, in one line
you can get the output example.
So even before we jump to hello
world, let me show you something.
So we have a op, we have a concept of J shell in Java.
So it was introduced in Java nine as I mentioned.
So you can open your terminal
and here let me just increase the size a bit.
So what I will do is I will click on J shell
or I will type J shell and it will give you a
J shell prompt.
Now J in this case is Java.
So you can it make, it should make sense now, okay?
So what you can do in Jshell is if you want
to experiment something, example, why do we write code?
Why do we build application?
So to solve problems right, now it can be a
very simple problem as well.
Example, if you want to add two numbers, it's very simple.
You can say two plus three.
And if I say enter, you can say we got five, right?
So we got the answer which is five, what if you want
to do a subtraction, you can do that.
So nine minus six, and you can see we got three.
So this is working, but what if you want to print something?
So in this case what you can do is when you were in Java,
if you want to do something,
we use something called methods.
At this point, you don't have to remember methods on
what the definition is.
Just remember that there's a concept called methods
using which you can do something.
The only thing you have to remember is if you want
to do something, you need methods.
In the same way, if you want to do something here,
I want to print something, right?
So we have to use a method called print.
It is a inbuilt method in Java so you don't have
to worry about it, just use it, it will work.
So whenever you call methods, you have to parse the values.
So I want to say, hey print,
but then it will say okay, I will print,
but what you want me to print?
So you can mention that in this bracket.
So in this round brackets, you can mention I want
to print hello world.
Now if you want to just print a number,
let's start with that first.
So let me just print a number, which is six.
And in Java there's one more thing.
You have to put a semicolon at the
end, it should work in this.
But then living with this, at the end put a semicolon.
That's how you mentioned, hey, something is getting ended.
So we've got a semicolon there.
And now what you can do is let's try to run this code.
Now errors, right?
Error are very important in your life,
in your programming life,
basically you see you got the error.
It says cannot find a simple call print, it's not working.
Okay, cool, no problem.
So let me just clear the screen.
A clear comment is not working, ignore that.
So let me open Jshell once again and let's,
because I just want to keep it on top.
So what I will do now is if I want to print something
and I want to print a value six at the end,
I want a semi colon as well.
Now Java says if you want to call print,
print belongs to something, right?
So it it when I say it is available inside Java.
So the statement you have
to always mention is system.out.print again.
See there will be a point where you, I will, will talk about
what is system, what is out.
At this point it's very difficult to understand.
So just bear with me.
This is a statement which you have
to use if you want to print something on the console.
So if I want to print something here,
just say system.out.print
and whatever value you want to pass, say enter.
You can say we got six,
but what if you want to print hello world,
I don't want to print six.
So if you want to repeat the same statement,
of course you can type or you can click on the up arrow,
it will give you the option.
Now here if you want to print hello world, you have to put
that in double codes.
So whenever you want to do something with text,
see numbers are easy to use, you can simply say six.
But if you want to work with a text, you have to put
that in double codes the way I've done it here.
So in this double codes you have
to mention hello world, right?
That's how you start a programming,
programming journey, right?
I will say enter and you can say we got hello world,
what if I want to print something
else, which is very simple.
You can say double codes, not being ready, Telusko.
And if I say enter, you can say we got the text.
So whatever you want to print, just put that in double codes
and it should work.
And you can see we are getting the output as well, so cool.
So we are able to do this with the help of J shell,
but will it work in this?
If I try to copy this, in fact why
to copy it, we can type it.
So let's type system.out.print.ln,
and here we'll say hello world
and let's give a semi colon
at the end, it was working on J shell.
But when you work with Java files,
because this is how you build a project, right?
J shell is not to build projects,
it's just for the experiment.
If you are learning a language, it is good,
but if you want to build a big application,
say dot java file and write your code there.
So let's compile this code.
Now how do we compile?
Okay, so there, there are two steps you have to follow.
First, when you write a code, you have to compile the code
and then you can run the code.
So to compile the code, you can say Java C in the terminal,
and let me just increase the font a bit.
So you have to say Java C
and then you have to mention the file name.
So first you have to be make sure
that you are in a correct folder, which is close.
You can see that this is a folder we have
and then you have to mention Java C.
And then the file name.
The file name in this case is hello.Java, click on enter.
Oh, we got an error.
Okay, so it says something is missing, you know,
something else was expected
and you are giving this, this is not working.
So this is not how you write applications
or code in Java file.
We have to do something else.
But at this point we have understood right?
How do you work with Jshell?
So you can, if you want to do something with Jshell,
just write a code, it will work.
If you want to add two numbers, it will work.
You can't do that here.
We have to do something extra, and what is that something,
that we'll see in the next video.