Varriables CSC 171 FALL 2001 LECTURE 2. History The abacus.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
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.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
FUNDAMENTAL DATA TYPES CSC 171 LECTURE 4. How do Computers represent information? Computers are switches Switches are “on” or “off” Suppose we want to.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5.
Primitive Types CSE 115 Spring 2006 April 3 &
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
String Escape Sequences
Java Building Elements Lecture 2 Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
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.
Chapter 4 Variables and Constants. Goals and Objectives 1. Understand simple data types (int, boolean, double). 2. Declare and initialize variables using.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3A Integral Data (Concepts)
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Primitive Variables.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Primitive Variables.
Programming with Visual C++: Concepts and Projects Chapter 3A: Integral Data (Concepts)
Chapter 2 Variables.
Copyright © – Curt Hill Types What they do.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
1.2 Primitive Data Types and Variables
CPS120: Introduction to Computer Science Variables and Constants.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
MIT AITI Lecture 2 The of Java In the following lectures you will learn the basic structures that make up the Java programming language: »Variables.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
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.
1 2. Program Construction in Java. 01 Java basics.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
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.
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Chapter 2 Variables.
Chapter 4 – Fundamental Data Types
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Multiple variables can be created in one declaration
Type Conversion, Constants, and the String Object
Unit-2 Objects and Classes
Computers & Programming Languages
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Chapter 2 Edited by JJ Shepherd
Chapter 2 Variables.
Object-Oriented Programming
Chapter 2: Java Fundamentals
Unit 6 - Variables - Fundamental Data Types
Java Programming Review 1
Primitive Types and Expressions
Unit 3: Variables in Java
Names of variables, functions, classes
Chapter 2 Variables.
Just Enough Java 17-May-19.
Variables and Constants
Presentation transcript:

Varriables CSC 171 FALL 2001 LECTURE 2

History The abacus

History – use of gears William Schickard 1623 Blaise Pascal 1642 Gottfried Leibniz 1673

Variables Variables are “places to put things/values” Variables correspond to locations in the computer’s memory – Name – Type – Size – Value

Declaration & assignment int x; int y = 7; x = 5; y = 12;

Expressions int x, y, z, a, b, c ; y = 7 ; x = 5 ; z = x + y ; a = x - 10 ; b = a * x + y ; a = a + x ;

Variables The variable “count” used above – Name : “count” – Type : integer (int) – Size : 4 bytes (32 bits) – machine dependent – Value : starts at zero, but the value varies/changes

Integers Assignment : a = 0; Arithmetic : +,-,* Integer division discards fractions – 17 / 5 == 3 Modulus operator generates remainders – 17 % 5 == 2

History – first “programs” 1801 Joseph-Marie Jacquard invented an automatic loom using punched cards for the control of the patterns in the fabrics.

Strings Generating new strings – String s1 = new String(); – s1 = new String(“*”); Adding Strings – s2 = s1 + s1 ; // == “**” Generating new strings from strings – s1 = new String(s1 + s2); // == “***”

Boolean expressions boolean expressions can take on one of two values (true or false) 3 <= 5 – true 3 > 5 – false

Boolean variables int x = 5, y = 3; boolean test1, test2, test3, test4; test1 = x < y ; test2 = x >= y; test3 = test1 && test2; test4 = test1 || test 2;

“OR” OPERATION ABA || B False True FalseTrue

“AND” OPERATION ABA && B False TrueFalse TrueFalse True

The Binding Pattern = ; Examples int score = 59 ; double todaysTemp = 67.4 ; char letterGrade = ‘A’; String firstName = “Ted”;

JAVA Primitive Data Types boolean – true or false char – character values ‘a’, byte – 8 bit values short – 16 bit integers int – 32 bit integers long – 64 bit integers float – 32 bit values, with decimal point double – 64 bit values, with decimal point

Identifiers The name of the thing is an identifier Must begin with a – ‘_’ – a letter The rest can consist of – ‘_’ – letters – digits

Style Choose meaningful variable names – Accurately describe the data entity – Neither too long nor too short – Adopt a convention Good variable naming is good documentation Good variable naming requires you to think about what your program is doing (design)

Code from Hell X = X – XX ; XXX = Aretha + ST(Aretha); X = X + LF(X1,X) + XXX; X = X + Intrst(X1,X);

As opposed to : Balance = Balance – LastPayment; MonthlyTotal = NewPurchases + SalesTax(NewPurchases); Balance = Balance + LateFee(CustomerID,Balance) + MontlyTotal; Balance = Balance + Interest(CustomerID,Balance);