Primitive Data Types and Operators

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
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.
Class 7.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Primitive Types CSE 115 Spring 2006 April 3 &
JavaScript, Fourth Edition
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.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
String Escape Sequences
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
Assignment Statements Operator Precedence. ICS111-Java Programming Blanca Polo 2 Assignment, not Equals  An assignment statement changes the value of.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Primitive Data Type Can write value as a literal Ex: int a=1732 Can perform operations using operator symbols Ex: x+1.
Building Java Programs Primitive Data and Definite Loops.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
Divide. Evaluate power – 3 = – 3 EXAMPLE – 3 = 3 2 – – 3 = 6 – 3 Multiply. Evaluate expressions Multiply and divide from.
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.
COM S 207 Literal, Operator, and Expression Instructor: Ying Cai Department of Computer Science Iowa State University
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Doing math In java.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
A: A: double “4” A: “34” 4.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
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.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
CS 106A, Lecture 4 Introduction to Java
Chapter 2 Basic Computation
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Overview: Programming Concepts
Multiple variables can be created in one declaration
Escape Sequences What if we wanted to print the quote character?
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
Examples of Primitive Values
Introduction to Java, and DrJava part 1
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs Chapter 2
Introduction to Java, and DrJava
Chapter 2 Programming Basics.
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
Building Java Programs Chapter 2
Building Java Programs
Introduction to Java, and DrJava part 1
Building Java Programs
Ch 1-2 Order of Operations
Building Java Programs
Building Java Programs
Presentation transcript:

Primitive Data Types and Operators © 2018 Kris Jordan

Data Types Every value, or piece of data, has a specific type In JavaScript and TypeScript there are three primitive data types number (numerical data) string (textual data) boolean (logical data) Primitive data types are the most basic types built into a language Later you will compose primitive data types together to form composite data types A value's type informs its capabilities If you have two number values, then you can add them, for example. 2

Numerical Type - number number Literal examples: 0, 1, 2, 3.14, 110.110 We tend to use numerical data in two ways: As integers, which are useful for counting As decimals, which are useful in simulations, modeling, and so on Lower-level programming languages like Java and C have specific types for integer (i.e. int) and decimal data (i.e. double). In TypeScript, it's just number.

number Operators Name Operator Symbol Example Exponentiation ** 2 ** 8 (is the same as 28) Multiplication * 10 * 3 Division / 100 / 5 Remainder % 18 % 5 (remainder of 18 divided by 5) Addition + 1 + 1 Subtraction - 111 – 1 Complex expressions can be formed of multiple operators and parenthesis: 4 / ((1 + 1) ** 2) is 1 Rules of precedence determine the order each operator is evaluated 4 / 1 + 1 ** 2 is 5 The groupings show operators tiered from high-to-low precedence. A sequence of operators of the same tier will be evaluated left-to-right. For example, 8 / 4 * 2 is 4. 1 2 3 © Kris Jordan

Textual Type - string string is short for "string of characters" Literal examples: "abc", "123", "~() @#z2" Useful for all textual data.

Concatenation When you "add" two Strings together it is called Concatenation "Hello" + "World" // evaluates to "HelloWorld" Concatenation means, simply, to "join" one string to another. When the program concatenates two strings, the result is a single String value. You can also concatenate numerical types to a String. This is very useful! "The answer is " + 42 // Evaluates to "The answer is 42" © Kris Jordan

Concatenation Gotcha Be careful concatenating two strings containing numbers together! What is: "1" + "2" It is "12"! © Kris Jordan

Logical Type - boolean Literal examples: true, false A boolean can only be one of two possible values, either true or false. An upcoming lesson will focus on boolean operators: not and or