Title: Data%20Types
1Introduction to the Java Language
- Data Types
- Operators
- Control Flow Statements
- Arrays
- Functions -- Static Methods
- View Classes as modules
2Exampe1 Hello.java
class Hello public static void main(String
args) System.out.println("Hello World!")
3Data Types
- byte,short,int,long
- float,double
- char
- boolean
- reference
- array
- object
4Operators
- Arithmetic operators , -, , /, , , --
- Relational operators gt, gt, lt, lt, , !
- Conditional operators , , !
- Bitwise operators gtgt, ltlt, gtgtgt, , , ,
5Control Flow Statements
- decision making
- if-else, switch-case
- loop
- for, while, do-while
- exception
- try-catch-finally, throw
- miscellaneous
- break, continue, label , return
6Arrays
Type a new Typen
a0
a1
an-1
- Dynamic
- Array initialization
- a.length
Type a ... a new Typeexpn
a new Typee1,e2,...,en A e1,e2,,en
7Example 2 Max.java
class Max public static void main(String
args) int a new int5,6,1,2,7,9,0,10
int max max a0 for (int i1
ilta.length i) if (aigtmax) max
ai System.out.println(" max"max)
8Example 3 PrintArray
class PrintArray public static void
main(String args) int a new
int1,2,3, 4,5,6, 7,8,9 for (int
i0 ilta.length i) for (int j0 jlt
a0.length j) System.out.print(aij"
") System.out.println()
9Functions -- Static Methods
class Max public static void main(String
args) int a new int5,6,1,2,7,9,0,10
System.out.println(" max"max(a))
static int max(int a) int max a0
for (int i1 ilta.length i) if
(aigtmax) max ai return max
10Functions -- Static Methods
class PrintArray public static void
main(String args) int a new
int1,2,3, 4,5,6, 7,8,9
printArray(a) static void
printArray(int a) for (int i0
ilta.length i) for (int j0 jlt
a0.length j) System.out.print(aij"
") System.out.println()
11View Classes as Modules
class Sort public static void
selectionSort(int a) int tmp for (int
i0 ilta.length i) for (int ji1
jlta.length j) if (aigtaj) tmp
ai ai aj aj tmp
12View Classes as Modules
public class TestSort public static void
main(String args) int a new
int5,6,1,2,7,9,0,10 Sort.selectionSort(a)
for (int i0 ilta.length i)
System.out.print(ai" ")