{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture2-Jan11-Review - 1 58 COP 3503 SPRING 2012 SHAYAN...

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

View Full Document Right Arrow Icon
1 / 58 COP 3503 SPRING 2012 SHAYAN JAVED LECTURE 2 Programming Fundamentals using Java
Background image of page 1

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

View Full Document Right Arrow Icon
2 / 58 Introduction to Java High-level language. Paradigm: Object-Oriented. WORA (“write - once, run anywhere”)
Background image of page 2
3 / 58 Introduction to Java Some languages are compiled (C/C++)
Background image of page 3

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

View Full Document Right Arrow Icon
4 / 58 Introduction to Java Some languages are compiled (C/C++) Some are interpreted (Python, Perl, Ruby, etc.)
Background image of page 4
5 / 58 Introduction to Java Some languages are compiled (C/C++) Some are interpreted (Python, Perl, Ruby, etc.) What about Java?
Background image of page 5

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

View Full Document Right Arrow Icon
6 / 58 Introduction to Java Source code (.java) Bytecode (.class) Interpret and run Compilation and Interpretation .java = compiled to .class .class = interpeted by Java Virtual Machine (JVM)
Background image of page 6
7 / 58 Java Syntax Similar to C/C++. Variables: byte, short, int, long, float, double, char, boolean Field Modifiers : final (“constant”) , static (applies to classes)
Background image of page 7

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

View Full Document Right Arrow Icon
8 / 58 Java Operators Numerical: +, -, *, /, % Boolean: >, <, <=, >=, ==, !=, !, instanceof Others: ++, --, Bitwise operators: & (AND), ^ (XOR), | (OR), <<, >> (shift)
Background image of page 8
9 / 58 if statements if ( boolean-expression ) { } else if (…) { } else { }
Background image of page 9

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

View Full Document Right Arrow Icon
10 / 58 Conditional expression boolean-expression ? expression1 : expression2 Example: int x = 3; int y = (x > 0) ? 1 : 5 ;
Background image of page 10
11 / 58 switch statement switch ( byte/short/char/int/String/etc. ) { case x: break; case y: ….. break; case …: break; default: ….. }
Background image of page 11

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

View Full Document Right Arrow Icon
12 / 58 Loops while ( boolean-expression ) { // do something } do { // something } while ( boolean-expression ); Difference?
Background image of page 12
13 / 58 Loops for ( expression1 ; boolean-expression ; expression2 ) { // do something } Example: int i; for ( i = 0 ; i <= 10 ; i++ ) i++; // Value of i?
Background image of page 13

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

View Full Document Right Arrow Icon
14 / 58 keyword break break = used to “break out” of a loop. Rest of the code is not executed. int sum = 0; int number = 0; while (number < 20) { number++; sum += number; if (sum > 100) break ; }
Background image of page 14
15 / 58 keyword continue continue = used in loops. Break out of current statement, but continue with the rest of the loop. int sum = 0; int number = 0; while (number < 20) { number++; if (number == 10) continue; sum += number; }
Background image of page 15

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

View Full Document Right Arrow Icon
16 / 58 Methods Program modularity.
Background image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}