Coding Standard & Javadoc

Slides:



Advertisements
Similar presentations
COSC 2006 Data Structures I Instructor: S. Xu URL:
Advertisements

Utilities (Part 3) Implementing static features 1.
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.
Class Design CSC 171 FALL 2004 LECTURE 11. READING Read Chapter 7 It’s abstract But it should help with project #1.
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
More sophisticated behavior Using library classes to implement some more advanced functionality 3.0.
Java Programming Review (Part I) Enterprise Systems Programming.
Java Language and SW Dev’t
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Writing JavaDocs Mimi Opkins CECS 274 Copyright (c) Pearson All rights reserved.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
Classes CS 21a: Introduction to Computing I First Semester,
Java Arrays …………. Java Arrays …………. * arrays are objects in Java * arrays are objects in Java * an array variable is a reference * an array variable is.
Java Syntax and Style JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin,
CIT 590 Intro to Programming First lecture on Java.
INTERFACES More OO Concepts. Interface Topics Using an interface Interface details –syntax –restrictions Create your own interface Remember polymorphism.
Documentation Array and Searching. Documentation rules Easy rules: –Naming convention for variables, constants and methods Difficult rules: –Professional.
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.
CS 151: Object-Oriented Design September 5 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak
Documentation Dr. Andrew Wallace PhD BEng(hons) EurIng
1 JAVA API & Packages Starring: Java Documentation Co-Starring: BlueJ IDE.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Identifiers.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming1 Programming.
Review and Java Questions 13 June Classes, objects, attributes, methods In Java, by convention a class name begins with Uppercase: Coffee, String.
Javadoc Summary. Javadoc comments Delemented by /** and */ Used to document – Classes – Methods – Fields Must be placed immediately above the feature.
Arrays and Array Lists CS 21a. Problem 1: Reversing Input Problem: Read in three numbers and then print out the numbers in reverse order Straightforward.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Variable Scope & Lifetime
More on Arrays Review of Arrays of ints, doubles, chars
More Sophisticated Behavior
Working with Java.
Crash course in the Java Programming Language
Introduction to Java part 2
Yanal Alahmad Java Workshop Yanal Alahmad
Exercise on Java Basics
JavaDoc CECS277 Mimi Opkins.
Implementing Classes Yonglei Tao.
Switch, Rounding Errors, Libraries
Basic Java Syntax The Java language will be described by working through its features: variable types and expressions selection and iteration classes exceptions.
Trainings 11/4 Intro to Java.
CS Week 14 Jim Williams, PhD.
More sophisticated behavior
Chapter Three - Implementing Classes
Exercise on Java Basics
Defining Your Own Classes Part 1
null, true, and false are also reserved.
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Introduction to Java part 2
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Chapter 1: Computer Systems
CS2011 Introduction to Programming I Objects and Classes
int [] scores = new int [10];
Applying OO Concepts Using Java
Arrays and Array Lists CS 21a.
Programs and Classes A program is made up from classes
Anatomy of a Java Program
Widely used guidance for writing better code.
JAVA CLASSES.
Introduction to Java part 2
Classes CS 21a: Introduction to Computing I
Chap 2. Identifiers, Keywords, and Types
Building Java Programs Appendix B
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Coding Standard & Javadoc

Java Naming Convention class name begins with Uppercase: Coffee, String method name uses camelCase: getMoreCoffee( ) variable name also uses camelCase: myCoffee constants use UPPER_CASE and _: MAX_VALUE package names are all lowercase (with a few exceptions): java.util java.io org.junit primitive type names are all lowercase: boolean, char, int, double, long

Example package ku.oop; import java.util.Scanner; public class Customer extends Principle { private String customerId; private List<Account> accounts; public Customer(String name) . . . public List<Account> getAccounts( )... public void addAccount(Account acct)...

Identify each of these Is it a ... class package primitive type Martian org.nerd.hacker System System.nanoTime( ) System.out System.out.println( ) double Double "Hello nerd".length( ) Double.MAX_VALUE java.concurrent java.util.ArrayList java.util.Comparable Is it a ... class package primitive type attribute ("field") method (static or instance) constant (static final attribute) interface (more advanced) something else???

Use Full Words as Names Good Name Bad Name BankAccount BankAct balance accountId num, id Exception: short names OK for local variables, esp. loop vars. double getTotal( ) { double sum = 0.0; for(int k=0; k<transactions.length; k++) { sum += transaction.getValue( ); ...

Writing Javadoc (Required) package ku.oop; /** * A Person contains information about a * person including name and contact info. * @author Bill Gates * @since 2014.01.12 */ public class Person { /** person's name, of course */ private String name; Must start with a complete sentence, ending with a period! @author, @since are tags. Use only the standard tags.

Method Javadoc /** * Set the person's birthday. * @param birthday a date containing the * person's birthday. Must not be null. */ public void setBirthday(Date birthday) { if (birthday == null) throw new IllegalArgumentException( "Read the javadoc, stupid!"); this.birthday = (Date)birthday.clone(); .

Method Javadoc with Return /** * Withdraw money from the coin machine. * @param amount is amount to withdraw. * @return array of money withdrawn, * or null if cannot withdraw the * requested amount. */ public Money[] withdraw(double amount) { if (double <= 0.0) return null; .

More Method Javadoc /** * Compare 2 coins by value. * @param a the first Coin to compare. * @param b the second Coin to compare * @return -1 if first coin's value is * smaller, +1 if first coin's value is * larger, and 0 if values are same. * @throws IllegalArgumentException if * the currencies are not the same. */ public int compare(Coin a, Coin b) { .

Bad Javadoc - what's wrong? /** * The Person class * @Bill Balmer * @Version 1.0 */ package ku.oop.badcode; public class Person { private String name; * get the firstname * @param k is index of first space in name public String getFirstname( ) { int k = name.indexOf(' '); return name.substring(0,k); // bug? }

Good Code has Documentation Use documentation to describe classes and methods. Describe what and why – not "how" which is obvious from the code. Describe rationale and logic that is not obvious from code. // sum elements in the array (BAD: it's obvious) int sum = 0; for(int k=0; k<array.length; k++) { sum += array[k]; } No Javadoc = No Credit

Generate Javadoc from your Code 3 ways: the javadoc command let Eclipse (or BlueJ or Netbeans) do it for you automatic build system, like Maven

Demo Demo how BlueJ will create Javadoc (HTML) from your Javadoc comments. Demo how Eclipse gives interactive help using Javadoc.