Lecture 2 Fundamental Data Types. Variable Declaration.

Slides:



Advertisements
Similar presentations
Pecan cinnamon cookies. Walnut Cinnamon Cookies 1/2 cup unsalted butter 3/4 cup granulated sugar, divided 1/4 cup packed light brown sugar 1 large egg.
Advertisements

L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Programming in Visual Basic
Baking Chocolate Chip Cookies Ms. Davis Life Skill Class July 11th, 2004.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Ingredients 1 1/2 cups sugar 2/3 cup shortening or butter* 2 eggs 2 tablespoons milk 1 teaspoon vanilla extract 3 ¼ cups flour 2 1/2 teaspoons baking.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Computer Science 101 Introduction to Programming.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Streptococcus pneumoniae. Fig. 6.3b Avery, McCarty and MacLoed, 1944.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
VARIABLES Introduction to Computer Science 1- COMP 1005, 1405 Instructor : Behnam Hajian
Computer Science 101 Introduction to Programming.
Chapter 1 Program Development Asserting Java © Rick Mercer.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Input, Output, and Processing
Following a Recipe The do’s and don’ts!. If you were taking a road trip to some place you had never been to before, what would you want to take with you?
1.02 C Work Plans 1 The secret for success!. Why use a work plan? Helps meal preparation run smoothly Implement these steps: 1.02CWork Plans2 Steps 1-
Snickerdoodles. Ingredients:  125ml margarine  185ml white sugar  1 egg  5ml vanilla extract  340ml all-purpose flour  5ml cream of tartar  2ml.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
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.
Chapter 2: Using Data.
How To Make Peanut Butter Cookies By: Stephanie Seifert.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
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.
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.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Following a Recipe The do’s and don’ts! Original Author Unknown Modified By: CTAE Resource Network.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 3: Assignment, Formatting, and Interactive Input.
C++ for Engineers and Scientists Second Edition Chapter 3 Assignment, Formatting, and Interactive Input.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
How to Make Chocolate Chip Cookies Caity Jozwiak Period 6.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
COMP Primitive and Class Types Yi Hong May 14, 2015.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
By Ricky Haitaian Day of the Dead. What is the Day of the Dead? The Day of the Dead is a Hispanic ritual/holiday to remember and welcome the dead back.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
REESES PEANUT BUTTER CUP COOKIES By:Darnita Coles.
Variables and Constants Chapter 4 Review. Declaring Variables A variable is a name for a value stored in memory. Variables and constants are used in programs.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary 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.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Chocolate Chip Cookies Measurements. Measure Smarter 18 (v) oz. all-purpose flour 1/3 T baking soda 3/4 t & 2 pinches salt 2 sticks butter, softened 12.
Your Name 1/4 cup unsalted butter, melted 1/2 teaspoon vanilla extract 1 egg, room temperature Set aside Andes Peppermint Chips. Scoop out and cream the.
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.
Following a Recipe The do’s and don’ts! Original Author Unknown
Lecture 3: Operators, Expressions and Type Conversion
Introduction to C++ Programming
Maple Peanut Butter Thumbprint Cookies
Chocolate Chip Cookies
Lecture3.
Primitive Types and Expressions
Unit 3: Variables in Java
Chapter 2 Primitive Data Types and Operations
Presentation transcript:

Lecture 2 Fundamental Data Types

Variable Declaration

Rules for Identifiers

Numeric Types

All Numeric Types have Finite Ranges value is 128 but the leading 1 indicates negative value value is 127

Floating Point Values are Approximate

Numeric Operators

Integer Division and Remainder

Increment and Decrement Operators Notice: In this course, we will NOT be using increment and decrement operators in regular assignment statements. (More on this later.)

Assignment Statements

When is "=" not Equal to "Equals"? In Java (and most other programming languages) the symbol = means assignment. X = X + 1 "X is assigned the value X + 1 X = X + 1 ALU Arithmetic Logic Unit ADD LOAD STORE

Augmented Assignment Operators

Declaring Constants

Mathematical Expressions

Ingredients 1 stick butter 1/2 cup sugar 1 egg 1 teaspoon vanilla extract 1/2 teaspoon salt 1 3/4 cups all-purpose flour Directions Mix the butter and sugar until light and fluffy. Beat in the egg, then vanilla and salt. Mix slowly while gradually adding the flour. Do not overmix. Shape into a 1-inch-thick disk, refrigerate for at least 2 hours. Heat oven to 350° F. Roll the dough ¼ inch thick, and cut the dough into shapes. Place 1 inch apart on prepared baking sheets, sprinkle with sugar. Bake until the edges just begin to brown, 12 to 15 minutes. Transfer to cooling racks. Sugar Cookie Recipe

Circle Area Algorithm Computer Algorithms can be simpler than a recipe for sugar cookies. ;-)

from Algorithm to Computer Program

Completed Program comments are ignored by the computer

Completed Program

Getting Input from the User We can use the Scanner software package provided as part of java.util to get information typed on the keyboard. Some of the methods provided in Scanner are:

User Input

Interactive Version of Circle Area Calculator

Convert Fahrenheit to Celsius

Convert Seconds to Minutes and Seconds Get total seconds from user. Calculate number of whole minutes. Calculate number of remaining seconds. Display results.

Convert Seconds to Minutes and Seconds

Numeric Type Conversions Java performs automatic type conversion in mathematical expressions. For example, when an integer and a floating-point value are multiplied, the integer is promoted to a floating-point value. We can override the default type conversions by specifying the type of each parameter.

9 2+ i 3 25 Oh great! Here come your friends, the odd couple. For starters, they're a couple of squares. Why can't you keep it real? I can't imagine why you don't like them. As usual, you're being irrational. Why do you insist on running on forever? Conflicting Data Types

ShowCurrentTime

Using Type Casting So why would we want to multiply and then divide by 100? x 0.06 =

A Sample Problem

An Implemention

Character Data Types and Operations

Unicode and ASCII Code no parent

Samples of Unicode

Escape Sequences for Special Characters

Format Specifiers

String Operations

Types of Programming Errors syntax errors - This type of error prevents the compilation of the program into an executable binary or into bytecode. runtime errors - This type of error prevents a running program from completing its normal execution. logic errors - With this type of error a program can complete its execution normally but the results obtained will be incorrect. easiest type of error to detect relatively simple to correct can be data dependent don't always occur (consider the divide-by-zero error) most difficult to detect (especially when they are intermittant) amenable to unit testing and other SW engineering methods can never be completely eliminated in large programs

using Input and Message Dialogs

The Math Library of Methods

Algorithms are like Recipes The Input-Process-Output Design Pattern Comments help make code understandible All Numeric Data Types have finite ranges Values can be converted from one data type to another Floats and Doubles approximate Real Numbers java.util Scanner methods support user input Understanding Assignment Operators Increment and Decrement Operators Introducing Processing.org Unicode and ASCII Code Escape Sequences Programming Errors Input and Message Dialogs Chapter 2 Summary