Primitive Data Type Can write value as a literal Ex: int a=1732 Can perform operations using operator symbols Ex: x+1.

Slides:



Advertisements
Similar presentations
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
Advertisements

Java Programming, 3e Concepts and Techniques Chapter 3 Section 63 – Manipulating Data Using Methods – Day 2.
CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
C++ Numerical Data Input/Output Programming. COMP 102 Prog Fundamentals I:C++ Numerical Data, Input/Output /Slide 2 Rules for Division l C++ treats integers.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Signed Numbers, Powers, & Roots
Chapter 2.2 Scientific Notation. Expresses numbers in two parts: A number between 1 and 10 Ten raised to a power Examples: 2.32 x x
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Python Types Python values are of various “types” Ints, Floats, Strings, Characters, and more Two representations of numbers 1 vs 1.0.
Input, Output, and Processing
Exponents & Scientific Notation MATH 102 Contemporary Math S. Rook.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
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.
Lesson 3 – Primitive Data Types Objective: Students will investigate the definition and usage of objects and primitive data types in Java in order to practice.
Building Java Programs Primitive Data and Definite Loops.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 Java Basics: Data Types, Variables, and Loops “ If debugging is the process of removing software bugs, then programming must be the process of putting.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Exponents and Scientific Notation MATH 017 Intermediate Algebra S. Rook.
Significant Figure Rules RulesExamples The following are always significant Non zero digits Zeros between non zero digits Zero to the right of a non zero.
Practice: a) cm – cm = b) 6.54 m x 0.37 m = c) 40.8 m 2  m =
Chapter 2 Variables.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
1 Chapter 2: Java Fundamentals cont’d Spring Lory Al Moakar.
Numeric Data Types There are six numeric data types: byte, short, int, long, float, and double. Sample variable declarations: int i, j, k; float numberOne,
Doing math In java.
Java Primitive Types, Operators, and Strings (Java: An Eventful Approach, Ch 5), Slides Credit: Bruce, Danyluk and Murtagh CSCI 120 Lecture October.
Chapter 3 Numerical Data. Objectives After you have read and studied this chapter, you should be able to Select proper types for numerical data. Write.
§ 5.5 Negative Exponents and Scientific Notation.
Operators.
SCIENTIFIC NOTATION RULES. Rules for converting to Scientific Notation One non-zero number before the decimal One digit after the decimal If you are making.
CHAPTER FOUR Performing Calculations and Manipulating Data: Expressions.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
Lecture 3 Java Operators.
Java Variables and Types
Building Java Programs
Arithmetic operations & assignment statement
Primitive and Reference Data Values
Building Java Programs Chapter 2
Topic 4 Expressions and variables
Building Java Programs
Topic 4 Expressions and variables
Building Java Programs Chapter 2
Building Java Programs
Building Java Programs
Chapter 2 Programming Basics.
Building Java Programs
Building Java Programs
Building Java Programs
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Building Java Programs
In this class, we will cover:
Building Java Programs Chapter 2
Building Java Programs
Topic 4 Expressions and variables
Primitive Data Types and Operators
Building Java Programs
Presentation transcript:

Primitive Data Type Can write value as a literal Ex: int a=1732 Can perform operations using operator symbols Ex: x+1

Operators vs. Method Invocations Operators produce new values Ex: if the value of count is 3 count+1 will produce 4, but will not change count Method Invocations can modify objects Ex: box.move(-1,-1); changes the position of the box

Operators and Precedence Rules Arithmetic and logical negations, - and ! Multiplication and division: * and / Addition and subtraction: + and – Comparisons:,>= Equality and inequality: == and != And: && Or: || Ex: a+b*c=a+(b*c) but not (a+b)*c

Numeric Types Integers: Ex: int anInt=99; Real numbers: Ex: double aDouble=98.6; An int can be converted into a double without loss of precision, but not vice versa

Dividing int and double intdouble intint resultdouble result doubledouble result Clearly, unless an integer is divided by another integer, all results are double. Ex: 3.0 / 4.0 = / 4.0= / 4 = 0 The following table summaries the types of result one will get when dividing two integers, two doubles, or a double and an integer

How a double is displayed If you print a double, the output is always accompanied by a decimal place. Ex: double a=1000; System.out.print(a); will output Large numbers use scientific notation Ex: double a= ; System.out.print(a); will output 1.0E9

Selecting a Numeric Type Use double instead of int whenever possible Use int when methods demand it Ex: setColor( int, int, int )

Useful Functions on double Math.pow(a,b)abab Math.exp (b)ebeb Math.ln(a)ln(a) Math.sqrt(a)Square root of a

System.currentTimeMillis() Used to check elapsed time Ex: printing out the duration of a mouse press public void onMousePress(Location point){ startingTime=System.currentTimeMillis(); } public void onMouseRelease(Location point){ System.out.println(System.currentTimeMillis()-startingTime)); }

String Java uses String to manipulate textual data Quoted text is of type String Programs can combine String objects Ex:String a= " He " ; String b= " llo " ; System.out.print(a+b); will print out Hello