Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 14 CS202.

Similar presentations


Presentation on theme: "Lecture 14 CS202."— Presentation transcript:

1 Lecture 14 CS202

2 Javadoc Javadoc is a tool that generates html documentation (similar to the reference pages at java.sun.com) from Javadoc comments in the code.  Javadoc Comments Javadoc recognizes special comments  /** .... */ which are highlighted blue by default in Eclipse (regular comments // and /* ... */ are highlighted green). Javadoc allows you to attach descriptions to classes, constructors, fields, interfaces and methods in the generated html documentation by placing Javadoc comments directly before their declaration statements.   Here's an example using Javadoc comments to describe a class, a field and a constructor:      /** Class Description of MyClass */ public class MyClass { /** Field Description of myIntField */ public int myIntField; /** Constructor Description of MyClass() */ public MyClass() { // Do something ... } } Javadoc Tags Tags are keywords recognized by Javadoc which define the type of information that follows. Tags come after the description (separated by a new line). Here are some common pre-defined tags: @author [author name] - identifies author(s) of a class or interface. @version [version] - version info of a class or interface. @param [argument name] [argument description] - describes an argument of method or constructor. @return [description of return] - describes data returned by method (unnecessary for constructors and void methods). @exception [exception thrown] [exception description] - describes exception thrown by method. @throws [exception thrown] [exception description] - same from

3 Javadoc package demos; /** John 1.0 */ public class Goose { private double weightInKg; weightInKg weight of the goose */ public void setWeightInKg(double weightInKg){ this.weightInKg = weightInKg; } public double getWeightInKg(){ return weightInKg;

4 Javadoc Mouse-hover over references to other classes to see Javadoc comments

5 Javadoc This is very handy when you use classes written by other programmers.

6 Javadoc Generating Javadoc creates html in the same format as Oracle's Java documentation. You can do this generate Javadoc in Eclipse with project/generate javadoc. Choose "Command" and find javadoc.exe, which will be in your jdk's bin directory:

7 Javadoc View Javadoc by finding it in Eclipse (you will need to refresh the project after generating it), right clicking on index.html and choosing Open With / Web Browser. Eclipse currently puts it in a doc subdirectory of the project.

8 View Declaration and View Call Hierarchy
To see the definition of a method in your code or an imported library which contains code, select code that calls the method, right click, and choose Open Declaration To find all calls to a method, select the method name, right click, and choose "view call hierarchy"

9 Using Libraries Java has a very strong culture of open-source software
Students, professors, programming hobbyists, and developers who choose to give back to the profession make many projects available for free This allows you to use functionality you lack the expertise to code or don’t have time for Quality control is nonexistent and malware is probably sometimes spread this way! You will learn several other ways to get libraries and integrate them into your projects, but here is the simple way

10 Using Libraries Find the website for the library you want and download it. If you have the choice to get the bytecode alone or with the source included, get the version that includes the source You will usually need to unzip or untar the library. The result will include one or more .jar files, which are archives of class files. Often there is also documentation, tutorials, and other material as well. Right click on the project name and choose "Build Path/Configure Build Path", then "Add External JARs", then find the .jar you need to add. The library should now appear under "Referenced Libraries" in your project

11 Using Libraries This example uses a library called pdfbox to extract plain text from a pdf.

12 Using Libraries

13 Using Libraries package pdfboxdemo; import java.io.File; import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.text.PDFTextStripper; public class Extractor { // adapted from public static void main(String[] args) { PDDocument pd; File input = new File("rj.pdf"); // The PDF file from where you would // like to extract try { pd = PDDocument.load(input); PDFTextStripper stripper = new PDFTextStripper(); stripper.setEndPage(20); String text = stripper.getText(pd); if (pd != null) { pd.close(); } System.out.println(text); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();

14 Unified Modeling Language (UML)
The first applications you wrote were easy to think out and code with no intermediate steps. Lab 7 involved some communication with your lab partner and the use of an interface to define how the parts of the application fit together. As your applications get larger and involve more people, they will require better planning tools. These often involve documents which specify requirements and describe how the parts of the application fit together. The textbook has introduced bits and pieces of Unified Modeling Language (UML); this lecture covers it in slightly more depth.

15 Unified Modeling Language (UML)
Most of the following slides are slightly revised versions of slides by Yi Luo, Carnegie-Mellon University:

16 UML Diagrams Types of UML Diagrams: Use Case Diagram Class Diagram
Sequence Diagram Collaboration Diagram State Diagram This is only a subset of diagrams chosen from among the most widely-used types Source of slides: Yi Luo, Carnegie-Mellon University

17 Use-Case Diagrams A use-case diagram shows a set of use cases
A use case is a model of the interaction between External users of a software product (actors) and The software product itself More precisely, an actor is a user playing a specific role describing a set of user scenarios capturing user requirements contract between end user and software developers Source of slide: Yi Luo, Carnegie-Mellon University

18 Use-Case Diagrams Use Case Boundary Actor Employee Client Supervisor
Library System Borrow Employee Client Order Title Fine Remittance Supervisor

19 Use-Case Diagrams Actors: A role that a user plays with respect to the system, including human users and other systems. e.g., inanimate physical objects (e.g. robot); an external system that needs some information from the current system. Use case: A set of scenarios that describing an interaction between a user and a system, including alternatives. System boundary: rectangle diagram representing the boundary between the actors and the system.

20 Use-Case Diagrams Association:
communication between an actor and a use case; Represented by a solid line. Generalization: relationship between one general use case and a special use case (used for defining special alternatives) Represented by a line with a triangular arrow head toward the parent use case.

21 Use-Case Diagrams Include: a dotted line labeled <<include>> beginning at base use case and ending with an arrows pointing to the include use case. The include relationship occurs when a chunk of behavior is similar across more than one use case. Use “include” in stead of copying the description of that behavior. <<include>> Extend: a dotted line labeled <<extend>> with an arrow toward the base case. The extending use case may add behavior to the base use case. The base class declares “extension points”. <<extend>>

22 Use-Case Diagrams Figure 16.12 The McGraw-Hill Companies, 2005

23 Use-Case Diagrams Both Make Appointment and Request Medication include Check Patient Record as a subtask (include) The extension point is written inside the base case Pay bill; the extending class Defer payment adds the behavior of this extension point. (extend) Pay Bill is a parent use case and Bill Insurance is the child use case. (generalization) (TogetherSoft, Inc)

24 Class diagram A class diagram depicts classes and their interrelationships Used for describing structure and behavior in the use cases Provide a conceptual model of the system in terms of entities and their relationships Detailed class diagrams are used for developers

25 Class diagram Each class is represented by a rectangle subdivided into three compartments Name Attributes Operations Modifiers are used to indicate visibility of attributes and operations. ‘+’ is used to denote Public visibility ‘#’ is used to denote Protected visibility ‘-’ is used to denote Private visibility Sometimes modifiers are not shown. By default, attributes are hidden and operations are visible.

26 UML Class Diagram Source: Liang

27 Example: Defining Classes and Creating Objects
TV Source: Liang TestTV Run

28 OO Relationships There are two kinds of Relationships
Generalization (parent-child relationship) Association (student enrolls in course) Associations can be further classified as Aggregation Composition

29 OO Relationships: Generalization
Supertype Example: Customer Regular Customer Loyalty Customer Subtype1 Subtype2 -Inheritance is a required feature of OOP -Generalization expresses a parent/child relationship among related classes. Used for abstracting details in several layers

30 OO Relationships: Association
Represent relationship between instances of classes Student enrolls in a course Courses have students Courses have exams Etc. Association has two ends Role names (e.g. enrolls) Multiplicity (e.g. One course can have many students) Navigability (unidirectional, bidirectional)

31 Association: Multiplicity and Roles
student 1 * University Person 0..1 * teacher employer Role Multiplicity Symbol Meaning 1 One and only one 0..1 Zero or one M..N From M to N (natural language) * From zero to any positive integer 0..* From zero to any positive integer 1..* From one to any positive integer Role “A given university groups many people; some act as students, others as teachers. A given student belongs to a single university; a given teacher may or may not be working for the university at a particular time.”

32 Class diagram [from UML Distilled Third Edition]

33 OO Relationships: Composition
Association Models the part–whole relationship Composition Also models the part–whole relationship but, in addition, every part may belong to only one whole, and If the whole is deleted, so are the parts Example: A number of different chess boards: Each square belongs to only one board. If a chess board is thrown away, all 64 squares on that board go as well. Class W Whole Class Class P1 Class P2 Part Classes [From Dr.David A. Workman] Example Figure 16.7 The McGraw-Hill Companies, 2005

34 OO Relationships: Aggregation
Container Class Aggregation: expresses a relationship among instances of related classes. It is a specific kind of Container-Containee relationship. express a more informal relationship than composition expresses. Aggregation is appropriate when Container and Containees have no special access privileges to each other. Class C AGGREGATION Class E1 Class E2 Containee Classes Example Bag Apples Milk [From Dr.David A. Workman]

35 Aggregation vs. Composition
Composition is really a strong form of association components have only one owner components cannot exist independent of their owner components live or die with their owner e.g. Each car has an engine that can not be shared with other cars. Aggregations may form "part of" the association, but may not be essential to it. They may also exist independent of the aggregate. e.g. Apples may exist independent of the bag.

36 Interaction Diagrams show how objects interact with one another
UML supports two types of interaction diagrams Sequence diagrams Collaboration diagrams

37 Sequence Diagram(make a phone call)
Caller Phone Recipient Picks up Dial tone Dial Ring notification Ring Picks up Hello

38 Sequence Diagram:Object interaction
Synchronous Asynchronous Transmission delayed Self-Call [condition] remove() *[for each] remove() Self-Call: A message that an Object sends to itself. Condition: indicates when a message is sent. The message is sent only if the condition is true. Condition Iteration

39 Sequence Diagrams – Object Life Spans
Creation Create message Object life starts at that point Activation Symbolized by rectangular stripes Place on the lifeline where object is activated. Rectangle also denotes when object is deactivated. Deletion Placing an ‘X’ on lifeline Object’s life ends at that point A B Create X Deletion Return Lifeline Activation bar

40 Sequence Diagram Message Sequence diagrams demonstrate the behavior of objects in a use case by describing the objects and the messages they pass. The horizontal dimension shows the objects participating in the interaction. The vertical arrangement of messages indicates their order. The labels may contain the seq. # to indicate concurrency.

41 Interaction Diagrams: Collaboration diagrams
start 6: remove reservation 3 : [not available] reserve title User Reservations 5: title available 6 : borrow title 1: look up 2: title data 4 : title returned Catalog 5 : hold title Collaboration diagrams are equivalent to sequence diagrams. All the features of sequence diagrams are equally applicable to collaboration diagrams Use a sequence diagram when the transfer of information is the focus of attention Use a collaboration diagram when concentrating on the classes

42 State Diagrams (Billing Example)
State Diagrams show the sequences of states an object goes through during its life cycle in response to stimuli, together with its responses and actions; an abstraction of all possible behaviors. End Start Unpaid Paid Invoice created paying Invoice destroying

43 State Diagrams (Traffic light example)
Start Traffic Light State Red Transition Yellow timer expires Yellow Car trips sensor Green timer expires Green Event

44 Installing Eclipse Add Ons
There are thousands of add-ons available to add functionality to Eclipse, many of them open source or otherwise free. Some look free but are actually evaluation versions Choose Help/Eclipse Marketplace, then enter text in the search box Many add ons can be installed with a few clicks

45 Eclipse Add Ons

46 Ways To Generate UML Diagrams
Microsoft Visio UMLet – Free UML tool Several Eclipse plug ins support UML diagrams. In Eclipse, go to Help / Eclipse Marketplace and enter "UML" in the find box. Some tools are evaluation versions of commercial software, while others are open-source. Model Goon provides an easy way to generate class diagrams Many others available


Download ppt "Lecture 14 CS202."

Similar presentations


Ads by Google