Software Practice 1 - OOP (3) API

Similar documents
Software Practice 1 - OOP (3) API Access Control Review Packages Java API Documentation

Software Practice 1 Basic Grammar

Software Practice 1. Course Overview Lecture Schedule Today s Task Contact

Software Practice 1 - OOP (1) Class and Method

Collections Framework: Part 2

Software Practice 1 - Multithreading

Software Practice 1 - File I/O

6.092 Introduction to Software Engineering in Java January (IAP) 2009

Chapter 10 Collections

Generics Collection Framework

Software Practice 1 - Error Handling

Topic 10: The Java Collections Framework (and Iterators)

Inheritance and Interfaces

Tony Valderrama, SIPB IAP 2010

Today. Book-keeping. Exceptions. Subscribe to sipb-iap-java-students. Collections. Play with problem set 1

17. Java Collections. Organizing Data. Generic List in Java: java.util.list. Type Parameters ( Parameteric Polymorphism ) Data Structures that we know

The Collections API. Lecture Objectives. The Collections API. Mark Allen Weiss

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 7. (A subset of) the Collections Interface. The Java Collections Interfaces

Strings and Arrays. Hendrik Speleers

Announcements. Hash Functions. Hash Functions 4/17/18 HASHING

MIDTERM EXAM THURSDAY MARCH

CITS1001 week 6 Libraries

Collections class Comparable and Comparator. Slides by Mark Hancock (adapted from notes by Craig Schock)

Lecture 15 Summary. Collections Framework. Collections class Comparable and Comparator. Iterable, Collections List, Set Map

Exploring the Java API, Packages & Collections

Lecture 6 Collections

Software Practice 1 - Socket

Advanced Programming Languages Effective Java Item 1. Spring 2015 Chungnam National Univ Eun-Sun Cho

Collections (Java) Collections Framework

Implementing Hash and AVL

1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1

Programming Languages and Techniques (CIS120)

COMP 250. Lecture 27. hashing. Nov. 10, 2017

Java Programming Unit 8. Selected Java Collec5ons. Generics.

CS 310: Maps and Sets

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

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

CONTAİNERS COLLECTİONS

Programming Languages and Techniques (CIS120)

Class 32: The Java Collections Framework

Introducing Design Patterns

Data Structures - CSCI 102. CS102 Hash Tables. Prof. Tejada. Copyright Sheila Tejada

CSC 1214: Object-Oriented Programming

CSE 143 Au03 Final Exam Page 1 of 15

Java Collections Framework. 24 April 2013 OSU CSE 1

Today's Agenda. > To give a practical introduction to data structures. > To look specifically at Lists, Sets, and Maps

Winter 2016 COMP-250: Introduction to Computer Science. Lecture 6, January 28, 2016

An Interface with Generics

(f) Given what we know about linked lists and arrays, when would we choose to use one data structure over the other?

CSC 172 Data Structures and Algorithms. Lecture 3 Spring 2018 TuTh 3:25 pm 4:40 pm

PIC 20A Collections and Data Structures

MIT AITI Lecture 18 Collections - Part 1

CS2110: Software Development Methods. Maps and Sets in Java

Java Collections Framework

Computer Science II (Spring )

Algorithms. Produced by. Eamonn de Leastar

Main loop structure. A Technical Support System. The exit condition. Main loop body

Le L c e t c ur u e e 8 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Collections

[TAP:AXETF] Inheritance

JAVA SYLLABUS FOR 6 WEEKS

From Java Code to Java Heap Understanding the Memory Usage of Your Application

Question 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so.

CS Programming Language Java. Fall 2004 Sept. 29

Adam Blank Lecture 5 Winter 2019 CS 2. Introduction to Programming Methods

Sets and Maps. Part of the Collections Framework

Announcements. Submit Prelim 2 conflicts by Thursday night A6 is due Nov 7 (tomorrow!)

Homework 4: Hash Tables Due: 5:00 PM, Mar 9, 2018

Lecture 15 Summary 3/11/2009. By the end of this lecture, you will be able to use different types of Collections and Maps in your Java code.

Lists and Iterators. CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology

תוכנה 1 מבני נתונים גנריים

Software 1 with Java. Recitation No. 6 (Collections)

Symbol Tables 1 / 15

Final Exam CS 251, Intermediate Programming December 13, 2017

Advanced Computer Programming

CS Ananda Gunawardena

CS 151. Exceptions & Javadoc. slides available on course website. Sunday, September 9, 12

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

An Introduction to Software Engineering. David Greenstein Monta Vista High School

CMSC 341. Nilanjan Banerjee

Collections. James Brucker

Collections, Maps and Generics

Full file at

CS 455 Midterm Exam 2 Fall 2015 [Bono] Nov. 10, 2015

Announcements. Java Review. More Announcements. Today. Assembly Language. Machine Language

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

EXAMINATIONS 2016 TRIMESTER 2

11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures

Lab5. Wooseok Kim

Outline. iterator review iterator implementation the Java foreach statement testing

CS 231 Data Structures and Algorithms Fall Binary Search Trees Lecture 23 October 29, Prof. Zadia Codabux

CS 211: Using ArrayList, Implementing Arraylist

1 Runtime Verification using JavaMOP

CS 211: Using ArrayList, Implementing Arraylist

CS Introduction to Data Structures Week 1 Thursday

Advanced Programming Generics Collections

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 6. The Master Theorem. Some More Examples...

Implementation. Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations

Midterms Save the Dates!

Homework #10 due Monday, April 16, 10:00 PM

Transcription:

Software Practice 1 - OOP (3) API Access Control Review Packages Java API Documentation Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim (42) T.A. Sujin Oh Junseong Lee (43) 1 / 41

2 / 41 ACCESS CONTROL REVIEW

3 / 41 Access Control - Bad public class CreditCard { String cardnumber; double expenses; double charge (double amount) { expenses = expenses + amount; String getcardnumber (String password) { if (password.equals ("SECRET!3*!")) { return cardnumber; return "jerkface";

4 / 41 Access Control - Good public class CreditCard { private String cardnumber; private double expenses; public double charge (double amount) { expenses = expenses + amount; public String getcardnumber (String password) { if (password.equals ("SECRET!3*!")) { return cardnumber; return "jerkface";

5 / 41 Public vs. Private Public Others can use this Private Only the class can use this public/private applies to any field or method

6 / 41 PACKAGES

7 / 41 What does Package do? Each class belongs to a package Classes in the same package serve a similar purpose Packages are just directories Classes in other packages need to be imported

8 / 41 Packages in Java Defining Packages package path.to.package.foo; public class Foo {... Using Packages // import a public class, Foo, in foo package import path.to.package.foo.foo; // import all public classes in foo package import path.to.package.foo.*;

9 / 41 Examples package parenttools; public class BabyFood { package parenttools; public class Baby { public void feed (BabyFood food);

10 / 41 Examples cont d // what s wrong with this code? package adult; public class Parent { public static void main (String[] args) { Baby baby = new Baby(); baby.feed (new BabyFood ());

11 / 41 Examples cont d // A-ha! package adult; import parenttools.baby; // get Baby from parenttools import parenttools.babyfood; // get BabyFood from parenttolls public class Parent { public static void main (String[] args) { Baby baby = new Baby(); baby.feed (new BabyFood ());

12 / 41 Examples cont d // Also this is possible package adult; import parenttools.*; // get all classes from parenttools public class Parent { public static void main (String[] args) { Baby baby = new Baby(); baby.feed (new BabyFood ());

13 / 41 Why Packages? Combine similar functionality org.university.libraries.library org.university.libraries.book Separate similar names shopping.list wish.list

14 / 41 Special Packages All classes see classes in the same package (no import needed) All classes see classes in java.lang Example: java.lang.string; java.lang.system

15 / 41 JAVA API

API In computer programming, an application programming interface(api) is a set of subroutine definitions, protocols, and tools for building application software. Good API makes it easier to develop a computer program * Extract from wikipedia 16 / 41

17 / 41 Java API Java includes lots of packages/classes Reuse classes to avoid extra work http://docs.oracle.com/javase/8/docs/api/

18 / 41 Arrays with items Create the array bigger than you need Track the next available slot Book[] books = new Book[10]; int nextindex = 0; books[nextindex ++] = b;

19 / 41 Arrays with items Create the array bigger than you need Track the next available slot Book[] books = new Book[10]; int nextindex = 0; books[nextindex ++] = b; What if the library expands?

20 / 41 Example import java.util.arrays; /* * Extend the capability of this * library by [additional capability]. */ int cap; String[] books; public void extendcapacity (int cap) { this.cap += cap;... this.books = Arrays.copyOf (this.books, this.cap);

21 / 41 Arrays.copyOf() Modifier and Type Method and Description copyof (T[] original, int newlength) static <T> T[] Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length

22 / 41 Digression What is T? Generic class or interface, so called generic type, that is parameterized over types public class Box<T> { // T stands for Type private T t; public void set (T t) { this.t = t public T get () { return t; Box<String> box = new Box<String>();

23 / 41 Digression public interface Pair<K,V> { public K getkey(); public V getvalue(); public class OrderedPari<K,V> implements Pair<K,V> { private K key; private V value; public OrderedPair (K key, V value) { this.key = key; this.value = value; public K getkey () { return this.key; public V getvalue () { return this.value; Pair<String,Integer> p1 = new OrderedPair<String,Integer> ( Even, 8); Pair<String,String> p2 = new OrderedPair<String,String> ( hello, world );

24 / 41 By the way, There must be more efficient API, because TA says Java is easy to develop!

25 / 41 By the way, There must be more efficient API, because TA says Java is easy to develop! Sure it is! (all in java.util package) Arrays, List, LinkedList, ArrayList, Vector, Map, HashMap, EnumMap, LinkedHashMap, AbstractMap, Set, HashSet, EnumSet, LinkedHashSet, AbstractSet, Buffer, Stream, StringStream, Dictionary, etc

26 / 41 By the way, There must be more efficient API, because TA says Java is easy to develop! Sure it is! (all in java.util package) Arrays, List, LinkedList, ArrayList, Vector, Map, HashMap, EnumMap, LinkedHashMap, AbstractMap, Set, HashSet, EnumSet, LinkedHashSet, AbstractSet, Buffer, Stream, StringStream, Dictionary, etc What the

27 / 41 By the way, There must be more efficient API, because TA says Java is easy to develop! Sure it is! (all in java.util package) Arrays, List, LinkedList, ArrayList, Vector, Map, HashMap, EnumMap, LinkedHashMap, AbstractMap, Set, HashSet, EnumSet, LinkedHashSet, AbstractSet, Buffer, Stream, StringStream, Dictionary, etc

28 / 41 List<E> Ordered collection (also known as sequence) In Java, List is an interface to precise control over where in the list each element is inserted enables user to access elements by their integer index enables user to search for elements in the list

29 / 41 ArrayList<E> Resizable-array implementation of List interface Most popular implementation With this class, you don t need to implement extendcap method! Because ArrayList already has the functionality! Example: http://beginnersbook.com/2013/12/java-arraylist/

30 / 41 Map<K,V> An object that maps keys to value. A map cannot duplicate keys Each key can map to at most one value In Java, Map is also an interface to map between keys and values enables user to access elements by their keys

31 / 41 HashMap<K,V> Hash table based implemenation of Map interface Most popular implementation HashMap has the functionality of checking existence of keys and values Example: http://beginnersbook.com/2013/12/hashmap-in-java-with-example/

32 / 41 Iterator<E> An iterator over a collection Iterator allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics Example with ArrayList: http://beginnersbook.com/2014/06/java-iterator-with-examples/

33 / 41 Java API As well as these APIs, there are huge number of prebuilt APIs in Java Your ability as a Java coder will be determined whether you can apply the properred APIs into the right position or not Don t hesitate to know more APIs Furthermore, understand how those APIs run and when to use them

34 / 41 JAVADOC

35 / 41 Documentation Many software engineers, even if some senior engineers, are bothered to make documents of their implementation However, high quality documenting skill cannot be too important for everyone to be a good engineer Then how can we make well-made documentations for Java implementation?

36 / 41 Javadoc Javadoc is a documentation generator created by Sun Mircrosoft for Java language (currently Oracle Cooperation) for generating API documentation in HTML format from Java source code. Most of all, perfectly easy to use

37 / 41 Syntax of Javadoc All contents of Javadoc is represented in the comment starting with two star marks The comments for Javadoc must be located right above of each class or method Each line has to start with a star mark A word starting with @ means that it is Javadoc keyword Closed braces({ ) are usually used for using keyword

38 / 41 Keywords of Javadoc Contents without keyword The main explanation about the class/method @param [parameter_name] [description] Explain about the [parameter_name] with [description] @return [description] Explain about the return value with [description] @link [package.class#member] [label] Link to [package.class#member] document in Javadoc See more: http://docs.oracle.com/javase/7/docs/technotes/tools/wind ows/javadoc.html

39 / 41 Javadoc Example /** * This class is for practice * @author SKKU */ public class Test { /** * This method prints the String display * @param str the str is {@link java.lang.string String which will be printed * @param x the x is unused variable * @return return true or Failed */ public boolean disp(string str, int x) { System.out.println("display"); return true;

[Lab Practice #4] Implement HashArray package HashArray public class HashArray Implement 5 methods boolean addition(key, value) boolean search(key, value) boolean delete(key, value) ArrayList getarray(key) int getcount(key) Use two external Library HashMap ArrayList 40 / 41

41 / 41 [Submit] Upload to i-campus Compress your HashArray.java file to zip file File name: studentid_lab04.zip Due date Today 23:59:59 Class 42 (4/02 Monday) Class 43 (4/04 Wednesday) Penalty: -10% of each lab score per one day