Java Primitive Types, Operators, and Strings (Java: An Eventful Approach, Ch 5), Slides Credit: Bruce, Danyluk and Murtagh CSCI 120 Lecture 15 30 October.

Slides:



Advertisements
Similar presentations
Java Programming, 3e Concepts and Techniques Chapter 3 Section 63 – Manipulating Data Using Methods – Day 2.
Advertisements

CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
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.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Hello, world! Dissect HelloWorld.java Compile it Run it.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Signed Numbers, Powers, & Roots
CS305j Introduction to ComputingPrimitive Variables 1 Topic 4 Variables “Once a programmer has understood the use of variables, he has understood the essence.
VARIABLES AND TYPES CITS1001. Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Scope.
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.
Physics Day 5 Objectives SWBAT do exponential math Understand factors of 10 Agenda Do Now Notes Worksheet HW2 due tonight HW3 Thursday.
Exponents & Scientific Notation MATH 102 Contemporary Math S. Rook.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Primitive Data Type Can write value as a literal Ex: int a=1732 Can perform operations using operator symbols Ex: x+1.
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.
Programming Process Programming in Java is an exercise in using pre-defined classes and writing new classes to fill in the gaps A procedure for determining.
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.
CSC 107 – Programming For Science. Announcements.
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.
Java Decision Making and booleans (Java: An Eventful Approach, Ch 4), Slides Credit: Bruce, Danyluk and Murtagh CS 120 Lecture October 2012.
Chapter 2 Variables.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
1.2 Built-in Types of Data Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · December.
PHP Programming with MySQL Slide 3-1 CHAPTER 3 Working with Data Types and Operators.
Doing math In java.
Java Working with Numbers (Java: An Eventful Approach, Ch 3), Slides Credit: Bruce, Danyluk and Murtagh CS 120 Lecture October 2012.
1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Topic 4 Expressions and variables Based on slides bu Marty Stepp and Stuart Reges from "Once a person has understood.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
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.
Unit 1 Seminar Welcome to MM150! To resize your pods:
Building Java Programs
Arithmetic operations & assignment statement
Primitive Data, Variables, Loops (Maybe)
Quantitative Measurements
OPERATORS (1) CSC 111.
IDENTIFIERS CSC 111.
Topic 4 Expressions and variables
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
Building Java Programs
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
Building Java Programs
Building Java Programs
Building Java Programs Chapter 2
Building Java Programs
Topic 4 Expressions and variables
Primitive Data Types and Operators
Building Java Programs
Presentation transcript:

Java Primitive Types, Operators, and Strings (Java: An Eventful Approach, Ch 5), Slides Credit: Bruce, Danyluk and Murtagh CSCI 120 Lecture October 2012

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 is the same as 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 int whenever you need whole numbers only. Use double when you need non-integer values 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 String accumulators: b = b + " world " ;

Student To Do’s HW09 –Exercise (Dicey) –Exercise (Random Box) –Due Monday 11/5 by 1:25pm –Submit your.java files and bluej project file. Read Java: An Eventful Approach –Ch. 5 (Today) 12