tailieunhanh - Lecture Java methods: Object-oriented programming and data structures (2nd AP edition): Chapter 6 - Maria Litvin, Gary Litvin

Chapter 6 - Data types, variables, and arithmetic. In this chapter, the learning objectives are: Discuss primitive data types; learn how to declare fields and local variables; learn about arithmetic operators, compound assignment operators, and increment/decrement operators; discuss common mistakes in arithmetic. | Data Types, Variables, and Arithmetic int chapter = 6; Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 2nd AP edition with GridWorld 6- Java’s primitive data types and arithmetic operators can be hazardous due to integer division and arithmetic overflow. Take your time with this chapter until your students are comfortable with arithmetic. Objectives: Discuss primitive data types Learn how to declare fields and local variables Learn about arithmetic operators, compound assignment operators, and increment / decrement operators Discuss common mistakes in arithmetic 6- Also review the style: naming variables and using symbolic constants. Variables A variable is a “named container” that holds a value. q = 100 - q; means: 1. Read the current value of q 2. Subtract it from 100 3. Move the result back into q count 5 mov ax,q mov bx,100 sub bx,ax mov . | Data Types, Variables, and Arithmetic int chapter = 6; Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 2nd AP edition with GridWorld 6- Java’s primitive data types and arithmetic operators can be hazardous due to integer division and arithmetic overflow. Take your time with this chapter until your students are comfortable with arithmetic. Objectives: Discuss primitive data types Learn how to declare fields and local variables Learn about arithmetic operators, compound assignment operators, and increment / decrement operators Discuss common mistakes in arithmetic 6- Also review the style: naming variables and using symbolic constants. Variables A variable is a “named container” that holds a value. q = 100 - q; means: 1. Read the current value of q 2. Subtract it from 100 3. Move the result back into q count 5 mov ax,q mov bx,100 sub bx,ax mov q,bx 6- The code in the blue box is 8086 assembly language for IBM PC; ax and bx are general-purpose registers; mov is the move instruction. Variables (cont’d) Variables can be of different data types: int, char, double, boolean, etc. Variables can hold objects; then the type is the class of the object. The programmer gives names to variables. Names of variables usually start with a lowercase letter. 6- More precisely, variables that represent objects hold references to (basically addresses of) objects. The space to hold the actual object is allocated elsewhere. Names of variables must be meaningful, not too long, not too short. If a name consists of several words, the subsequent words are capitalized. A name cannot start with a digit. Variables (cont’d) A variable must be declared before it can be used: int count; double x, y; JButton go; Bug bob; String firstName; Type Name(s) 6- Several variables of the same type can be declared in the same statement, separated by commas.

TỪ KHÓA LIÊN QUAN