1 CS1110 Fall 2011 David Gries, Steve Marschner Reading for this lecture and previous lecture: Sections 1.1, 1.2, 1.3. Lab 1 will give you practice with.

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
0 CS100J September 2007 CS100J: 12 weeks programming using Java, 2 using Matlab. David Gries. CS100M: 7 weeks of Matlab and 7 of Java. Daisy Fan. CS100H:
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
1 CS1130 Spring 2011: David Gries & Walker White Transition to Object-Oriented Programming Assumes programming knowledge in a language like Matlab, C,
1 CS1110 Fall 2011: David Gries & Steve Marschner CS1112: Matlab No prior programming experience One semester of calculus Math- & engineering- type problems.
1 CS1110 Fall 2010 Instructors: David Gries & Lillian Lee CS1112: Matlab No prior programming experience One semester of calculus Math- & engineering-
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
1-1 University of Hail College of Computer Science and Engineering Department of computer Science and Software Engineering Course: ICS313: Fundamentals.
C H A P T E R S E V E N Expressions and Assignment Statements.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
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.
1 CS1110. Lecture 1, 31 Aug Types, expressions, variables, assignment statements Can’t install DrJava and running a Microsoft operating system? Contact.
CS100J Spring 2006 CS100J: 11 weeks of programming using Java and 2 weeks using Matlab. David Gries is teaching CS100J. Graeme Bailey is teaching a special.
Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
1 CS1110. Lecture 1, 31 Aug Types, expressions, variables, assignment statements Summary of lectures : On course webpage, click on “Lecture summaries”.
Arithmetic Expressions
Introduction to Programming Languages S1.3.1Bina © 1998 Liran & Ofir Introduction to Programming Languages Programming in C.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
1 CS1100 Fall Instructor: David Gries CS100M: Matlab No prior programming experience One semester of calculus Math & engineering type problems CS100J:
ISBN Chapter 7 Expressions and Assignment Statements.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
1 CS1110 Fall Instructors: David Gries & Lillian Lee CS1112: Matlab No prior programming experience One semester of calculus Math- & engineering-
COMP Primitive and Class Types Yi Hong May 14, 2015.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 CS100J Spring Instructor: David Gries CS100M: Matlab No prior programming experience One semester of calculus Math & engineering type problems.
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.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
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.
Expressions and Assignment Statements
CompSci 230 S Programming Techniques
Expressions and Assignment Statements
7.2 Arithmetic Expressions
CS1110 Spring Instructor: David Gries
Chapter 7: Expressions and Assignment Statements
Expressions and Assignment Statements
Java Primer 1: Types, Classes and Operators
Tokens in C Keywords Identifiers Constants
Object Oriented Programming
Chapter 7: Expressions and Assignment Statements
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Multiple variables can be created in one declaration
Expressions and Assignment Statements
Type Conversion, Constants, and the String Object
Java Programming: From Problem Analysis to Program Design, 4e
Expressions and Assignment Statements
Expressions and Assignment Statements
College of Computer Science and Engineering
Expression and Asignment Statements
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Chapter 7 Expressions and Assignment Statements.
CS100J CS100M is in Kimball Bll.
Basic Programming Concepts
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
PRESENTED BY ADNAN M. UZAIR NOMAN
Review of Java Fundamentals
Presentation transcript:

1 CS1110 Fall 2011 David Gries, Steve Marschner Reading for this lecture and previous lecture: Sections 1.1, 1.2, 1.3. Lab 1 will give you practice with concepts and details of 1.2, 1.3. PLive: Lesson 0, Lesson page 1.3, Activity

2 Results of last lecture’s questionnaire Number completed: 305 (about 50 students did not) No programming experience: 171 (56%) < 5 months experience: 73 (24%) >= 5 months experience: 61 (20%) Number not in science/engineering: 44 (14%) Number expressing concern because of lack of experience compared to others or the work load: 88 (29%)

3 Terminology Programming language (Java, C, Fortran, Matlab, Python): a language in which you write programs, often to be executed on a computer. Program: A set of instructions, written in a programming language, to be executed (carried out, performed) to get some task done. Like a recipe in a cookbook. Machine language. The language of instructions that a computer is able to execute (carry out, perform). Java Compiler. A program that translates a Java program into a machine language form so that it can be executed on a computer.

4 Type: A set of values together with operations on them. Type integer: values: …, –3, –2, –1, 0, 1, 2, 3, 4, 5, … operations: +, –, *, /, unary – Memorize this definition! Write it down several times. Type int: values: – , – , …, –3, –2, –1, 0, 1, 2, 3, 4, 5, …, , operations: +, –, *, /, unary – Principal: These int operations must yield an int. b / c rounds toward 0 Integer.MIN_VALUE Integer.MAX_VALUE – –1

5 Type: A set of values together with operations on them. Type double: values: Examples: –22.51E6 equivalent to – or –22.51 * E–6 equivalent to or * 10 –6 An approximation to the real numbers. operations: +, –, *, /, unary – exponentmantissa Double.MIN_VALUE 4.9E-324 Double.MAX_VALUE E308 Smallest POSITIVE value

6 Casting between double and int (int) 2.56casts 2.56 to type int. Value is 2 This is a narrowing cast. Java never does it automatically because it might lose information and it may be done automatically by Java if is is necessary. Other examples: (double)(int) 2.56 Value is 2.0 (double) 2.56Value is 2.56 (double) 2casts 2 to type double. Value is 2.0 This is a widening cast, and it may be done automatically by Java if is is necessary.

7 Type: A set of values together with operations on them. Type boolean: values: true false operations: ! (not) && (and) || (or) b && c, read “b and c”, is trueif both b and c are true, false otherwise b || c, read “b || c”, is true if b is true or c is true, false otherwise !b is true if b is false and false if b is true i = j i > j i != j evaluate to true or false ==, not = !!

8 Precedence of operators (page 23) Unary operators: + – ! Binary arithmetic: * / % Binary arithmetic: + – Arithmetic relations: = Equality relations: == != Logical and: && Logical or: | | You will practice working with expressions in Lab 01.

99 Variables. p. 26 A variable is a name together with a value. A variable is a named box with a value in the box. 5 Memorize definition! Write it down several times. xHere’s variable x, with value 5. It can contain an int value. int 20.1 areaHere’s variable area, with value It can contain a double value. double

10 Declaration of a variable. p. 26 In Java, a declaration of a variable gives the name of the variable and the type of value it can contain. Memorize these two definitions! Write them down several times. int x;Here’s a declaration of x, indicating that it contain an int value. double area;Here’s a declaration of area, indicating that it can contain a double value. Assignment statement. p. 27 Execution of an assignment statement stores a value in a variable. x= x + 1;Evaluate expression x+1 and store its value in variable x. To execute the assignment = ; evaluate expression and store its value in variable.

11 Type: A set of values together with operations on them. Type String: values: Any sequence of characters operations: + (catenation, or concatenation) + is overloaded: Consider x + y (1) If one operand (x or y) is a String, the other is converted to a String (if necessary) and catenation is done. (2) Otherwise, if one operand is a double, the other is cast to a double (if necessary) and a double addition is done. (3) Otherwise, both operands are ints and an int addition is done. Here is String catenation: "bc" + "fg" String literal: sequence of chars enclosed in double quotes: e.g. " abcex3$g<&“ Question: what can you do to convert the value of an expr, e.g , to a String

12 Recitations (Labs) in the Engineering ACCEL LAB Start Today and Tomorrow! To get to the ACCEL Lab, go into the Engineering Library in Carpenter Hall, walk straight until you come to a staircase on your left, and go up the stairs. Do not be concerned if you haven’t been able to register for a recitation section. Just go to the one you want this week. Here are the times of the recitation-labs: Attend ONE of them. Tuesday:12:20, 1:25, 2:30, 3:35 Wednesday:12:20, 1:25, 2:30, 3:35 You can help by bringing your own laptop