CS2_07_Expressions_Operators_Statements

CS2_07_Expressions_Operators_Statements - CS2 • Module 7...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS2 • Module 7 • Category: Elements of Java • Topic: Expressions, Operators and Statements • Objectives – Introduce basic Java language elements CS 2 Introduction to Object Oriented Programming Module 7 Elements of Java Expressions, Operators and Statements Expressions • Formed by combining – Variables – Selected reserved words – Methods (Java/OO speak for procedures and functions) – Literal values – Operators – Syntax mostly borrowed from C/C++ Reserved Words (Keywords) abstract default if private throw boolean do implements protected throws break double import public transient byte else instanceof return try case extends int short void catch final interface static volatile char finally long super while class float native switch const* for new synchronized continue goto* package this Don't worry about what all these words mean or do, but be aware that you cannot use them for other purposes like variable names. Don't worry about what all these words mean or do, but be aware that you cannot use them for other purposes like variable names. Operators • Assignment: (=, +=, -=, *=, /=, etc.) • Arithmetic: +, -, *, /, % (modulo) and unary minus • String concatenation: + (overloaded) • Increment and Decrement Operators • Comparison: ==, !=, <. <=. >, >= • Boolean: && (and), || (or), ! (not) plus others (&, |, ^) • Bitwise: Not used in CS2 (~, &, |, ^, <<, >>, >>>) • Conditional: ?: • Plus others which we will introduce as appropriate: – instanceof, . , , (), new, etc. Operator Issues • Typically have operands (one or more) – Different type operands may change meaning of operator (+) • Operators always return a value • Operators may also have side effects • Order of evaluation Assignment • Basic assignment: = – Compute value of expression on right hand side of operator – Store result in variable on left hand side • Combination assignment operators (+=, -=, *=, /=, etc.) – Calculate value of expression on right hand side – Perform operation (first part of symbol) using variable on left hand side and value of expression – Store result in variable on left hand side a += 1; is equivalent to: a = a + 1; • Note: The format of these operators is: – "operation” then "equals sign” – x += 2; – Not: x =+ 2 which just means assign to x the value positive 2 Arithmetic • +, -, *, /, % (modulo), unary minus • Precedence – Unary minus – *, /, % – +, - The following table shows the precedence assigned to the operators. The operators in this table are listed in precedence order: the higher in the table an operator appears, the higher its precedence. Operators with higher precedence are evaluated before operators with a relatively lower precedence. Operators on the same line have equal precedence....
View Full Document

This note was uploaded on 01/23/2012 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Tech.

Page1 / 64

CS2_07_Expressions_Operators_Statements - CS2 • Module 7...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online