Hi everyone, welcome back. In this lecture we are going to be writing a similar functionality
but we are going to be exploring the coding assistant which is our github copilot that we
have installed and we are going to use the coding assistant to write the similar code for us because
the coding assistants are on the rise and all the organizations today are recommending the developers
to start leveraging these tools to improve the productivity and also using these tools the right
way will benefit you in many ways and using the wrong way is not going to benefit you in many ways
so in this course i'll walk you through what are the ways that we can use these tools in the
correct way that can benefit the developers i don't have the whole course updated with the
github copilot assistant but whatever new lectures all the java 25 features that we are going to
explore we are going to leverage the copilot assistant now what i'm going to do is there are
different modes available here so number one is the ask mode number two is the agent mode number
three is a edit mode ask mode is something which you can chat and interact with like how you can
do it with chat cpt so now what i'm going to do is i'm going to ask can you write a simple java
program using the compact main functionality that's introduced in java 25 okay so then i'm
going to press enter so this is not going to edit the source code files this is going to just give
you the program for you so that you can take this program and then put this in your class file as
you can see so here is a simple java program using the compact main functionality introduced in java
25 and you can see that it gave me this code whatever we wrote right so it took us like
probably uh three to five minutes to write this code and explain the code but here you go you have
the code readily available within a few seconds so this is the beauty of these copilot ai coding
assistant tools but one thing we need to make sure is that we need to ask the right question so that
you will get the right answer and the model that i'm using is that clarkson at 4.5 and what i did
was i went ahead and subscribed for the github copilot pro license which is 10 dollars per month
that's the reason why i have access to all these models i'm using the clarkson at 4.5 this is the
latest and greatest model at the time of recording this lecture if you're using a free tier you might
be having access to 3.5 or something like that or the 4.1 version so use the latest model that's
available to you but using the premium models is what is going to give you the right code because
java 25 is one of the latest feature if you use the older model it might not have knowledge about
the java 25 features at all so it's better to use the latest and greatest model so this is the ask
mode so what i'm going to do is i'm going to look into the edit mode so in the edit mode what i'm
going to do let me copy the prompt over here copy it over here and then click on the edit mode i'm
going to ask can you introduce a variable named course and then print it in the console okay and
then you need to add the files where you want to edit to happen so select the simple hello hold
there you go we have the simple hello world selected and then send when you do this what
this is going to do is this is going to go ahead and edit the file for you as you can see it added
the course name as modern java and then printed that value in the console so now it has this
changes being made as a user of the coding assistant we are the developers we need to
accept this change or discard this change when you accept this change this is going to be basically
making the code available in the class if you discard the change then it will automatically
remove the change now i'm going to execute this particular class and as you can see the class is
getting executed there you go so we have the course value as modern java now let's take a look
at the agent mode agent mode is something which is an advanced mode which can go ahead and create the
class for you which can also create the functions variables whatnot whatever you ask it to do
it will actually do it for you but you need to be really clear about what you want the agent to do
otherwise it will try to do something which you do not expect it to do so what i'm going to do is
i'm going to copy the same thing over here and place it over here so i'm going to be telling
that create a simple java program using the compact main and make sure you have the latest
model here i'm selecting the clotson at 4.5 and here i'm going to ask it to do the new class name
should be simple hello world one or i can say v1 okay so you need to be explicit about what you want
the agent to do otherwise it will do some random things which is not expected so i'm going to press
enter okay so it created a class named simple hello world v1 right so it is actually over here
and you can see that it added bunch of things over here right so you didn't ask it to do it but still
it went ahead and added all these different things so now i'm going to accept it all and then show
you what it means so it basically took some of the examples that we did in the simple hello world
class and also it added what is the benefit of the compact main feature so it has the no class
declaration needed no public static modifiers required and simplified io dot main method
and top level instance variables are allowed it also showed the traditional system dot out dot
printer and syntax and also it created the function for you so basically we didn't ask it to do all
of these things but it did went ahead and made those changes so now we can actually ask it hey
it looks like you made more changes than what i expected can you just have the first four lines
of println okay and then you can tell it to remove all the other code and then press enter so you can
see that the simple hello world v1 is the one which is being referenced now it went ahead and
removed all the changes for you okay so you can see that it edited the file perfect i have
simplified the code it says that now it just has the three instance variable at the top and the
main function with only the first four println statements now we accept this change and you do
the accept all there you go you have the simplified compact main function readily available the code
is completely written by the copilot assistant so this is one of the benefit of using these
a assistant tools what it can do is that it can help you learn the new features faster and you
don't have to write the code the basic code from scratch you can use the assistant to write for you
another thing is that you can actually highlight the code and ask and interact with the assistant
directly from the code itself so you can actually select this you can say like what is the benefit
of using this over system.out.println it will also give you thoughts of why using io.println
instead of system.out.println can provide benefits such as abstraction easier testing and flexibility
and also using different models will give you different answer but using the latest model
always gives you the best answer as far as i can think of because the newer models are
continuously better in reasoning they are really better in latest and greatest training data so i'm
going to ask the same question what is the benefit of io.println over system.out.println
so you see that right using io.println over system.out.println provides several benefits
cleaner syntax simplified imports consistency with modern java to also talk about the simplified java
features designed to reduce ceremony of simple programs testing flexibility feature proof so this
model gave me the right answer when i used a 4.1 it gave an answer but it is not a great answer
so this is also another feature when you install this copilot assistant you can directly highlight
the code and you can ask it to explain what that code is it will be able to provide you a answer
and you can actually read through it and get an understanding on it with this we came to the end
of this lecture i hope you all had fun coding the compact main functionality completely using the
copilot assistant these copilot assistants are going to stay and this is going to be the feature
which all the organizations are going to push the developers to get comfortable with
if you're not going to be comfortable using these tools i'm really sorry to say that you'll be left
out and the companies will continuously going to enforce this tools to be used in your day-to-day
development this marks the end of this lecture thank you for watching