Академический Документы
Профессиональный Документы
Культура Документы
Java
(CT038-3.5-2)
Programming Concepts
Data Types, Operators & Expression
Decision making & Looping
Recap
Nil
Programming Concepts
Learning Outcome
At the end of this lesson you will be able to:
understand data types and object type
use primitive data types and wrapper classes
explain standard operators
apply if, if-else, else-if and nested if and switch
apply while, do-while, for, enhanced-for
Programming Concepts
Programming Concepts
Programming Concepts
String class
The char represents only one character.
A string is a set of characters, usually represents
by a String class.
It is a predefined class in Java library. (special
class for data type).
Programming Concepts
Numeric Literal
A literal is a constant value that appears directly
in a program. E.g.,
int i = 43;
long k = 100000;
double d = 5.0;
String s = Welcome to Java;
Programming Concepts
Numeric Operator
Programming Concepts
Programming Concepts
Conditional Operator
Symbol
Description
&
Logical AND
&&
Conditional AND
Logical OR
||
Conditional OR
Exclusive OR (XOR)
Programming Concepts
10
instanceof Operator
The Type Comparison Operator
instanceof
The instanceof operator compares an
object to a specified type. You can use it to
test if an object is an instance of a class, an
instance of a subclass, or an instance of a
class that implements a particular interface.
Programming Concepts
11
Selection Statement
Simple if statement
if(boolean){
statements
If..else statement
if(boolean){
statements
}else{
statements
Programming Concepts
12
Selection Statement
Nested if statement
if(boolean){
if(boolean){
statements
}
}else if(boolean){
statements
}else{
statements
}
Programming Concepts
13
Selection Statement
A switch works with the byte, short, char, and
int primitive data types.
It also works with enumerated types, the String class,
and a few special classes that wrap certain primitive
types:
Character, Byte, Short, and Integer.
switch (month) {
case 1: statement
break;
case 2: statement
break;
default: statement
break;
}
CT038-3.5-2 Object Oriented Development with Java
Programming Concepts
14
Loop Statement
while loop
while(loop-continuation-condition){
//loop body
do-while loop
do{
//loop body
}while(loop-continuation-condition);
Programming Concepts
15
Loop Statement
for loop
for(initial-action; loop-continuation-condition;
action-after-each-iteration){
//loop body
Programming Concepts
16
Loop Statement
Enhanced-for
The enhanced for-loop is a popular feature
introduced with the Java SE platform in
version 5.0.
Its simple structure allows one to simplify
code by presenting for-loops that visit each
element of an array/collection without
explicitly expressing how one goes from
element to element.
Programming Concepts
17
Loop Statement
Enhanced-for
for (int i=0; i < array.length; i++) {
System.out.println("Element: " + array[i]);
}
Programming Concepts
18
Summary
We discussed the module covering the following:
data types and object type
primitive data types and wrapper classes
standard operators
if, if-else, else-if and nested if and switch
while, do-while, for, enhanced-for
Programming Concepts
19
Q&A
Programming Concepts
20
Next Lecture
Principles of Visual Modeling from
Software Development Perspective
Programming Concepts
21