Writing JavaDocs Mimi Opkins CECS 274 Copyright (c) Pearson 2013. All rights reserved.

Slides:



Advertisements
Similar presentations
Classes and Objects CMSC 202. Version 9/122 Programming & Abstraction All programming languages provide some form of abstraction. – Also called information.
Advertisements

Building Java Programs Appendix B
1 CSE 331 Programming by contract: pre/post conditions; Javadoc slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer,
Utilities (Part 3) Implementing static features 1.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
16-Jun-15 javadoc. 2 Javadoc placement javadoc comments begin with /** and end with */ In a javadoc comment, a * at the beginning of the line is not part.
Object-Oriented Enterprise Application Development Javadoc Last Updated: 06/30/2001.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 8: Classes and Objects.
1 More on Arrays Arrays of objects Command line arguments The ArrayList class Javadoc Review Lecture 8 notes and L&L 7.1 – 7.2 Reading for this lecture:
JavaDoc COMP 302. JavaDoc javadoc: The program to generate java code documentation. Input: Java source files (.java)  Individual source files  Root.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMING PRACTICES API documentation.
Writing Classes (Chapter 4)
JavaDoc1 JavaDoc DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY July 24, 2006 by Emil Vassev & Joey Paquet revision 1.2 –
Program documentation using the Javadoc tool 1 Program documentation Using the Javadoc tool.
1 Documenting with Javadoc. 2 Motivation  Why document programs? To make it easy to understand, e.g., for reuse and maintenance  What to document? Interface:
Classes CS 21a: Introduction to Computing I First Semester,
Utilities (Part 2) Implementing static features 1.
Javadoc: Advanced Features & Limitations Presented By: Wes Toland.
INTERFACES More OO Concepts. Interface Topics Using an interface Interface details –syntax –restrictions Create your own interface Remember polymorphism.
Javadoc Comments.  Java API has a documentation tool called javadoc  The javadoc tool is used on the source code embedded with javadoc-style comments.
Software Documentation Section 5.5 ALBING’s Section JIA’s Appendix B JIA’s.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 10 - Interfaces.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Documentation javadoc. Documentation not a programmer's first love lives in a separate file somewhere usually a deliverable on the schedule often not.
Javadoc A very short tutorial. What is it A program that automatically generates documentation of your Java classes in a standard format For each X.java.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Chapter 13 Implementing.
JavaDoc and Contracts Spring Documenting Contracts with JavaDoc Contract model for methods Preconditions Postconditions JavaDoc Industry standard.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
A brief introduction to javadoc and doxygen. What’s in a program file? 1. Comments 2. Code.
Encapsulation ◦ Blackbox concept Data and method(s) Hidden details InterfaceEffect(s) methods called class.
1  lecture slides online
Javadoc Summary. Javadoc comments Delemented by /** and */ Used to document – Classes – Methods – Fields Must be placed immediately above the feature.
Page 1 – Autumn 2009Steffen Vissing Andersen SDJ I1, Autumn 2009 Agenda: Java API Documentation Code Documenting (in javadoc format) Debugging.
Computer Science 209 Software Development Handing Errors and Creating Documentation.
Java Doc Guideline R.SANTHANA GOPALAN. Java Doc Guideline Audience Internal Developers PQA - who write test plans PPT – who write the documentation Customers.
Class Design I Class Contracts Readings: 2 nd Ed: Section 9.5, Advanced Topic nd Ed: Section 8.5, Advanced Topic 8.2 Some ideas come from: “Practical.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
1 Documenting with Javadoc CS 3331 Section and Appendix B of [Jia03] How to Write Doc Comments for the Javadoc TM Tool available from
Lecture 7 February 24, Javadoc version and author Tags These go in the comments before named classes. –Put your SS# on a separate line from the.
Documentation Javadocs. Design/Documentation An essential ingredient of good Object Oriented programming is known as design by contract. This means that.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
Advanced Programing practices
More Sophisticated Behavior
Lecture 3 John Woodward.
The Class ArrayLinearList
Software Development Handing Errors and Creating Documentation
JavaDoc CECS277 Mimi Opkins.
Preconditions precondition: Something your method assumes is true at the start of its execution. Often documented as a comment on the method's header:
Introduction to javadoc
Coding Standard & Javadoc
Design by Contract Fall 2016 Version.
Chapter Three - Implementing Classes
Building Java Programs
Building Java Programs
slides created by Ethan Apter
Object initialization: constructors
slides created by Ethan Apter
JavaDoc and Contracts Fall 2008.
Advanced Programing practices
Introduction to javadoc
JAVA CLASSES.
Go to pollev.com/cse143.
Classes CS 21a: Introduction to Computing I
slides created by Ethan Apter and Marty Stepp
Building Java Programs Appendix B
Software Specifications
Presentation transcript:

Writing JavaDocs Mimi Opkins CECS 274 Copyright (c) Pearson All rights reserved.

2 Javadoc comments /** * description of class/method/field/etc. * tag attributes *... tag attributes */ Javadoc comments: Special comment syntax for describing detailed specifications of Java classes and methods. –Put on class headers, methods, constructors, public fields,... Benefit: Tools can turn Javadoc comments into HTML spec pages. –Eclipse and other editors have useful built-in Javadoc support. Main drawback: Comments can become bulky and harder to read.

3 Javadoc tags on a method or constructor: on a class header: name descriptiondescribes a descriptiondescribes what value will be ExceptionType reasondescribes an exception that may be thrown (and what would cause it to be thrown) sourcecode } for showing Java code in the comments allows a subclass method to copy Javadoc comments from the superclass version nameauthor of a numberclass's version number, in any format

4 Javadoc example /** * Each BankAccount object models the account information for * a single user of Fells Wargo bank. James T. Kirk 1.4 (Aug ) */ public class BankAccount { /** The standard interest rate on all accounts. */ public static final double INTEREST_RATE = 0.03;... /** * Deducts the given amount of money from this account's * balance, if possible, and returns whether the money was * deducted successfully (true if so, false if not). * If the account does not contain sufficient funds to * make this withdrawal, no funds are withdrawn. * amount the amount of money to be withdrawn true if amount was withdrawn, else false IllegalArgumentException if amount is negative */ public boolean withdraw(double amount) {... }

5 Javadoc output as HTML Java has tools to convert Javadoc comments into web pages –from Terminal: javadoc -d doc/ *.java –Eclipse has this built in:Project → Generate Javadoc... –The actual Java API spec web pages are generated from Sun's Javadoc comments on their own source code:

6 Javadoc HTML example from java.util.List interface source code: /** * Returns the element at the specified position * in this list. * This method is not guaranteed to run * in constant time. In some implementations it may * run in time proportional to the element position. * index index of element to return; must be * non-negative and less than size of this list the element at the specified position IndexOutOfBoundsException if the index is * out of range * index = this.size()}) */ public E get(int index); –Notice that HTML tags may be embedded inside the comments.

7 Javadoc enums, constants Each class constant or enumeration value can be commented: /** * An instrument section of a symphony orchestra. John Williams */ public enum OrchestraSection { /** Woodwinds, such as flute, clarinet, and oboe. */ WOODWIND, /** Brass instruments, such as trumpet. */ BRASS, /** Percussion instruments, such as cymbals. */ PERCUSSION, /** Stringed instruments, such as violin and cello. */ STRING; }

8 Don't repeat yourself or write vacuous comments. /** Takes an index and element and adds the element there. index index to use element element to add */ public boolean add(int index, E element) {... better: /** Inserts the specified element at the specified * position in this list. Shifts the element currently at * that position (if any) and any subsequent elements to * the right (adds one to their indices). Returns whether * the add was successful. index index at which the element is to be inserted element element to be inserted at the given index true if added successfully; false if not IndexOutOfBoundsException if index out of range * index size()}) */ public boolean add(int index, E element) {...

9 Your Javadoc is your spec Whenever you write a class to be used by clients, you should write full Javadoc comments for all of its public behavior. –This constitutes your specification to all clients for your class. –You can post the generated HTML files publicly for clients to view. –Common distribution of a library of classes: binaries (.class files, often packaged into an archive) specification (Javadoc.html files, or a public URL to view them) –Eclipse uses Javadoc for auto-completion. Write Javadoc comments for all exposed API elements. (anything that is non-private)

10 Javadoc and private Private internal methods do not need Javadoc comments: /**... a Javadoc comment... */ public void remove(int index) {... } // Helper does the real work of removing // the item at the given index. private void removeHelper(int index) { for (int i = index; i < size - 1; i++) { elementData[i] = elementData[i + 1]; } elementData[size - 1] = 0; size--; } –Private members do not appear in the generated HTML pages.

11 Custom Javadoc tags Javadoc doesn't have tags for pre/post, but you can add them: –By default, these tags won't show up in the generated HTML. But... condition notes a precondition in API documentation; describes a condition that must be true for the method to perform its condition notes a postcondition in API documentation; describes a condition that is guaranteed to be true at the end of the method's functionality, so long as all preconditions were true at the start of the method

12 Applying custom tags –from Terminal: javadoc -d doc/ -tag pre:cm:"Precondition:" -tag post:cm:"Postcondition:" *.java –in Eclipse: Project → Generate Javadoc... → Next → Next → in the "Extra Javadoc options" box, type: -tag pre:cm:"Precondition:" -tag post:cm:"Postcondition:" –The generated Java API web pages will now be able to display pre and post tags properly!

13 More custom Javadoc tags object(s) a more specific postcondition; describes any state of this object or other object(s) that may be changed by a call to this object(s) a more specific postcondition; describes any promises this method makes about the final state in which it will leave some other object(s) when it is done running