Chapter Two Bonus Lesson: JavaDoc

Similar documents
Class 1: Homework. Intro to Computer Science CSCI-UA.0101 New York University Courant Institute of Mathematical Sciences Fall 2017

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Lecture (01) Getting started. Dr. Ahmed ElShafee

JAVA: A Primer. By: Amrita Rajagopal

CS 177 Recitation. Week 1 Intro to Java

Write for your audience

Laboratory. of Java and. specifically. On the line the method. does, e.g.: /** Obtains. of the die.

List of Slides 1 Title 2 Chapter 2: Sequential execution and program errors 3 Chapter aims 4 Section 2: Example:Hello world 5 Aim 6 Class: programs ar

1. Download the JDK 6, from

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Website Development Komodo Editor and HTML Intro

Lesson 04: Our First Java Program (W01D4

17 Hello world 18 Type: String: literal 19 Standard API: System: out.println() 20 Hello world 21 Statement 22 Statement: simple statements are ended w

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

CS 11 java track: lecture 1

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Instructions. First, download the file

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

Chapter 4 Defining Classes I

COMP 1210 Documentation Guidelines Page 1 of 7. Class documentation (Chapter 1):

Comp151 Lab Documentation using Doxygen

Getting Started with Java. Atul Prakash

Scripting With Jython

Starting In Java With JPT in Eclipse

Lecture 1 - Introduction (Class Notes)

Java: Comment Text. Introduction. Concepts

Example Program. public class ComputeArea {

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

Refresher workshop in programming for polytechnic graduates General Java Program Compilation Guide

Java using LEGO Mindstorms and LeJOS. University of Idaho

CPSC 324 Topics in Java Programming

Java Bytecode (binary file)

COMP 215: INTRO TO PROGRAM DESIGN. Prof. Chris Jermaine Chris Prof. Chris Dr. Chris

javadoc Java Primer Javadoc-1 Scott MacKenzie

Computer Science 62 Lab 8

PROGRAMMING STYLE. Fundamentals of Computer Science I

CSC116: Introduction to Computing - Java

COMP6700/2140 JDK Tools

Import Statements, Instance Members, and the Default Constructor

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

Java Style Guide. 1.0 General. 2.0 Visual Layout. Dr Caffeine

How to make a "hello world" program in Java with Eclipse *

First Simple Interactive JSP example

Basic Keywords Practice Session

Express Yourself. Writing Your Own Classes

Code Ninjas: Introduction to Computer Science. Macomb Science Olympiad Presented by Swati Dharia

CSC116: Introduction to Computing - Java

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

Certified Core Java Developer VS-1036

For live Java EE training, please see training courses at

The Very Basics of the R Interpreter

An overview of Java, Data types and variables

Javadocing in Netbeans (rev )

Advanced Computer Programming

Lecture 02, Fall 2018 Friday September 7

Tips from the experts: How to waste a lot of time on this assignment

Getting Started with Command Prompts

Imperative and Object Oriented Programming. Tutorial 1. Charlie Abela Department of Artificial Intelligence

Summer Assignment for AP Computer Science. Room 302

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

Getting Started with Eclipse for Java

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Using NetBeans to document code. The NetBeans IDE can be used to help generate Javadoc documentation and to check that the documentation is complete.

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

CMSC162 Intro to Algorithmic Design II Blaheta. Lab March 2019

C02: Overview of Software Development and Java

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

Anatomy of a Java Program: Comments

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

Instructions PLEASE READ (notice bold and underlined phrases)

6.170 Laboratory in Software Engineering Java Style Guide. Overview. Descriptive names. Consistent indentation and spacing. Page 1 of 5.

These two items are all you'll need to write your first application reading instructions in English.

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Special Edition Using Java Installing the JDK and Getting Started

16.410: Jump Starting With Java

Life Without NetBeans

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Creating Word Outlines from Compendium on a Mac

Lecture 2, September 4

Morpheus_eProbe Software to probe your Java environment. Version Copyright 2016 Dennis E. Slice

Embedding Graphics in JavaDocs (netbeans IDE)

Setup and Getting Startedt Customized Java EE Training:

CS3901 Intermediate Programming and Data Structures Winter 2008 (Q2 AY 08) Assignment #5. Due: noon Tuesday, 3 March 2008

Fundamentals of Programming. By Budditha Hettige

CSCI 201 Lab 1 Environment Setup

Creating an Object Design Document with Javadoc

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

Tips from the experts: How to waste a lot of time on this assignment

Getting Started (1.8.7) 9/2/2009

NetBeans IDE Java Quick Start Tutorial

11 Coding Standards CERTIFICATION OBJECTIVES. Use Sun Java Coding Standards

Exceptions and Libraries

Transcription:

We ve already talked about adding simple comments to your source code. The JDK actually supports more meaningful comments as well. If you add specially-formatted comments, you can then use a tool called javadoc to automatically create HTML files, turning turn your simple comments into flashy documentation! To use JavaDoc, you will create a specific type of comment just before each class, field and method in your code. These comments will always begin with these characters: /** and end with these characters:. The text between these marks will contain text that describes the class, field or method in some detail. If you have multiple lines of text in your JavaDoc comment, each line will start with an asterisk *. This asterisk character and any whitespace before the first word in the line are ignored by the JavaDoc program when creating the HTML output. In this example we have described our main HelloWorld class using several lines of text. /** TeenCoder: Java Programming<br /> * Chapter 02<br /> * The HelloWorld class will print "Hello, World" to the console<br/> class HelloWorld Since the text after the * will be output directly to HTML, we ended each line with a <br />. In HTML this marks the end of a line. You can use any HTML formatting you like within this block such as <b> for bold or <i> for italics if you know more about HTML. In this class we ll simply use the <br /> marker at the end of the line to ensure text is displayed on the HTML page the same way we see it in the source code. JavaDoc Tags Within a JavaDoc comment block you can add special tags that start with the symbol @. These tags will hold specific pieces of information that the HTML output will treat differently. One common tag is @author, which should be followed by a name. This tag will describe the author of the class. This tag is typically used once, at the top of your source code. @author name The @version tag is useful when you are revising a piece of code. In this case, you want to be able to give an indication that this is a newer version of the code. So, you can give it a version number, like 2.0 or 1.5 to indicate the version of the code. This tag is typically only used once at the top of a source file, just like the @author tag. @version version Copyright 2013 by Homeschool Programming, Inc. 1

One of the most commonly used JavaDoc tags is the @param tag. This tag is used to describe a method parameter. We will discuss methods in further detail in a future lesson, but for now, you should understand that a method is a block of code that can take certain parameters as data. You can think of the parameters as the ingredients for the method. The @param tag will allow you to describe the name of the parameter and the data that should be contained within the parameters. @param name description You can use one @param tag for each parameter in the method that you are describing. The @param tag is followed by a name and a description. After any @param tags, the JavaDoc @return tag can be used to describe the data that a method (or a block of code) will be returning to the calling program. @return description You will only need one @return tag for any method that returns a value. We have only described the most commonly used JavaDoc tags. There are many other tags you can use to increase the information available in your HTML output pages. JavaDoc Comment Location You must place your JavaDoc comments in particular spots, or they will be ignored. Your class-level comments should go directly above your class keyword and below any import statements. Your functionlevel comments should go directly above your function declaration. import java.util.*; // any comments above your imports are ignored /** class-level comments go here! class HelloWorld /** function-level comments go here! public static void main(string args[]) // main entry point to the program Copyright 2013 by Homeschool Programming, Inc. 2

JavaDoc Example If we were to add some JavaDoc comments to our HelloWorld program, it could look something like this: import java.util.*; // any comments above your imports are ignored /** TeenCoder: Java Programming<br /> * Chapter 02<br /> * The HelloWorld class will print "Hello, World" to the console<br /> * @author Chris * @version 1.0 on March 30th, 2012 class HelloWorld /** * The main function is run automatically when the program is started. * @param args The command-line arguments passed into the program public static void main(string args[]) // main entry point to the program System.out.println("Hello, World"); // a program statement! Let s take a look at what we have done! First, notice that the top comment block is now enclosed in JavaDoc markers /** and. Each line within the block starts with an asterisk *. We have also added the @author and @version tags to identify the programmer, version, and date. Next we also added a JavaDoc comment in front of our main() function. The JavaDoc comment gives a brief description of the main() function and also identifies the parameters into the function. Since there is no data returned from the function, we have no @return tag. Using the JavaDoc Tool Once we have JavaDoc comments in the source file, we can run the javadoc program to create the HTML output. Since the javadoc tool is part of the JDK like the javac compiler, you will run it from the command line just like you did javac. In a Mac OS Terminal you can type javadoc and the tool will be found automatically, but in a Windows Command Prompt you will use the fully qualified path to the JDK s bin directory. Copyright 2013 by Homeschool Programming, Inc. 3

There are many parameters you can use to guide how JavaDoc produces output. Just run javadoc with no parameters to see a complete list of options. The major ones we ll use are: -private -author -version This tells JavaDoc to include all classes in your program, not just the ones declared for public use by other programmers. This tells JavaDoc to use your @author tag to create an author section. This tells JavaDoc to use your @version tag to create a version section. -Xdoclint:none This tells JavaDoc to allow self-closing HTML tags such as <br /> in your comments only needed on JDK 8+. -d <dir> This tells JavaDoc to send all of the HTML output files into the specified directory. If you don t use this, the JavaDoc will be dumped right into your root source file directory, which can be confusing. <source file> At the end of all the other parameters, simply specify your source file name such as HelloWorld.java On Windows we would run javadoc as shown below. Keep in mind your actual JDK version may be different, and the Xdoclint:none parameter is only needed on JDK8 installations. The same example on Mac OS looks like this: Once you run the javadoc program, you will see a bunch of output as individual HTML files are created. Copyright 2013 by Homeschool Programming, Inc. 4

Or you may see descriptive error messages if it found something in your comments that did not meet the JavaDoc standard. Notice we specified doc as our output directory, so after the program runs we will have a new doc subdirectory underneath the HelloWorld directory. The image below shows an example list of the output files in the doc directory as seen in Windows Explorer (details may vary): That s quite a lot of files to document one simple class! But you can simply pull up the index.html page in your favorite web browser to see the documentation for your program (no Internet connection required). Copyright 2013 by Homeschool Programming, Inc. 5

Here s what our index.html page looks like in a typical web browser: The top part shows our HelloWorld class description, author, and version. Notice the overall framework is pretty fancy and can handle multiple classes listed on the left side, and has a number of tabs across the top as well. While this may be overkill for one simple class, if you are documenting many classes such as the Java class library, all the extra organization really comes in handy. Copyright 2013 by Homeschool Programming, Inc. 6

If you scroll down on the HTML page you will see additional information. We haven t talked about constructors yet so you can ignore those sections, but notice that your main() function is clearly described and has a hyperlink that will take you right to the full definition. Finally if you keep scrolling towards the bottom you will find the documentation for each of your individual class functions. In our case we have only one function, main(), which appears with it s descriptive method text and parameter description. As you can see, JavaDoc is a very powerful tool that can produce complete documentation on your program, all for the price of a few specially formatted comments in your code. Following the JavaDoc standard is especially important when you are writing classes that you expect other programmers to understand and use. Copyright 2013 by Homeschool Programming, Inc. 7