Java cơ bản
Chia sẻ bởi Vũ Chí Cương |
Ngày 29/04/2019 |
60
Chia sẻ tài liệu: java cơ bản thuộc Bài giảng khác
Nội dung tài liệu:
Introduction to
Java Programming
Y. Daniel Liang
Edited by Hoàng Văn Hậu – VTC Academy – THSoft co.,ltd
https://play.google.com/store/apps/developer?id=THSoft+Co.,Ltd
VTC Academy
THSoft Co.,Ltd
2
Introduction
Course Objectives
Organization of the Book
VTC Academy
THSoft Co.,Ltd
3
Course Objectives
Upon completing the course, you will understand
Create, compile, and run Java programs
Primitive data types
Java control flow
Methods
Arrays (for teaching Java in two semesters, this could be the end)
Object-oriented programming
Core Java classes (Swing, exception, internationalization, multithreading, multimedia, I/O, networking, Java Collections Framework)
VTC Academy
THSoft Co.,Ltd
4
Course Objectives, cont.
You will be able to
Develop programs using Eclipse IDE
Write simple programs using primitive data types, control statements, methods, and arrays.
Create and use methods
Write interesting projects
VTC Academy
THSoft Co.,Ltd
5
Session 01 Introduction to Java and Eclipse
What Is Java?
Getting Started With Java Programming
Create, Compile and Running a Java Application
VTC Academy
THSoft Co.,Ltd
6
What Is Java?
Java language programming market
VTC Academy
THSoft Co.,Ltd
7
History
James Gosling and Sun Microsystems
Oak
Java, May 20, 1995, Sun World
HotJava
The first Java-enabled Web browser
JDK Evolutions
J2SE, J2ME, and J2EE (not mentioned in the book, but could discuss here optionally)
VTC Academy
THSoft Co.,Ltd
8
Characteristics of Java
Java is simple
Java is object-oriented
Java is distributed
Java is interpreted
Java is robust
Java is secure
Java is architecture-neutral
Java is portable
Java’s performance
Java is multithreaded
Java is dynamic
VTC Academy
THSoft Co.,Ltd
9
Java IDE Tools
Forte by Sun MicroSystems
Borland JBuilder
Microsoft Visual J++
NetBean by Oracle
IBM Visual Age for Java
Eclipse by Sun MicroSystems
VTC Academy
THSoft Co.,Ltd
10
Getting Started with Java Programming
A Simple Java Application
Compiling Programs
Executing Applications
VTC Academy
THSoft Co.,Ltd
11
A Simple Application
Example 1.1
//This application program prints Welcome
//to Java!
package chapter1;
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
Run
Source
NOTE: To run the program, install slide files on hard disk.
VTC Academy
THSoft Co.,Ltd
12
Creating and Compiling Programs
On command line
javac file.java
VTC Academy
THSoft Co.,Ltd
13
Executing Applications
On command line
java classname
VTC Academy
THSoft Co.,Ltd
14
Example
javac Welcome.java
java Welcome
output:...
VTC Academy
THSoft Co.,Ltd
15
Compiling and Running a Program
Where are the files stored in the directory?
VTC Academy
THSoft Co.,Ltd
16
Anatomy of a Java Program
Comments
Package
Keywords
Variables – Data type
Operators
Control flow
If else statement
VTC Academy
THSoft Co.,Ltd
17
Comments
Eclipse shortcut key:
Ctrl + Shift + C
Ctrl + Shift + /
Ctrl + /
VTC Academy
THSoft Co.,Ltd
18
Package
VTC Academy
THSoft Co.,Ltd
19
Keywords (reserved words)
http://en.wikipedia.org/wiki/List_of_Java_keywords
VTC Academy
THSoft Co.,Ltd
20
Blocks
A pair of braces in a program forms a block that groups components of a program.
VTC Academy
THSoft Co.,Ltd
21
Data Types
byte 8 bits
short 16 bits
int 32 bits
long 64 bits
float 32 bits
double 64 bits
char 16 bits
VTC Academy
THSoft Co.,Ltd
22
Constants
final datatype CONSTANTNAME = VALUE;
final double PI = 3.14159;
final int SIZE = 3;
VTC Academy
THSoft Co.,Ltd
23
Operators
+, -, *, /, %, ++, --, +=, -=, *=, /=, ^, &, |
5/2 yields an integer 2.
5.0/2 yields a double value 2.5
5 % 2 yields 1 (the remainder of the division)
VTC Academy
THSoft Co.,Ltd
24
Arithmetic Expressions
is translated to
(3+4*x)/5 – 10*(y-5)*(a+b+c)/x + 9*(4/x + (9+x)/y)
VTC Academy
THSoft Co.,Ltd
25
Shortcut Assignment Operators
Operator Example Equivalent
+= i+=8 i = i+8
-= f-=8.0 f = f-8.0
*= i*=8 i = i*8
/= i/=8 i = i/8
%= i%=8 i = i%8
VTC Academy
THSoft Co.,Ltd
26
Increment and
Decrement Operators
VTC Academy
THSoft Co.,Ltd
27
Increment and
Decrement Operators, cont.
VTC Academy
THSoft Co.,Ltd
28
Variables
// Compute the first area
radius = 1.0;
area = radius*radius*3.14159;
System.out.println("The area is “ + area + " for radius "+radius);
// Compute the second area
radius = 2.0;
area = radius*radius*3.14159;
System.out.println("The area is “ + area + " for radius "+radius);
VTC Academy
THSoft Co.,Ltd
29
Declaring Variables
int x; // Declare x to be an
// integer variable;
double radius; // Declare radius to
// be a double variable;
char a; // Declare a to be a
// character variable;
VTC Academy
THSoft Co.,Ltd
30
if ... Else
VTC Academy
THSoft Co.,Ltd
31
Displaying Text in a Message Dialog Box
you can use the showMessageDialog method in the JOptionPane class. JOptionPane is one of the many predefined classes in the Java system, which can be reused rather than “reinventing the wheel.”
Run
Source
VTC Academy
THSoft Co.,Ltd
32
Actions on Eclipse
Development environment
Copy folder: Java_setup_thsoft
Install JDK
JAVA_HOME=path_to_jre
Install Eclipse (copy folder only)
Create workspace
Create simple project
VTC Academy
THSoft Co.,Ltd
33
Actions on Eclipse
Create, build, run welcome.java and welcomeBox.java
Rewrite demo
Calcule this expression with a = b = c = 2.5; x = y = z = 8.7
VTC Academy
THSoft Co.,Ltd
34
Actions on Eclipse
Problem ax + b = 0
Problem ax^2 + bx + c = 0
Input data by user. (JOptionPane)
VTC Academy
THSoft Co.,Ltd
35
Action on class
Teacher
[email protected]
0984380003
https://play.google.com/store/search?q=thsoft+co&c=apps
Captions
Members
Java Programming
Y. Daniel Liang
Edited by Hoàng Văn Hậu – VTC Academy – THSoft co.,ltd
https://play.google.com/store/apps/developer?id=THSoft+Co.,Ltd
VTC Academy
THSoft Co.,Ltd
2
Introduction
Course Objectives
Organization of the Book
VTC Academy
THSoft Co.,Ltd
3
Course Objectives
Upon completing the course, you will understand
Create, compile, and run Java programs
Primitive data types
Java control flow
Methods
Arrays (for teaching Java in two semesters, this could be the end)
Object-oriented programming
Core Java classes (Swing, exception, internationalization, multithreading, multimedia, I/O, networking, Java Collections Framework)
VTC Academy
THSoft Co.,Ltd
4
Course Objectives, cont.
You will be able to
Develop programs using Eclipse IDE
Write simple programs using primitive data types, control statements, methods, and arrays.
Create and use methods
Write interesting projects
VTC Academy
THSoft Co.,Ltd
5
Session 01 Introduction to Java and Eclipse
What Is Java?
Getting Started With Java Programming
Create, Compile and Running a Java Application
VTC Academy
THSoft Co.,Ltd
6
What Is Java?
Java language programming market
VTC Academy
THSoft Co.,Ltd
7
History
James Gosling and Sun Microsystems
Oak
Java, May 20, 1995, Sun World
HotJava
The first Java-enabled Web browser
JDK Evolutions
J2SE, J2ME, and J2EE (not mentioned in the book, but could discuss here optionally)
VTC Academy
THSoft Co.,Ltd
8
Characteristics of Java
Java is simple
Java is object-oriented
Java is distributed
Java is interpreted
Java is robust
Java is secure
Java is architecture-neutral
Java is portable
Java’s performance
Java is multithreaded
Java is dynamic
VTC Academy
THSoft Co.,Ltd
9
Java IDE Tools
Forte by Sun MicroSystems
Borland JBuilder
Microsoft Visual J++
NetBean by Oracle
IBM Visual Age for Java
Eclipse by Sun MicroSystems
VTC Academy
THSoft Co.,Ltd
10
Getting Started with Java Programming
A Simple Java Application
Compiling Programs
Executing Applications
VTC Academy
THSoft Co.,Ltd
11
A Simple Application
Example 1.1
//This application program prints Welcome
//to Java!
package chapter1;
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
Run
Source
NOTE: To run the program, install slide files on hard disk.
VTC Academy
THSoft Co.,Ltd
12
Creating and Compiling Programs
On command line
javac file.java
VTC Academy
THSoft Co.,Ltd
13
Executing Applications
On command line
java classname
VTC Academy
THSoft Co.,Ltd
14
Example
javac Welcome.java
java Welcome
output:...
VTC Academy
THSoft Co.,Ltd
15
Compiling and Running a Program
Where are the files stored in the directory?
VTC Academy
THSoft Co.,Ltd
16
Anatomy of a Java Program
Comments
Package
Keywords
Variables – Data type
Operators
Control flow
If else statement
VTC Academy
THSoft Co.,Ltd
17
Comments
Eclipse shortcut key:
Ctrl + Shift + C
Ctrl + Shift + /
Ctrl + /
VTC Academy
THSoft Co.,Ltd
18
Package
VTC Academy
THSoft Co.,Ltd
19
Keywords (reserved words)
http://en.wikipedia.org/wiki/List_of_Java_keywords
VTC Academy
THSoft Co.,Ltd
20
Blocks
A pair of braces in a program forms a block that groups components of a program.
VTC Academy
THSoft Co.,Ltd
21
Data Types
byte 8 bits
short 16 bits
int 32 bits
long 64 bits
float 32 bits
double 64 bits
char 16 bits
VTC Academy
THSoft Co.,Ltd
22
Constants
final datatype CONSTANTNAME = VALUE;
final double PI = 3.14159;
final int SIZE = 3;
VTC Academy
THSoft Co.,Ltd
23
Operators
+, -, *, /, %, ++, --, +=, -=, *=, /=, ^, &, |
5/2 yields an integer 2.
5.0/2 yields a double value 2.5
5 % 2 yields 1 (the remainder of the division)
VTC Academy
THSoft Co.,Ltd
24
Arithmetic Expressions
is translated to
(3+4*x)/5 – 10*(y-5)*(a+b+c)/x + 9*(4/x + (9+x)/y)
VTC Academy
THSoft Co.,Ltd
25
Shortcut Assignment Operators
Operator Example Equivalent
+= i+=8 i = i+8
-= f-=8.0 f = f-8.0
*= i*=8 i = i*8
/= i/=8 i = i/8
%= i%=8 i = i%8
VTC Academy
THSoft Co.,Ltd
26
Increment and
Decrement Operators
VTC Academy
THSoft Co.,Ltd
27
Increment and
Decrement Operators, cont.
VTC Academy
THSoft Co.,Ltd
28
Variables
// Compute the first area
radius = 1.0;
area = radius*radius*3.14159;
System.out.println("The area is “ + area + " for radius "+radius);
// Compute the second area
radius = 2.0;
area = radius*radius*3.14159;
System.out.println("The area is “ + area + " for radius "+radius);
VTC Academy
THSoft Co.,Ltd
29
Declaring Variables
int x; // Declare x to be an
// integer variable;
double radius; // Declare radius to
// be a double variable;
char a; // Declare a to be a
// character variable;
VTC Academy
THSoft Co.,Ltd
30
if ... Else
VTC Academy
THSoft Co.,Ltd
31
Displaying Text in a Message Dialog Box
you can use the showMessageDialog method in the JOptionPane class. JOptionPane is one of the many predefined classes in the Java system, which can be reused rather than “reinventing the wheel.”
Run
Source
VTC Academy
THSoft Co.,Ltd
32
Actions on Eclipse
Development environment
Copy folder: Java_setup_thsoft
Install JDK
JAVA_HOME=path_to_jre
Install Eclipse (copy folder only)
Create workspace
Create simple project
VTC Academy
THSoft Co.,Ltd
33
Actions on Eclipse
Create, build, run welcome.java and welcomeBox.java
Rewrite demo
Calcule this expression with a = b = c = 2.5; x = y = z = 8.7
VTC Academy
THSoft Co.,Ltd
34
Actions on Eclipse
Problem ax + b = 0
Problem ax^2 + bx + c = 0
Input data by user. (JOptionPane)
VTC Academy
THSoft Co.,Ltd
35
Action on class
Teacher
[email protected]
0984380003
https://play.google.com/store/search?q=thsoft+co&c=apps
Captions
Members
* Một số tài liệu cũ có thể bị lỗi font khi hiển thị do dùng bộ mã không phải Unikey ...
Người chia sẻ: Vũ Chí Cương
Dung lượng: |
Lượt tài: 1
Loại file:
Nguồn : Chưa rõ
(Tài liệu chưa được thẩm định)