Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

sent with the starter code Your code may be amazing but without proper documentation nobody, including yourself, will use and build on it later (Or

sent with the starter code
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Your code may be amazing but without proper documentation nobody, including yourself, will use and build on it later (Or do you enjoy reading source code just to see what it does or judge if it's useful to you?). It is therefore no surprise that the classes in the Java standard library are really well documented: If you ever searched for specific Java classes or types online, you will have come across documentation pages like this one on String B or this one on Arrays. E. Have you ever wondered how they are created and maintained? Well obviously this is not done by hand! These pages are automatically generated from the java source code files using a neat tool called javadoc. It comes with the JDK, meaning if you have a Java compiler you will almost certainly also have javadoc installed. Fun fact: Javadoc was one of the very first such documentation generators and is part of the JDK since version 1.0 (Jan 1996)! How does it work? Jiva code is already quite structured so that it gets past the compiler. Fpr instance, a classes' superclass, and the precise signatures of its public methods and attributes can be automatically extracted. To add more info, javadoc will look for special javadoc comments and interpret them. Javadoc comments are basically multi-line comments that start in instead of just /. This way they are ignored by the compiler as it interprets the extra asterisk just as the first symbol of a comment. Javadoc, however considers only those types of comments. In it you can put any text. HTML code and extra tags to document your code. Let's have a look at an example, the file How does it work? Java code is already quite structured so that it gets past the compiler. For instance, a classes' superclass, and the precise signatures of its public methods and attributes can be automatically extracted. To add more info, javadoc will look for special javadoc comments and interpret them. Javadoc comments are basically multi-line comments that start in instead of just /. This way they are ignored by the complier as it interprets the extra asterisk just as the first symbol of a comment. Javadoc, however considers only those types of comments. In it you can put any text, HTML code and extra tags to document your code. Let's have a look at an example, the file from the starter code. It contains two javadoc comments: the first one at the very top which documents the class, and another one in lines 9 to 20 , which documents the method These comments also contain some tags which mention the author and version of the code and describe method parameters and return types. Ignoring for now that the method is incredibly silly, I hope you agree that it is much more understandable - and thus useful - than the undocumented method below (what exactly is meant be swap?l?). Generating HIML Let's fire up javadoc and generate the documentation page for this class. To do this, open a terminal and enter fayesec - docs Stringtools. java This will generate a whole bunch of files in the folder. Hint: "Command Parameters" The parameter tells javadoc to create everything in a directory called If you omit this then it will dump everything in the current folder. You can also call this on more than just this one file like this: lavadec tigia Check out the help page for the javadoc command: to see what else it can do for you. Now let's have a look at the generated pages in a browser by opening the file Voila! Notice that this page contains the documentation from our two javadoc comments plus some extra info on the class, such as listing its methods: You can also call this on more than just this one file like this: jovodoc - jave Check out the help page for the javadoc command: to see what else it can do for you. Now let's have a look at the generated pages in a browser by opening the file Voil! Notice that this page contains the documentation from our two javadoc comments plus some extra info on the class, such as listing its methods. Your Turn: Document the remaining two methods As an exercise, provide javadoc comments for the remaining two methods in our class. Can you figure out just from reading the source code what means? Reading other people's code is annoying isn't it? In your documentation, add at least tags to describe the parameters and return values. There are a few more tags that javadoc interprets Er and which you are welcome to use. Re-generate the HTML pages by executing as above as often as you want. + A bunch of utility functions for Strings. * * ebuthor Patrick Totzke * eversian 1.0 *f public class StringToots f I Conputes the length of a string. - This is done by tirst turning it into an Array of characters, then * Iteratively increnenting an integer variable for every, character. - This 15 of course are realty silty solution because 5 tring. tength or Arrayisize can be used instead. * In fact, the latter is inplicitly used in the teraination criterion of the for losp. - cuara str the string to consider * Areturn the length of the given string. if publle statile int length(String str) char tl ten str. tocharArrayti: int a 0 : for(char ch : ten) f ya+1+1 return a; If To004 add javadoc coment here public statle string suap(string a)d String revi: for(int jos, tength ():j jed 1)( ) y return revi

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago