COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 10 – Programming with Java Datatypes Type Casting.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 09 – Programming with Java Datatypes and Flow Control.
Expressions ► An expression can be a single variable, or can include a series of variables. If an expression includes multiple variables they are combined.
Introduction to Computers and Programming Lecture 7:
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
CS102 Data Types in Java CS 102 Java’s Central Casting.
COMS W1004 Introduction to Computer Science June 1, 2009.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
March 2005Java Programming1. March 2005Java Programming2 Why Java? Platform independence Object Oriented design Run-time checks (fewer bugs) Exception.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Java Building Elements Lecture 2 Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University
Java Fundamentals Expanded SE1021 Dr. Mark L. Hornick 1.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 13 – Having Fun with Arrays in Java Webpage:
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
COMP 116: Introduction to Scientific Programming Lecture 28: Data types.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3A Integral Data (Concepts)
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Final Exam Review Closed book Closed laptop One sheet of notes permitted SE-0010 Dr. Mark L. Hornick 1.
JAVA 0. HAFTA Algorithms FOURTH EDITION Robert Sedgewick and Kevin Wayne Princeton University.
CISC105 – General Computer Science Class 9 – 07/03/2006.
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 35 – Overview of Java Web Programming Webpage:
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Introduction to Programming
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Programming with Visual C++: Concepts and Projects Chapter 3A: Integral Data (Concepts)
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 11 – How to Get Started on Assignment #2 Webpage:
Java Programming, Second Edition Chapter Two Using Data Within a Program.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Lecture 9.4 Java Interfaces. © 2006 Pearson Addison-Wesley. All rights reserved Java does not support multiple inheritance. Interface Characteristics...
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
“Great leaders are never satisfied with current levels of performance. They are restlessly driven by possibilities and potential achievements.” – Donna.
 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
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 20 – Inheritance and Polymorphism in Java Webpage:
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 06 – Java Datatypes Webpage:
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 39 – Command Line Args & Recursion Webpage:
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
100e Hosted by vhs © Don Link, Indian Creek School, 2004 Jeopardy.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 14 – How to Complete Assignment 2, Part III Webpage:
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 08 – Hand-On Work: Assignment 1, Part III Webpage:
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.
April 13, 1998CS102-02Lecture 3-1 Data Types in Java CS Lecture 3-1 Java’s Central Casting.
COP2800 – Computer Programming Using JAVA
Chapter 4 – Fundamental Data Types
Sachin Malhotra Saurabh Choudhary
Lecture 2: Data Types, Variables, Operators, and Expressions
Chapter 2.
Conversions of the type of the value of an expression
Explicit and Implicit Type Changes
Unit-2 Objects and Classes
Java Programming Language
Java Basics Data Types in Java.
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.
Chapter 2 Primitive Data Types and Operations
Presentation transcript:

COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 10 – Programming with Java Datatypes Type Casting and Type Conversion Webpage:

COP2800 – Programming in JAVA Course Objectives – Basic Knowledge of Computers & Programming – Specific Knowledge of JAVA Programming – Practical Programming Projects Build Skills Today’s Class – What is Type Casting? – Examples of Type Conversion via Type Casting – Look-Ahead at Assignment #2 Filtering Numbers

Review: Java Program Structure HIGH-LEVEL VIEW JAVA Units: -Packages -Classes (Instances) -Methods -Instructions -Variables PICTURE CREDIT:

Review: Java Package Structure PICTURE CREDIT:

New: Java Typecasting A typecast in Java: One object reference can be type cast into another object reference. The cast can be to its own class type or to one of its subclass or superclass types or interfaces. There are compile-time rules and runtime rules for casting in Java

Java Typecasting (cont’d) A typecast in Java can implement implicit type conversion: Type conversion makes one datatype into another datatype.  float  double  double  string  int  long  byte  short

Java Typecasting (cont’d) Correct: (float to double) float x = ; doubley = x ; # 32 bits to 64 bits Incorrect: (float to short) float x = -1.23e-7; shorty = x ; # 32 bits to 16 bits

Java Typecasting (cont’d) TYPE CONVERSION HIERARCHY: Type Hierarchy: integers: byte < short < int < long decimals:float < double

Java Type Conversion (cont’d) A float (single-precision floating-point number) is a positive or negative decimal number specified by float descriptor (reserved word) Example: float x = ; Can we convert an int to a float? int x = 6; float y = x; System.out.println(y); Output = 6.0  “.0” denotes floating-point

Java Type Conversion (cont’d) Explicit Type Conversion: to-String //Double to String String s=Double.toString(doublevalue); //Long to String String s=Long.toString(longvalue); //Float to String String s=Float.toString(floatvalue);

Java Type Conversion (cont’d) Explicit Type Conversion: to-Int //String to Integer String s=”7”; int i=Integer.valueOf(s).intValue(); - or - int i = Integer.parseInt(s); //Character to Integer char c = ’9’; int i =(char)c;

Java Type Conversion (cont’d) Explicit Type Conversion: from-String [String s;] //String to Double double a=Double.valueOf(s).doubleValue(); //String to Long long b=Long.valueOf(s).longValue(); - or - long b=Long.parseLong(s); //String to Float float x = Float.valueOf(s).floatValue()

NEW: Assignment #2 Part I Vocabulary Terms Part II Simple Numerical Filter Program Part III Numerical Filtering with Arrays and Loops Step 1. Input a number Step 2. Determine to which interval a number belongs Step 3. Keep track of the count of numbers per interval Step 4. Print out the counts of numbers in the intervals

What Code Shall We Start With? From Last Class -- Java Code Fragment: // assign datatypes and initial values to bounds int y = 10, z = 15; // test to see if number is in-range void testNumber(int x) { if ( x = y ) { System.out.println(“Winner!”); } else { System.out.println(“Loser!”); } } Boolean oper- ator means logical “and”

This Week: Java Program Design Next Class (Friday) How to e-submit Assignment #1 How to Start Assignment #2, Parts I and II More on “type casting” Look-Ahead (Monday) More on Type Casting and Type Conversion Arrays