1 JAVA API & Packages Starring: Java Documentation Co-Starring: BlueJ IDE.

Slides:



Advertisements
Similar presentations
Designing Classes Chapter 8. Classes Collection of objects Objects are not actions Class names – Nouns Method names – Verbs What Makes a Good Class Represent.
Advertisements

Utilities (Part 3) Implementing static features 1.
CPSC150 Week 6 notes Chapter 5 and other topics. toString Try to print any class Many print “garbage” (e.g., an address) All classes inherit from Object.
CSM-Java Programming-I Spring,2005 Class Design Lesson - 4.
Java Programming Chapter 3 More about classes. Why?  To make classes easier to find and to use  to avoid naming conflicts  to control access  programmers.
Programming in Java CSE301 Half Lecture Harry Erwin, PhD University of Sunderland.
Object-Oriented Enterprise Application Development Javadoc Last Updated: 06/30/2001.
1 Lecture 2 Java Packages  What are Java packages?  Why do wee need packages?  How to create a Java package?  Some examples.
Java Library Java provides a huge library or collection of useful programs A gold mine of well-tested code that can save you countless hours of development.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMING PRACTICES API documentation.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 9 Source File Anatomy.
Java Packages and Libraries M Taimoor Khan
Writing JavaDocs Mimi Opkins CECS 274 Copyright (c) Pearson All rights reserved.
Program documentation using the Javadoc tool 1 Program documentation Using the Javadoc tool.
Week1 Using the Library (the Java API) Classes are grouped together in packages –To use a class you have to know which package it is in –Every package.
1 Java: AP Curriculum Focus and Java Subset Alyce Brady.
Objects and Classes Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary.
CIT 590 Intro to Programming First lecture on Java.
Static. Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. A static method does not operate on an object double dY.
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.
10-Nov-15 Java Object Oriented Programming What is it?
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.
Class Libraries Chapter 1 1 Source Intro to Java Programming Y. Daniel Liang.
23-October-2002cse JavaIntro © 2002 University of Washington1 Intro to Java CSE 413, Autumn 2002 Programming Languages
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming1 Programming.
Everything is an object (CH-2) Manipulating Objects with References. Manipulating Objects with References. String s; String s = “IS2550” String s = new.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. A class represents a single concept from the problem domain, or a.
Javadoc. Purpose of javadoc javadoc is a program that reads your Java program and produces great-looking documentation in HTML format Without any help,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Application Programming Interfaces. Java comes with a bunch of classes that are already written. Java comes with a bunch of classes that are already written.
Lesson 6 – Libraries & APIs Libraries & APIs. Objective: We will explore how to take advantage of the huge number of pre-made classes provided with Java.
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.
Chapter 3 Objects and Classes. Objects Object – a data type with structure, state, and operations to access and manipulate state - an instance of a class.
1 Chapter 6 Programming with Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive.
Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Chapter 3: Using Classes and Objects Coming up: Creating Objects.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
© 2004 Pearson Addison-Wesley. All rights reserved September 5, 2007 Packages & Random and Math Classes ComS 207: Programming I (in Java) Iowa State University,
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
© 2004 Pearson Addison-Wesley. All rights reserved3-1 Objects Declaration: String title;  title (object variable) of type String( Class )  title is just.
Java Packages - allow you to group classes as a collection Standard Java library has packages: java.lang and java.util … Also hierarchical: java and javax.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
The AP Java Subset Topics. A Topics Primitive Types int double boolean.
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
More Sophisticated Behavior
Classes, Libraries & Packages
Java Basics Packages.
More sophisticated behavior
Coding Standard & Javadoc
Packages Written part of final exam Alex Rudniy
Packages and Interfaces
Defining Classes and Methods
Applying OO Concepts Using Java
Joel Adams and Jeremy Frens Calvin College
Chapter 6 Objects and Classes
Classes 5/5 May 14, 2019 ICS102: Classes 5/5.
Presentation transcript:

1 JAVA API & Packages Starring: Java Documentation Co-Starring: BlueJ IDE

2 Purpose: In this lecture series we will learn the following: Java API in more detail Java Package Access Java Documentation

3 Resources: Java API Big Java Appendix A5 p.1086 & A10 p.1159 Packages Deitel & Deitel “Java How to Program” Chapter p.379 Lambert Comprehensive Appendix G & H Java Methods p.102 Big Java Chapter 7.9 P.310 AP Student Reference Material --- posted online BLUEJ IDE for Creating Java Documentation --- bluejsetup-122

4 Intro: We will get more comfortable with the Java API by examining with the required AP Subset of Java Classes Then we will look at Java packages and we will see how Java’s file structure affects how we import classes into our programs. Finally, we will discuss PACKAGE level access

5 Java API: All of Java’s classes are represented in Java’s Documentation of its API. We will have utilized many of the classes in Java’s vast library, but we will focus on only a few, especially the classes identified in the AP Subset. Java API (Document) Go through some classes (java lang, util, system)

6 Java API: java.lang.Object java.lang.Comparable java.lang.Integer java.lang.Double java.langString java.lang.Math java.util.Random java.util.List java.util.ArrayList java.util.LinkedList

7 Java API: java.util.Set java.util.HashSet java.util.TreeSet java.util.Map java.util.HashMap java.util.TreeMap java.util.Iterator java.util.ListIterator We are required to be able to understand and implement ALL of these classes for the AP exam.

8 Packages:Students are expected to have a basic understanding of packages and a reading knowledge of import statements of the form import packageName.subpackageName.ClassName;

9 A package is a set of related classes To Include your class into a specific package, you say: package SpecificPackageName; At the top of your class source code. This must be the initial instruction. Netbeans provides a default package for each program you create.

10 When placing a class into a package the class file itself MUST be in a specific location. A Package is located in a subdirectory that matches the PACKAGE NAME. The DOT notation is used to list the directory tree of that package.

11 For example, if I create a package that contains classes used in our AP class, I can Create a package Farrell.APJava.Samples In this case I must have created a directory Farrell / APJava / Samples / in which I place all of my classes.

12 Sun suggests that a consistent naming convention be used when creating package libraries. Use as the directory of your packages, the reverse name of your URL. For example, development for our school would have the following package name: com.highschool.millburn.apjava You need to place your classes in an appropriately named directory.

13 The package name is now part of the class name, so if another program wished to use one of your classes, or the entire package they would need to import them as follows: import com.highschool.millburn.apjava.* import com.highschool.millburn.apjava.OurMath Class

14 Also, when writing a class that will belong to a specific package, you can use ANY other class in that package without having to IMPORT that class (or package). java.lang is a package that contains the most common classes like Math, Object, System & String. This package is auto loaded into any program so the import is not required.

15 However, in order to use any other java package, you must import that package OR import a specific CLASS located in that package

16 import javax.swing.* // imports entire // package import java.util.LinkedList // imports one // class in the package The IMPORT statement tells the compiler where to find the classes and interfaces You wish to use in your program. You can import an entire package or a specific class.

17 If you did not use import to bring in classes to your project, you would need to fully qualify the class path in your code. For example, to use Swing’s JButton, you would code javax.swing.JButton myButton = new javax.swing.JButton;

18 In cases where different packages contain classes that have the same class name, you still need to preface the class name, when referencing the class in your code, with it’s package name. This obviates the ambiguity. For example, the List class exists in java.util as well as java.awt so in code, you need to specify java.util.List myList = new ArrayList( );

19 Common Classes: java.lang java.util java.io java.awt java.applet javax.swing

20 Package Access Control: We have already discussed Public, private and protected access for classes but there is one more level of access to consider and that is Package access. This level of access is NOT an AP topic, but it is interesting to consider.

21 Package Access Control: If you DO NOT declare a class level attribute OR method in a class as public, private or protected then that attribute gets PACKAGE level access. With Package access, ALL classes in the same package can access a package level attribute. But NO other class in any other package can use it (Public provides for such access).

22 For Example: public class Account { double balance; … }

23 In this example, the balance class level attribute is not Private as it should be. It has package level access SO ANY method in ANY class in the same package as the Account class can mutate this attribute. This violates the principle of encapsulation.

24 In addition, PROTECTED access not only allows subclasses to access a given class attribute, it gives access to ALL classes in the same package. SO, for this reason it is preferable to limit scope of class level attributes to PRIVATE and provide necessary accessor and mutator methods.

25 JavaDoc: Just like the online Documentation for Java’s API and the Case Study (MBS) Documentation, you can create your own Java Doc. You need to provide JAVA DOC style comments for your Classes, Methods and Class Level Attributes /** */ Place each comment IMMEDIATELY above the item it documents.

26 Each document “set” contains information followed by tags TAGS Keep the first part of the Java Doc short and make it a summary explanation of the class, method or attribute you are documenting. JavaDoc will extract these statements automatically.

27 Use tag for each argument being passed Example of correctly commented code: import java.util.ArrayList; /** * Write a description of your class here. * (your name) (a version number or a date) */ public class YOURCLASS { CLASS Level Attributes Declared /** * Constructor. Sets the initial state of class level attributes */ public YOURCLASS ( ) { } /**

28 * Returns the Salary of the Person Given SSN the social of the person to find LN the Last Name of the person to find the persons net salary IllegalArgumentException if the SSN is not valid */ public int getSalary (String SSN, String LN) { if(SSN.length() < 9) throw new IllegalArgumentException( ); return salary; }

29 Generating the Documentation: RUN javadoc GET MORE INFO ONLINE ON HOW TO DO THIS java.sun.com/j2se/javadoc

30 Generating the Documentation: Install and utilize BlueJ’s IDE to generate Documentation Lets Illustrate using BlueJ

31 Project: Create your own JavaDoc for your last class created

32 NO TEST FOR THIS LESSON !!!