Not let's look at some more cool shortcuts for automatic code Glenning an automatic cogeneration. 2
Let's begin with automatic quote cleaning first one is organizing imports. 3
So for that you would use. 4
Control shift or iron. 5
What it does is it organizes all the import statements in some predefined order. 6
It also deletes any import statements that are not used in that class. 7
So let's just take this class Turing Test which we wrote earlier. 8
I just added this import statement which is not being used. 9
And so you see this yellow warning here. 10
So let's just go ahead and hit Control Shaeffer or. 11
And as you can see since it's not being used it got deleted. 12
Now let me show you a different code base where a lot of statements here. 13
So let me go ahead and copy these javac statements here and it here. 14
So I'm just creating them. 15
Let me do a control shift or and they go back to their original place. 16
You see they go on the run back here too. 17
So that's Control shift. 18
Oh. 19
Or stands for organizing organizing. 20
So they're organizing the import statements. 21
OK. 22
So that's the first one. 23
To go back to the previous eclipse next is which we have already seen it as can truly shift f underoath 24
for formatting. 25
So if you see here and this class. 26
So this is not indented properly. 27
And this student object creation statement is also not indented properly. 28
So it's here and part offered is. 29
And the next line. 30
So that's just head control shift F and got indented properly. 31
Everything is formatted properly and we have seen this in our coding conventions since. 32
OK. 33
So that's the second one. 34
Now if you want to move toward one as if you want to move some chord if you want to shift the entire 35
code to what's right all you can do is just hit tab. 36
Now if you want to bring it back. 37
Hit shift tab. 38
OK. 39
And it goes back to the left side. 40
Let's say if you want to add some comments here let's go here. 41
Let's see if you want to comment this code. 42
All you can do is get control and forward slash. 43
You'll see the got commented out on if you are uncommon then just do the same thing again. 44
That's it. 45
Now if you want to insert block chords then hit Control shift and forward slash and there you go you 46
can see those block notes here. 47
Now if you're uncommon if you want to uncommented you need to do control shift in backslash for this 48
and that's it. 49
So let's just put control forward slash and let's leave it like that. 50
So that's about some chord cleaning tactics. 51
Next let's see how we can automatically generate some sort score. 52
So here I'm going to construct a couple of items and the first one that I'm going to demonstrate as 53
how we can automatically insert some template. 54
OK so let's just go out and do that. 55
But before that let's just recap of this chord. 56
So this is the code that we wrote in our students demo class. 57
And here is the Student class which has a few fields like the ID name on gender and so on. 58
Yeah only three fields are here and here in the student best is tester class where we are creating three 59
instances just print and then initializing them with name and gender and then just printing the name 60
here in front of one of those students the name was misspelled. 61
So we are setting the right name. 62
And then we are printing the right name once again. 63
So just a simple student demo. 64
So let's just go ahead and create a new instance. 65
So for that new instance of student just type in the keyword new and hit control space on it it will 66
show a pop up here just select new and the template code is here. 67
So all we need to do is just fill up these details here so it has to be student. 68
And this has to be student and we need to pass the arguments for the constructor. 69
So Karen I'm female that's now go ahead and bring these for students but for that let me just sow so 70
discord and this needs to be stored and for 71
so all I'm doing is creating a student array for the elements and the four elements that we have the 72
four student objects that we how are are being stored in the tree and it's called us a list. 73
Now let's just print this out. 74
Let's put in for each. 75
So this is a key word on his control space once again and said this. 76
And let's just go ahead and put in the names. 77
So for this let's just create create two variables also need to do and not get name. 78
So this is it automatically helps us to pick one of them and their names so that they're counting off 79
eclipse next string gender. 80
But there is more than gender method. 81
So we need to write that. 82
So it's just this year if we were over here it says this quick fix allows us and gives us an option 83
to create the method their gender so let's just do that. 84
So it creates this template code here once again in the Student class so let's just say this in our 85
gender and this sort of combines. 86
Now let's put a couple of print statements. 87
So just type in sys out and then control space and it inserts this Prindle and statement for us. 88
So just say the 89
same thing here says how to control space. 90
So that's the thing. 91
So you hear we try new and here for each and here says oh come on we can do many other things like you 92
can try switch. 93
You can try far. 94
You can try even the main method you can insert but we already have the main method here. 95
All you do is Maine and then head control space and let's say if you want to insert like a public method 96
just type in public underscore method Hensick control space and it creates a template for that. 97
All you need to do is change. 98
Or you know insert some return type and the name has to be changed. 99
So these are some commonly used ones and you might how more so that for me. 100
Now where are these templates stored. 101
For that we can go into Windows 102
preferences just go into java going to editor here and written editor select templates on here you can 103
see all the names here. 104
For example for each here. 105
So these are all the templates that we have. 106
If you click on for each slide shows you the template. 107
OK that's where all the templates are. 108
Let's go ahead and automatically generate more source code. 109
So let's just create a class called course. 110
Let's add two variables here 111
Id a name. 112
And here we can see this yellow icon. 113
And if we click at once it's just create getter and sector for ID. 114
So those getters and setters will be created automatically and we actually looked at this in the information 115
hiding listen. 116
So we have already seen this where both getters and setters would be automatically created. 117
So let's just do it in a different way. 118
So let's go here into source and select this Jenrette getters and setters. 119
Here it shows both the fields ID and name so and it says select all and the insertion point. 120
Let's say after name and let's hit OK here. 121
As you can see it has created the getters and setters automatically. 122
So that's one way to do it. 123
Let's go next let's create a constructor automatically let's go here into source and there is this option 124
called gendered constructor using friens. 125
Let's do that let's create a constructor using one or more of these views. 126
So let's go here let's select on let's just go insertion point after name is fine and it's just hit 127
. 128
OK. 129
OK. 130
So it created a new constructor and it has two parameters your ID a name and there are initialized here 131
. 132
So that's how you would automatically generate ID getters and setters and the constructors also. 133
So that's about it. 134
And whatever we have seen and this lesson everything can be done from here from the source. 135
So as you can see there is organized import here and there is formatting here. 136
And we have all the getter on several generations and also the constructor generation or here. 137
So everything can be done here or you can also use the shortcuts like control shift or control shift 138
F and so on. 139
That's about it.