Documentation (and midterm review)

Similar documents
1 of 12 8/17/2004 5:55 PM

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Javadoc. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 7

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Procedural Abstraction

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Construction: High quality code for programming in the large

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Documentation of Sotfware

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

CSE331 Winter 2014, Midterm Examination February 12, 2014

CS 11 java track: lecture 3

SCHEME OF COURSE WORK

Certification In Java Language Course Course Content

JAVA. Duration: 2 Months

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

Contents. iii Copyright 1998 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1998, Revision B

15CS45 : OBJECT ORIENTED CONCEPTS

Iteration Abstraction

Core Java Contents. Duration: 25 Hours (1 Month)

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

1 Shyam sir JAVA Notes

Classes, interfaces, & documentation. Review of basic building blocks

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Chapter 5 Object-Oriented Programming

Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview

CS506 Web Design & Development Final Term Solved MCQs with Reference

Core Java Syllabus. Pre-requisite / Target Audience: C language skills (Good to Have)

Thread Programming. Comp-303 : Programming Techniques Lecture 11. Alexandre Denault Computer Science McGill University Winter 2004

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

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

Comp151 Lab Documentation using Doxygen

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Java 8 Programming for OO Experienced Developers

Java Programming Course Overview. Duration: 35 hours. Price: $900

A- Core Java Audience Prerequisites Approach Objectives 1. Introduction

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1

Page 1

Name of subject: JAVA PROGRAMMING Subject code: Semester: V ASSIGNMENT 1

Advanced Java Programming

Chapter Two Bonus Lesson: JavaDoc

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

Casting -Allows a narrowing assignment by asking the Java compiler to "trust us"

Type Hierarchy. Lecture 6: OOP, autumn 2003

Object Oriented Programming with Java. Unit-1

CSCI 261 Computer Science II

CSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams

Synchronization SPL/2010 SPL/20 1

Documenting Java Code. Javadoc: The Tool and the Legend

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

Java Object Oriented Design. CSC207 Fall 2014

UMBC CMSC 331 Final Exam

Complete Java Contents

the gamedesigninitiative at cornell university Lecture 13 Architecture Design

CSCI 200 Lab 3 Using and implementing sets

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

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

About the required reading. Construction: High quality code for programming in the large. What is high quality code?

1 OBJECT-ORIENTED PROGRAMMING 1

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

Declarations and Access Control SCJP tips

Files and Streams

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Enums. In this article from my free Java 8 course, I will talk about the enum. Enums are constant values that can never be changed.

Administrivia. CMSC433, Fall 2001 Programming Language Technology and Paradigms. Administrivia (cont.) Project 1. Copy constructor.

LTBP INDUSTRIAL TRAINING INSTITUTE

Core Java Interview Questions and Answers.

Govt. of Karnataka, Department of Technical Education Diploma in Information Science & Engineering. Fifth Semester

Objects First with Java

Course Description. Learn To: : Intro to JAVA SE7 and Programming using JAVA SE7. Course Outline ::

the gamedesigninitiative at cornell university Lecture 12 Architecture Design

CS 251, Intermediate Programming Midterm Exam October 9, 2013

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

QueueBlock, ReversalADT, LinkedList,CustomerAccount, not MaintainCustomerData

Software Specifications. CMSC 433 Programming Language Technologies and Paradigms Spring Specifications Help You Write Code

Training topic: OCPJP (Oracle certified professional Java programmer) or SCJP (Sun certified Java programmer) Content and Objectives

[Course Overview] After completing this module you are ready to: Develop Desktop applications, Networking & Multi-threaded programs in java.

Pages and 68 in [JN] conventions for using exceptions in Java. Chapter 8 in [EJ] guidelines for more effective use of exceptions.

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

PESIT Bangalore South Campus

/ / JAVA TRAINING

Java SE 8 Programming

SRM INSTITUTE OF SCIENCE & TECHNOLOGY Faculty of Science and Humanities Department of Computer Science UNIT I - INTRODUCTION TO JAVA

SYLLABUS JAVA COURSE DETAILS. DURATION: 60 Hours. With Live Hands-on Sessions J P I N F O T E C H

Programming Handbook

CSE 501N Final Fall Points Possible

104. Intermediate Java Programming

CS2 Advanced Programming in Java note 8

CPS122 Lecture: Defining a Class

Java Training For Six Weeks

Language Features. 1. The primitive types int, double, and boolean are part of the AP

Chapter 4 Defining Classes I

Transcription:

Documentation (and midterm review) Comp-303 : Programming Techniques Lecture 13 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 1

Last lecture... Java Sockets work a lot like any other TCP/IP sockets. Java provides two socket objects : Socket and ServerSocket. Communicating over sockets is identical to reading/writing to files. Java provides serialization as a mean to save object and transmit them. ObjectOutputStream and ObjectInputStream can be used file any kind of streams (files, socket, etc). By implementing Serializable, your objects will be serializable. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 2

Today s lecture A small change to Assignment 2. Corrections / Confusions in the previous lectures Deterministic / Determined String equality Public, protected, private Socket behavior Using JavaDoc for automatic documentation generation Review for midterm February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 3

Assignment 2 Because I didn t figure in associativity correctly when planning the SumOfSquare Adder, the specification in the assignment won t calculate the correct result. As such, I m removing the SumOfSquare Adder from the assignment. The rest of the assignment remains unchanged. That means less work for you. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 4

Deterministic / Determined Determined: a procedure is considered determined if the acceptable output is unique. Undetermined: a procedure is considered undetermined if the acceptable output is a set. Deterministic Implementation: these procedures will produce exactly the same output when give the same input. Non-deterministic Implementation: these procedures can produce different outputs when give the same input. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 5

Comparing Deterministic and Determined Deterministic Nondeterministic Determined The procedure always returns the same value By definition, cannot exists Undetermined The procedure always returns the same output for a given input. The procedure can return any given set of output for any given set of input. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 6

Comparing Strings For optimization purposes, strings in Java are handled in two ways. Unfortunately, comparing the two types of strings can yield different results. Some strings are declared as objects. String objectstring = new String("test"); Others are declared like a primitive. They are store as constants in the class file. String constantstring = "test"; The tricky thing is that these two types of string react differently to the == sign. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 7

Proof by example String constantstring = "test"; String objectstring = new String("test"); System.out.println("test" == "test"); System.out.println(constantString == "test"); System.out.println(objectString == "test"); System.out.println(objectString == new String("test")); System.out.println(objectString == constantstring); System.out.println(constantString.equals("test")); System.out.println(objectString.equals("test")); System.out.println(objectString.equals(new String("test"))); System.out.println(objectString.equals(constantString)); System.out.println(constantString.equals(constantString)); February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 8

Proof by example : Results String constantstring = "test"; String objectstring = new String("test"); System.out.println("test" == "test"); \\ true System.out.println(constantString == "test"); \\ true System.out.println(objectString == "test"); \\ false System.out.println(objectString == new String("test")); \\ false System.out.println(objectString == constantstring); \\ false System.out.println(constantString.equals("test")); \\ true System.out.println(objectString.equals("test")); \\ true System.out.println(objectString.equals(new String("test"))); \\ true System.out.println(objectString.equals(constantString)); \\ true System.out.println(constantString.equals(constantString)); \\ true In other words, equals has constant behavior. When comparing strings, using the equals method. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 9

Public/Protected/Private Java Interfaces, Classes Variables, Methods, Inner- Classes Public visible everywhere visible everywhere, inherited by all subclasses Protected - visible to any class in the package, inherited by all subclasses in or outside the package blank visible only in current package visible to any class in the package, inherited by all subclasses in the package but not outside package Private - not visible to any class, not inherited by any class February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 10

Client requests connection Listening Port Server 80 1030 Client To make a connection request, the client tries to rendezvous with the server on the server s machine and port. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 11

Server accepts connection Listening Port Server 80 1030 Client Upon acceptance, the server gets a new socket. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 12

JavaDoc Sun has a different approach to documentation. The idea is that the comments in the code should be the documentation. The Java API is built upon this idea. JavaDoc is the tool used to extract comments from code and build the documentation. To properly format the documentation, you need to add a few tags to your comments. Comments written for JavaDoc can be formatted using HTML. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 13

Writing API Specifications API Specifications are defined by the documentation comments in the source code and any documents marked as specifications reachable from those comments. API Specifications are a contract between callers and implementation. API Specifications assertions need to be implementation-independent. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 14

The format of a comment /** * Returns an Image object that can then be painted on the screen. * The url argument must specify an absolute {@link URL}. The name * argument is a specifier that is relative to the url argument. * <p> * This method always returns immediately, whether or not the * image exists. When this applet attempts to draw the image on * the screen, the data will be loaded. The graphics primitives * that draw the image will incrementally paint on the screen. * * @param url an absolute URL giving the base location of the image * name the location of the image, relative to the url argument * @return the image at the specified URL * @see Image */ public Image getimage(url url, String name) { February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 15

Proper documentation The first sentence of each doc comment should be a summary sentence, containing a concise but complete description of the API item. This sentence ends at the first period that is followed by a blank, tab, or line terminator, or at the first tag. As much as possible, write doc comments as an implementation-independent API specification. Define clearly what is required and what is allowed to vary across platforms/implementations. Make it complete enough for conforming implementors. Realistically, include enough description so that someone reading the source code can write a substantial suite of conformance tests. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 16

Proper documentation (cont.) Where appropriate, mention what the specification leaves unspecified or allows to vary among implementations. If you must document implementation-specific behavior, please document it in a separate paragraph with a lead-in phrase that makes it clear it is implementation-specific. If the implementation varies according to platform, then specify On platform at the start of the paragraph. Javadoc tool duplicates (inherits) or links comments for methods that override or implement other methods. So lines won t wrap, limit any doc-comment lines to 80 characters. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 17

Tags @author (classes and interfaces only, required) @version (classes and interfaces only, required) (see footnote 1) @param (methods and constructors only) @return (methods only) @exception (@throws is a synonym added in Javadoc 1.2) @see @since @serial (or @serialfield or @serialdata) @deprecated (see How and When To Deprecate APIs) Note: The order is important. Try to use tags in the following order. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 18

@author You can provide one @author tag, multiple @author tags, or no @author tags. Multiple @author tags should be listed in chronological order, with the creator of the class listed at the top. If the author is unknown, use unascribed as the argument to @author. he @author tag is not critical, because it is not included when generating the API specification, and so it is seen only by those viewing the source code. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 19

@version Useful when multiple version of a class is available. Follows this format : 1.39, 02/28/97 (mm/dd/yy) February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 20

@param The @param tag is followed by the name (not data type) of the parameter, followed by a description of the parameter. By convention, the first noun in the description is the data type of the parameter. An exception is made for the primitive int, where the data type is usually omitted. Parameter names are lowercase by convention. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 21

@return The @return is use to describe the output of a method. Omit @return for methods that return void and for constructors. Include it for all other methods, even if its content is entirely redundant with the method description. Whenever possible, supply return values for special cases (out-of-bounds). February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 22

@deprecated The @deprecated description in the first sentence should at least tell the user when the API was deprecated and what to use as a replacement. Only the first sentence will appear in the summary section and index. If the member has no replacement, the argument to @deprecated should be No replacement. /** * @deprecated As of JDK 1.1, replaced by {@link #setbounds(int,int,int,int)} */ February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 23

@since Specify the product version when the name was added to the API specification. The Javadoc tool does not proliferate the value of the @since clause down the hierarchy. When a class (or interface) is introduced, specify one @since tag in its class description and no @since tags in the members. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 24

@throws A @throws tag should be included for any checked exceptions (declared in the throws clause) They should also be included for any unchecked exceptions that the caller might reasonably want to catch, with the exception of NullPointerException. Errors should not be documented as they are unpredictable. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 25

@see The @see tag is a reference to other packages / classes / methods / constructors / fields. They should be ordered from nearest to farthest access, from least-qualified to fully-qualified. @see #field @see #Constructor(Type, Type...) @see #Constructor(Type id, Type id...) @see #method(type, Type,...) @see #method(type id, Type, id...) @see Class @see Class#field @see Class#Constructor(Type, Type...) @see Class#method(Type, Type,...) @see package.class @see package.class#field @see package.class#constructor(type, Type...) @see package February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 26

@serial, @serialfield, @serialdata The following tags are used to document custom serialization behavior. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 27

{@link} The style guide encourages programmers to add links for API names (package, classes, methods,... ) using the {@link} tag. A link to an API name should be added if: The user might actually want to click on it for more information (in your judgment). Only for the first occurrence of each API name in the doc comment (don t bother repeating a link). February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 28

Comment template package java.blah; import java.blah.blahdy.blahblah; /** * OVERVIEW: Class description goes here. * * @version 1.82 18 Mar 1999 * @author Firstname Lastname */ public class Blah extends SomeClass { /* A class implementation comment can go here. */ February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 29

Comment template (cont.) /** classvar1 documentation comment */ public static int classvar1; /** * classvar2 documentation comment that happens to be * more than one line long */ private static Object classvar2; /** instancevar1 documentation comment */ public Object instancevar1; /** instancevar2 documentation comment */ protected int instancevar2; /** instancevar3 documentation comment */ private Object[] instancevar3; February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 30

Comment template (cont.) /** *...constructor Blah documentation comment... */ public Blah() { //...implementation goes here... } /** *...method dosomething documentation comment... * * <p> REQUIRES: blah blah * <p> MODIFIES: blah blah * <p> EFFECTS: blah blah * <p> */ public void dosomething() { //...implementation goes here... } February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 31

Comment template (cont.) /** *...method dosomethingelse documentation comment... * * <p> REQUIRES: blah blah * <p> MODIFIES: blah blah * <p> EFFECTS: blah blah * <p> * @param someparam description * @return description */ public int dosomethingelse(object someparam) { //...implementation goes here... } } February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 32

Lecture 1: Programming Techniques Decomposition Abstraction Abstraction in modern programming language Four different types of abstraction. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 33

Lecture 2: How does Java work? Definition of Object-oriented programming and why use it Abstract classes and Interfaces Overloading and overridding February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 34

Lecture 3: Objects, Types and Variables Objects and primitives Assignment Mutability Type Substitutability / Checking Type Conversion / Casting Method dispatch Packages February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 35

Lecture 4: Crash course in UML UML Class diagrams Sequence diagrams February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 36

Lecture 5: Procedural Abstraction Procedural abstraction Requires / Modifies / Effects clauses Implicit Inputs Properties of procedures February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 37

Lecture 6: Data Abstraction Data Abstraction Abstract Data Types Instance variables Records Methods inherited from Object February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 38

Lecture 7: Exceptions Exceptions Building Exceptions Throwing Exceptions Handling Exceptions Defensive programming February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 39

Lecture 8: Iteration Abstraction Iteration Iterators Generators Iterators over iterators Functions as objects (plug-ins) February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 40

Lecture 9: Type Hierarchy Type Hierarchy Method Dispatch How to use protected Rules to change specification February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 41

Lecture 10 : Polymorphic Abstractions Using Polymorphic Abstractions Equality Comparing Containers Flexibility by using interfaces (Adder) February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 42

Lecture 11: Thread Programming Creating Threads Life of a Thread Priority / Scheduling in threads Synchronizing / Locking Dangers of threading February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 43

Lecture 12: Socket and Serialization Creating Sockets (client/server) Reading and writing to sockets Serialization February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 44

Summary Corrections / Confusions in the previous lectures Deterministic / Determined String equality Public, protected, private Socket behavior Using JavaDoc for automatic documentation generation Review for midterm February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 45

Tool of the day: JavaDoc I think I ve talked enough about JavaDoc for today. February 16, 2004 Lecture 13 Comp 303 : Programming Techniques Page 46