Professional Documents
Culture Documents
Content: Nguyen Thi Thu Trang
Content: Nguyen Thi Thu Trang
Content: Nguyen Thi Thu Trang
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn @NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 2
Content
1. Identifiers
OBJECT-ORIENTED PROGRAMMING 2. Data Types
1.2 JAVA BASICS 3. Operators
Nguyen Thi Thu Trang 4. Control Statements
trangntt@soict.hust.edu.vn 5. Arrays
1 2
3 4
3 4
Page 1
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 1
1 – Java Basics
5 6
7 8
7 8
Page 2
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 2
1 – Java Basics
9 10
Integer Real
• Signed integer • Initially created with value 0.0
• Initially created with value 0
9 10
11 12
11 12
Page 3
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 3
1 – Java Basics
13 14
• string boolean……….true
character……….'A'
string………….."A"
13 14
15 16
15 16
Page 4
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 4
1 – Java Basics
17 18
Escape sequence
2.3. Casting
• Characters for keyboard control
• \b backspace • Java is a strong-type languge
• \f form feed • Casting a wrong type to a variable can lead to a compiler
• \n newline error or exceptions in JVM
• \r return (về đầu dòng)
• \t tab
• JVM can implicitly cast a data type to a larger
• Display special characters in a string data type
• \" quotation mark • To cast a variable to a narrower data type, we
• \’ apostrophe need to do it explicitly
• \\ backslash
double f;
int a, b; int d; long g;
short c; short e; f = g;
a = b + c; e = (short)d; g = f; //error
17 18
19 20
19 20
Page 5
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 5
1 – Java Basics
21 22
21 22
Command Content
• Command ends with; 1. Identifiers
• Multiple commands can be written on one line 2. Data Types
• A command can be written in multiple lines
3. Operators
• Example:
4. Control Statements
System.out.println(
5. Arrays
“This is part of the same line”);
23 24
Page 6
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 6
1 – Java Basics
25 26
25 26
27 28
27 28
Page 7
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 7
1 – Java Basics
29 30
31 32
31 32
Page 8
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 8
1 – Java Basics
33 34
33 34
35 36
35 36
Page 9
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 9
1 – Java Basics
37 38
37 38
39 40
39 40
Page 10
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 10
1 – Java Basics
1. Identifiers reference
2. Data Types • Finite set of elements of the same type
3. Operators • Must be declared before use Array or Object
• Declaration:
4. Control Statements
• Syntax:
5. Arrays • datatype[] arrayName= new datatype[ARRAY_SIZE];
• datatype arrayName[] = new datatype[ARRAY_SIZE];
• Example:
• char c[] = new char[12];
41 42
43 44
43 44
Page 11
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 11
1 – Java Basics
45 46
45 46
47
Row 0
b[ 0 ][ 0 ] b[ 0 ][ 1 ] b[ 0 ][ 2 ] b[ 0 ][ 3 ]
Row 1
b[ 1 ][ 0 ] b[ 1 ][ 1 ] b[ 1 ][ 2 ] b[ 1 ][ 3 ]
Row 2
b[ 2 ][ 0 ] b[ 2 ][ 1 ] b[ 2 ][ 2 ] b[ 2 ][ 3 ]
Column index
Row index
Array name
47
Page 12
@NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 12