Inside Class Methods Chapter 4. 4 What are variables? Variables store values within methods and may change value as the method processes data.

Slides:



Advertisements
Similar presentations
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Advertisements

Variables and Operators
Types and Arithmetic Operators
Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Mathematical Operators: working with floating point numbers and more operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
Expressions An expression is a sequence of operands and operators that reduces to a single value expression operator operand An operator is a language-specific.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
JavaScript, Third Edition
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
1 MATERI PENDUKUNG OPERATOR Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
Chapter 4: Basic C Operators
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.
1 Overloading Operators Object-Oriented Programming Using C++ Second Edition 8.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Exercises A-Declare a variable of double type with initial value=0.0; B- Declare a constant of String type with initial value=“Good” C- Declare a variable.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
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.
Chapter 2: Using Data.
Assignment Statements Operator Precedence. ICS111-Java Programming Blanca Polo 2 Assignment, not Equals  An assignment statement changes the value of.
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
CHAPTER 4 GC 101 Data types. DATA TYPES  For all data, assign a name (identifier) and a data type  Data type tells compiler:  How much memory to allocate.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
03 August 2004 NLP-AI Java Lecture No. 4 Operators & Decision Constructs Satish Dethe.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
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.
Primitive Variables.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Arithmetic, Class Variables and Class Methods Week 11
© 2005 Lawrenceville Press Slide 1 Chapter 4 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms:
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Programming Fundamentals. The setw Manipulator setw changes the field width of output. The setw manipulator causes the number (or string) that follows.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
COMP 110: Spring Announcements Lab 1 due Wednesday at Noon Assignment 1 available on website Online drop date is today.
Operators.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
STRUCTURED PROGRAMMING C++ Operators. Content 2  C++ operators  Assignment operators  Arithmetic operators  Increment and decrement operators  Decision.
Java-02 Basic Concepts Review concepts and examine how java handles them.
Programming Fundamentals. Summary of Previous Lectures Phases of C++ Environment Data Types cin and cout.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
JAVA Practical Unary operators 2. Using Reals 3. Conversions 4. Type Casting 5. Scope 6. Constants.
LESSON 3 Expressions, Statements, & Operators. STATEMENTS A statement Controls the sequence of execution Evaluates an expression Does nothing (the null.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Chapter Sections 1.1 – Study Skills for Success in Mathematics
Operators And Expressions
Data Types, Identifiers, and Expressions
Multiple variables can be created in one declaration
Chapter 5: Loops and Files.
Unit-1 Introduction to Java
Chapter 2: Java Fundamentals
Chapter 2 Programming Basics.
Engineering Problem Solving with C++ An Object Based Approach
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Module 2 Variables, Data Types and Arithmetic
Variables and Constants
Presentation transcript:

Inside Class Methods Chapter 4

4 What are variables? Variables store values within methods and may change value as the method processes data.

4 Variables The scope of a variable determines how long it holds its value. Local variables maintain their scope within the block of code in which they are declared. Local variables are not fields of the class.

4 Declaring and Initializing Variables Declare a variable by identifying its type and the identifier (name): double averageSpeed; Initialization is when you declare a variable and assign it a value at the same time: double averageSpeed = 21.6;

4 What are operators? Operators are symbols that take action within a program. Assignment operator (=) assigns a value to a field or variable: averageSpeed = 21.6; Mathematical operators include: +, -, *, and / Relational operators include:, ==, and !=

4 A Self-Assignment Operator Manipulates a variable and assigns the results back to itself. Self-assignment operators include +=, -=, *=, and %= int x = 5; int y = 6; x += y; x has the value (5 + 6) = 11

4 Precedence Java follows mathematical rules of precedence. Multiplication and division are handled first, followed by addition and subtraction Use parentheses to force evaluation

4 Increment and Decrement Operators The increment operator (++) means increment (add) by one. ++x; The decrement operator (--) means decrement (subtract) by one. --x;

4 Prefix vs. Postfix Prefix notation increments, then fetches: int x = 5; int y = ++x; Value of y is 6 (1 + 5), value of x is 6 Postfix notation fetches, then increments: int x = 5; int y = x++; Value of y is 5, value of x is 6

4 What is a constant? A constant is a variable with a fixed value (cannot be changed). Use the keyword final to designate a constant. Constant identifiers are typically UPPER_CASE notation to distinguish them from other variables.

4 Relational Operators Evaluate the equality or inequality of two intrinsic types. Return a boolean value (true or false) Equality: == Inequality:, =, != (not equal)