CSCE 121- Spring 2016 J. Michael Moore

Slides:



Advertisements
Similar presentations
Type Conversion. C provides two methods of changing the type of an expression: Type conversion (done implicitly) Cast expressions (done explicitly) Examples.
Advertisements

L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Copyright © by Curt Hill Expressions and Assignment Statements Part 2.
Type Checking.
Numeric literals and named constants. Numeric literals Numeric literal: Example: A numeric literal is a constant value that appears in a Java program.
Constants and Variables  Memory cells used in program  Called constants and variables  Identifiers for constants and variables should be declared before.
Review Question What kind error is it when I try to multiply a number in a program by 1000 and store in a variable, but the variable is too small for the.
CS102 Data Types in Java CS 102 Java’s Central Casting.
Java Intro. Strings “This is a string.” –Enclosed in double quotes “This is “ + “another “ + “string” –+ concatenates strings “This is “ “ string”
CS150 Introduction to Computer Science 1
1 CSC 1401 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
1 Chapter 2: Elementary Programming Shahriar Hossain.
Using Java's Math & Scanner class. Java's Mathematical functions (methods) (1)
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Floating point variables of different lengths. Trade-off: accuracy vs. memory space Recall that the computer can combine adjacent bytes in the RAM memory.
Copyright © 2003 Pearson Education, Inc. Slide 2-1 Problem Solving with Java™ Second Edition Elliot Koffman and Ursula Wolz Copyright © 2003 Pearson Education,
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Type Equivalence Rules Ada –Strict name equivalence except for almost everything Unique array constructors give rise to unique types Subtypes can create.
Introduction to Java CSIS 3701: Advanced Object Oriented Programming.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 3: Objects, Types, and Values 1 Based on slides.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3A Integral Data (Concepts)
Defining and Converting Data Copyright Kip Irvine, 2003 Last Update: 11/4/2003.
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Looping and Counting Lecture 3 Hartmut Kaiser
Programming with Visual C++: Concepts and Projects Chapter 3A: Integral Data (Concepts)
Java Programming, Second Edition Chapter Two Using Data Within a Program.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Data Types (3) 1 Programming Languages – Principles and Practice by Kenneth C Louden.
LESSON 5 – Assignment Statements JAVA PROGRAMMING.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Expressions Version Topics Arithmetic expressions Conversions Operator precedence String class 2.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Dr. M. Al-Mulhem Introduction 1 Chapter 6 Type Systems.
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.
7-1/27 Chapter 7 Expressions and Assignment Statements Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean.
April 13, 1998CS102-02Lecture 3-1 Data Types in Java CS Lecture 3-1 Java’s Central Casting.
7.2 Arithmetic Expressions
Chapter 7: Expressions and Assignment Statements
Chapter 2 Elementary Programming
Lecture 3: Operators, Expressions and Type Conversion
Chapter 7: Expressions and Assignment Statements
Multiple variables can be created in one declaration
Type Conversion, Constants, and the String Object
Data Types.
Chapter 2.
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Programming Goals CSCE 121 J. Michael Moore.
Conversions of the type of the value of an expression
Explicit and Implicit Type Changes
Lecture 3 Expressions Richard Gesick.
Lecture 8.
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
Numerical Data Types.
Destructor CSCE 121 J. Michael Moore.
Data Types and Expressions
Java’s Central Casting
Object-Oriented Programming Part 3 Bank Account Embezzling
Type Conversion It is a procedure of converting one data type values into another data type In C programming language we are having two types of type conversion.
B=15 b = a + fun(a); a=10 fun(a)=5.
Casting Converting types.
CSCE 206 Lab Structured Programming in C
Data Types and Expressions
Data Types and Expressions
Presentation transcript:

CSCE 121- Spring 2016 J. Michael Moore Type Safety CSCE 121- Spring 2016 J. Michael Moore

Type Safety Every object will be used only according to its type Variable is only used after it is initialized Only operations defined for the variables type will be applied Every operation defined for a variable results in a valid value IDEAL! Static type safety Compiler finds all type safety violations. IDEAL! Dynamic type safety Run-time system finds all safety violations not found by compiler

Type Safety Important! C++ not completely statically type safe Try hard not to violate Compiler can help C++ not completely statically type safe Most languages are not Reduces ability to express ideas C++ is not completely dynamically type safe Many languages are, but… Being dynamically type safe can cause performance problems Most things in class will be type safe

Type Conversion Implicit conversion Explicit conversion One type automatically converted to another type BEWARE!!! Explicit conversion While not recommended almost everything can be cast

Mostly Safe Conversions “Widening” conversions long int x = 112233445566778899; double y = x; // loss of precision char b = 'k'; int a = b; // a is numerical representation of b, but no loss of information

Unsafe Conversions “Narrowing” conversions double x = 2.7; int y = x; // truncation int a = 1000; char b = a; How to ‘outlaw’ unsafe conversions? See Stroustrup book. (Possible test question…)