Chapter 2 Data abstraction: introductory concepts.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
23-Apr-15 Abstract Data Types. 2 Data types I We type data--classify it into various categories-- such as int, boolean, String, Applet A data type represents.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
Data Types and Expressions
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Variables Pepper. Variable A variable –box –holds a certain type of value –value inside the box can change Example –A = 2B+1 –Slope = change in y / change.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
CMT Programming Software Applications
Java Syntax Primitive data types Operators Control statements.
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
String Escape Sequences
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
Object Oriented Software Development
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Object Oriented Design: Identifying Objects
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3A Integral Data (Concepts)
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Primitive Variables.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Object-Oriented Programming •Object-Oriented Programming (OOP) allows you to create your program based upon modeling objects.  Your program’s properties.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Copyright Curt Hill Variables What are they? Why do we need them?
Java Programming, Second Edition Chapter Two Using Data Within a Program.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Chapter One Lesson Three DATA TYPES ©
1 MATERI PENDUKUNG TIPE DATA Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
Chapter 3 AS3 Programming. Introduction Algorithms + data structure =programs Why this formula relevant to application programs created in flash? The.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 06 – Java Datatypes Webpage:
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Chapter 4 – Fundamental Data Types
Documentation Need to have documentation in all programs
Lecture2.
Principles of Computer Programming (using Java) Chapter 2, Part 1
Unit-2 Objects and Classes
Introduction to Abstract Data Types
Computers & Programming Languages
Introduction to Java, and DrJava part 1
Introduction to Primitive Data types
Object-Oriented Programming
Chapter 2: Java Fundamentals
Storing Information Each memory cell stores a set number of bits (usually 8 bits, or one byte) (byte addressable)
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Introduction to Primitives
Introduction to Primitives
Chapter 3 Introduction to Classes, Objects Methods and Strings
Variables and Constants
Introduction to Primitive Data types
Presentation transcript:

Chapter 2 Data abstraction: introductory concepts

This chapter discusses n How to build components of a software system. n Foundational notions of value/type and object/class. n Java primitives. n Reference values.

Values and types n value: a fundamental pieces of information that can be manipulated in a program. n type: a set of related values along with the operations that can be performed with them.

Values n 2 kinds of values: u simple (atomic): integers, characters u composite: date(day, month, year), string(several characters) n Values are abstractions used to model various aspects of a problem.

Types n Values grouped together according to how we use them and what operations we perform on them. Example:Integers use +,-,, etc.

Primitives n Built-in types. Java primitives: byte, short, int, long, float, double, char, and boolean. n Java has no built-in composite primitives.

Numbers n Integers:  byte (1 byte)  short (2 bytes)  int (4 bytes)  long (8 bytes) n Used for counting (whole numbers).

Numbers (cont.) n Floating point: u float (4 bytes) u double (8 bytes) n Used to represent things we measure (anything with a decimal point). n The computer’s representation may not be exact.

Characters char includes upper case and lower case letters, digits, punctuation marks, and other special characters. n Characters contained in the Unicode character set. n Used for input/output.

Boolean Only 2 values: true or false.

Objects n The fundamental abstractions from which we build software systems. n Designed to support the functionality of the system. n Responsible for performing specific tasks.

Queries and properties n Furnish relevant information about what the object represents. n properties: characteristics about which the object provides information. n Each property has an associated value. n queries: requests for information concerning properties.

Commands and state n The values of properties can change at any time. n state: the set of an object’s properties and associated values at any given time.

Commands and state (cont.) n Commands instruct the object to perform some action which often results in the object changing state. n At any given time, a particular value is associated with each property of an object.

EXAMPLE SYSTEM USING OBJECTS University registration System What are the objects? StudentCourse

Queries: Student Course What is your name? How many credit hours? What are you enrolled in? Have you paid your fees? What is the course number? How many credit hours is it? What room is the course held in? Properties: name address ssn credit hours major year in school course number section professor room time/day total seats seats taken

States: StudentCourse Commands: add a course drop a course change the address determine fees change the room number set professor calculate the number of seats available

States and commands

Designing with objects n What are the objects? n What features should these objects have?

Particular object responsibility n What must an object know? u The properties of the entity the object is modeling, and u About other objects with which it needs to cooperate.

Particular object responsibility (cont.) n What must an object do? u Compute particular values. u Perform actions that modify state. u Create and initialize other objects. u Control and coordinate the activities of other objects.

Particular object responsibility (cont.) n Asking what an object knows: object queries. n Asking what an object does: object commands and queries.

Knows: StudentCourse Does(Commands): Student’s name Student’s address Student’s social security number Number of credit hours enrolled Course’s title Course’s section Course’s professor Course’s time Course’s room number Add a course to the student’s schedule Drop a course from the student’s schedule Calculate student’s fees Change room assignment Add a student to the roll Print a class roll Decide if the class is full

Does(Queries): StudentCourse Supplies a student’s name. Query: What is the student’s name? Supplies a student’s current classes. Supplies the student’s address Supplies the Professor of the class. Query: Who is teaching this class? Supplies the number of student’s enrolled in the class.

Ticket dispenser example n Queries: u How many tickets have we sold? u How many tickets are left? n Properties: u Next ticket number u Tickets left

Ticket dispenser example (cont.) States and Commands

Chess example n Queries: u Where is a certain piece? u What color is a player’s pieces? u Is a player in check? n Properties: u Player’s color u Piece’s position

Chess example (cont.) States

Chess example (cont.) n Commands: u Move a piece? u Change whose turn it is?

Classes n An object is an instance of a class. n A class specifies the features of a group of similar objects. n Two objects from the same class will have the same set of queries and commands, but usually contain different values.

Objects as properties of objects n A relation associates two or more objects in a specific, well defined way. n Relations define how objects interact to solve a problem. n An object’s property can be a reference to another object.

Reference Examples

Reference n A value that denotes an object n null reference: refers to no object.

We’ve covered n Introduction of fundamental notions of values and objects. n Java provides:  Integer types ( byte, short, int, long )  Real or floating type ( float, double )  Character type ( char )  Boolean type ( boolean-- true/false )

Glossary

Glossary (cont.)