CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology/George Koutsogiannakis.

Slides:



Advertisements
Similar presentations
How to Create a Java program CS115 Fall George Koutsogiannakis.
Advertisements

CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology/George Koutsogiannakis.
OBJECT ORIENTED PROGRAMMING I LECTURE 1 GEORGE KOUTSOGIANNAKIS
Class Modifiers So far we have seen many examples of such modifiers E.g. Public Abstract etc.
CS116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 Part II GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology- George Koutsogiannakis.
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
COMP Introduction to Programming Yi Hong May 13, 2015.
Welcome to IIT and cs115!.
CSC 212 Object-Oriented Programming and Java Part 1.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
The Java Programming Language
CSCI 51 Introduction to Computer Science Dr. Joshua Stough January 20, 2009.
Welcome to CS 115! Introduction to Programming. Class URL Write this down!
1 Principles of Computer Science I Note Set 1 CSE 1341.
1 Object-Oriented Programming Using C++ CLASS 1. 2 Review of Syllabus Catalog Description –An introduction to object oriented programming techniques using.
Principles of Computer Science I Honors Section Note Set 1 CSE 1341 – H 1.
CSE 1301 Lecture 5 Writing Classes Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 7 Object-Oriented Programming Part 2: User-Defined Classes.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
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 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
CSE 1301 Lecture 6 Writing Classes Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2014 Illinois Institute of Technology- George Koutsogiannakis 1.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 5 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Data Structures and Algorithms in Java AlaaEddin 2012.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
CS 116 Lecture 1 John Korah Contains content provided by George Koutsogiannakis & Matt Bauer.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
CS 116 Object Oriented Programming II Lecture 4 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
A High Flying Overview CS139 – Fall 2010 How far we have come.
Computer Science I ISMAIL ABUMUHFOUZ | CS 180. CS 180 Description BRIEF SUMMARY: This course covers a study of the algorithmic approach and the object.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
CS 201 Accelerated Introduction to Computer Science LECTURE 1 GEORGE KOUTSOGIANNAKIS 1 Copyright: FALL 2016 Illinois Institute of Technology/ George Koutsogiannakis.
OBJECT ORIENTED PROGRAMMING II GEORGE KOUTSOGIANNAKIS
Exam 3 Information George Koutsogiannakis
CS 116 OBJECT ORIENTED PROGRAMMING II MIDTERM EXAM INFORMATION
OBJECT ORIENTED PROGRAMMING II LECTURE 1 GEORGE KOUTSOGIANNAKIS
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
OBJECT ORIENTED PROGRAMMING II LECTURE 2 GEORGE KOUTSOGIANNAKIS
OBJECT ORIENTED PROGRAMMING II LECTURE 7 GEORGE KOUTSOGIANNAKIS
CS116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 Part II
OBJECT ORIENTED PROGRAMMING II GEORGE KOUTSOGIANNAKIS
Java programming lecture one
Lecture 14 Writing Classes part 2 Richard Gesick.
FINAL EXAM INFORMATION
FINAL EXAM INFORMATION
CS139 – Fall 2010 How far we have come
Lecture 13 Writing Classes Richard Gesick.
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Quiz 2 Information George Koutsogiannakis
OBJECT ORIENTED PROGRAMMING II GEORGE KOUTSOGIANNAKIS
OBJECT ORIENTED PROGRAMMING II GEORGE KOUTSOGIANNAKIS
OBJECT ORIENTED PROGRAMMING II GEORGE KOUTSOGIANNAKIS
Accelerated Introduction to Computer Science
CS 116 OBJECT ORIENTED PROGRAMMING II FINAL EXAM INFORMATION
OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS
OBJECT ORIENTED PROGRAMMING I LECTURE 5 GEORGE KOUTSOGIANNAKIS
Midterm Exam Information
CS201 Fall 2016 George Koutsogiannakis
Object Oriented Programming in java
Presentation transcript:

CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology/George Koutsogiannakis

Administrative Information Instructor’s name: George Koutsogiannakis Office : SB214 Office Hours: Mondays and Wednesdays – No appointment is needed – 11:20 a.m. - 1:40 p.m. or – By appointment on another time frame. Phone:

COURSE ADMINISTRATION COURSE WEB SITE: – – Use it to get : Instructor’ s office hours TAs office hours. Access to extra credit practice exercises description files. Access to laboratories description files. Access to the lecture presentations. 3

COURSE ADMINISTRATION Due dates for lab. assignments/exams. Example code. Solution to exercises, laboratories, quizzes, exams. Information on grading policies. Information on upcoming quizzes or exams. Link available from Blackboard. 4

COURSE ADMINISTRATION BLACKBOARD – View your grades. – Submission of assignments: Go to your blackboard account then click on information Choose assignment that you are submitting. Only one submission is allowed per assignment. In case of errors you have to me so that I can approve a deletion and a resubmission. Zip the files that you are submitting by: Select files (or folders ) to be submitted Right click the mouse and choose : sent to->Compressed (zipped) folder. 5

COURSE ADMINISTRATION Be careful to submit under the assignment assignment. Most common error: submitting an extra credit exercise under a lab assignment and vice versa. Note: If you accessing the course web site from the Blackboard link, you need to refresh the browser every time. 6

COURSE INFORMATION -TEXT JAVA ILLUMINATED- An Active Learning Approach By Julie Anderson and Herve Franceschi Jones and Bartlett Publishers. FOURTH Edition BRING THE TEXT TO CLASS !! SOMETIMES EXERCISES FROM THE TEXT ARE ASSIGNED for practice in class. 7

COURSE ADMINISTRATION Extra Credit Exercises- 8. Laboratories – 8 labs Tests- 2 quizzes a midterm and a final exam. Project 8

COURSE ADMINISTRATION course work Extra Credit Practice Exercises (8 assigned 5 needed to be submitted) – Shorter than labs. Single Task, emphasize a specific topic. Must be done during class period on specified dates. They carry no grade until the end of the Semester. – Must be checked for correctness before submission by Instructor/TA – Submitted on Blackboard at the end of class period. No late submissions are allowed. – Must be checked for correctness before submission by TA or myself. – If at least 5 out of 8 have been submitted (correctly done) an extra credit of 5 points will be issued at the end of the Semester. – No credit will be issued if less than 5 are submitted. – Credit will be issued at the end of the semester!! 9

COURSE ADMINISTRATION course work Laboratories (8) – Multiple Tasks. Could cover more than one topic. – Start work on them in advance. Work on them in class on the assigned date (as per the schedule). Finish outside of class and submit on Blackboard by the specified deadline, – Ask questions in class. – Ask questions via s to the instructor or the TA. – Do not hesitate to visit me in my office to ask questions. – Total points awarded : 30 10

COURSE ADMINISTRATION course work – Read laboratory document in advance. Due dates are posted on the course’ s web site. – Lab assignments can be done in groups of two. This is effective after the first quiz starting with Lab assignment # 2. Pairs will be assigned by instructor at that time (same pair as for extra credit exercises). 11

COURSE INFORMATION -Course Work You must receive at least 43.4 cumulative points in all tests/exams (70% of 62 points) in order to have your lab grades and extra credit added to your score. 12

COURSE ADMINISTRATION 13 Lab #Points earned Lab 12 Lab 22 Lab 33 Lab 43 Lab 53 Lab 64 Lab 76 Lab 87 Lab grades

COURSE ADMINISTRATION Project (1) – To be done individually. No pairing is allowed for project. – Description will be provided as per schedule. – Must submit source code and compiled files on Blackboard by deadline. – 8 points 14

COURSE ADMINISTRATION SUBMISSION ON BLACKBOARD – Zip (do not RAR) all files for the particular assignment. – Name the zipped file as follows: firstName_lastName_AssignmentName.zip i.e John_Doe_InClassExercise1.zip Mary_Smith_Lab1.zip – Submit under the correct assignment folder in your Blackboard account. – Ask for help if needed. Erroneous submissions need to be deleted by me first before a resubmission is allowed. 15

COURSE ADMINISTRATION Exams/Quizzes (2/2) – Closed Book/Closed Notes. Programming questions. – Must be done on a Text Editor, like Edit Plus, and submitted on Blackboard. – Must submit source code and Compiled files. – Final Exam covers material from midterm to end of the Semester. – Midterm exam.: 20 points. – Final exam. : 30 points. – Quiz 1: 4 points – Quiz 2: 8 points. 16

COURSE ADMINISTRATION CAUTION: IN ORDER TO PASS THE COURSE YOU MUST GET AT LEAST 70% OF THE CUMULATIVE POINTS ASSIGNED TO TESTS/QUIZZES REGARDLESS IF YOUR SCORES IN LABS OR EXTRA CREDIT EXERCISES OR PROJECT.! I.E. 62 POINTS ALLOCATED TO EXAM S x 0.70 = 43.4 THEREFORE, 43.4 IS THE MINIMUM CUMMULATIVE SCORE THAT YOU CAN HAVE IN ALL EXAMS/QUIZZES IN ORDER TO PASS THE COURSE WITH A GRADE OF C OR BETTER. ANY SCORE BELOW THAT IN TESTS WILL RESULT IN EITHER A D OR AN E IN THE COURSE. 17

Summary of Points 18 ASSIGNMENTNUMBER OF ASSIGNMNETS POINTS FOR EACH TOTAL POINTS Extra Credit Practice Exercises 8 No grade until end of Semester 5 extra points if at least 5 are submitted correctly. (7 points if all 8 are submitted) Labs9 varies30 Project1 8 8 Quizzes2 4/812 Exams220/3050 Total Points100.

COURSE ADMINISTRATION More on Submissions – Submissions for labs and exercises are not accepted after the solution is posted on the course’s web site. – Quiz and Exams are also submitted on Blackboard at the end of the allotted time on the day of the exam/quiz. Make sure that you submit the files in the proper folder named after the exam or the quiz. Do not turn your station computer off until your submission is verified by either the TA or the instructor. 19

COURSE ADMINISTRATION No laptops are allowed during exams or quizzes. Only the lab ‘ s station computers can be used. No flash drives are allowed in class during exams. No access to Internet or os allowed during exams. 20

COURSE ADMINISTRATION Teaching Assistants – You will be working with the same teaching assistant through the Semester. Make sure that you know his/her name, office hours and address (see the course web site for that information). – For grading purposes you are assigned to a specific assistant. – Grading of exercises and labs is done by the TAs. – Grading of quizzes and exams is done by the instructor. – Learn the name and the address of your Teaching Assistant. The list will be published and posted on the web site at the end o fteh first week. You must participate in the course by asking questions either during the lectures or by visiting the instructor or teaching assistant during office hours. 21

ETHICS The following rules apply during a quiz or exam. – Violation of the items below will result in you having to drop the course or receive a E grade for the course: Opening the service during the exam. Opening another student’s blackboard account during the exam. Accessing the internet without permission. Having hard copies of solutions on your desk. Using a flash drive during the test. If you are sitting in front of computer terminal that has been left logged in by a previous user you must turn it off and login again before you start the exam! If you get caught having access to files not created by you during the exam. and having obtaining then by any other means besides the aforementioned. 22

ETHICS Lab assignments are to be done individually. – The first two copying accusations will result in zero grade for each assignment. – Any new attempt after that will result in getting an E grade for the course. – Copying includes having obtained previous solutions of lab assignments from students who took the course and resubmitting them!!! NOTE: Most lab assignments have changes from Semester to Semester in key parts of the assignment. The TAs will be aware of the changes. Most students get caught by submitting the original solution thinking that it is the same! 23

CLASS ATTENDANCE 1.Mandatory for freshman classes. Must sign in attendance sheet otherwise you will be reported absent. 2.During lectures material and solution could be distributed that will not be posted on the web site. It is your responsibility to get a copy. 3.During lectures you are not allowed to surf the internet. 4.Class participation is encouraged in terms of questions, answers to questions, working on impromptu exercises. 24

INFORMATION ON JAVA Web sites for Java material: – To download Java Development Kit for your own computer (optional) s/index.html s/index.html SE (Standard Edition) Download JDK 7 – For online API AND TUTORIAL For the Java API (Application Programming Interface) 25

INFORMATION ON JAVA See me if you need help with the tools needed for the course installations on your laptop!! 26

INFORMATION ON JAVA TOOLS JDK – Java Development Kit- (Used when you write a program) – Provides: The compiler Other tools (not needed in this class) JRE – Java Runtime Environment- Used when you are ready to execute (interpret) a program. – Provides: The runtime environment JVM (Java Virtual Machine) The interpreter 27

INFORMATION ON JAVA TOOLS Edit Plus or Notepad++ – The text editor tool used by this class to write (edit) java programs. (note that there are other editors besides edit plus but this one is the approved for the class). – You can use other text editors as long as they don’t produce code. – Notepad++ is free – EditPlus is not free. 28

INFORMATION ON JAVA TOOLS Use text editor to write a program (i.e Notepad++) – Use Java API as help. – Use text and text examples for help. – Use class lectures and exercises done in class as help. – The file with the code is referred to as the “source code file”. 29

INFORMATION ON JAVA TOOLS – Note: There are text editors for MAC equivalent to Edit Plus for windows: JEdit available at: – Review how to compile command line. If you need help on using command lien download the help document available on the course’s web site : HELP DOCUMENT FOR COMPILING USING COMMAND LINE. (practice following instructions). 30

Programming Styling When typing a Java program follow the guidelines as described in : (cwu: Central Washington University) Style refers to the way a Java program should be typed in the source code file. 31

Style of a Java Program Naming Conventions »Variable Names »Constant Names »Method Names »Parameters Names Commenting »File Header Comments »Single-Line Comments »Trailing Comments Formatting »Indentation »White Space »Line Length 32

Topics in CS116 Enumerations. Packaging. Sorting Algorithms. Abstract Classes. Abstract methods. Method Overloading and Overriding. Interfaces. Inheritance. Polymorphism. Exceptions and User Defined Exceptions. 33

Topics in CS116 IO Streams – Writing and reading text files. – Writing and reading binary coded files. – Writing and reading serializable objects into or from a file. Recursion. – Recursion with a single base case – Recursion with two base casses. 34

REVIEW OF OBJECT ORIENTED PROGRAMMING CONCEPTS. 35 Service Class and Client Class. Defining Instance Variables/static variables. Writing Accessor/Mutator methods. The toString and equals methods. The Object Reference this. static instance variables. Static versus non static methods.

REVIEW OF OBJECT ORIENTED PROGRAMMING CONCEPTS. Providing input into a program: – Command Line input. – Keyboard input (using Scanner object). – Reading data from a file (Using Scanner object). Arrays of primitive data types. Arrays of Objects. 36

CLASS Class – An abstract representation of a category or a group. i.e. We can represent Students by creating a class called Student. – Usually given a sentence, the nouns represent classes: i.e. The student earned a grade of A Student will be a class. Grade can also be a class if we wanted. 37

CLASS Classes that the programmer creates are called: User Defined Classes. Classes that are part of the Java Library of classes are called: Pre Defined Classes. – Notice that a pre defined class is also a class that someone has already created and made available for us to use. – Pre Defined Library classes are described in the API – The API is available online. 38

User-Defined Classes 39 Combine data and the methods that operate on the data. A service class defines the category of data (i.e. Student class). A Client Classes can use one or more service classes.

Service (Template classes) Advantages: – The class methods are responsible for the validity of the data – Implementation details can be hidden – The class can be reused. – Does not need a main method. 40

Service (Template classes) Structure  Instance variables.  Default and non default constructors.  Accessor and mutator methods.  toString method.  Equals method.  Other help methods as required. 41

Client Classes Client of a Service class(classes) i.e ClientStudent class). Needs a main method. – A program that instantiates objects and calls (invokes) the methods of the Service class (or classes) in its main method. – In the main method we can instantiate an object of the Client class and use it to invoke not static methods of the Client class. – We can make direct calls to its static methods (without an object). 42

Syntax for Defining a Class 43 accessModifier class ClassName { // class definition goes here } ***Note that the curly braces are required. i.e public class Student { // class definition goes here }

Client Class public class ClientStudent { //must have a main method (plus other methods also). //we would instantiate Student service class //objects in the method(s) of this class. //Use objects to invoke methods or access fields //of the Service class Student. } 44

Class-Important Terminology 45 Fields – instance variables: the data for each object – class data: static data that all objects share – Visible by all methods of the class. Members – fields and methods Access Modifier – determines access rights for the class and its members – defines where the class and its members can be used

Class Access Modifiers 46 Access ModifierClass or member can be referenced by… publicmethods of the same class and methods of other classes privatemethods of the same class only protectedmethods of the same class, methods of subclasses (this term will be explained later on in the course), and methods of classes in the same package No access modifier (package access) methods in classes belonging to the same package as the class we are trying to reference only

Class-What is a Package? Classes can reside in packages – Library (pre defined classes) reside in packagesi.e. import java.util.Scanner; Scanner class is in package: java.util – Notice that a package is actually a directory path where the.class files are located. We can create a package for our user defined classes also. We will learn how to do that shortly in the course. Some editors, like Eclipse, can create packages for our programs. We will learn how to incorporate the code manually in our programs using the proper keywords in the code and compiling command line. (if you don’t know how to compile command line follow the tutorial I have available on the course’s web site). 47

Defining Instance Variables Syntax: accessModifier dataType identifierList; dataType can be primitive date type or a class type identifierList can contain: – one or more variable names of the same data type – multiple variable names separated by commas – initial values Instance variables can be declared as final 48

Examples of Instance Variable Definitions private String name = ""; private final int PERFECT_SCORE = 100, PASSING_SCORE = 60; private int startX, startY,width,height; 49

Primitive Data Types 50 primitive integral booleanfloating point float double byte char short int long Note: A String is not a primitive data type but rather a pre defined class object

SOFTWARE ENGINEERING TIP Define instance variables for the data that all objects will have in common. Define instance variables as private so that only the methods of the class will be able to set or change their values. Begin the instance variable identifier with a lowercase letter and capitalize internal words. 51

The Auto Class public class Auto { private String model; private int milesDriven; private double gallonsOfGas; } The Auto class has three instance variables: model, milesDriven and gallonsOfGas. 52

Static Instance Variables Also called class variables One copy of a static variable is created per class static variables are not associated with an object static constants are often declared as public To define a static variable, include the keyword static in its definition: Syntax: accessSpecifier static dataType variableName…; Example : public static int countAutos = 0; 53

Static Instance Variables Every instance of the class (object) can see the same value of the static variable (the latest value assigned to that variable). If an object modifies the value of the static variable then all objects of that class see the new value. 54

Class Members A class has – Instance variables (also called global variables sometimes). – Constructors Default- has no arguments. Initializes the instance variables to pre determined value (i.e. zero, “ “, etc). Non default- has arguments. Initializes the instance variables to values passed in the arguments. – Methods One of the methods is a main method if the class is a client class. 55

Accessor/Mutator methods Accessor methods – return the value of an instance variable i.e. public String getModel() { return model; } 56

Accessor/Mutator methods Mutator methods – Set the value of an instance variable i.e. public void setModel (String mod) { model=mod; } 57

To String method Often classes have a toString method that outputs the values of its instance variables. public String toString() { String output=“The value of model is”+model+”\n”+”The miles driven:”+milesDriven………..etc…..”); return output; } 58

Creating Objects of a class Classes are a template used to create specific objects An object of a class is created by using the new operator and calling one of the constructors of the class: i.e. Auto car1=new Auto(); or Auto car2=new Auto(String bmw, int 1000, int 20); 59

Comparing Objects For Equality Objects of the same class can be compared for equality. The definition of the term equality is up to the programmer: – i.e Suppose we have class Student with instance variables as shown public class Student { String firstName=“ “; String lastName=“ “; int StudentID=0; String address=“ “; ……………………………………………. …………………………………………….. 60

Comparing Objects For Equality We may decide that two Student objects are equal if and only if the studentID instance variable has the same value for both objects (regardless if the rest of the instance variables have the same values or not). We create a method called equals to test for the equality of two objects of the same class. 61

Comparing Objects For Equality Example code for equals method to be included in Student class: public boolean equals (Student st) { if(this.getStudentID()==st.getStudentID()) return true; else return false; } 62

Comparing Objects For Equality In the client class that uses Student we can make comparisons of Student objects: public class StudentClient { public static void main(String [] args) { Student st=new Student(“George”, “Kay”, 1234, “654 somestreet”); Student st1=new Student(“Nicholas”, “Jones”, 1234, “654 somestreet”); boolean b= st.equals(st1); if(b==true) System.out.println(“They are equal”); else System.out.println(“They are NOT re equal”); } 63

Comparing Objects For Equality Notice that in the equals method this refers to object st that invokes the equals method. 64

Terminology Object reference: identifier of the object. The name we used for the object. Object data: The data encaptulated by a specific object (reference). The values of the instance variables as pertained to that specific object. i. e. If we create a Student template class then a specific object reference called st may have such data as: firstName=“John” lastName=“Doe” Instantiating an object: creating an object of a class by using the new operator. Instance of the class: the object we created. Methods: the code to manipulate the object data. Calling a method: invoking a service for an object. 65