SlideShare a Scribd company logo
CSE240 – Introduction to
Programming Languages
Lecture 05:
Data, Data types and Type Checking
Javier Gonzalez-Sanchez
javiergs@asu.edu
javiergs.engineering.asu.edu
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2
Data | Memory management
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3
Data Types
• A set of primary values allowed and operations on these values.
• Data types define size and format – used to declare variables.
// Java
int (4) (-231 to 231 ) ; -2,147,483,648 to 2,147,483,647
float (4) 3.4e−038 to 3.4e+038
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4
Data Types
• A set of primary values allowed and operations on these values.
• Data types define size and format – used to declare variables.
00000000000000000000000000000011int i = 3;
01000000010000000000000000000000float j = 3.0f;
sign exponent fraction
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5
Type Checking (semantic)
• Ensuring that the types of operands of an operator are legal or
equivalent to the legal type.
"Hello" + 5;
5 > 7 + “Hello”
char x = 60 + 5;
float a = 2.0;
double b = 2.0;
int b = 'a';
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6
Data Types Equivalence (Complex Types)
• Structural equivalence
Two types are equivalent if they have the same set of values and
operations.
• Name equivalence
Two types are equivalent if they have the same name
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 7
Data Types Equivalence (Complex Types)
class Foo {
int data[100];
int count;
}
class Bar {
int data[100];
int count;
}
Foo x, y;
Bar r, s;
// name
// equivalence
// correct
x = y;
r = s;
// incorrect
x = r;
// structural
// equivalence
// correct
x = y;
r = s;
// correct
x = r;
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8
§ Coercion –implicitly convert Type_A to Type_B.
§ Casting: –explicitly convert Type_A to Type_B.
§ Type error.
Type Conversion
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 9
Type Conversion
int x = 5;
// Coercion: Implicit type conversion (int to float)
float f = 3.14f + x;
// Casting: Explicit type conversion (float to int)
int i = (int) f + x;
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 10
A strongly typed language is one in which:
§ each name in a program has a single type associated with it;
§ the type is known at compilation time;
§ type errors are always reported.
StrongWeak
C C++ Java
Strong Type Checking
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 11
A strongly typed language is one in which:
§ each name in a program has a single type associated with it;
§ the type is known at compilation time;
§ type errors are always reported.
Strong Type Checking
Is strong type checking good?
☐ Yes
☐ No
☐ Maybe
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 12
A strongly typed language is one in which:
§ each name in a program has a single type associated with it;
§ the type is known at compilation time;
§ type errors are always reported.
Strong Type Checking
Is strong type checking good?
Trade flexibility for reliability!
Strong type increase reliability,
but it loses the flexibility.
float x = 3.0f; // Java
float x = 3.0; // C
(defvar x 3.0) // LISP
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 13
Homework
Homework 1: Programming with Java
Next lecture: Programming with C
Read Chapter 2
Topics: data types, input/output, pointers, struct type
CSE240 – Introduction to Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Fall 2017
Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.

More Related Content

PDF
201801 CSE240 Lecture 03
PDF
201801 CSE240 Lecture 02
PDF
201505 CSE340 Lecture 04
PDF
201505 CSE340 Lecture 03
PDF
201505 - CSE340 Lecture 01
PDF
201505 CSE340 Lecture 02
PDF
201506 CSE340 Lecture 10
PPTX
201801 CSE240 Lecture 03
201801 CSE240 Lecture 02
201505 CSE340 Lecture 04
201505 CSE340 Lecture 03
201505 - CSE340 Lecture 01
201505 CSE340 Lecture 02
201506 CSE340 Lecture 10

Similar to 201801 CSE240 Lecture 05 (16)

PDF
201801 CSE240 Lecture 07
PDF
201801 CSE240 Lecture 09
PDF
201707 CSE110 Lecture 03
PDF
201707 CSE110 Lecture 20
PDF
Dependent Types for Cryptography Implementations
DOCX
MaciasWinter 2020ENG 107Project #2A Year in Gami.docx
PDF
Compiler Construction | Lecture 7 | Type Checking
PDF
201707 CSE110 Lecture 15
PDF
201801 CSE240 Lecture 11
PDF
201801 CSE240 Lecture 01
PDF
201707 CSE110 Lecture 04
PDF
201801 CSE240 Lecture 06
PDF
Tony clark caise 13-presentation
PPTX
Breakdown of Regression Models for Dissertations
PDF
Avoiding Checkmate: Strategies for Design Systems - Stephanie Rewis - Codemot...
PPTX
Complete Notes on Angular 2 and TypeScript
201801 CSE240 Lecture 07
201801 CSE240 Lecture 09
201707 CSE110 Lecture 03
201707 CSE110 Lecture 20
Dependent Types for Cryptography Implementations
MaciasWinter 2020ENG 107Project #2A Year in Gami.docx
Compiler Construction | Lecture 7 | Type Checking
201707 CSE110 Lecture 15
201801 CSE240 Lecture 11
201801 CSE240 Lecture 01
201707 CSE110 Lecture 04
201801 CSE240 Lecture 06
Tony clark caise 13-presentation
Breakdown of Regression Models for Dissertations
Avoiding Checkmate: Strategies for Design Systems - Stephanie Rewis - Codemot...
Complete Notes on Angular 2 and TypeScript
Ad

More from Javier Gonzalez-Sanchez (20)

PDF
201804 SER332 Lecture 01
PDF
201801 SER332 Lecture 03
PDF
201801 SER332 Lecture 04
PDF
201801 SER332 Lecture 02
PDF
201801 CSE240 Lecture 26
PDF
201801 CSE240 Lecture 25
PDF
201801 CSE240 Lecture 24
PDF
201801 CSE240 Lecture 23
PDF
201801 CSE240 Lecture 22
PDF
201801 CSE240 Lecture 21
PDF
201801 CSE240 Lecture 20
PDF
201801 CSE240 Lecture 19
PDF
201801 CSE240 Lecture 18
PDF
201801 CSE240 Lecture 17
PDF
201801 CSE240 Lecture 16
PDF
201801 CSE240 Lecture 15
PDF
201801 CSE240 Lecture 14
PDF
201801 CSE240 Lecture 13
PDF
201801 CSE240 Lecture 12
PDF
201801 CSE240 Lecture 10
201804 SER332 Lecture 01
201801 SER332 Lecture 03
201801 SER332 Lecture 04
201801 SER332 Lecture 02
201801 CSE240 Lecture 26
201801 CSE240 Lecture 25
201801 CSE240 Lecture 24
201801 CSE240 Lecture 23
201801 CSE240 Lecture 22
201801 CSE240 Lecture 21
201801 CSE240 Lecture 20
201801 CSE240 Lecture 19
201801 CSE240 Lecture 18
201801 CSE240 Lecture 17
201801 CSE240 Lecture 16
201801 CSE240 Lecture 15
201801 CSE240 Lecture 14
201801 CSE240 Lecture 13
201801 CSE240 Lecture 12
201801 CSE240 Lecture 10
Ad

Recently uploaded (20)

PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
System and Network Administration Chapter 2
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Digital Strategies for Manufacturing Companies
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
ai tools demonstartion for schools and inter college
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Navsoft: AI-Powered Business Solutions & Custom Software Development
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
How Creative Agencies Leverage Project Management Software.pdf
Reimagine Home Health with the Power of Agentic AI​
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
System and Network Administration Chapter 2
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
wealthsignaloriginal-com-DS-text-... (1).pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Digital Strategies for Manufacturing Companies
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Operating system designcfffgfgggggggvggggggggg
Which alternative to Crystal Reports is best for small or large businesses.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
How to Migrate SBCGlobal Email to Yahoo Easily
Odoo POS Development Services by CandidRoot Solutions
ai tools demonstartion for schools and inter college
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...

201801 CSE240 Lecture 05

  • 1. CSE240 – Introduction to Programming Languages Lecture 05: Data, Data types and Type Checking Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2 Data | Memory management
  • 3. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3 Data Types • A set of primary values allowed and operations on these values. • Data types define size and format – used to declare variables. // Java int (4) (-231 to 231 ) ; -2,147,483,648 to 2,147,483,647 float (4) 3.4e−038 to 3.4e+038
  • 4. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4 Data Types • A set of primary values allowed and operations on these values. • Data types define size and format – used to declare variables. 00000000000000000000000000000011int i = 3; 01000000010000000000000000000000float j = 3.0f; sign exponent fraction
  • 5. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5 Type Checking (semantic) • Ensuring that the types of operands of an operator are legal or equivalent to the legal type. "Hello" + 5; 5 > 7 + “Hello” char x = 60 + 5; float a = 2.0; double b = 2.0; int b = 'a';
  • 6. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6 Data Types Equivalence (Complex Types) • Structural equivalence Two types are equivalent if they have the same set of values and operations. • Name equivalence Two types are equivalent if they have the same name
  • 7. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 7 Data Types Equivalence (Complex Types) class Foo { int data[100]; int count; } class Bar { int data[100]; int count; } Foo x, y; Bar r, s; // name // equivalence // correct x = y; r = s; // incorrect x = r; // structural // equivalence // correct x = y; r = s; // correct x = r;
  • 8. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8 § Coercion –implicitly convert Type_A to Type_B. § Casting: –explicitly convert Type_A to Type_B. § Type error. Type Conversion
  • 9. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 9 Type Conversion int x = 5; // Coercion: Implicit type conversion (int to float) float f = 3.14f + x; // Casting: Explicit type conversion (float to int) int i = (int) f + x;
  • 10. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 10 A strongly typed language is one in which: § each name in a program has a single type associated with it; § the type is known at compilation time; § type errors are always reported. StrongWeak C C++ Java Strong Type Checking
  • 11. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 11 A strongly typed language is one in which: § each name in a program has a single type associated with it; § the type is known at compilation time; § type errors are always reported. Strong Type Checking Is strong type checking good? ☐ Yes ☐ No ☐ Maybe
  • 12. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 12 A strongly typed language is one in which: § each name in a program has a single type associated with it; § the type is known at compilation time; § type errors are always reported. Strong Type Checking Is strong type checking good? Trade flexibility for reliability! Strong type increase reliability, but it loses the flexibility. float x = 3.0f; // Java float x = 3.0; // C (defvar x 3.0) // LISP
  • 13. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 13 Homework Homework 1: Programming with Java Next lecture: Programming with C Read Chapter 2 Topics: data types, input/output, pointers, struct type
  • 14. CSE240 – Introduction to Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Fall 2017 Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.