Java. Representing Data. Representing data. Primitive data types

Similar documents
2. The object-oriented paradigm

2. The object-oriented paradigm!

Java. Error, Exception, and Event Handling. Error, exception and event handling. Error and exception handling in Java

PIC 20A Number, Autoboxing, and Unboxing

Java Object Oriented Design. CSC207 Fall 2014

Chapter 6 Introduction to Defining Classes

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

CS260 Intro to Java & Android 03.Java Language Basics

Use the scantron sheet to enter the answer to questions (pages 1-6)

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

The Final Exam Paper. Duration: 2 hours Reading: 15 minutes Total marks: 65 Hurdle: 32.5

8359 Object-oriented Programming with Java, Part 2. Stephen Pipes IBM Hursley Park Labs, United Kingdom

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Introduction to Programming Using Java (98-388)

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

COS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Object Oriented Programming. Java-Lecture 11 Polymorphism

Computational Expression

Objects and Classes Lecture 2

Extending Classes (contd.) (Chapter 15) Questions:

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

Lecture 7: Classes and Objects CS2301

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Lecture 1: Object Oriented Programming. Muhammad Hafeez Javed

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Programming overview

PROGRAMMING FUNDAMENTALS

Inheritance and Polymorphism

Java Basic Datatypees

Creating Java Programs with Greenfoot

JAVA MOCK TEST JAVA MOCK TEST II

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

COP 3330 Final Exam Review

CSC Java Programming, Fall Java Data Types and Control Constructs

ITI Introduction to Computing II

Object typing and subtypes

Pascal: operations on basic data structures (selection) (I) 2.3 Accessing and manipulating data

C12a: The Object Superclass and Selected Methods

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

ITI Introduction to Computing II

Exam 1. CSC 121 Spring Lecturer: Howard Rosenthal. March 1, 2017

Lec 3. Compilers, Debugging, Hello World, and Variables

Inheritance (cont.) Inheritance. Hierarchy of Classes. Inheritance (cont.)

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Fundamentals of Programming Data Types & Methods

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Object-Oriented Programming Concepts

Many strategies have been developed for this, but they often produce surprising results.

Special Topics: Programming Languages

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

type conversion polymorphism (intro only) Class class

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

VARIABLES AND TYPES CITS1001

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Java Identifiers, Data Types & Variables

OBJECT ORİENTATİON ENCAPSULATİON

Inheritance, Polymorphism, and Interfaces

CS313D: ADVANCED PROGRAMMING LANGUAGE

Programming Languages and Techniques (CIS120)

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Inheritance. Quick Review of Last Lecture. November 12, Passing Arguments. Passing Arguments. Variable Assignment Revisited

Java Overview An introduction to the Java Programming Language

Primitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline

Simple Component Writer's Guide

In Java, to create a class named "B" as a subclass of a class named "A", you would write

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation

CSE 431S Type Checking. Washington University Spring 2013

Polymorphism and Interfaces. CGS 3416 Spring 2018

Derived and abstract data types. TDT4205 Lecture 15

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

1 Shyam sir JAVA Notes

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Java Primer. CITS2200 Data Structures and Algorithms. Topic 2

ESc101 : Fundamental of Computing

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Distributed Systems Recitation 1. Tamim Jabban

Programming Languages: OO Paradigm, Polymorhism and Class Members

Software Architecture (Lesson 2) Object-Oriented Paradigm (1)

CIS 110: Introduction to computer programming

Programming in the Large II: Objects and Classes (Part 2)

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Java Primer 1: Types, Classes and Operators

c) And last but not least, there are javadoc comments. See Weiss.

Programming with Java

Transcription:

Computer Science Representing Data Java 02/23/2010 CPSC 449 161 Unless otherwise noted, all artwork and illustrations by either Rob Kremer or Jörg Denzinger (course instructors) Representing data Manipulating data is key in this paradigm In order to be manipulated, data has to be represented There can be many different types of data And data can be combined to form more complex data Terminology is a little bit unclear: data structure vs data type vs abstract data type But in general we describe sets of elements that have a certain structure or feature Often we associate with (abstract) data types additional axioms that all elements fulfill 162 Primitive data types Object-oriented programming languages usually have the following primitive data types: All kinds of numbers A Boolean type Characters All elements of a primitive data type are known to the compiler and we will see later that the ways to manipulate them are also already predefined 163

Java: primitive data types (I) Build-in data types for boolean : {true,false Examples: true, false char : Unicode character (16 bits) Examples: a, d, &, %, 5, 0, ö byte : signed integer of 8 bits: [-128,127] Examples: -5, 4, 127 short : signed integer of 16 bits: [-32768,32767] Examples: -5, 4, 127, 30000 164 Java: primitive data types (II) int : integer: [-2147483648, 2147483647] Examples: -5, 4, 127, 30000, -10000000 long : integer: [-9223372036854775808, 9223372036854775807] Examples: -5, 4, 127, 30000, -100000000000000000 float : floating point number 32 bits (IEEE 754) [±1.40239846E-45, ±3.40282347E+38] double : floating point number 64 bits (IEEE 754) [±4.94065645841246544E-324, ±1.79769313486231570E+308] 165 Java: building more complex data structures Java has two general ways of defining complex structures Generating classes that define objects Defining arrays of objects By defining class hierarchies, one class can inherit parts from another class 166

A class is a collection of data and methods that operate on this data. Classes (I) The elements of a class are called objects. We also refer to an object as an instance of a class In this section, we will only cover the definition part of classes Abstract classes and interfaces allow for defining parameterized data types 167 Example: public class Circle { public double x,y; public double r; Visibility Class name public double circumference() { method body public double area() { method body Classes (II) Defines data, using already defined data structures Methods associated with class 168 Subclass, inheritance Defining a subclass: Superclass public class GraphicCircle extends Circle { public Color outline, fill; subclass superclass every object of subclass is also object of superclass Every object of subclass has all the data types defined in superclass inheritance 169

Interface Interfaces are "empty shells" that define requirements on real classes that have to be met by real classes implementing an interface public interface Drawable { public void setcolor (Color c); public void setposition (double x, double y); public void draw(drawwindow dw); public class Car implements Drawable {. 170 Abstract classes Abstract classes also are shells that need to be filled in order to produce a real data structure with elements, but this "filling" is achieved by defining subclasses of it public abstract class shape { public abstract void draw(); public setposition (int x, int y) { 171 Interface vs. abstract class Both allow for defining parameterized data structures just by being used in the definition of other classes Both do not contain any elements as long as additional steps (implementation, subclass generation) are not performed Classes can extend only one abstract class but implement many interfaces Different restrictions with regard to methods (see later) 172

Arrays Are dynamically generated without having to define them as data structures Button[] buttons = new Button[10]; int[] lookup_table = {1,2,4,8,18,32; byte[][] TwoDimArray = new byte[256] [16] Since they are implicitly defined by defining a variable of the array type, an initial element can be assigned to the new variable 173 Complex data structures in object-oriented programming Objects (resp. classes) as centre point Class hierarchies partially mimic data structures that are build Representing objects in memory is outside of the influence of the programmer Close connection between data structures and methods that work on them Identifying type (class) of a data object is responsibility of run-time system usually limitations on the class hierarchy to stay decidable 174