ITM 352 - © Port, KazmanVariables - 1 ITM 352 Data types, Variables.

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

10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Data types and variables
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
CS150 Introduction to Computer Science 1
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
JavaScript, Third Edition
Basic Elements of C++ Chapter 2.
Lecture 2 - Variables, program execution, calculations, print() COMPSCI 101 Principles of Programming.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Variables, Assignment & Math Storing and naming data.
Week 9 PHP Cookies and Session Introduction to JavaScript.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
2440: 211 Interactive Web Programming Expressions & Operators.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
1 Working with Data Types and Operators. 2 Using Variables and Constants The values stored in computer memory are called variables The values, or data,
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
1 C++ Syntax and Semantics, and the Program Development Process.
CSE1222: Lecture 2The Ohio State University1. mathExample2.cpp // math example #include using namespace std; int main() { cout
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
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.
ITM © Port, KazmanVariables - 1 ITM 352 Expressions, Precedence, Working with Strings.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Strings, output, quotes and comments
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Primitive Variables.
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
PHP Programming with MySQL Slide 3-1 CHAPTER 3 Working with Data Types and Operators.
ITM © Port, Kazman1 ITM 352 Simple Arrays. ITM © Port, Kazman2 Arrays r Collections r Array basics m Declaration, allocation, and initialization.
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter 3 Introduction to PHP. Incorporating PHP Within HTML By default, PHP documents end with the extension.php files ending with.htm or.html to also.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables Class #4.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
A Sample Program #include using namespace std; int main(void) { cout
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Tarik Booker CS 290 California State University, Los Angeles.
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.
ITM 352 Data types, Variables
Documentation Need to have documentation in all programs
ITM 352 Expressions, Precedence, Working with Strings Class #5
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
Web Programming– UFCFB PHP Basics Lecture 18
Introduction to Primitives
Introduction to Primitives
Presentation transcript:

ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables

ITM © Port, KazmanVariables - 2 Announcements  Apache and NetBeans must be installed and working on your laptop NOW  During class:  Start NetBeans and create a new project “Lab1”  Go to the Lab 1 assignment on Laulima. You may copy and paste the exercises in to Word then back into the submission area or work directly on Laulima (just be sure to save a draft frequently)

ITM © Port, KazmanVariables - 3 Agenda  Lecture:  Outputting to the screen and console  Data types  Variables

ITM © Port, KazmanVariables - 4 Output in JS  Use document.write() for simple output to the current browser page  document.write('hello'); // could use "hello"  To write to a particular location (i.e. page element) set its innerHTML attribute document.getElementById("place").innerHTML='hello';  Use console.log output to the JS console which is not displayed on the browser page. It can only be seen through the browser tools or NetBeans Output (good for testing) console.log( " hello ") ;

ITM © Port, KazmanVariables - 5 Output in PHP  Use echo for simple output  echo 'hello';  echo 'hello', ' goodbye';  echo ('hello');  print is virtually the same syntax  print 'hello';  You can use () if you like  echo('hello');  print('hello');  New line for console output (we don’t do much of this)  echo " line1\nline2 " ;  New line for HTML output  echo 'line1 line2';

ITM © Port, KazmanVariables - 6 What is a Variable?  A named location to store data  a container for data (like a box or bucket)  It can hold only one type of data at a time  for example only integers, only floating point (real) numbers, or only characters  A variable with a scalar type holds one scalar value  A variable with a compound type holds multiple scalar values, BUT the variable still holds only a single (the compound type itself) value  Syntax for a variable is $  PHP Example: $name, $age  JS Example: var name, var age  Case sensitive! $name $age 'Dan'30.3

ITM © Port, KazmanVariables - 7 Assigning Values to Variables  The assignment operator: "="  "sets" a value for a variable  not the "is equal to" sign; not the same as in algebra  It means - "Assign the value of the expression on the right side to the variable on the left side."  Can have the variable on both sides of the equals sign: $count = 10;// initialize counter to ten $count = $count - 1;// decrement counter var count = 10;// initialize counter to ten var count = count - 1;// decrement counter  new value of count = = 9

ITM © Port, KazmanVariables - 8 Creating Variables  A variable is declared the first time a value is set for it  A variable declaration associates a name with a storage location in memory and specifies the type of data it will store:  $a = 1.1 ;// declares and sets a real number  $a = true ;// declares and sets a boolean  $a = 'Zip Zap' ; // declares and sets a string  var a = 1.1 ;// declares and sets a real number  var a = true;// declares and sets a boolean  var a = 'Zip Zap' ; // declares and sets a string

ITM © Port, KazmanVariables - 9 Variable Names: Identifiers Rules (these must be obeyed)  all identifiers must follow the same rules  must not start with a digit  must contain only numbers, letters, underscore (_) and some other special characters  names are case-sensitive (ThisName and thisName are two different variable names)  No spaces! Good Programming Practice (these should be obeyed)  always use meaningful names from the problem domain (for example, eggsPerBasket instead of n, which is meaningless, or count, which is not meaningful enough)  start variable names with lower case  capitalize interior words (use eggsPerBasket instead of eggsperbasket )  use underscore (_) for spaces  CAPITALIZE constants (i.e. variables that do not change values)

ITM © Port, KazmanVariables - 10 Variable Default Values  Variables have default values  $a = $a + 1; // $a=0 by default  $s = $s."Fred"; // default $s=''  var a = a + 1; // a=0 by default  var s = s + "Fred"; // default s=""  IMPORTANT: It is best to not assume the default value is what you want. Always explicitly set the initial value of a variable!!!! e.g.  $a = 0; $s = ""; $b = false;

ITM © Port, KazmanVariables - 11 Two Main Kinds of Data Types Scalar  the simplest types  also called "primitive" or "basic" types  cannot decompose into other types  contain single values only  Examples:  Integer  Floating point (real)  String  Boolean Compound also call class types  more complex  composed of other types (primitive or class types)  can contain multiple values  Examples:  Arrays  Objects (more about these in ITM353)

ITM © Port, KazmanVariables - 12 Which Ones to Know for Now - 1  integer  just whole numbers  may be positive or negative  no decimal point  may use  Octal: 0755 // starts '0'  Hex: 0xFF // starts '0x'  In PHP these are referred to as int  boolean  only two values – true or false  used for 'conditional' tests (e.g. if, when )  In PHP these are referred to as bool  floating point  real numbers, both positive and negative  has a decimal point (fractional part)  two formats  number with decimal point, e.g  e (or scientific, or floating-point) notation, e.g E2, which means x 10 2  In PHP these are referred to as double  null  The 'nothing' type (more on this later)

ITM © Port, KazmanVariables - 13  A string is a sequence of characters  A very common data type  Names, passwords, addresses, histories, etc.  Often used to represent complex data  Dates, phone numbers, SS numbers, formatted output  A common data-interchange or data-sharing type  key-value pairs, XML, comma delimited data, logs  PHP has a vast and powerful set of functions for working with strings. JS not so much, but there are frameworks such as JQuery that do.  Manipulation, searching, comparing, translation, etc.  Check out php.net  Examples: “Mr. Smith”, ‘ ’, ‘21.7’, “1202 King St.” Which Ones to Know for Now – 2.

ITM © Port, KazmanVariables - 14 NULL  Null is a special type that means "no value"  It can be used to unset a variable  It is used as a place holder within compound types (more on this later…)  $a = NULL; // $a is “unset”, also can use unset($a)  var a = null; // var a; would set a as “undefined” not null Do Exercise #1 in lab

ITM © Port, KazmanVariables - 15 Simple Expressions  Data types can be operated on (e.g. arithmetic, string operations) echo 1+2; echo 3*2; echo "Big". " ". "Dude"; printf("5/3 is about %3d", 5/3); Operators: +, -,., *, /, %

ITM © Port, KazmanVariables - 16 Simple Expressions With Variables  Variables can be operated on (e.g. arithmetic) // add 1 to value in $a and set in $add $add = $a + 1; // multiply value in $a by 2 and set in $mult $mult = $a * 2; // concatenate string in $s with 'Fred' and // set in $str $str = $s. " Fred";

ITM © Port, KazmanVariables - 17 Printf()  Use printf() for more complex formatted output printf('This prints 2 decimal places %.2f', ); This prints 2 decimal places 3.14  Printf() is a function whose first argument is a string that describes the desired format and the remaining arguments are the values to substitute into the type specifications (anything that starts with %) Do Exercise #2,#3 (and bonus if you wish) in lab