# Accelerating Information Technology Innovation

Size: px
Start display at page:

Transcription

1 Accelerating Information Technology Innovation Cali, Colombia Summer 2012 Lesson 02 Variables and Operators

2 Agenda Variables Types Naming Assignment Data Types Type casting Operators 2

3 What is a Variable? In basic algebra, variables are symbols that can represent values in equations. y = x + 5 Similarly, variables in computer program represent data. In computer programming, variables can represent more than just numbers 3

4 An Analogy Think of variables as a box that you can put values in. We can label the box with a name like Box X and re-use it many times. Can perform tasks on the box without caring about what s inside: Move Box X to Shelf A Put item Z in box Open Box X Remove contents from Box X 4

5 Declaring Variables in Java type name; Variables are created by declaring their type and their name as follows: Declaring an integer named x : int x; Declaring a string named greeting : String greeting; Note that we have not assigned values to these variables 5

6 Java Types: Integer Types Integer Types: int: Most numbers you will deal with. long: Big integers; science, finance, computing. short: Smaller integers. Not as useful. byte: Very small integers, useful for small data. 6

7 Java Types: Other Types Floating Point (Decimal) Types: float: Single-precision decimal numbers double: Double-precision decimal numbers. Some phone platforms do not support FP. String: Letters, words, or sentences. boolean: True or false. char: Single Latin Alphanumeric characters 7

8 Assigning Values to Variables name = value; Assign values to variables using the syntax: For example: x = 100; greeting = Jambo ; Illegal to assign a variable the wrong type: x = Jambo ; x = 1.2; greeting = 123; We can declare and assign in one step: int x = 100; String greeting = Jambo ; 8

9 Naming Variables Variable names (or identifiers) may be any length, but must start with: A letter (a z, A-Z), A dollar sign (\$), Or, an underscore ( _ ). Identifiers cannot contain special operation symbols like +, -, *, /, &, %, ^, etc. Certain reserved keywords in the Java language are illegal. int, double, String, etc. 9

10 Naming Variables Java is case sensitive A rose is not a Rose is not a ROSE Choose variable names that are informative Good: int studentexamgrade; Bad: int tempvar3931; Camel Case : Start variable names with lower case and capitalize each word: camelshavehumps. 10

11 Review Which of the following are valid variable names? \$amount 6tally my*name salary _score first Name short 11

12 Integer Types There are 4 primitive integer types: byte, short, int, long. Each type has a maximum value, based on its underlying binary representation: Bytes: ± 128 (8 bits) Short: ± ,000 (16 bits) Int: ± billion (32 bits) Long: ± 2 63 really big (64 bits) 12

13 Overflow What happens when if we store Bill Gates s net worth in an int? Int: ± billion (32 bits) Bill s net worth: > \$40 billion USD Undefined! 13

14 Why use different types of integers? Why not simply use long values all the time? Storage requirements (data memory) Computational speed Power efficiency Use smallest type that will not overflow 14

15 Floating Point Types Initialize doubles as you would write a decimal number: double y = 1.23; double w = -3.21e-10; // -3.21x10-10 float z = 3.45; Doubles are more precise than Floats, but may take longer to perform operations. 15

16 Floating Point Types We must be careful with integer division: double z = 1/3; // z = 0.0 Why? At least one of the operands must be a double: double z = 1.0/3; // z =

17 Type Casting When we want to convert one type to another, we use type casting The syntax is as follows: Example code: (new type)variable double decimalnumber = 1.234; int integerpart = (int)decimalnumber; Results: decimalnumber == 1.234; integerpart == 1; 17

18 Boolean Type Boolean is a data type that can be used in situations where there are two options, either true or false. The values true or false are casesensitive keywords. Not True or TRUE. Booleans will be used later for testing properties of data. Example: boolean monsterhungry = true; boolean fileopen = false; 18

19 Character Type Character is a data type that can be used to store a single characters such as a letter, number, punctuation mark, or other symbol. Characters are a single letter enclosed in single quotes. Example: char firstletterofname = 'e' ; char myquestion = '?' ; 19

20 String Type Strings are not a primitive. They are what s called an Object, which we will discuss later. Strings are sequences of characters surrounded by double quotations. Strings have a special append operator + that creates a new String: String greeting = Ho + la ; String biggreeting = greeting +! ; String numgreeting = greeting + 25; 20

21 Review What data types would you use to store the following types of information?: Population of Colombia World Population Approximation of π Open/closed status of a file Your name First letter of your name \$ int long double boolean String char double 21

22 A Note on Statements A statement is a command that causes something to happen. All statements are terminated by semicolons ; Declaring a variable is a statement. Method (or function) calls are statements: System.out.println( Hello, World ); In lecture 4, we ll learn how to control the execution flow of statements. 22

23 What are Operators? Expressions can be combinations of variables, primitives and operators that result in a value Operators are special symbols used for: - mathematical functions - assignment statements - logical comparisons Examples with operators: // uses + operator * (5 3) // uses +, -, * operators 23

24 The Operator Groups There are 5 different groups of operators: - Arithmetic Operators - Assignment Operator - Increment / Decrement Operators - Relational Operators - Conditional Operators The following slides will explain the different groups in more detail. 24

25 Arithmetic Operators Java has the usual 5 arithmetic operators: +, -,, /, % Order of operations (or precedence): 1.Parentheses (Brackets) 2.Exponents (Order) 3.Multiplication and Division from left to right 4.Addition and Subtraction from left to right 25

26 Order of Operations (Cont d) Example: / 5; The result is different depending on whether the addition or division is performed first ( ) / 5 = (15 / 5) = 13 Without parentheses, Java will choose the second case You should be explicit and use parentheses to avoid confusion 26

27 Integer Division In the previous example, we were lucky that ( ) / 5 gives an exact integer answer (5). But what if we divide 63 by 35? Depending on the data types of the variables that store the numbers, we will get different results. 27

28 Integer Division (Cont d) int i = 63; int j = 35; System.out.println(i / j); Output: 1 double x = 63; double y = 35; System.out.println(x / y); Output: 1.8 The result of integer division is just the integer part of the quotient! 28

29 Assignment Expression The basic assignment operator (=) assigns the value of expr to var name = value Java allows you to combine arithmetic and assignment operators into a single statement Examples: x = x + 5; is equivalent to x += 5; y = y * 7; is equivalent to y *= 7; 29

30 Increment/Decrement Operators ++ is called the increment operator. It is used to increase the value of a variable by 1. For example: i = i + 1; can be written as: ++i; or i++; -- is called the decrement operator. It is used to decrease the value of a variable by 1. i = i - 1; can be written as: --i; or i--; 30

31 Increment Operators (cont d) The increment / decrement operator has two forms : - Prefix Form e.g ++i; --i; - Postfix Form e.g i++; i--; 31

32 Prefix increment /decrement The prefix form first adds/subtracts 1 from the variable and then continues to any other operator in the expression Example: int numoranges = 5; int numapples = 10; int numfruit; numfruit = ++numoranges + numapples; numfruit has value 16 numoranges has value 6 32

33 Postfix Increment/ Decrement The postfix form i++, i-- first evaluates the entire expression and then adds/subtracts 1 to the variable Example: int numoranges = 5; int numapples = 10; int numfruit; numfruit = numoranges++ + numapples; numfruit has value 15 numoranges has value 6 33

34 Relational (Comparison) Operators Relational operators compare two values They produce a boolean value (true or false) depending on the relationship Operation a > b a >= b a == b a!= b a <= b a < b.is true when a is greater than b a is greater than or equal to b a is equal to b a is not equal to b a is less than or equal to b a is less than b Note: == sign! 34

35 Examples of Relational Operations int x = 3; int y = 5; boolean result; 1) result = (x > y); result is assigned the value false because 3 is not greater than 5 2) result = (15 == x*y); now result is assigned the value true because the product of 3 and 5 equals 15 3) result = (x!= x*y); now result is assigned the value true because the product of x and y (15) is not equal to x (3) 35

36 Conditional Operators Symbol &&! Name AND OR NOT Conditional operators can be referred to as boolean operators, because they are only used to combine expressions that have a value of true or false. 36

37 Truth Table for Conditional Operators x y x && y x y!x True True True True False True False False True False False True False True True False False False False True 37

38 Examples of Conditional Operators boolean x = true; boolean y = false; boolean result; Let result = (x && y); result is assigned the value false Let result = ((x y) && x); (x y) evaluates to true (true && x) evaluates to true now result is assigned the value true 38

39 Using && and false && true Java performs short circuit evaluation Evaluate && and expressions from left to right Stop when you are guaranteed a value 39

40 Short-Circuit Evaluation (a && (b++ > 3)); What happens if a is false? Java will not evaluate the right-hand expression (b++ > 3) if the left-hand operator a is false, since the result is already determined in this case to be false. This means b will not be incremented! (x y); What happens if x is true? Similarly, Java will not evaluate the right-hand operator y if the left-hand operator x is true, since the result is already determined in this case to be true. 40

41 Review 1) What is the value of result? int x = 8; int y = 2; boolean result = (15 == x * y); 2) What is the value of result? boolean x = 7; boolean result = (x < 8) && (x > 4); 3) What is the value of z? int x= 5; int y= 10; int z= y++ + x+ ++y; 41

42 new native long interfac e int return public protected private package switch super strictfp static short while violate void try transient throws throw this synchronized instanceof import implements if goto for float finally final extends else double do default continue const class char catch case byte break boolean assert abstract Appendix I: Reserved Keywords 42

43 Appendix II: Primitive Data Types This table shows all primitive data types along with their sizes and formats: Data Type byte short int long Description Variables of this kind can have a value from: -128 to +127 and occupy 8 bits in memory Variables of this kind can have a value from: to and occupy 16 bits in memory Variables of this kind can have a value from: to and occupy 32 bits in memory Variables of this kind can have a value from: to and occupy 64 bits in memory 43

44 Appendix II: Primitive Data Types Real Numbers Data Type float Description Variables of this kind can have a value from: 1.4e(-45) to 3.4e(+38) double Variables of this kind can have a value from: 4.9e(-324) to 1.7e(+308) Other Primitive Data Types char boolean Variables of this kind can have a value from: A single character Variables of this kind can have a value from: True or False 44

### Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

Lecture 2: Variables and Operators AITI Nigeria Summer 2012 University of Lagos. Agenda Variables Types Naming Assignment Data Types Type casting Operators Declaring Variables in Java type name; Variables

### Lecture 3 Operators MIT AITI

Lecture 3 Operators MIT AITI - 2004 What are Operators? Operators are special symbols used for mathematical functions assignment statements logical comparisons Examples: 3 + 5 // uses + operator 14 + 5

### 3. Java - Language Constructs I

Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

### Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

### Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

### Program Fundamentals

Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

### Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

### CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

### Programming Lecture 3

Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

### 3. Java - Language Constructs I

Names and Identifiers A program (that is, a class) needs a name public class SudokuSolver {... 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations,

### The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

### false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

### The Arithmetic Operators

The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

### Programming with Java

Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

### CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

### Chapter 2. Elementary Programming

Chapter 2 Elementary Programming 1 Objectives To write Java programs to perform simple calculations To obtain input from the console using the Scanner class To use identifiers to name variables, constants,

### 5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Today! Build HelloWorld yourself in BlueJ and Eclipse. Look at all the Java keywords. Primitive Types. HelloWorld in BlueJ 1. Find BlueJ in the start menu, but start the Select VM program instead (you

### Object-Oriented Programming

Object-Oriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,

### BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines

### BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators

Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

### Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

### Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

### false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

### DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ OBJECT-ORIENTED PROGRAMMING IN JAVA 2 Programming

### Full file at

Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

### Language Fundamentals Summary

Language Fundamentals Summary Claudia Niederée, Joachim W. Schmidt, Michael Skusa Software Systems Institute Object-oriented Analysis and Design 1999/2000 c.niederee@tu-harburg.de http://www.sts.tu-harburg.de

### Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

### Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators, Expressions, Statements and Arrays. Java technology is: A programming

### AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

### false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

### COMP 202 Java in one week

COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of

### Chapter 3: Operators, Expressions and Type Conversion

101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

### Elementary Programming

Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG Learning Outcomes Learn ingredients of elementary programming: data types [numbers, characters, strings] literal

### DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net COURSE ORGANIZATION 2 Course Elements Lectures: 10 lectures Find schedule and class rooms in online

### Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Tester vs. Controller Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG For effective illustrations, code examples will mostly be written in the form of a tester

### Declaration and Memory

Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier

### Unit 3. Operators. School of Science and Technology INTRODUCTION

INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

### DEPARTMENT OF MATHS, MJ COLLEGE

T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

### Operators. Java operators are classified into three categories:

Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

### Basics of Java Programming

Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

### cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

topics: introduction to java, part 1 cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 cis20.1-fall2007-sklar-leci.2 1 Java. Java is an object-oriented language: it is

### false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 45

### Chapter 2: Using Data

Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

### Java Programming. Atul Prakash

Java Programming Atul Prakash Java Language Fundamentals The language syntax is similar to C/ C++ If you know C/C++, you will have no trouble understanding Java s syntax If you don't, it will be easier

### Zheng-Liang Lu Java Programming 45 / 79

1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius

### Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

### Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

### An overview of Java, Data types and variables

An overview of Java, Data types and variables Lecture 2 from (UNIT IV) Prepared by Mrs. K.M. Sanghavi 1 2 Hello World // HelloWorld.java: Hello World program import java.lang.*; class HelloWorld { public

### JAVA Programming Fundamentals

Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

### Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Entry Point of Execution: the main Method Elementary Programming EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG For now, all your programming exercises will

### 1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 41 / 68 Example Given the radius

### Introduction to C# Applications

1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

### UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . \$, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

### Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Java Language Essentials Java is Case Sensitive All Keywords are lower case White space characters are ignored Spaces, tabs, new lines Java statements must end with a semicolon ; Compound statements use

CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

### JAVA Ch. 4. Variables and Constants Lawrenceville Press

JAVA Ch. 4 Variables and Constants Slide 1 Slide 2 Warm up/introduction int A = 13; int B = 23; int C; C = A+B; System.out.print( The answer is +C); Slide 3 Declaring and using variables Slide 4 Declaring

### More Programming Constructs -- Introduction

More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

### Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes

Entry Point of Execution: the main Method Elementary Programming EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG For now, all your programming exercises will be defined within the

### Ex: If you use a program to record sales, you will want to remember data:

Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T\$1.00. Customer Name:

### COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

### Programming in C++ 5. Integral data types

Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long

### Creating a C++ Program

Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

### Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

### A Java program contains at least one class definition.

Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public

### CSCI 123 Introduction to Programming Concepts in C++

CSCI 123 Introduction to Programming Concepts in C++ Brad Rippe C++ Basics C++ layout Include directive #include using namespace std; int main() { } statement1; statement; return 0; Every program

### Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs

Welcome to CSE 142! Zorah Fung University of Washington, Spring 2015 Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs reading: 1.1-1.3 1 What is computer science? computers?

### University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Second week Variables Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable.

### Software Practice 1 Basic Grammar

Software Practice 1 Basic Grammar Basic Syntax Data Type Loop Control Making Decision Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim (42) T.A. Sujin Oh Junseong Lee (43) 1 2 Java Program //package details

### Fundamental of Programming (C)

Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

### Variables. Data Types.

Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

### SECTION II: LANGUAGE BASICS

Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators

### COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,

### C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

### Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch

### Welcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018

Welcome to CSE 142! Whitaker Brand University of Washington, Winter 2018 1 What is computer science? computers? science? programming? late lonely nights in front of the computer? ALGORITHMIC THINKING al

### Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00

### DM503 Programming B. Peter Schneider-Kamp.

DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! VARIABLES, EXPRESSIONS & STATEMENTS 2 Values and Types Values = basic data objects 42 23.0 "Hello!" Types

### Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Tools : The Java Compiler javac [ options ] filename.java... -depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. -O: Optimizes code,

### 4 Programming Fundamentals. Introduction to Programming 1 1

4 Programming Fundamentals Introduction to Programming 1 1 Objectives At the end of the lesson, the student should be able to: Identify the basic parts of a Java program Differentiate among Java literals,

### CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

### Introduction to Java & Fundamental Data Types

Introduction to Java & Fundamental Data Types LECTURER: ATHENA TOUMBOURI How to Create a New Java Project in Eclipse Eclipse is one of the most popular development environments for Java, as it contains

### Lecture 3. More About C

Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

### Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

### 2 rd class Department of Programming. OOP with Java Programming

1. Structured Programming and Object-Oriented Programming During the 1970s and into the 80s, the primary software engineering methodology was structured programming. The structured programming approach

### Fundamentals of Programming

Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

### Values and Variables 1 / 30

Values and Variables 1 / 30 Values 2 / 30 Computing Computing is any purposeful activity that marries the representation of some dynamic domain with the representation of some dynamic machine that provides

### Midterms Save the Dates!

University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Primitive Data Types Arithmetic Operators Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch 4.1-4.2.

Sir Muhammad Naveed Arslan Ahmed Shaad (1163135 ) Muhammad Bilal ( 1163122 ) www.techo786.wordpress.com CHAPTER: 2 NOTES:- VARIABLES AND OPERATORS The given Questions can also be attempted as Long Questions.

### Data Types. 1 You cannot change the type of the variable after declaration. Zheng-Liang Lu Java Programming 52 / 87

Data Types Java is a strongly-typed 1 programming language. Every variable has a type. Also, every (mathematical) expression has a type. There are two categories of data types: primitive data types, and

### Fundamentals of Programming CS-110. Lecture 2

Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout

### Datatypes, Variables, and Operations

Datatypes, Variables, and Operations 1 Primitive Type Classification 2 Numerical Data Types Name Range Storage Size byte 2 7 to 2 7 1 (-128 to 127) 8-bit signed short 2 15 to 2 15 1 (-32768 to 32767) 16-bit

### Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

### Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how