08-adt - Abstract Data Types Apr 23, 2009 Data types I We...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Apr 23, 2009 Abstract Data Types
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Data types I We type data--classify it into various categories-- such as int , boolean , String , Applet A data type represents a set of possible values, such as { ... , -2 , -1 , 0 , 1 , 2 , ... }, or { true , false } By typing our variables, we allow the computer to find some of our errors Some operations only make sense when applied to certain kinds of data--multiplication, searching Typing simplifies internal representation A String requires more and different storage than a boolean
Background image of page 2
3 Data types II A data type is characterized by: a set of values a data representation, which is common to all these values, and a set of operations, which can be applied uniformly to all these values
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Primitive types in Java Java provides eight primitive types: boolean char , byte , short , int , long float , double Each primitive type has a set of values a data representation a set of operations These are “set in stone”—there is nothing the programmer can do to change anything about them
Background image of page 4
5 Primitive types as data types Type  Values Representation Operations boolean  true, false Single byte &&, ||, ! char, byte, short, int, long Integers of varying sizes Two’s complement +, -, *, /, others float, double Floating point numbers of varying sizes and precisions Two’s complement with exponent and mantissa +, -, *, /, others
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Classes in Java A class is a data type The possible values of a class are called objects The data representation is a reference (pointer) to a block of storage The structure of this block is defined by the fields (both inherited and immediate) of the class The operations on the objects are called methods Many classes are defined in Java’s packages You can (and must) define your own, as well
Background image of page 6
7 Methods and operators An operator typically Is written with non-alphabetic characters: + , * , ++ , += , , etc. Is written as prefix, infix, or postfix: -x , x+y , x++ Has only one or two arguments, or operands A method (or function ) typically Is written with letters, and its arguments are enclosed in parentheses: toString() , Math.abs(n) Has any (predetermined) number of arguments
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Methods are operators The differences between methods and operations are only syntactic differences, not fundamental ones Many languages (not including Java) let you define new operators, that is, new syntax When you define a new class and its methods, you are, fundamentally, defining a new data type and its operators Suppose a language defines the operator @ to mean “times 3 plus 1”; for example @7 is 22 Would you consider this a good operation to have in the language? What does this suggest about defining classes and their methods?
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 31

08-adt - Abstract Data Types Apr 23, 2009 Data types I We...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online