COMPUTER 2430 Object Oriented Programming and Data Structures I

Slides:



Advertisements
Similar presentations
Programming Methodology (1). Implementing Methods main.
Advertisements

Based on Java Software Development, 5th Ed. By Lewis &Loftus
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Class Scope class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa;
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
Web Application Development Slides Credit Umair Javed LUMS.
Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
C++ Classes & Data Abstraction
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Object Oriented Programming in Java. Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Lecture 9 Concepts of Programming Languages
Like our natural language. Designed to facilitate the expression and communication ideas between people and computer Like our natural language. Designed.
Introduction to Object-oriented programming and software development Lecture 1.
Object Oriented Programming Concepts OOP – reasoning about a program as a set of objects rather than as a set of actions Object – a programming entity.
Object Oriented Programming: Java Edition By: Samuel Robinson.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
P Chapter 2 introduces Object Oriented Programming. p OOP is a relatively new approach to programming which supports the creation of new data types and.
1 Writing a Good Program 8. Elementary Data Structure.
Prepared by: Elsy Torres Shajida Berry Siobhan Westby.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Classes Structured Programming 256 Chapter 8 Classes - Part I OOP & Class Object Terminology File Management.
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Class Method Read class Student { private: string id; string firstName, lastName; float gpa; public: // Will the method change any data members? // Yes!
CS 116 Lecture 1 John Korah Contains content provided by George Koutsogiannakis & Matt Bauer.
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.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
Object-Oriented Programming Using C++ Third Edition Chapter 7 Using Classes.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 3- Introduction to Object Oriented Programming concepts Topic 3.1 Fundamental Concepts.
COMPUTER 2430 Object Oriented Programming and Data Structures I
OOP: Encapsulation &Abstraction
Objects as a programming concept
Programming Logic and Design Seventh Edition
Yanal Alahmad Java Workshop Yanal Alahmad
Object-Oriented Programming Using C++
Lecture 9 Concepts of Programming Languages
COMPUTER 2430 Object Oriented Programming and Data Structures I
CS 1430: Programming in C++.
Student Data Score First Name Last Name ID GPA DOB Phone ...
CSC 253 Lecture 8.
CS 1430: Programming in C++.
CSC 253 Lecture 8.
CS 1430: Programming in C++.
null, true, and false are also reserved.
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
Object oriented vs procedural programming
COMPUTER 2430 Object Oriented Programming and Data Structures I
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade
COMPUTER 2430 Object Oriented Programming and Data Structures I
Simple Classes in Java CSCI 392 Classes – Part 1.
CPS120: Introduction to Computer Science
Introduction to Data Structure
CS 2430 Object Oriented Programming and Data Structures I
Object-Oriented Programming Using C++
Object Oriented Programming in java
Web Design & Development Lecture 4
COMPUTER 2430 Object Oriented Programming and Data Structures I
CPS120: Introduction to Computer Science
Lecture 9 Concepts of Programming Languages
Presentation transcript:

COMPUTER 2430 Object Oriented Programming and Data Structures I Day1 on Thursday, before lab1

Java Class Everything in Java is inside a class Class Data with functions on the data Other features Fields: Data items inside a class Methods: Functions inside a class main(): test bed function

Lab0 public class IntegerList { private final int MAX_SIZE = 50; private int intArray[] = new int[MAX_SIZE]; private int valCount = 0; public boolean addValue ( int intValue ) . . . public int find( int target ) public void print() public static void main( String [] args ) IntegersList list = new IntegersList(); int inputValue, target, index; Scanner sc = new Scanner(System.in); inputValue = sc.nextInt(); list.addValue(inputValue); }

Procedural Programming in C++ const int MAX_SIZE = 50; // Function prototypes boolean addValue ( int[] s[], int& size, int xValue ); int find( const int[] s[], int size, int target ); void print(const int[] s[], int size); int main() { int intArray[] = int[MAX_SIZE]; int valCount = 0, xVal; cin >> xVal; if ( addValue( intArray, valCount, xVal) ) cout << “Value ” << xVal << “ is added.”; else cout << “Value ” << xVal << “ is not added.”; . . . return 0; }

Features of OOP Abstraction Data Encapsulation (Data Hiding) Inheritance Polymorphism

Abstraction Abstract Data Type (ADT) Mathematical model Data plus operations on that data Abstraction Java class to implement ADT

Data Encapsulation Private data fields Public methods The data can only be manipulated via methods. Methods Implementation Hiding the details (users don’t know) Change it when needed Implementer and User

Data Encapsulation The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature Encapsulation gives maintainability, flexibility and extensibility to our code.

Features of OOP Abstraction Data Encapsulation (Data Hiding) (Inheritance) (Polymorphism)

Lab0 public class IntegerList { private final int MAX_SIZE = 10; private int intArray[] = new int[MAX_SIZE]; private int valCount = 0; public boolean addValue ( int intValue ) . . . public int find( int target ) public void print() public static void main( String [] args ) IntegersList list = new IntegersList(); int inputValue, target, index; Scanner sc = new Scanner(System.in); inputValue = sc.nextInt(); list.addValue(inputValue); }

Creating Java Classes in NetBeans Creating a project in NetBeans Copying files Adding new class files to a project File / New File Category: Java File Type: Java class Class Name Location

public class Student { private String firstName, lastName; private float gpa; public boolean setGPA (float value) if ( value < 0 || value > 4.0 ) return false; gpa = value; return true; } public float getGPA() return gpa; ...

Private vs. Public // Most fields are private private String firstName, lastName; private float gpa; // Most methods are public public boolean setGPA (float value) ... public float getGPA()

// A variable of class Student // can reference a Student object Student s; // Class instance (object) is created in memory // Variable s points to the object s = new Student(); s.setGPA(3.0F); // The default is double System.out.println(“GPA: ” + s.getGPA()); // float is converted to string and // appended (+) to “GPA: ”

// A variable of type class Student // Can reference a Student object Student s; // Class instance (object) is created in memory // Variable s points to the object // s = new Student(); s.setGPA(3.0F); System.out.println(“GPA: ” + s.getGPA()); // Will it work? No object!

Variables and Memory num1 num2 int num1, num2; num1 = 4; The same for all non-class data types In C++ and Java 4 5 Need to initialize!

References and Objects int num1, num2; num1 = 4; num2 = num1 + 1; Student s; s is a reference to class Student, or a pointer to a Student object. It keeps the addresses where the object is stored s = new Student(); Objects are allocated in Heap memory. Variables are in Stack. num1 num2 4 5 s gpa lastName firstName

Java (OOP) Programming Create classes Declare class variables Create class instances (objects) Call methods

Due 10 pm, Friday, September 15 Prog0: 15 Points Due 10 pm, Friday, September 15

Building/Labs Access Open: 7 am – 5 pm Using your card: 5 pm – 11 pm Closed: 11 pm – 7 am

Lab0 Due 10 pm, Friday, September 8 Zero differences! Any questions?