CISC124 Assignment 3 due tomorrow at 7pm.

Slides:



Advertisements
Similar presentations
Introduction to classes Sangeetha Parthasarathy 06/11/2001.
Advertisements

Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Winter 2006CISC121 - Prof. McLeod1 Last Time Misc. useful classes in Java: –String –StringTokenizer –Math –System.
Fall 2015CISC124 - Prof. McLeod1 CISC124 Have you filled out the lab section survey? (As of last night 54 left to fill out the survey.) TA names have been.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Problems with assn 3? Discuss at your team meeting tonight.
Today protected access modifier Using the debugger in Eclipse JUnit testing TDD Winter 2016CMPE212 - Prof. McLeod1.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
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.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
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.
Lecture 5:Interfaces and Abstract Classes
A variable is a name for a value stored in memory.
JAVA MULTIPLE CHOICE QUESTION.
CISC124 Labs start this week in JEFF 155: Meet your TA.
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 3 due and Quiz 2 in the lab next week.
Winter 2018 CMPE212 9/21/2018 CMPE212 – Stuff…
Fall 2017 CISC124 9/21/2018 CISC124 First onQ quiz this week – write in lab. More details in last Wednesday’s lecture. Repeated: The quiz availability.
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
Object Based Programming
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 Last Quiz this week. Topics listed in last Tuesday’s lecture.
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Packages and Interfaces
CISC124 Assignment 3 due this Wednesday at 7pm.
CMPE212 – Stuff… Assn 2 due this Friday. Winter 2018
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 Assn 3 due tomorrow, 7pm.
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
Coding Concepts (Basics)
CISC124 Assignment 4 on Inheritance due today at 7pm.
CISC124 Assignment 4 on Inheritance due next Friday.
CISC124 Assignment 4 on Inheritance due next Friday.
CISC/CMPE320 - Prof. McLeod
CISC124 Labs start this week in JEFF 155.
CISC124 Labs start this week in JEFF 155. Fall 2018
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
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.
Introduction to Data Structure
CISC101 Reminders All assignments are now posted.
CMPE212 – Reminders Assignment 2 sample solution is posted.
CMPE212 – Reminders Assignment 3 due next Friday.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
CISC101 Reminders Quiz 1 marking underway.
Last Time Some discussion of program “efficiency”. Arrays – 1D and 2D
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Review: libraries and packages
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.
CMPE212 – Reminders Assignment 2 due next Friday.
CMPE212 – Reminders Assignment 4 on Inheritance due next Friday.
Presentation transcript:

CISC124 Assignment 3 due tomorrow at 7pm. Fall 2018 CISC124 1/16/2019 CISC124 Assignment 3 due tomorrow at 7pm. Quiz 2 next week, starting Monday at 8:30. Topics in yesterday’s notes. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

Today Debugging in Eclipse. (Last quiz 2 topic.) Packages. Enumerated Types. Inner Classes. Fall 2018 CISC124 - Prof. McLeod

Debugging Sometimes a mental “walk-through” of your code is not enough to figure out an error. With the debugger you can run to a breakpoint, stop your program and then execute one line at a time while watching the call stack, variables and custom expressions. Let’s fix UseDebugger.java Fall 2018 CISC124 - Prof. McLeod

Debugging, Summary See “Java development users guide” > “Concepts” > “Debugger” and “Java development user guide” > “Getting Started” > “Basic tutorial” > “Debugging your programs” in the Eclipse help system. Place one or more breakpoints in your edit window. Run in debug mode. Use the “step” choices. View the method call stack, variables, and use expressions if needed. Fall 2018 CISC124 - Prof. McLeod

Aside – Skipping JRE Code in Debugger Goto Window > Preferences > Java > Debug > Step Filtering. “Select All”: Then “Apply and Close”. Fall 2018 CISC124 - Prof. McLeod

Skipping JRE Code in Debugger, Cont. When in Debug mode: Turn on “Use Step Filters”: Now, you won’t see as much JRE code when you are stepping through your code. Fall 2018 CISC124 - Prof. McLeod

Upcoming Topics & Terms Packages, Enumerated Types Hierarchies, Inheritance, Polymorphism Interfaces, Anonymous Classes, Abstract Classes, Lambda Functions, Inner Classes Generic Classes Fall 2018 CISC124 - Prof. McLeod

package package_name; Fall 2013 CISC124 Packages “package” is a Java keyword. It provides a means of grouping classes together into a package. All classes in a package share some common theme. It is used as in: package package_name; This line is at the top of a class definition, before the public class… Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

Packages and Eclipse Eclipse would prefer that you to create classes in a package. When you create a new Class, specify what package you want it to belong to. This will automatically add the package package_name; line to the top of the class, the proper folder is created in src, and the new class in saved in this folder. Eventually, you will create a *.jar (or *.zip) file with all the *.class files in your package. Put this user library somewhere in or below your classpath and then another class will be able to import it. Fall 2018 CISC124 - Prof. McLeod

Packages, Cont. The structure is: classpath\folder\packagename “folder” can be a series of folders. The import statement looks like: import folder.packagename.*; The “.*” says to import all classes in the package, or you can import specific classes. Fall 2018 CISC124 - Prof. McLeod

Packages and Eclipse, Cont. You can add to the classpath by right clicking on Project - Properties to get the following window: Then choose “Add…” Fall 2018 CISC124 - Prof. McLeod

Packages, Cont. We have been importing existing packages already import java.util.Scanner; import java.io.*; … Fall 2018 CISC124 - Prof. McLeod

Packages, Cont. Note that Java automatically imports the java.lang.* package for you. This package contains many classes fundamental to the Java language: String Math all Wrapper classes (Boolean, Character, Integer, Long, Float, and Double) System, and a few others… Fall 2018 CISC124 - Prof. McLeod

import static java.lang.Math.*; static Import Used to import all static methods in a class, so that they can be used as if they were declared within the class that uses them. For example: import static org.junit.jupiter.api.Assertions.*; Another example: import static java.lang.Math.*; See StaticImportMath.java. Fall 2018 CISC124 - Prof. McLeod

Aside – Protected Access So far we have used public and private access modifiers. protected is what you get if you don’t specify an access modifier. This means “public inside the package, private outside the package”. Used in the API. Use sparingly! Fall 2018 CISC124 - Prof. McLeod

Fall 2013 CISC124 Enumerated Types enum is a keyword that is new since Java 5.0, but C has had enum’s for a while! For example: enum IceCream {CHOCOLATE, VANILLA, STRAWBERRY, GOLD_MEDAL_RIBBON, WOLF_PAWS, BUBBLE_GUM}; Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

Enumerated Types, Cont. Code that would use IceCream: Displays: IceCream favourite = IceCream.GOLD_MEDAL_RIBBON; IceCream leastFavourite = IceCream.BUBBLE_GUM; System.out.println("Favourite is " + favourite); System.out.println("Least Favourite is " + leastFavourite); Displays: Favourite is GOLD_MEDAL_RIBBON Least Favourite is BUBBLE_GUM Fall 2018 CISC124 - Prof. McLeod

Enumerated Types, Cont. The contents of IceCream are not Strings, but they are a kind of Object. IceCream is also an Object. They behave as named constants, so by convention, they should be in upper case. Once you have specified the possible values for IceCream in the enum declaration, you cannot change them. A variable of type IceCream can only be assigned to one of the possible types. Fall 2018 CISC124 - Prof. McLeod

Enumerated Types, Cont. The objects in an enum object inherit a few methods, including: equals() toString() compareTo() ordinal() values() The first three look familiar! Fall 2018 CISC124 - Prof. McLeod

ordinal() Method Returns the numeric location of the value in the list (numbering starts from zero.) For example System.out.println("Location = " + favourite.ordinal()); Displays: Location = 3 Fall 2018 CISC124 - Prof. McLeod

values() Method Returns an array of the enum’s Objects in exactly the same order. For example: IceCream[] flavours = IceCream.values(); System.out.println(flavours[3]); Displays: GOLD_MEDAL_RIBBON Fall 2018 CISC124 - Prof. McLeod

Enumerated Types, Cont. You can use equals() or == to test for equality. For example: System.out.println(leastFavourite == IceCream.BUBBLE_GUM); Prints out true to the console. compareTo() compares the members on the basis of their position in the enum collection. Fall 2018 CISC124 - Prof. McLeod

Enumerated Types, Cont. Another practical example in the API is the Pos enum in the javafx.geometry package. See the API docs. Fall 2018 CISC124 - Prof. McLeod

Enumerated Types, Summary So what’s the point of these things? enum’s are used when you need a short, simple list of things, or “named values”, or constants with a theme. The list has a finite size, will not grow and will not (and cannot) change, unlike arrays. You want to know that you can access only the defined members of the list and no others. Modern IDE’s will provide a list of all the values, when you type a period after the name of the enum. Yes, there are other ways to do this - but an enum is pretty easy to use! Fall 2018 CISC124 - Prof. McLeod

Inner Classes Simply defined as a class defined within a class! Neat! Fall 2013 CISC124 Inner Classes Simply defined as a class defined within a class! Neat! public class OuterClass { private class InnerClass { Attributes of innerclass Methods of innerClass } // end InnerClass Attributes of OuterClass Methods of OuterClass } // end OuterClass Fall 2013 CISC124 - Prof. McLeod Prof. Alan McLeod

Inner Classes, Scope Rules See the demo program InnerClassDemo.java, used with TestInnerClassDemo.java. The inner class can easily get at all the attributes and methods of the outer class. The outer class can also access the attributes and methods of the private inner class, after it instantiates the inner class. However, all private classes, methods and attributes are hidden outside InnerClassDemo. Fall 2013 CISC124 - Prof. McLeod

Inner Classes, Why private? If you are declaring a non-static object inside your class, you are only doing so because you want to hide it away. This object can only be used inside the outer class and is hidden everywhere else. How else can you make a class private? Fall 2013 CISC124 - Prof. McLeod

Inner Classes, Cont. So, what’s the point of private inner classes? (Used quite often with GUI coding…) One reason - When you wish to use a small class (in terms of the size of its definition), but don’t want to bother creating a separate class definition file. Fall 2013 CISC124 - Prof. McLeod

Inner Classes, Cont. An inner class can be a “hidden” object! This is often used with Linked List definitions to define the node object. Yes, you can have an inner class inside an inner class! Fun! Fall 2013 CISC124 - Prof. McLeod

public static Inner Classes What is the point of declaring an inner class public static? It would allow you to “categorize” methods into topical groups. Invoke them as below: First: TestClass tc = new TestClass(); Then, invoking methods from public static inner classes: tc.Group1.method(); tc.Group2.anotherMethod(); Fall 2013 CISC124 - Prof. McLeod