CS-0401 INTERMEDIATE PROGRAMMING USING JAVA Prof. Dr. Paulo Brasko Ferreira Fall 2014.

Slides:



Advertisements
Similar presentations
L3:CSC © Dr. Basheer M. Nasef Lecture #3 By Dr. Basheer M. Nasef.
Advertisements

CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Wednesday, 10/2/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/2/02  QUESTIONS (on HW02 – due at 5 pm)??  Today:  Review of parameters  Introduction.
1 Classes Overview l Classes as Types l Declaring Instance Variables l Implementing Methods l Constructors l Accessor and Mutator Methods.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 3rd Edition.
C++ Classes in Depth. Topics Designing Your Own Classes Attributes and Behaviors Writing Classes in C++ Creating and Using Objects.
Chapter Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 9 Objects and Classes.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
UML Basics & Access Modifier
Centre for Computer Technology ICT115 Object Oriented Design and Programming Week 2 Intro to Classes Richard Salomon and Umesh Patel Centre for Information.
BCS 2143 Introduction to Object Oriented and Software Development.
Java Class Syntax CSIS 3701: Advanced Object Oriented Programming.
Object Oriented Design: Identifying Objects
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java: From Control Structures through Objects Third Edition.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java: Early Objects Third Edition by Tony Gaddis Chapter.
Java Classes Using Java Classes Introduction to UML.
Starting Out with Java: From Control Structures through Objects.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
1 Programming for Engineers in Python Autumn Lecture 6: More Object Oriented Programming.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
CS305j Introduction to Computing Classes 1 Topic 23 Classes – Part I "A 'class' is where we teach an 'object' to behave." -Rich Pattis Based on slides.
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
CS170 ygao JAVA, C4Slide 1. CS170 ygao JAVA, C4Slide 2.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Page 4.1 – Autumn 2010Steffen Vissing Andersen SDJ I1, Autumn 2010 Agenda – Session 4 – 7. September 2009 Java fundamentals, checkpoint from chapter 2.
© 2010 Pearson Addison-Wesley. All rights reserved. 6-1 Chapter Topics Chapter 6 discusses the following main topics: –Classes and Objects –Instance Fields.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Objects and Classes.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 5 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
CS1101 Group1 Discussion 6 Lek Hsiang Hui comp.nus.edu.sg
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 1 Introduction to Object-Oriented Programming and.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
OOP Basics Classes & Methods (c) IDMS/SQL News
Class Everything in Java is in a class. The class has a constructor that creates the object. If you do not supply a constructor Java will create a default.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Class Definitions and Writing Methods Chapter 3 3/31/16 & 4/4/16.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Introduction of Object Oriented Programming.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
CS16: UML’s Unified Modeling Language. UML Class Diagram A UML class diagram is a graphical tool that can aid in the design of a class. The diagram has.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Introduction to Object-oriented Programming
Andrew(amwallis) Classes!
Concepts of Object Oriented Programming
Classes and OOP.
Objects as a programming concept
Chapter 7 Classes & Objects.
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
Chapter 4: Writing classes
Chapter 9 Classes & Objects.
Chapter 9 Objects and Classes
Today’s topics UML Diagramming review of terms
Session 2: Introduction to Object Oriented Programming
Dr. R Z Khan Handout-3 Classes
ITE “A” GROUP 2 ENCAPSULATION.
Chapter 4 Test Review First day
Presentation transcript:

CS-0401 INTERMEDIATE PROGRAMMING USING JAVA Prof. Dr. Paulo Brasko Ferreira Fall 2014

Chapter 6 Presentation Outline Classes and Objects Instance Fields and Methods Constructors Overloading Methods and Constructors Scope of Instance Fields Getters and Setters Packages and Import Statements

The concepts of class and object Java is an OOP language Object-oriented programming language Tries to mimic the way we see the world Makes it easier to program and maintain a code A program based on objects? How?

Similar houses in my neighborhood

The Class and Object Concepts Class Concept: A Class is like a blueprint of something, like such as a blue print of a house A class is NOT a house, but it is an “instruction manual” that tells you how to build one if needed Object Concept: The object is the actual thing (e.g., the house) The object is constructed based on the blueprint (a Class) An object is created by using the word “new” House paulosHouse = new House(); House marysHouse = new House();

Create objects is similar to create primitive variables double distance = 10.5; “Variable” type “Variable” name “Variable” value House paulosHouse = new House(); “Object” type “Object” name “Object” value

Similarities when creating objects int number = 3; int daysOfTheWeek = 7; House paulosHouse = new House(); House marysHouse = new House(); int number; number =3; House johnsHouse; johnsHouse = new House();

The main idea You create a class: -Put the functionality you want -Put some data/parameters you want You create objects based on your class: - Home majorHouse = new Home(); - majorHouse.getAddress();

Other Examples of Classes

Humans

Components of a Class Attributes: Channel number Volume level Close-caption off What are the attributes/char acteristics? Operations: Change Channel Increase Volume Turn Close-caption on What are the operations you can perform?

Class Major Components Fields (characteristics): Internal variables (int, double) or objects (wheels on a car) Example: Class Bike Gear Number Cadence Color Methods (what operations you can perform): Functions that uses the internal variables/objects to perform some type of action paintBike(Red) switchToLowerGear() estimateActualVelocity()

Example of a Bike Class Topics to discuss while programming in class: Creating a Bike class with fields and methods Class default and non-default constructors Creating a test program that creates objects of the Bike class Different objects have different attribute values How to call methods for a given object Differences between public and private methods Differences between public and private fields (why is encapsulation important) Getters and setters: Standard names for getters and setters How NetBeans can help you creating them

Visual Aid on Encapsulation

Class Fields Class fields are global variables for the class methods The fields can be public or private For class encapsulation, they are normally private Example: changing bike gears The concept of getters and setters They are normally placed at the top of the class

Class Methods Methods can be private or public Public methods can be accessed from other classes Math.sqrt() is a public method from Math class getters and setters methods Private methods can be only accessed from other methods of the same class Internal calculations or verifications that no one cares besides the class itself

Creating a class What Am I suppose to put inside a class? First imagine the object that will be created by this class What are its main characteristics? What methods would you think it should have?

Questions to ask when creating a class What variables (fields) a rectangle class would have? How could we set the values of those fields? In what ways could I create an object of this class? Rectangle myBedroom = new Rectangle(); Rectangle myBedroom = new Rectangle(5, 7);

The Rectangle Class Class Name Goes Here Public(+) or Private(-) NameField Type Or Method input arguments Method returning type Fields Methods UML diagram for the Rectangle Class

Any Questions? 25