CMPE212 – Reminders Assignment 2 due in a week.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Files and Streams (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Documentation javadoc. Documentation not a programmer's first love lives in a separate file somewhere usually a deliverable on the schedule often not.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
Page 1 – Autumn 2009Steffen Vissing Andersen SDJ I1, Autumn 2009 Agenda: Java API Documentation Code Documenting (in javadoc format) Debugging.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
Winter 2006CISC121 - Prof. McLeod1 Stuff We had better discuss a midterm date… –27 Feb. to 3 March or –6 to 10 March.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
Today Review passing by reference and pointers. null pointers. What is an Object? Winter 2016CMPE212 - Prof. McLeod1.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Today Encapsulation. Build a fully encapsulated Halloween class, going from Halloween1 to Halloween6 (eventually!): –The final version will have overloaded.
Today… StringTokenizer class. Method Overloading. Catching Exceptions (and what they are!). Start Pointers and Aliasing. Winter 2016CMPE212 - Prof. McLeod1.
Today Enumerated Types - Summary. Start Nested Classes: Inner Classes, Local Classes, Anonymous Classes, Lambda Functions Next: Interfaces, Abstract Classes.
Notices Assn 2 is due Friday, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including Thursday’s lecture: Big Topics.
CISC124 - Notices Assn 2 due this Friday. You already know what you need to do this assignment: –Another procedural program. –Uses text file I/O (see Exercise.
Advanced Programing practices
More Sophisticated Behavior
Winter 2018 CMPE212 9/18/2018 CMPE212 – Stuff…
Fall 2017 CISC124 9/18/2018 CISC124 First onQ quiz this week – write in lab. More details in last Wednesday’s lecture. Repeated: The quiz availability.
CMPE212 – Stuff… Assn 2 due next Friday. Winter 2018
CMPE212 – Stuff… Assn 3 due and Quiz 2 in the lab next week.
Winter 2018 CMPE212 9/21/2018 CMPE212 – Stuff…
CISC/CMPE320 - Prof. McLeod
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
Winter 2018 CMPE212 11/12/2018 CMPE212 – Stuff…
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
CISC124 Quiz 1 marking nears completion!
CMPE212 – Stuff… Assn 2 due this Friday. Winter 2018
CISC101 Reminders Assn 3 due Friday, this week. Quiz 3 next week.
Fall 2018 CISC124 12/1/2018 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
Fall 2018 CISC124 12/3/2018 CISC124 or talk to your grader with questions about assignment grading. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod.
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
CISC/CMPE320 - Prof. McLeod
CISC124 Assignment 3 due tomorrow at 7pm.
Defining Classes and Methods
CISC124 Assignment 4 on Inheritance due next Friday.
JavaDoc and Contracts Fall 2008.
Fall 2018 CISC124 2/1/2019 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
Fall 2018 CISC124 2/22/2019 CISC124 Quiz 1 This Week. Topics and format of quiz in last Tuesday’s notes. The prof. (me!) will start grading the quiz.
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
Advanced Programing practices
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
CISC124 Assignment 3 sample solution will be posted tonight after 7pm.
Winter 2019 CMPE212 4/5/2019 CMPE212 – Reminders
CMPE212 – Reminders Assignment 2 sample solution is posted.
CMPE212 – Reminders Assignment 3 due next Friday.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
CMPE212 – Reminders Quiz 1 marking underway. Assignment 1 due today.
CMPE212 – Reminders Assignment 2 due this Friday.
CMPE212 – Reminders Quiz 1 marking done. Assignment 2 due next Friday.
Winter 2019 CMPE212 5/3/2019 CMPE212 – Reminders
Winter 2019 CMPE212 5/10/2019 CMPE212 – Reminders
CMPE212 – Reminders Assignment 2 due today, 7pm.
Winter 2019 CMPE212 5/25/2019 CMPE212 – Reminders
CISC101 Reminders Assignment 3 due today.
Review of Previous Lesson
CMPE212 – Reminders Assignment 2 due next Friday.
CMPE212 – Reminders Assignment 4 on Inheritance due next Friday.
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

CMPE212 – Reminders Assignment 2 due in a week. Winter 2019 CMPE212 5/10/2019 CMPE212 – Reminders Assignment 2 due in a week. Assn 1 solution posted. Halloween zip archive linked to the lecture notes page has been updated. Winter 2019 CMPE212 - Prof. McLeod Prof. Alan McLeod

Today Encapsulation, Cont. Javadoc Documentation. Winter 2019 Winter 2019 CMPE212 5/10/2019 Today Encapsulation, Cont. Javadoc Documentation. Winter 2019 CMPE212 - Prof. McLeod Prof. Alan McLeod

Halloween Encapsulation, So Far private attributes. Overloaded constructors. Mutators. Accessors. toString(). equals(). Next: compareTo(), clone(), some refinement to yield Halloween5, and Javadoc comments. Winter 2019 CMPE212 - Prof. McLeod

compareTo() Method Compares a supplied Halloween4 object with the current one, based on your comparison criteria. It returns an int value. (Like the compareTo() method in the String class.) You have to decide on the basis for comparison. For Halloween4 you could just use numMunchkins, for example. The base Object class does not have this method, so you don’t have to worry about writing one to take an Object as a parameter. Winter 2019 CMPE212 - Prof. McLeod

clone() Method Returns a deep copy of the current object. A “deep copy” is not aliased in any way to the original object, but contains the same values for each attribute. Why not just write return this; ? See TestHalloween4.java for our object in action! Winter 2019 CMPE212 - Prof. McLeod

Test Halloween4 TestHalloween4 puts the Halloween4 class through its paces. Note the poor attempt to deal with the dependent attribute problem in Halloween4: If you wanted to edit {12, 10, 11, 9} and “rain” to {-6, -7, -9} and “snow”, you would have to change the weather string to “clear” or “unknown” first and then change it to the actual value after you changed the temperatures. Yuk! Winter 2019 CMPE212 - Prof. McLeod

Exercises and Assignment You are now able to work on both Exercises 7 and 8. After we see how to implement a couple of interfaces in Halloween5 and discuss Javadoc commenting you will know what you need for assignment 3. Winter 2019 CMPE212 - Prof. McLeod

Halloween5 Same structure as Halloween4, but the weather mutator is fixed and it has implemented two interfaces: Comparable<Halloween5> This is a generic interface that allows this object to be sorted with sort methods built into Java. Serializable This allows this object to be saved directly to a file. (Both of these are used in Assignment 3.) Winter 2019 CMPE212 - Prof. McLeod

Aside – What is an Interface? An interface is a totally abstract class – none of the methods in the class are implemented – they don’t contain any concrete code. (Weird!) Instead of doing something – an interface acts as a design specification and can be used as a type. A class that implements an interface promises to have concrete versions of all the abstract methods in the interface. More on these little beasties later. Winter 2019 CMPE212 - Prof. McLeod

Halloween5, Cont. See the changes in Halloween5. See TestHalloween5.java for tests that focus on what the interface implementations allow us to do with this class that we could not do with Halloween4. Winter 2019 CMPE212 - Prof. McLeod

Aside - Serialization Uses ObjectOutputStream and ObjectInputStream to read and write an entire object to a file with a single method call. The file will contain the structure of the object as well as the current values of all the object’s attributes. If a class’ attribute cannot be serialized for some reason, then mark it as transient and it will not be saved to the file. The .readObject() method from ObjectInputStream returns an Object which must then be cast to the proper type. Winter 2019 CMPE212 - Prof. McLeod

Aside – The serialVersionUID Thing This is a unique code ID value that is used to identify your object. Auto-generation uses various aspects of the structure of your class to generate this value. If you change the structure, you should re-generate this number. It is saved with the contents of your object in the file (“serialized”). When you read the object (“deserialize”), the number is compared to the number stored in the class to make sure the cast will work. If readObject() cannot find the bytecode file of the definition of your class, you will get a ClassNotFoundException. Winter 2019 CMPE212 - Prof. McLeod

The Comparable<T> Interface More on this interface later, but: We have already implemented this interface by the way we wrote compareTo(Halloween5), so no further changes are required. However, it is important for us to implement the interface, so our instance can be typed to be of type Comparable<Halloween5>. Winter 2019 CMPE212 - Prof. McLeod

Variations on a Theme… This standard encapsulated class structure is followed by every class in Java. Some classes don’t need all the pieces. For example: Attributes but no mutators. (Immutable) No attributes – then you don’t need constructors, mutators or accessors. (This class is probably just composed of utility methods, maybe all static.) An object that will never be part of a collection – you might not need equals() or compareTo(). A class that just has a main method. This is just the starting point of a program – possibly no other methods are required. Winter 2019 CMPE212 - Prof. McLeod

More Variations Of course, a class may need more methods than those we have discussed. Think of the additional behaviour that will be useful to the user of your object. A majority of methods should have something to do with the attributes of the object. But you might add a few static methods if you cannot think of anywhere else to put them (the wrapper classes are like this…). Winter 2019 CMPE212 - Prof. McLeod

Fall 2013 CMPE212 Javadoc Javadoc.exe is a program that comes with the JDK. (It is in the same directory as javac.exe and java.exe – the “bin” folder). It is not included in the JRE only. If I have written a class, “MyClass.java”, that contains properly formatted comments (more below), then running “javadoc MyClass.java” generates a file “MyClass.html”. (And lots of other files, actually.) The html file contains external documentation generated from the formatted comments in the source code. Winter 2019 CMPE212 - Prof. McLeod Prof. Alan McLeod

Javadoc - Cont. Normal block comments in Java are delimited by “/*” and “*/”. Everything between these delimiters, usually multiple lines, is a comment. Javadoc block comments are delimited by “/**” and “*/”. Winter 2019 CMPE212 - Prof. McLeod

Javadoc - Cont. The general form of a Javadoc comment: /** * Summary sentence. * More general information about the * class, attribute or method which * follows the comment, using as many lines * as necessary. (html tags can be included) * * javadoc tags to specify more specific * information, such as parameters and * return values for a method */ Winter 2019 CMPE212 - Prof. McLeod

Javadoc - Cont. The general form of a Javadoc tag is: @tagName comment The tags you use depend on what you are describing (class, method or attribute). In the case of methods, you can have a tag for each parameter, the return value, and a tag for each thrown exception. Eclipse (really nice!!) will generate a blank tag for you after you type “/**”. Typically, you will only write javadoc comments for public attributes and methods… Winter 2019 CMPE212 - Prof. McLeod

Eclipse Javadoc Assist For example, if you have the method header: public static double[] generateRandomArray(int size) Type /** right above this line and press <enter>. You will get: /** * * @param size * @return */ Winter 2019 CMPE212 - Prof. McLeod

Eclipse Javadoc Assist, Cont. Then you have to finish the comment: /** * Generates an array of random doubles. * * The method uses the Math.random() method to generate * an array of doubles between 0.0 and 1.0. * @param size The desired size of the array. * @return The array of random doubles. */ Winter 2019 CMPE212 - Prof. McLeod

Eclipse Javadoc Assist, Cont. Hold your cursor over the method header and you will get a preview of what the processed Javadoc will look like: (Or view the Javadoc tag in the same view as the Console tag.) Winter 2019 CMPE212 - Prof. McLeod

Common Javadoc Tags @param Parameter_name description @throws Exception_name description @return description @see packageName.ClassName, packageNamme.ClassName#methodName, etc. @author @version Winter 2019 CMPE212 - Prof. McLeod

Javadoc - Cont. Html tags can also be added to the comments to add more formatting to the resulting document: <em> for emphasis <code> for code font <img> for images <ul><li> </li></ul> for bulleted lists Etc… Winter 2019 CMPE212 - Prof. McLeod

Javadoc Reference The best reference for javadoc is at: http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html Winter 2019 CMPE212 - Prof. McLeod

Javadoc - Cont. The output from Javadoc looks exactly like the API documentation you have already seen - since that is the way it has been generated! The advantage is that when source code is changed, the Javadoc comments can be changed in the source, at the same time. The external documentation is then easily re-generated. Javadoc also provides a consistent look and feel to these API documents. Winter 2019 CMPE212 - Prof. McLeod

Javadoc - Cont. Most modern IDE’s (like NetBeans and Eclipse) allow you to run Javadoc from within the environment, and provide tools and wizards to help you create comments. In Eclipse, select “Project”, then “Generate Javadoc…”. Let’s run javadoc on the Halloween5 class. (Note that the first time you do this, you will have to tell Eclipse where javadoc.exe resides.) Winter 2019 CMPE212 - Prof. McLeod