Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,420 --> 00:00:05,850
Documents can be used to describe what a function does in the past three workbooks, LFG documents to
2
00:00:05,850 --> 00:00:09,480
guide your code, and this one is from Workbook four point three.
3
00:00:10,380 --> 00:00:15,000
Notice how easy it is to read, because very succinctly, it tells you exactly what the function does,
4
00:00:15,300 --> 00:00:18,210
what the parameters are and what the function returns.
5
00:00:19,500 --> 00:00:25,290
If you're working in a team of developers, you should have a document for every function, it helps
6
00:00:25,290 --> 00:00:29,340
collaborators understand what your function does without having to read your code.
7
00:00:32,619 --> 00:00:35,680
So in this lesson, you're going to learn how to write documents.
8
00:00:38,230 --> 00:00:43,120
First thing I need you to do is create a new class by yourself inside the section for project, create
9
00:00:43,120 --> 00:00:47,260
a new file named Comments Java and make sure the class has a main method.
10
00:00:55,400 --> 00:00:57,260
So we're going to start off by writing a function.
11
00:00:59,030 --> 00:01:02,150
Inside documents generate a random function that void.
12
00:01:03,790 --> 00:01:05,170
I'm going to call that Grete.
13
00:01:12,050 --> 00:01:13,550
And it's just going to print high.
14
00:01:23,700 --> 00:01:26,910
And just before the function, I'm going to write slash star star.
15
00:01:28,040 --> 00:01:34,850
And press enter a few times, and Java creates a skeleton first threat, a dark comment next to the
16
00:01:34,850 --> 00:01:36,770
first hour, I'm going to write function name.
17
00:01:40,220 --> 00:01:41,330
Which is Grete.
18
00:01:47,990 --> 00:01:51,110
And beside the last hour, I'm going to write inside the function.
19
00:01:59,980 --> 00:02:04,330
Followed by a bullet point that describes what it does and it prints hi.
20
00:02:10,460 --> 00:02:11,050
There you go.
21
00:02:11,110 --> 00:02:14,470
This document effectively describes whatever function does.
22
00:02:15,650 --> 00:02:17,690
Now we're going to write a function with parameters.
23
00:02:21,050 --> 00:02:22,160
Public static.
24
00:02:29,770 --> 00:02:32,680
It's going to be void and I'm going to call it print text.
25
00:02:41,330 --> 00:02:44,720
And it's going to receive, too, string parameters, name and age.
26
00:02:51,150 --> 00:02:53,340
And inside the function, I'm going to print high.
27
00:02:54,870 --> 00:02:55,350
I'm.
28
00:02:57,830 --> 00:02:59,690
Whatever name value was Pastan.
29
00:03:07,870 --> 00:03:09,880
And whatever age value is Pastan.
30
00:03:13,160 --> 00:03:13,940
Years old.
31
00:03:21,920 --> 00:03:25,460
And now, once again, before the function, I'm going to write Star Star.
32
00:03:27,860 --> 00:03:33,530
Press enter a few times and check it out, it recognizes the two parameters in my function.
33
00:03:35,000 --> 00:03:39,920
And now this is just the preference, but in brackets, I'm going to add the data type of each parameter,
34
00:03:40,700 --> 00:03:42,560
so the name parameters of type string.
35
00:03:44,930 --> 00:03:47,270
And the parameter is of type string as well.
36
00:03:50,260 --> 00:03:53,410
Now, like before, right, the function name beside the first star.
37
00:04:02,190 --> 00:04:06,720
And describe the function beside the last hour, so we'll say inside the function.
38
00:04:08,920 --> 00:04:09,460
Colin.
39
00:04:13,520 --> 00:04:18,750
I'm going to add a bullet point that says this function prince, the name and age is part of a text.
40
00:04:28,330 --> 00:04:31,300
Now we're going to read a function where they return value and documenter.
41
00:04:35,350 --> 00:04:37,420
I'm going to make a function that returns a double.
42
00:04:44,550 --> 00:04:46,440
I'm going to call it calculate area.
43
00:04:53,000 --> 00:04:56,060
And it's going to receive two parameters, length and what?
44
00:05:07,550 --> 00:05:12,080
And inside the function, I'm going to calculate the area of a rectangle by multiplying the length and
45
00:05:12,080 --> 00:05:13,730
width values that are passed in.
46
00:05:19,190 --> 00:05:21,230
And then I'm going to return the area value.
47
00:05:26,280 --> 00:05:29,820
And once again, right before the function, I'm going to write Star Star.
48
00:05:32,700 --> 00:05:38,490
Press enter a few times and check it out this time it recognizes the parameters and that you have a
49
00:05:38,490 --> 00:05:39,260
return value.
50
00:05:39,780 --> 00:05:43,080
And you know me, I like the data type of each thing in brackets.
51
00:05:43,590 --> 00:05:45,330
The parameters are all of type double.
52
00:05:47,100 --> 00:05:49,070
And the return value as a double as well.
53
00:05:56,480 --> 00:05:58,370
As always, I would add the function name.
54
00:06:10,050 --> 00:06:14,940
And next to the last hour, I'm going to describe the function by saying inside the function.
55
00:06:20,130 --> 00:06:24,510
And then I'll add a bullet point that says this function calculates the area and returns.
56
00:06:30,120 --> 00:06:31,800
That's all pretty easy, isn't it?
57
00:06:32,430 --> 00:06:38,190
All you have to do is press star, star a few times and Java creates a skeleton that we can use to fill
58
00:06:38,190 --> 00:06:39,840
out and document our function.
59
00:06:43,050 --> 00:06:48,690
In this lesson, you learn to describe functions using Javadoc when you write Star, a star followed
60
00:06:48,690 --> 00:06:54,960
by Enter Jova generates the format and all you have to do is write the function name, give a small
61
00:06:54,960 --> 00:07:00,300
description, and if you want to get super fancy, write the type of each thing in brackets.
6012
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.