Variables and Conditionals Hal Helms halhelms.com.

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

Chapter 7:: Data Types Programming Language Pragmatics
Chapter 5 Types. 5-2 Topics in this Chapter Values vs. Variables Types vs. Representations Type Definition Operators Type Generators SQL Facilities.
Arrays.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
VBA Modules, Functions, Variables, and Constants
Visual Basic.NET Fundamentals. Objectives Use primitive data types, naming conventions, and style rules Understand and apply the control structures supported.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Software Testing and Quality Assurance
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
© 2011 Pearson Education, publishing as Addison-Wesley 1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 6 focuses.
OOP Languages: Java vs C++
Python quick start guide
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
Programming Languages and Paradigms Object-Oriented Programming.
Advanced Java New York University School of Continuing and Professional Studies.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 2: Major Concepts of Programming.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Website Development with PHP and MySQL Saving Data.
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
Learners Support Publications Classes and Objects.
Term 2, 2011 Week 1. CONTENTS Problem-solving methodology Programming and scripting languages – Programming languages Programming languages – Scripting.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Copyright © Curt Hill Structured Data What this course is about.
Basic Data Types Numbers (integer and floating point)‏ Strings (sequences of characters)‏ Boolean values (true/false)‏
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
DT228/3 Web Development Databases. Querying a database: Partial info Search engines, on-line catalogues often need to allow user to search a database.
Chapter 5 Types. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.5-2 Topics in this Chapter Values vs. Variables Types vs. Representations.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
©2003 Hal Helms, Inc. Variables The Tao that can be told is not the eternal Tao. The name that can be named is no t the eternal Name. —Lao-Tzu.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Controlling Computers with Programs When you create a computer program you are creating a set of instructions that tell the computer exactly and completely.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
Inside Class Methods Chapter 4. 4 What are variables? Variables store values within methods and may change value as the method processes data.
Using Structures With CFCs By Selene Bainum. June 27 th - 30 th 2007www.cfunited.com Why Am I here? Familiar with structures Familiar with ColdFusion.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Today Review passing by reference and pointers. null pointers. What is an Object? Winter 2016CMPE212 - Prof. McLeod1.
1 Java for ColdFusion Programmers Hal Helms halhelms.com.
Windows Programming Lecture 03. Pointers and Arrays.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
Dr. M. Al-Mulhem Introduction 1 Chapter 6 Type Systems.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Unit 2 Technology Systems
Data Types In Text: Chapter 6.
Chapter 3: Using Methods, Classes, and Objects
Variables and Conditions Nicholas Tunney Senior Software Architect
JavaScript: Functions.
Classes and Objects.
Language-based Security
Presentation transcript:

Variables and Conditionals Hal Helms halhelms.com

What we'll cover Basics of variables Types of variables (strings, arrays, etc.) Scopes of variables (session, application, etc.) Conditionals (working with boolean variables)

Basics Variables are name/value pairs Variables permit our programs to work with values that can't be known at design time or that may change from their original value customerName yourStreetAddress currentUser

Basics Variables give context and constraint to values The value "42" is meaningless apart from a context, usually provided by variable name (e.g. meaningOfLife ) Data typing constrains variables to hold meaningful values isNumeric() returns a boolean value randRange() returns an integer value

Strong data typing Some languages employ strong typing, requiring the programmer to declare a variable's data type prior to using it String myName; int myAge; Company myEmployer; Examples Java C#

Weak data typing Other languages use weak typing, in which the language implicitly determines the data type of a variable Examples Smalltalk ColdFusion Weakly typed languages are not untyped languages!

Data typing Different data types hold different types of values string int structure Car "Visualize whirled peas" 1024 name"Hal Helms" ACMmembertrue numberOfChildren1

ColdFusion data types string numeric query list (string) structure array object boolean date GUID UUID

Complex variable type: query query series of 1 or more rows with column or field values for each row iddescriptionprice 100Widget Framus, left-handed75.00 addressable products.price — refers to current row products.price[2] — specifies row products

Complex variable type: structure structure collection of name/value pairs grouped around a central idea or item teacherHal Helms addressable javaClass.maxStudents javaClass['maxStudents'] maxStudents10 isActivetrue Ben Edwards javaClass

Complex variable type: 1-d array one-dimensional array collection of ordered values resembles a single row of a spreadsheet Hal Helms addressable onedee[2] Sean CorfieldBen Edwards onedee [1][2][3]

Complex variable type: 2-d array two-dimensional array collection of ordered values resembles multiple rows of a spreadsheet 68 addressable twodee[1][3] 8472 twodee [1][2][3] 6269 [1] [2]

Complex variable type: object Objects are fundamentally different from all other data types in that they encapsulate both data and behavior Objects allow us to create scale models of the world under consideration Car getMake(): string addGas(gallons): void accelerate(): void

Quiz time! For each of the following,explain which data type you'd use and why final test scores for all students collection of Student objects lyrics to "Memories" (thank heavens for garbage collection!) number of students in a class information from LDAP server composer's date born, date died, nationality, typical genre an hourly employee

Understanding scopes A variable typically has a lifespan and a scope lifespan: how long the system keeps a reference to a variable scope: location from which variable is visible In ColdFusion, a variable's scope and lifespan are bound together in a single attribute, scope, which is prefixed to the variable name

Understanding scopes prefixvisibilitylifespan applicationeverywhere in same applife of application attributeswithin custom tag (for variables passed into custom tag) current request callerwithin custom tag (for variables on calling page) current request cgieverywherecurrent request clienteverywhere in same application for an individual user varies by purge timeframe cookieeverywhere in all apps on domain varies; set by cookie formeverywherecurrent request requesteverywherecurrent request servereverywhere by all apps on single server varies by server timeout setting sessioneverywhere in same app for an individual user varies by session timeout setting urleverywherecurrent request variableslocal to page/CFC and any included pages current request

Quiz time! For each of the following,explain which scope you'd use and why global "constants" such as datasource name query meant to be created and used on same page a CFC, currentUser, that encapsulates data and behavior for the currently logged in user a cookie crumb array a userID meant to identify the user between visits a custom tag "reaching into" the base template to read or set a variable on that page

Conditionals All conditionals involve carrying out some instructions based on whether an expression evaluates to true

iif()

switch/case

Conclusion Variables are the basis of all programs Data typing, although mostly hidden in ColdFusion, is very important—particularly in OO languages Do experiment with "complex" data types; you'll find they make your code easier to write and maintain Conditionals allow us to execute commands based on the result of some run time boolean value