Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.

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

DATA TYPES, VARIABLES, ARITHMETIC. Variables A variable is a “named container” that holds a value. A name for a spot in the computer’s memory This value.
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.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double,
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Chapter 2 Data Types, Declarations, and Displays
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.
L EC. 02: D ATA T YPES AND O PERATORS (1/2) Fall Java Programming.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
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.
Imperative Programming Part One. 2 Overview Outline the characteristics of imperative languages Discuss other features of imperative languages that are.
CIS Computer Programming Logic
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
C Tokens Identifiers Keywords Constants Operators Special symbols.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
 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.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Data Types and Operations On Data Objective To understand what data types are The need to study data types To differentiate between primitive types and.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Java Data Types.
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
COMP Primitive and Class Types Yi Hong May 14, 2015.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CSI 3125, Preliminaries, page 1 Data Type, Variables.
1.2 Primitive Data Types and Variables
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
 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.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Selenium WebDriver Web Test Tool Training
Java package classes Java package classes.
2. Understanding VB Variables
IDENTIFIERS CSC 111.
Introduction to Abstract Data Types
Introduction to Data Structure
Java Basics Data Types in Java.
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

Lec 6 Data types

Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together with a set of operations for creating and manipulating them DT= class of Dos+ Set of Operations

There are two types of operations 1-primitive Operations: They are specified as part of the language definition. 2-Programmer - defined Operations:- They are defined in form of subprogram or method declarations as part of class definitions. An Operation is a mathematical function for a given input argument it has a well-defined and uniquely determined result.

The domain of operation is the set of possible input argument which it is defined. The rang of Operation is set of possible results that it may produce. The action of the Operation defines the result produced for any given set of arguments. The algorithm is a Common method for specifying the action of an Operation.

The Basic elements of a specification of a DT are: 1-The attributes that distinguish data object of that type. 2- The values that Dos of that type may have. 3- The Operations that define the possible manipulations of Dos of that type. Example // The Specification of an array data type Attributes: the number of dimensions, the subscript rang for each dimension. Values: The set of numbers that from valid values for array components. Operations: include subscripting to select in divided array compounds and possibly. Other operations to create arrays, to change their shape, to access attributes such as upper and lower bounds of subscripts, and perform arithmetic on pairs of arrays.

The basic elements of the implementation of a data type 1- The storage representation that is used to represent the Dos of the DT in the computer during program execution. 2- The algorithms or procedures that manipulate the chosen storage representation of the Dos.

Declarations -The name of DO. -The type of DO. -The life time of DO. -The information about operations. Declaration is a program statement that serves to communicate to the language translator information about the name and type of Dos needed during program execution. Purposes of Declerations 1-choice of storage representation. 2-Storage management (life time) 3-Polymorphic operations (the same Symbol for multi Operation).

Primitive Data Types Reference/Object Data Types 1. Primitive Data Types: There are eight primitive data types supported by Java. Primitive data types are predefined by the language and named by a keyword.

byte: Byte data type is an 8-bit signed two's complement integer. Minimum value is -128 (-2^7) Maximum value is 127 (inclusive)(2^7 -1) Default value is 0 Byte data type is used to save space in large arrays, mainly in place of integers, since a byte is four times smaller than an int. Example: byte a = 100, byte b = -50

short: Short data type is a 16-bit signed two's complement integer. Minimum value is -32,768 (-2^15) Maximum value is 32,767 (inclusive) (2^15 -1) Short data type can also be used to save memory as byte data type. A short is 2 times smaller than an int Default value is 0. Example: short s = 10000, short r =

int: Int data type is a 32-bit signed two's complement integer. Minimum value is - 2,147,483,648.(-2^31) Maximum value is 2,147,483,647(inclusive).(2^31 -1) Int is generally used as the default data type for integral values unless there is a concern about memory. The default value is 0. Example : int a = , int b = long : Long data type is a 64-bit signed two's complement integer. Minimum value is -9,223,372,036,854,775,808.(-2^63) Maximum value is 9,223,372,036,854,775,807 (inclusive). (2^63 - 1) T his type is used when a wider range than int is needed. Default value is 0L. Example: long a = L, int b = L

float: Float data type is a sing le-precision 32-bit IEEE 754 floating point. Float is mainly used to save memory in large arrays of floating point numbers. Default value is 0.0f. Float data type is never used for precise values such as currency. Example: float f1 = 234.5f double: double data type is a double-precision 64-bit IEEE 754 floating point. This data type is generally used as the default data type for decimal values, generally the default choice. Double data type should never be used for precise values such as currency. Default value is 0.0d. Example : double d1 = 123.4

boolean: Boolean data type represents one bit of information. There are only two possible values: true and false. This data type is used for simple flags that track true/false conditions. Default value is false. Example : boolean one = true char: Char data type is a sing le 16-bit Unicode character. Minimum value is '\u0000' (or 0). Maximum value is '\uffff' (or 65,535 inclusive). Char data type is used to store any character. Example : char letterA ='A'

. Reference Data Types: Reference variables are created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed. For example,Employee,

Java Literals: A literal is a source code representation of a fixed value. They are represented directly in the code without anycomputation.Literals can be assigned to any primitive type variable. For example: Byte a = 68; char a = 'A' int decimal = 100; int octal = 0144; int hexa= 0x64;

String literals in Java are specified like they are in most other languages by enclosing a sequence of charactersbetween a pair of double quotes. Examples of string literals are: "Hello World" "two\nlines" "\"This is in quotes\"" String and char types of literals can contain any Unicode characters. For example: Char a = '\u0001'; String a = "\u0001";

Java provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

Example: The following code snippets are examples of this syntax: Creating Arrays: You can create an array by using the new operator with the following syntax:

The above statement does two things: It creates an array using new data Type[arraySize]; It assigns the reference of the newly created array to the variable arrayRefVar.

Example: Following statement declares an array variable, myList, creates an array of 10 elements of double type and assigns its reference to myList:

Example: Here is a complete example of showing how to create, initialize and process arrays :

Passing Arrays to Methods: Just as you can pass primitive type values to methods, you can also pass arrays to methods. For example, the following method displays the elements in an int array: You can invoke it by passing an array. For example, the following statement invokes the printArray method to display 3, 1, 2, 6, 4, and 2:

Returning an Array from a Method: A method may also return an array. For example, the method shown below returns an array that is the reversal of another array: