msi 692: special topics in information technology sanjay goel university at albany, suny fall 2004

51
1 Sanjay Goel, School of Business, University at Albany, SUNY MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

Upload: tania

Post on 14-Jan-2016

35 views

Category:

Documents


3 download

DESCRIPTION

MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004. Outline for the Class Part 1. Introduction What is Java? How is Java different from other languages? Tools for Programming in Java Java Language – Lexical elements Keywords Identifiers - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

1Sanjay Goel, School of Business, University at Albany, SUNY

MSI 692: Special Topics in Information

Technology

Sanjay GoelUniversity at Albany, SUNY

Fall 2004

Page 2: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

2Sanjay Goel, School of Business, University at Albany, SUNY

• Introduction• What is Java?• How is Java different from other

languages?• Tools for Programming in Java• Java Language – Lexical elements

– Keywords– Identifiers– Literals– Operators– Punctuation

Outline for the ClassPart 1

Page 3: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

3Sanjay Goel, School of Business, University at Albany, SUNY

• Data Types• Variables and initializations• Methods• Numbers

– Types– Ranges– Expressions– Conversions

• Operators– Assignment and Increment– Precedence and Associativity

Outline for the ClassPart 2

Page 4: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

4Sanjay Goel, School of Business, University at Albany, SUNY

Programming

Page 5: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

5Sanjay Goel, School of Business, University at Albany, SUNY

ProgrammingWhy do we need to write programs?

• Humans talk in a different language than computers do and we need to translate human talk into computer talk or instructions.– You write the program in a language you are

comfortable with– The compiler takes your program and smooshes it,

digests it, and creates a stream of zeros and ones for the computer to understand.

• Normally, different computers have different languages that they understand similar to the various human languages (i.e. French, English, Sanskrit & German)

• Thus, we have different compilers for different computers.

Page 6: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

6Sanjay Goel, School of Business, University at Albany, SUNY

ProgrammingWhat are the advantages of Java?

• Eliminates pitfalls of C/C++ by eliminating pointer arithmetic and explicit memory management.

• Is object-oriented which helps enforce better programming techniques and to better visualize the code

• Interpreted environment which improves speed of development– Reduces compile-link-load cycle– Is portable across multiple platforms

• Runs more than one parallel activity via threads

• Enables security by checking code modules that are loaded

Page 7: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

7Sanjay Goel, School of Business, University at Albany, SUNY

ProgrammingHow is Java different from other languages?

• Uses a Java Virtual Machine (JVM)– JVM is a byte-code interpreter unique for different

hardware

– Takes burden of compling on multiple hardware away from user

• C/C++: Source Compiler Machine Code

• Java: Source Java Compiler Byte Code Java Virtual Machine Machine Code

• Garbage Collection– No memory management

• Code Security

Page 8: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

8Sanjay Goel, School of Business, University at Albany, SUNY

ProgrammingWhat are the advantages?

• Expands your programming horizons across the enterprise– You are able to write programs which span across

the internet– You can have a database sitting in one location on a

compute server in another location and a web server in a third place which will communicate

– Java makes it easier to program across the network– You can develop user interfaces

• All these facilities are available as extensions of the basic core Java language. – We are going to focus on the core language in this

class

Page 9: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

9Sanjay Goel, School of Business, University at Albany, SUNY

ProgrammingIDE Options

• Requirements for Development of Programs– Editor (Emacs/Wordpad)– Compiler (Java SDK for Windows)– Execution Environment (Unix Shell/DOS Prompt)

• Several Different Development Environments exist– BlueJ– JBuilder– Forte from Java– JDeveloper from Oracle – Java Visual Café

• If any one wants to install java on their personal computers a link to the instructions is located on the syllabus. – Please interact with Tony Manes or D.J. Anderson with

questions about this installation.– Come to me if they are unavailable or unable to help.

Page 10: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

10Sanjay Goel, School of Business, University at Albany, SUNY

Language Constructs

Page 11: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

11Sanjay Goel, School of Business, University at Albany, SUNY

Language ConstructsIntroduction

• Like any language a programming language has some symbols and some rules to combine these symbols to make sense.– A compiler breaks individual characters the

program into tokens. These tokens are then interpreted with respect to the context they exist in and processed.

• Most of the previous languages were based on the 127 ASCII characters – Adequate representation to the English language

keyboard.

• Java is based on Unicode that has 64000 characters– Allows representation of multiple languages other

than English for programming.

Page 12: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

12Sanjay Goel, School of Business, University at Albany, SUNY

Language ConstructsTypes of Tokens

• There are five types of tokens which are processed:– Keywords– Identifiers– Literals– Operators– Punctuation

• There are two types of tokens that are not processed– White Space– Comments

Page 13: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

13Sanjay Goel, School of Business, University at Albany, SUNY

Language ConstructsWhite Space

• Uses– Used to separate tokens in program that are

not separated by separators– Make the program more readable

•  There are three types of white spaces– space (when you hit the space bar)– tab (when you hit the tab key)– newline (when you hit the newline key)

Page 14: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

14Sanjay Goel, School of Business, University at Albany, SUNY

Language ConstructsComments

• Comments are used for documenting the code. • There are 3 types of comments

– Single line comments // This is a single line comment

– Multi-line comment/* This is a multi-line commentSo write multiple lines here or only one if you choose to*/

– javadoc comments /** This is a javadoc comment to generate documentation at the endof the code @author Sanjay Goel@deprecated*/

Page 15: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

15Sanjay Goel, School of Business, University at Albany, SUNY

KeywordsReserved words with special meaning

• These are reserved words in the language and have a special meaning to them. – There are 47 key words in Java language. – The keyword is separated from other keywords

or identifiers by white space, comment or punctuation.

• const and goto have no meaning in java but had meaning in C & C++. – They have been included to facilitate error

reporting when users use these words in java – null, true and false are not keywords but are

literals.

Page 16: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

16Sanjay Goel, School of Business, University at Albany, SUNY

KeywordsKeywords in Java

• The keywords in the Java language are as follows:– abstract double int strictfp – boolean else interface super – break extends long switch – byte final native synchronized – case finally new this – catch float package throw – char for private throws – class goto protected transient – const if public try – continue implements return void – default import short volatile – do instanceof static while  

Page 17: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

17Sanjay Goel, School of Business, University at Albany, SUNY

IdentifiersNaming the Java elements

• These are the names that used to specify elements of the Java program, such as class variable or method i.e. – These are the names that you assign to different

constructs of the program.

• An identifier is any sequence of Java letters and digits.– The first of that must be a Java letter.– A key word can not be an identifier and the literals

null, true and false can not be identifiers.

• Java letters include the upper and lower case letters of the English alphabet – i.e. a-z, A-Z, $, and underscore "_"

• Java digits are 0-9

Page 18: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

18Sanjay Goel, School of Business, University at Albany, SUNY

LiteralsValue representations for primitive numeric types

• Java has built in types for numbers, characters and Booleans. – It also has a built in class for String.

• Literals are the value representations for the primitive numeric types, the Boolean and character as well as the standard class type of String.– String "Carrot“– String "Emily“– char 'a‘– char 'b‘– Boolean true– Boolean false– double 3.21– int 12– int 234234

Page 19: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

19Sanjay Goel, School of Business, University at Albany, SUNY

OperatorsMathematical

• Operators– /, *, +, -, =

• Precedence– Hierarchy that determines the order in which

operators are evaluated

• Associativity– Order in which operators of equal precedence

are evaluated (Left to Right or Right to Left)

• BODMAS – Binary operation of Division, Multiplication,

Addition, Subtraction

Page 20: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

20Sanjay Goel, School of Business, University at Albany, SUNY

OperatorsRelational

• They determine the relationship between two operands (values).

• They are used in a condition expression in order to test whether a particular kind of relationship exists between two operands.

• All relational operators return a Boolean Value, which evaluates if the relationship between the operands is true or false.

• Java utilizes a conditional expression, which uses one or more relational operators to discover if the statement is true or false.

Page 21: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

21Sanjay Goel, School of Business, University at Albany, SUNY

• Relational Operators: Equal to = =

Not equal to ! = Greater than >Less than <Greater than or equal to > =Less than or equal to < =

• Example: The if..else statement. If the expression is true, execute the if statement, and if it is false, execute the else statement. b < = a• If b is less than or equal to a, then the expression is true, and the if statement is executed. If b is greater than a, then the expression is false, and the else statement is executed.

OperatorsRelational

Page 22: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

22Sanjay Goel, School of Business, University at Albany, SUNY

• In order for Java to assess two relational expressions, they must be linked together using a logical operator.

• Logical Operators:And &&OR llAnd &OR lTernary if-then-else ?:

• The AND Logical Operator (&&)- For the statement to be true, both relational expressions have to be true. If one or both of the expressions is false, then the AND logical operator returns a Boolean false.

OperatorsLogical

Page 23: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

23Sanjay Goel, School of Business, University at Albany, SUNY

• The OR Logical Operator (ll)- For the statement to be true, only one of the relational expressions has to be true. If both of the expressions are false, then the OR logical operator returns a Boolean false.

• The Single AND and OR Logical Operators (&,l)- When using the && and ll Operators, only the first expressions are evaluated. If the first expression is false in the && Operator, then the second does not need to be evaluated. If the first expression is true in the ll Operator, then the second does not need to be evaluated. However, when using the single AND and OR Operators, both expressions need to be evaluated regardless of if they return a Boolean true or false.

• The Ternary Operator (?:)- Uses a relational expression and two values. If the relational expression is true, the ternary operator uses the first value. If it is false, it uses the second value.

OperatorsLogical

Page 24: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

24Sanjay Goel, School of Business, University at Albany, SUNY

• Bitwise Operators help the programmer change the value of a bit (binary digit) from zero to one, or one to zero.

• Bitwise AND Operator (&)- It compares two bits. If both of the bits are 1’s, then the AND operator returns a 1. If only one bit is 1 or both are 0, then it returns a 0.Example 00001111

& 00001010 00001010

• Bitwise Inclusive OR Operator (l)- If one or both bits are a binary 1, then a binary 1 is returned. If both bits are a binary 0, then a binary 0 is returned.Example 00001111

l 0000101000001111

OperatorsBitwise

Page 25: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

25Sanjay Goel, School of Business, University at Albany, SUNY

• Bitwise Exclusive OR Operator (^)- If one bit is a binary 1, then a binary 1 is returned. If both bits are a binary 1, then a binary 0 is returned. If both bits are a binary 0, then a binary 0 is returned. Example- 00001111

^ 00001010 00000101

• Bitwise Left Shift Operator (<<)- This operator moves bits one position to the left. Then leftmost bit then drops, and the rightmost bit is replaced with a 0. Example- 00001111 00011110

OperatorsBitwise

Page 26: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

26Sanjay Goel, School of Business, University at Albany, SUNY

• Bitwise Signed Right Shift Operator (>>)- This operator moves bits one position to the right. The empty position on the left is filled with a value that represents the same sign as the rightmost bit that was shifted. (positive bit = 0, negative bit = 1)Example- 10001111 10000111

• Bitwise Unsigned Right Shift Operator (>>>)- This operator moves bits one position to the right. The empty position on the left is always filled with a binary 0 (the sign of the bit is not significant).

• Bitwise Complement Operator (~)- This operator reverses the values of the bits. Binary 1’s become Binary 0’s, and vice versa.Example- 00001111 11110000

• “Two’s Complement”- This term refers to reversing all of the bits, and then adding 1 to the result.

OperatorsBitwise

Page 27: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

27Sanjay Goel, School of Business, University at Albany, SUNY

PunctuationSeparators

• These are the separators used in expressions i.e. – ";" – ","– "{ }”

Page 28: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

28Sanjay Goel, School of Business, University at Albany, SUNY

Data Types and Variable Declarations

Page 29: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

29Sanjay Goel, School of Business, University at Albany, SUNY

Data Types and Variable DeclarationsIntroduction• Data type determines how data is represented in

computer memory. Each variable has to have a defined type

• There are 8 primitive types. – Numeric - byte, short, int, long, float, double– Character – char– Logic - boolean (can have value of true or false)

• In addition there are built in classes like Button, Frame, Point, String. – There are more than a few thousand classes and new

classes are added continuously.– There is a SUN community process that determines

what new classes to add.

• The data values of classes are called objects.

Page 30: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

30Sanjay Goel, School of Business, University at Albany, SUNY

Data Types and Variable DeclarationsVariables• These are identifiers that are used to refer

to values stored in the computers memory.– e.g. int i; – int j, k;

• Variables can be initialized also– e.g. int j = 10;– boolean flag = true, iflag = false;– String sentence = "Who am I";

Page 31: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

31Sanjay Goel, School of Business, University at Albany, SUNY

Number Types

Page 32: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

32Sanjay Goel, School of Business, University at Albany, SUNY

Number TypesTypes of Numbers

• Two types– Integer representations– Floating point representations

• A binary digit (bit) is the smallest unit of information that can be stored on the computer and can have a binary value i.e. 0 or 1.

• A combinations of bits is used to represent larger range of values.

• For integers bits are interpreted with the binary number system.– Integers can be represented as a combination of binary digits or bits.– Different precisions are used to store different numbers

• Negative numbers use two’s complement representation– Allows use of binary arithmetic operations on signed integers – Positive 2's complement numbers are represented as simple binary. – Negative 2's complement numbers are represented as the binary

number that when added to a positive number of the same magnitude equals zero.

Page 33: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

33Sanjay Goel, School of Business, University at Albany, SUNY

Number TypesNegative Numbers and Floating Point Types

• Integral Types

byte 8 -128 to 127

short 16 -32768 to 32767

char 16 0 to 65536

int 32 -2147483648 to –2147483647

long 64 -9223372036854775808 to 9223372036854775807

Float 32 Precision: 7 digits

Double

64 Precision: 15 digits

• Floating point types

Page 34: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

34Sanjay Goel, School of Business, University at Albany, SUNY

Number TypesArithmetic Expressions

• There are 5 basic arithmetic operators– Addition– Subtraction– Multiplication– Division– Modulus

Page 35: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

35Sanjay Goel, School of Business, University at Albany, SUNY

Number TypesConversion

• Any primitive numeric types can be used with these arithmetic operators.

• If the operators are of different types the types are converted so that they are of the same type.

• This conversion scheme is called the binary numeric promotion.– if either operand is double the other operand is converted to

double

– else if either operand is float other operand is converted to float

– else if either operand is long other operand is converted to long

– else both operands are converted to int.

Page 36: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

36Sanjay Goel, School of Business, University at Albany, SUNY

Number TypesExplicit Type Conversions

• There are two type of conversions• Widening primitive conversions

– These go from a lower resolution to a higher resolution type and thus there is no loss of information.

– These conversions are sometimes done via binary numeric promotion

– Example:int x = 1, y = 2;float z = x + y;

Page 37: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

37Sanjay Goel, School of Business, University at Albany, SUNY

Number TypesExplicit Type Conversions cont’d

• Narrowing primitive conversions– These go from a higher resolution type to a lower

resolution type and can lead to loss of resolution.– An explicit conversion is required via a cast operator to

achieve this.– This is dangerous and should be done carefully

int i = 127, j = 128;byte iAsByte = (byte)i;byte jAsByte = (byte)j;System.out.println(i);System.out.println(j);output:127-128

– Since the max positive number is 127 the number representation gets screwed up in memory.)

Page 38: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

38Sanjay Goel, School of Business, University at Albany, SUNY

Number TypesOperators

• Assignment operator : "=“– assigns the rhs to the lhs– i.e. i = 10;

+= -= *= %= >>= <<= &= ^= != 

• Increment and decrement operators++i --i i++ i--

Page 39: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

39Sanjay Goel, School of Business, University at Albany, SUNY

Number TypesAssociativity and precedence

• Precedence - hierarchy of evaluation

• Associativity - If level is the same what is the order of evaluation

• You can make the expression more explicit by using parentheses.– e.g. a + b * c vs. (a + b) * c

Page 40: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

40Sanjay Goel, School of Business, University at Albany, SUNY

Building a Program

Page 41: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

41Sanjay Goel, School of Business, University at Albany, SUNY

Building a ProgramSample Program

• Let us examine a simple program

• Prior to dissecting this let us look at the various structures in the program.

• Just like in writing a book you construct the basic characters into words, words into statements, statements into paragraph and paragraphs into chapters and chapters into books.

• Similarly we can arrange the program constructs into a

hierarchy.

Page 42: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

42Sanjay Goel, School of Business, University at Albany, SUNY

Building a ProgramMethods

• Methods are group of instructions with a name. • You can write very simple programs in a single

monolithic block but programs can get large and as large as a few million lines. – You need to separate pieces out for ease of development and

maintenance.

• The way to separate them is writing methods which are a group of instructions with a name and signature. – Depending on the size of the program there can be many

methods. – Some methods are already defined in the language.

• main method– The main method is a special method. The program starts

execution from the main method.public static void main(String args[]) {}

Page 43: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

43Sanjay Goel, School of Business, University at Albany, SUNY

Building a ProgramWriting to console

Hello World program/** Hello world program for class lecture * @author Sanjay Goel * @created August 26, 2001 * */import java.io.*;

 public class HelloWorld { public static void main(int args[]) { String string1 = "Hello "; String string2 = "World"; System.out.println(string1 + string2);

} }

/** Program to sum two numbers * @author Sanjay Goel * @created August 26, 2001 * */import java.io.*;

 public class Sum{ int a = 10; int b = 30;

  int sum = a + b;  System.out.println("a = " + a + " b =

" + b + " Sum = " + sum);}

• System.out.print(ln)– System.out.print("I want to test without carriage return");– System.out.println("I want to test with carriage return");

Page 44: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

44Sanjay Goel, School of Business, University at Albany, SUNY

Review

Page 45: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

45Sanjay Goel, School of Business, University at Albany, SUNY

RecapKeywords and Identifiers

• Keywords– Reserved words which have special purpose

and can’t be used for any thing else– 47 in total – new words may be added as

language expands

• Identifiers– Also called variables are names of the data

elements which you have stored in memory– Formed by sequence of Java letters and digits– All keywords and three literals (true, false,

null) can not be used as identifiers– Note: Java letters are A-Z, a-z, underscore & $ – Java numbers 0-9

Page 46: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

46Sanjay Goel, School of Business, University at Albany, SUNY

RecapLiterals

• Literals– These are the values you assign to the

variables– The variables have to be of specific types

• Types of Literals– Numeric

• Whole Numbers – integer type numerics• Fractional Numbers – floating point type numerics

– Char • single character, digit, symbol

– Boolean logic– Strings– Text

Page 47: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

47Sanjay Goel, School of Business, University at Albany, SUNY

RecapNumeric Types

• The numeric types are: – Byte 8 bits– Short 16 bits– Int 32 bits– Char 32 bits– Long 64 bits– Float 32 bit– Double 64 bits

• Why do we have so many different types? – To economize on use of memory– We use more memory for larger whole numbers or for

fractional numbers with higher precision.

• The ranges were discussed in the previous class.

Page 48: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

48Sanjay Goel, School of Business, University at Albany, SUNY

RecapOperators, Punctuation, White Space & Comments

• Operators– These are the symbols used for arithmetic operations on

numbers– Unary operators operate only on one number ++, --– Binary operators operate on two numbers +, -, /, %

• Punctuation– These are the elements that act as separators – ; {} [] ,

• White Space– Spaces, tabs, newline

• Comments– Three types: Single line, multiline, Javadoc comment

Page 49: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

49Sanjay Goel, School of Business, University at Albany, SUNY

RecapInitialization, Methods, and I/O

• Variable initialization– Specify type, value, and name– Terminated by a semicolon

• Methods– User Defined– System Defined

• Simple I/O– System.out.println(“This is a test”);– Console.in.readInt();

Page 50: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

50Sanjay Goel, School of Business, University at Albany, SUNY

RecapArithmetic Expressions and Conversion

• Arithmetic Expressions– Syntax– Mixed mode arithmetic– Binary numeric promotion

• Type conversion• Widening primitive conversions

– Goes from lower precision to higher precision– Can be automatic or an explicit cast

• Narrowing primitive conversions– Has to be explicit

Page 51: MSI 692: Special Topics in Information Technology Sanjay Goel University at Albany, SUNY Fall 2004

51Sanjay Goel, School of Business, University at Albany, SUNY

RecapArithmetic Operators, Associativity and Precedence

• Arithmetic Operators– Variable = expression (a = b + c)– Assignment (=, +=, -=, *=, /=, %=)– Increment and Decrement Operators (++, –-)

• Precedence– order in which operators are evaluated

• Associativity – Order in which operators of same precedence

are evaluated (L->R, R->L)

• You can make the expression more explicit by using parentheses.