Exercises Software Development I. 05 Conversions and Promotions; Lifetime, Scope, Shadowing. November 5th, 2014

Size: px
Start display at page:

Download "Exercises Software Development I. 05 Conversions and Promotions; Lifetime, Scope, Shadowing. November 5th, 2014"

Transcription

1 Exercises Software Development I 05 Conversions and Promotions; Lifetime, Scope, Shadowing November 5th, 2014 Software Development I Winter term 2014/2015 Priv.-Doz. Dipl.-Ing. Dr. Andreas Riener Institute for Pervasive Computing Johannes Kepler University Linz riener@pervasive.jku.at

2 Conversions and Promotions

3 Operations on Mixed Data Types: Conversions and Promotions Every expression in Java has a specific data type... Can be deduced from the structure of the expression and the types of the literals, variables, and methods mentioned in the expression It is possible, however, to write an expression in a context where the type of the expression is not appropriate in some cases this leads to an error at compile time in other cases the context may be able to accept a type that is related to the type of the expression; (during the assignment, the compiler performs an implicit casting conversion rather than requesting the programmer to specifiy an explicit conversion) short shortvar = 1000; // int literal, is implicitly casted to short Java specifies five conversion contexts in which conversion of expressions may occur: casting conversion, String conversion, assignment conversion, numeric promotion, method invocation conversion Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 3

4 Operations on Mixed Data Types: Conversion Contexts - Example public class ConversionContexts { public static void main(string[] args) { // Casting conversion of a float literal to type int (without the cast operator, this // would be a compile-time error, because this is a narrowing conversion) int i = (int)12.5f; // String conversion of i's int value System.out.println("(int)12.5f==" + i); // Assignment conversion of i's value to type float (this is a widening conversion) float f = i; // String conversion of f's float value System.out.println("after float widening: " + f); // NUMERIC PROMOTION of i's value to type float (this is a binary numeric promotion); // after promotion, the operation is float*float System.out.print(f); f = f * i; // Two string conversions of i and f System.out.println("*" + i + "==" + f); // Method invocation conversion of f's value to type double, needed because the method // Math.sin accepts only a double argument double d = Math.sin(f); Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 4

5 I Operations on Mixed Data Types: Numeric Promotions Numeric promotion is applied to the operands of an arithmetic operator Numeric promotions are used to convert the operands of a numeric operator (on literals and variables) to a common type so that an operation can be performed example: numeric operation involving different data types 17.0 double + 4 int two kinds of numeric promotions: unary numeric promotion and binary numeric promotion numeric promotion contexts allow the use of - an identity conversion - a widening conversion - an unboxing conversion Data type conversion is also required on data types "shorter" (smaller) than int (float, double). Why? Numeric operations are only defined for int (or larger types), never on byte, char, or short type conversion table! numeric promotion: "widening conversion" of all operands smaller than int ("smallest" target data type is int), operation is executed after the conversion Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 5

6 Operations on Mixed Data Types: Numeric Promotions Numeric promotion is applied to the operands of an arithmetic operator Example byte b = 100; byte c = 100, d; d = b * c; Is this operation valid in Java? no, operation is illegal - result of the multiplication operation is of type int - result assignment requires "narrowing conversion" (explicit type cast) to data type byte ok, but what about: d = (byte) b*c;? - illegal; the unary cast operator has higher priority than the multiplication operator correct operation: d = (byte)(b*c); Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 6

7 I Operations on Mixed Data Types: Numeric Promotions Conversion rules One operand double second operand converted to double Else: one operand float second operand converted to float Else: one operand long second operand converted to long Else: both operands converted to int Affected operators multiplicative operators *, /, % addition, subtraction +, - numeric comparison <, <=, >, >= numeric parity/imparity ==,!= bitwise operations &,, ^ Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 7

8 Operations on Mixed Data Types: Widening Conversion - Example public class Widening Conversion { public static void main(string[] args) { int big = ; float approx = big; System.out.println(big - (int)approx); // Expected: ~0, actual output: -46 System.out.println((float)big - approx); // Expected: ~0, actual output: 0.0 information was lost during the conversion from type int to type float (values of type float are not precise to nine significant digits) information lost two times difference is now 0.0 ; output is E9 Widening and Narrowing Primitive Conversion The following examples combines both widening and narrowing conversions byte bytea = 65; char chara; chara = 65; bytea = 65; chara = (byte)65; chara = bytea; OK OK OK first, the byte is converted to an int via widening conversion then the resulting int is converted to a char by narrowing conversion NO! Type mismatch: cannot convert from byte to char! Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 8

9 Operations on Mixed Data Types: Widening Conversion - Example public class Widening Conversion { public static void main(string[] args) { int big = ; float approx = big; System.out.println(big - (int)approx); // Expected output: ~0 // Actual output: -46! information was lost during the conversion from type int to type float (values of type float are not precise to nine significant digits) Widening and Narrowing Primitive Conversion The following example combines both widening and narrowing conversions byte bytea = 65; char chara; chara = bytea; first, the byte is converted to an int via widening conversion then the resulting int is converted to a char by narrowing conversion Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 9

10 Operations on Mixed Data Types: Numeric Promotions Conversion rules (detailed) A widening conversion does not lose information about the overall magnitude of a numeric value A widening conversion from an integral type to another integral type, or from float to double (FP-strict expression only), does not lose any information at all; the numeric value is preserved exactly non FP-strict float to double widening conversion may lose information about the overall magnitude of the converted value. A widening conversion of an int or a long value to float, or of a long value to double, may result in loss of precision - that is, the result may lose some of the least significant bits of the value A widening conversion of a signed integer value to an integral type simply sign-extends the two's-complement of the integer value (fill-up) A widening conversion of a char to an integral type zero-extends the representation of the char value to fill the wider format Despite the fact that loss of precision may occur, a widening primitive conversion never results in a run-time exception Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 10

11 Operations on Mixed Data Types: Unary Numeric Promotion public class UnaryPromotion { public static void main(string[] args) { byte b = 2; int a[] = new int[b]; // dimension expression promotion char c = '\u0001'; a[c] = 1; // index expression promotion a[0] = -c; // unary numeric promotion System.out.println("a: " + a[0] + "," + a[1]); b = -1; int i = ~b; // bitwise complement promotion System.out.println("~0x" + Integer.toHexString(b) + "==0x" + Integer.toHexString(i)); i = b << 4L; // shift promotion (left operand) System.out.println("0x" + Integer.toHexString(b) + "<<4L==0x" + Integer.toHexString(i)); Program output: a: -1,1 ~0xffffffff==0x0 0xffffffff<<4L==0xfffffff0 Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 11

12 Operations on Mixed Data Types: Unary Numeric Promotion public class UnaryPromotion { public static void main(string[] args) { byte b = 2; int a[] = new int[b]; // dimension expression promotion char c = '\u0001'; a[c] = 1; // index expression promotion a[0] = -c; // unary numeric promotion System.out.println("a: " + a[0] + "," + a[1]); b = -1; int i = ~b; // bitwise complement promotion System.out.println("~0x" + Integer.toHexString(b) + "==0x" + Integer.toHexString(i)); i = b << 4L; // shift promotion (left operand) System.out.println("0x" + Integer.toHexString(b) + "<<4L==0x" + Integer.toHexString(i)); Program output: a: -1,1 ~0xffffffff==0x0 0xffffffff<<4L==0xfffffff0 Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 12

13 Operations on Mixed Data Types: Binary Numeric Promotion public class BinaryPromotion { public static void main(string[] args) { int i = 0; float f = 1.0f; double d = 2.0; // First int * float is promoted to float * float, then float == double is // promoted to double == double if (i * f == d) System.out.println("oops"); // A char & byte is promoted to int & int byte b = 0x1f; char c = 'G'; int control = c & b; System.out.println(Integer.toHexString(control)); // Here int:float is promoted to float:float f = (b==0)? i : 4.0f; System.out.println(1.0/f); Program output: Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 13

14 I Operations on Mixed Data Types: Character Promotions Recall: It is possible to perform numeric calculations using characters Example 1 int x = 'a' 'a'; int y = 'b' 'a'; Example 2 char f = 'a' + 5; Example 3 char c = 'a'; c = c + 5; c = c + (char)5; c = (char) (c + 5); // = 0 // = 1 // ok; 'a'...char literal, // 5...int literal // ok, correct assignment // error, result type 'int' // error, extended to int, result type 'int' // char + char = int // ok, int result with explicit cast to char Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 14

15 I Operations on Mixed Data Types: Binary+Character Promotions public class BinaryCharPromotion { public static void main(string[] args) { // int + int literals; implicit cast to short (value fits!) short s = 5 + 5; System.out.println(s); // int + int literals; implicit cast to byte (value fits!) byte b1 = ; System.out.println(b1); // int + int literals; result = 128? (value does not fit into byte)? byte b2 = ; System.out.println(b2); // continued on next slide... Program output: Type mismatch: cannot convert from int to byte at BinaryPromotion.main(BinaryPromotion.java:12) Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 15

16 I Operations on Mixed Data Types: Binary+Character Promotions char f = 'a' + 5; // char in Java: 16bit (Unicode) System.out.println(f); // operation on 'int' type (automatic widening+narrowing conversion) f = 'a' - 'a' ; // maximum value for 16bit/char = 2^16-1 = System.out.println(f); // max. value for char+1 -> overflow or automatic extension char -> int? f = 'a' - 'a' ; System.out.println(f); Program output: f = character in Unicode table at position Type mismatch: cannot convert from int to char... Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 16

17 Operations on Mixed Data Types: Operator Differences i+=f, i=i+f? public class OperatorDifferences { public static void main(string[] args) { int i = 10; float f = 1.23f; // += operator has strong binding to 'i' (double function: result, operand) i += f; System.out.println(i); // i = i + (int)f; // "normal" widening conversion: int -> float i = i + f; // i(int) = i(float) +(float) f(float) System.out.println(i); // i(int) = 10.0f f = 11.23f Program output: 11 Type mismatch: cannot convert from float to int at OperatorDifferences.main(OperatorDifferences.java:12) Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 17

18 Lifetime, Scope, Shadowing

19 I Declaration: Variables, Constants Variables Declaration introduces a new variable with name, data type, (initial value) Before its first use (in general at the begin of the program, right after public static void main() Preferred "local", not "global" declaration (i.e., start of the innermost block that uses this variable) not mixed with assignments Constants Declaration introduces a new constant with name, data type, fixed value In general at the very begin of the program (before main method), e.g. public class ConstantDeclaration { static final int FACTOR = 10; // integer constant, value 10 static final boolean NO = false; // boolean constant, value false public static void main(string[] args) { NO = true; //??? Compilation error: The final field // ConstantDeclaration.NO cannot be assigned Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 19

20 Declaration: Variables, Constants - Example public class ConstantDeclaration { static final int FACTOR; // =0; //error: the blank final field FACTOR may not have been initialized static final int FACTOR2 = 10; public static void main(string[] args) { final int FACTOR3 = 20; FACTOR3 = 30; //error: the final local variable FACTOR3 cannot be assigned... System.out.println(FACTOR); System.out.println(FACTOR2); System.out.println(FACTOR3); Program output: Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 20

21 I Declaration: Variables, Constants - Example public class ConstantDeclaration2 { static int decfact = 10; // variable, global, not a constant! static int hexfact = binfact * 8; // error: 'binfact' not yet declared static int binfact = 2; // ok, variable, global final static int OCTFACT = binfact * 4; // ok, constant, global, uses 'binfact' to inizialize // Notice: Use global variables only if more than just one method accesses it; // declare variables in general locally (i.e. within a block or method). public static void main (String[] arg) {// variable 'arg', type String[] int i = decfact, j = 2 * i; // two variables 'i', 'j'; local // Notice: global variable 'decfact' used to initialize 'i'; once 'i' is // declared it can already be used to initialize 'j' int num = Input.readInt(); System.out.println("num: " + num + ", decfact: " + decfact + ", i: " + i); while (num > 0) { int decfact = binfact; // local 'decfact' overlaps global 'decfact'; shadowing num = num / decfact; // local 'decfact' used in the division! System.out.println("num: " + num + ", decfact: " + decfact); Program output: 3 num: 3, decfact: 10, i: 10 num: 1, decfact: 2 num: 0, decfact: 2 Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 21

22 I Declaration of Variables, Constants: Lifetime (Durability) Lifetime of Variables is the time from its creation (in memory) until the point in time where it is released again (deleted in memory, "freed" by garbage collector), i.e., lifetime is the time the variable is accessible In Java, lifetime of variables is distinguished in three contexts local variables are declared in methods and blocks and are created for each execution of the method or block; after the execution of the method/block completes, local (non-final) variables are no longer accessible; method parameter exist from the procedure entry until its end as long as the procedure is active, i.e., in memory and executed global (static) variables [class variables, not instance variables] are created when the class is loaded at runtime, and exist as long as the class exists (i.e., from start to termination of the program) instance variables [members of a class] are created for each object of the class (i.e., every object of the class will have its own copies of these variables); the values of these variables at any given time constitute the state of the object; instance variables exist as long as the corresponding object they belong to exists Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 22

23 Declaration of Variables, Constants: Scope Scope of a variable is the part of the program where this variable can be accessed Scope is defined for local variables: the block { in which the variable has been declared; accessible from the point of declaration until the end of the block global variables (class variables), constants: accessible throughout the entire class/in the whole class parameter (special form of local variable): in the whole body of a function/ procedure public class Scope { static int a; // global variable, can be used in the whole class/program static int b; // same as before public static void main (String[] arg) { //parameter 'arg' can be used in 'main' int c; // local variables 'c','d'; defined only within 'main' (from this int d // position until the closing '' of main) if (c == d) { int e = 3; // variable 'e' might be used here // 'e' is no longer valid here Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 23

24 I Declaration of Variables, Constants: Shadowing What exactly is shadowing in Java? nothing but redeclaring a variable that has been already declared somewhere else; the effect of shadowing is to hide the previously declared variable in such a way that it may look as though you are using the hidden variable, but you are actually using the shadowing variable Most common is to "Hide an instance variable by shadowing it with a local variable" shadowing does not limit the lifetime of a variable, i.e., a global variable might be temporarily not visible/accessible at a certain program position, but still exists after leaving, e.g., this block, the local variable has disappeared, the global variable is visible again shadowing might limit the visibility of a (global) variable Shadowing happens most of the times by accident causes hard-to-find bugs Local variables and function parameters must not be shadowed Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 24

25 Declaration of Variables, Constants: Shadowing - Examples import java.lang.math.*; public class ShadowingMotivation { static double x = 3.0; static double y; global variables 'x', 'y' public static void main(string[] args) { y = Math.powerOfTwo(x); System.out.println(y); public class Math { private static double poweroftwo(double y) { double x; x = y * y; local variable 'x', (local) parameter 'y' return x; // poweroftwo declared private: code invisible outside! Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 25

26 Declaration of Variables, Constants: Shadowing - Examples public class NotShadowing { public static void main (String[]arg){ int i = 0; int sum = 0; while (i > 0) { int i = 4; this declaration is not allowed (even if code is never reached ) local variable must not be shadowed by another local var. for (int i = 1; i <= 100; i++) { for (int i = 20 ; i!= 10; i--) { sum = sum + i; // 'i' is undefined here (i.e., outside the 'for'-block) System.out.println("sum: " + sum); second declaration of 'i' is not allowed already a 'i' variable in this scope (=block) for (int i = 1; i <= 70; i++) {... for (int i = 52 ; i!= 10; i--) {... this is finally allowed (but is not shadowing!) 2 blocks with each local declarations of 'i' Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 26

27 Declaration of Variables, Constants: Shadowing - Examples public class ConstantShadowing { static int a = 10; // global variable static final int b = 100; // global constant public static void main (String[] arg) { int a = 5; // local variable (shadowing global 'a') int b = 50; // local variable (shadowing global constant 'b') System.out.println(a); System.out.println(b); declaration allowed; a global constant 'b' might be redeclared as local variable 'b' Program output: 5 50 Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 27

28 The Big Picture: Visibility, Scope, Shadowing public class LifeTimeScope { static int a; a = 10; global variable public static void main (String[]arg) { int a = 5; int b; Person p = new Person(); local variables // a redeclared a, c not defined here if (a < 10) { int c = a; int a = 3; b = poorcalc(a); System.out.print(b); local a (=5) // global a shadowed! new local variable c, value=5 not allowed (local-local shadowing) call uses local a (=5) p = null; p.name = "Franz"; public static int poorcalc (int a) { int b; b = 2 * a; return b; local variables/parameter (independent block) Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 28

29 The Big Picture: Visibility, Scope, Shadowing public class LifeTimeScope { static int a; a = 10; public static void main (String[]arg) { int a = 5; int b; Person p = new Person(); scope a (global) if (a < 10) { int c = a; int a = 3; scope c scope b scope a (local) b = poorcalc(a); System.out.print(b) p = null; p.name = "Franz"; public static int poorcalc (int a) { int b; b = 2 * a; return b; scope b scope a (local) Software Development I // Exercises // 05 Conversions and Promotions; Variables and Constant Declarations // 29

30 Exercises Software Development I 05 Conversions and Promotions; Lifetime, Scope, Shadowing November 5th, 2014 Software Development I Winter term 2014/2015 Priv.-Doz. Dipl.-Ing. Dr. Andreas Riener Institute for Pervasive Computing Johannes Kepler University Linz riener@pervasive.jku.at

Number Representation & Conversion

Number Representation & Conversion Number Representation & Conversion Chapter 4 Under the covers of numbers in Java 1 How (Unsigned) Integers Work Base 10 Decimal (People) Base 2 Binary (Computer) 10 2 10 1 10 0 2 3 4 2 7 2 6 2 5 2 4 2

More information

Operators and Expressions

Operators and Expressions Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

More information

Zheng-Liang Lu Java Programming 45 / 79

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

More information

Lecture Set 4: More About Methods and More About Operators

Lecture Set 4: More About Methods and More About 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

More information

Expressions & Flow Control

Expressions & Flow Control Objectives Distinguish between instance and local variables 4 Expressions & Flow Control Describe how instance variables are initialized Identify and correct a Possible reference before assignment compiler

More information

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014 Exercises Software Development I 03 Data Representation Data types, range of values, ernal format, literals October 22nd, 2014 Software Development I Wer term 2013/2014 Priv.-Doz. Dipl.-Ing. Dr. Andreas

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Chapter 3: Operators, Expressions and Type Conversion

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

More information

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz) SOFTWARE DEVELOPMENT 1 Operators 2018W (Institute of Pervasive Computing, JKU Linz) OPERATORS Operators are required to form expressions. Depending on the number of operands they take, they are called:

More information

Exercises Software Development I. 08 Objects II. Generating and Releasing Objects (Constructors/Destructors, this, Object cloning) December 3rd, 2014

Exercises Software Development I. 08 Objects II. Generating and Releasing Objects (Constructors/Destructors, this, Object cloning) December 3rd, 2014 Exercises Software Development I 08 Objects II Generating and Releasing Objects (Constructors/Destructors, this, Object cloning) December 3rd, 2014 Software Development I Winter term 2014/2015 Priv.-Doz.

More information

Prof. Navrati Saxena TA: Rochak Sachan

Prof. Navrati Saxena TA: Rochak Sachan JAVA Prof. Navrati Saxena TA: Rochak Sachan Operators Operator Arithmetic Relational Logical Bitwise 1. Arithmetic Operators are used in mathematical expressions. S.N. 0 Operator Result 1. + Addition 6.

More information

Lecture Set 4: More About Methods and More About Operators

Lecture Set 4: More About Methods and More About 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

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Java Programming Language. 0 A history

Java Programming Language. 0 A history Java Programming Language 0 A history How java works What you ll do in Java JVM API Java Features 0Platform Independence. 0Object Oriented. 0Compiler/Interpreter 0 Good Performance 0Robust. 0Security 0

More information

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

3. Java - Language Constructs I

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

More information

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

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

More information

The Arithmetic Operators

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

More information

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions

More information

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>= Operators in java Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc. There are many types of operators in java which are given below: Unary Operator, Arithmetic

More information

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions

More information

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2 Java Foundations Introduction to Program Design and Data Structures 4th Edition Lewis TEST BANK Full download at : https://testbankreal.com/download/java-foundations-introduction-toprogram-design-and-data-structures-4th-edition-lewis-test-bank/

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

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

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

More information

Primitive Data Types: Intro

Primitive Data Types: Intro Primitive Data Types: Intro Primitive data types represent single values and are built into a language Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types

More information

Slide 1 Side Effects Duration: 00:00:53 Advance mode: Auto

Slide 1 Side Effects Duration: 00:00:53 Advance mode: Auto Side Effects The 5 numeric operators don't modify their operands Consider this example: int sum = num1 + num2; num1 and num2 are unchanged after this The variable sum is changed This change is called a

More information

Program Fundamentals

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

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

More information

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 / 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

More information

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail. OOP in Java 1 Outline 1. Getting started, primitive data types and control structures 2. Classes and objects 3. Extending classes 4. Using some standard packages 5. OOP revisited Parts 1 to 3 introduce

More information

Chapter 6 Primitive types

Chapter 6 Primitive types Chapter 6 Primitive types Lesson page 6-1. Primitive types Question 1. There are an infinite number of integers, so it would be too ineffient to have a type integer that would contain all of them. Question

More information

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line A SIMPLE JAVA PROGRAM Class Declaration The Main Line INDEX The Line Contains Three Keywords The Output Line COMMENTS Single Line Comment Multiline Comment Documentation Comment TYPE CASTING Implicit Type

More information

ESc101 : Fundamental of Computing

ESc101 : Fundamental of Computing ESc101 : Fundamental of Computing I Semester 2008-09 Lecture 9+10 Types Range of numeric types and literals (constants) in JAVA Expressions with values of mixed types 1 I : Range of numeric types and literals

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II 1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables

More information

1.00 Lecture 4. Promotion

1.00 Lecture 4. Promotion 1.00 Lecture 4 Data Types, Operators Reading for next time: Big Java: sections 6.1-6.4 Promotion increasing capacity Data Type Allowed Promotions double None float double long float,double int long,float,double

More information

Selenium Class 9 - Java Operators

Selenium Class 9 - Java Operators Selenium Class 9 - Java Operators Operators are used to perform Arithmetic, Comparison, and Logical Operations, Operators are used to perform operations on variables and values. public class JavaOperators

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data

More information

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 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,

More information

Java Fall 2018 Margaret Reid-Miller

Java Fall 2018 Margaret Reid-Miller Java 15-121 Fall 2018 Margaret Reid-Miller Reminders How many late days can you use all semester? 3 How many late days can you use for a single assignment? 1 What is the penalty for turning an assignment

More information

CS61B Lecture #14: Integers. Last modified: Wed Sep 27 15:44: CS61B: Lecture #14 1

CS61B Lecture #14: Integers. Last modified: Wed Sep 27 15:44: CS61B: Lecture #14 1 CS61B Lecture #14: Integers Last modified: Wed Sep 27 15:44:05 2017 CS61B: Lecture #14 1 Integer Types and Literals Type Bits Signed? Literals byte 8 Yes Cast from int: (byte) 3 short 16 Yes None. Cast

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

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

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

More information

Primitive Data, Variables, and Expressions; Simple Conditional Execution

Primitive Data, Variables, and Expressions; Simple Conditional Execution Unit 2, Part 1 Primitive Data, Variables, and Expressions; Simple Conditional Execution Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Overview of the Programming Process Analysis/Specification

More information

More Programming Constructs -- Introduction

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

More information

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2 CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,

More information

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor:

More information

Programming with Java

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

More information

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Selections EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Learning Outcomes The Boolean Data Type if Statement Compound vs. Primitive Statement Common Errors

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming Variables; Type Casting; Using Variables in for Loops Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu

More information

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Data Types, Variables and Arrays OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani Identifiers in Java Identifiers are the names of variables, methods, classes, packages and interfaces. Identifiers must

More information

when you call the method, you do not have to know exactly what those instructions are, or even how the object is organized internally

when you call the method, you do not have to know exactly what those instructions are, or even how the object is organized internally I. Methods week 4 a method consists of a sequence of instructions that can access the internal data of an object (strict method) or to perform a task with input from arguments (static method) when you

More information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

CSC 1214: Object-Oriented Programming

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:

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

CS61B Lecture #14: Integers

CS61B Lecture #14: Integers Announcement: CS61B Lecture #14: Integers Project #0 due Tuesday night. Programming contest SATURDAY! You can still sign up at https://inst.eecs.berkeley.edu/~ctest/contest/register. Test #1 will be Tuesday,

More information

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School CSE 201 JAVA PROGRAMMING I Primitive Data Type Primitive Data Type 8-bit signed Two s complement Integer -128 ~ 127 Primitive Data Type 16-bit signed Two s complement Integer -32768 ~ 32767 Primitive Data

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

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

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

More information

Example: Tax year 2000

Example: Tax year 2000 Introductory Programming Imperative Programming I, sections 2.0-2.9 Anne Haxthausen a IMM, DTU 1. Values and types (e.g. char, boolean, int, double) (section 2.4) 2. Variables and constants (section 2.3)

More information

PROGRAMMING FUNDAMENTALS

PROGRAMMING FUNDAMENTALS PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write

More information

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

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

More information

Special Topics: Programming Languages

Special Topics: Programming Languages Lecture #23 0 V22.0490.001 Special Topics: Programming Languages B. Mishra New York University. Lecture # 23 Lecture #23 1 Slide 1 Java: History Spring 1990 April 1991: Naughton, Gosling and Sheridan (

More information

Computer Science II (20082) Week 1: Review and Inheritance

Computer Science II (20082) Week 1: Review and Inheritance Computer Science II 4003-232-08 (20082) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Syntax and Semantics of Formal (e.g. Programming) Languages Syntax

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

More information

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

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

More information

Integer Representation

Integer Representation Integer Representation Representation of integers: unsigned and signed Modular arithmetic and overflow Sign extension Shifting and arithmetic Multiplication Casting 1 Fixed- width integer encodings Unsigned

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

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

More information

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value Lecture Notes 1. Comments a. /* */ b. // 2. Program Structures a. public class ComputeArea { public static void main(string[ ] args) { // input radius // compute area algorithm // output area Actions to

More information

Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java

Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java Electrical and Computer Engineering Object-Oriented Topic 2: Fundamental Structures in Java Maj Joel Young Joel.Young@afit.edu 8-Sep-03 Maj Joel Young Java Identifiers Identifiers Used to name local variables

More information

1.3b Type Conversion

1.3b Type Conversion 1.3b Type Conversion Type Conversion When we write expressions involved data that involves two different data types, such as multiplying an integer and floating point number, we need to perform a type

More information

Full file at

Full file at Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

More information

JAVA Programming Fundamentals

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

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review

More information

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

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

More information

ECE 122 Engineering Problem Solving with Java

ECE 122 Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction Outline Problem: How do I input data and use it in complicated expressions Creating complicated expressions

More information

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 1: Types and Control Flow http://courses.cs.cornell.edu/cs2110/2018su Lecture 1 Outline 2 Languages Overview Imperative

More information

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003 Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an

More information

Programming Language Basics

Programming Language Basics Programming Language Basics Lecture Outline & Notes Overview 1. History & Background 2. Basic Program structure a. How an operating system runs a program i. Machine code ii. OS- specific commands to setup

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE 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

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

CS110D: PROGRAMMING LANGUAGE I

CS110D: PROGRAMMING LANGUAGE I CS110D: PROGRAMMING LANGUAGE I Computer Science department Lecture 7&8: Methods Lecture Contents What is a method? Static methods Declaring and using methods Parameters Scope of declaration Overloading

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types

More information

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018 Motivating Examples (1.1) Selections EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG 1 import java.util.scanner; 2 public class ComputeArea { 3 public static void main(string[] args)

More information

Java enum, casts, and others (Select portions of Chapters 4 & 5)

Java enum, casts, and others (Select portions of Chapters 4 & 5) Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The

More information

Declaration and Memory

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

More information

Expressions and Casting

Expressions and Casting Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence

More information

COMP-202: Foundations of Programming. Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016

COMP-202: Foundations of Programming. Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016 COMP-202: Foundations of Programming Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016 More Tutoring Help The Engineering Peer Tutoring Services (EPTS) is hosting free tutoring sessions

More information

CS Programming I: Primitives and Expressions

CS Programming I: Primitives and Expressions CS 200 - Programming I: Primitives and Expressions Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code:

More information

Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5. Iulian Năstac Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

More information

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Basic Operations jgrasp debugger Writing Programs & Checkstyle Basic Operations jgrasp debugger Writing Programs & Checkstyle Suppose you wanted to write a computer game to play "Rock, Paper, Scissors". How many combinations are there? Is there a tricky way to represent

More information

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

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

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Selected Questions from by Nageshwara Rao

Selected Questions from  by Nageshwara Rao Selected Questions from http://way2java.com by Nageshwara Rao Swaminathan J Amrita University swaminathanj@am.amrita.edu November 24, 2016 Swaminathan J (Amrita University) way2java.com (Nageshwara Rao)

More information

CIS 110: Introduction to Computer Programming

CIS 110: Introduction to Computer Programming CIS 110: Introduction to Computer Programming Lecture 3 Express Yourself ( 2.1) 9/16/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline 1. Data representation and types 2. Expressions 9/16/2011

More information

Exercises Software Development I. 06 Arrays. Declaration, Initialization, Usage // Multi-dimensional Arrays. November 14, 2012

Exercises Software Development I. 06 Arrays. Declaration, Initialization, Usage // Multi-dimensional Arrays. November 14, 2012 Exercises Software Development I 06 Arrays Declaration, Initialization, Usage // Multi-dimensional Arrays November 4, 202 Software Development I Winter term 202/203 Institute for Pervasive Computing Johannes

More information

COMP6700/2140 Data and Types

COMP6700/2140 Data and Types COMP6700/2140 Data and Types Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU February 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February

More information

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Integers II. CSE 351 Autumn Instructor: Justin Hsia Integers II CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/557/

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

More information