Introduction to         Java Programming                Y. Daniel LiangEdited by Hoàng Văn Hậu – VTC Academy – THSoft co.,...
Introduction Course Objectives Organization of the BookVTC Academy       THSoft Co.,Ltd   2
Course Objectives   Upon completing the course, you will understand    –   Create, compile, and run Java programs    –   ...
Course Objectives, cont. You         will be able to    – Develop programs using Eclipse IDE    – Write simple programs u...
Session 01 Introduction to Java           and Eclipse What  Is Java? Getting Started With Java Programming   – Create, C...
What Is Java? Java        language programming marketVTC Academy              THSoft Co.,Ltd     6
History James        Gosling and Sun Microsystems Oak Java,       May 20, 1995, Sun World HotJava    – The first Java-...
Characteristics of Java   Java is simple   Java is object-oriented   Java is distributed   Java is interpreted   Java...
Java IDE Tools Forteby Sun MicroSystems Borland JBuilder Microsoft       Visual J++ NetBean        by Oracle IBM     ...
Getting Started with Java                    ProgrammingA     Simple Java Application Compiling        Programs Executi...
A Simple ApplicationExample 1.1//This application program prints Welcome//to Java!package chapter1;public class Welcome { ...
Creating and Compiling Programs                                  Create/Modify Source Code On command line  – javac file....
Executing Applications On command line  – java classname                                    Bytecode        Java         ...
Example  javac Welcome.java  java Welcome  output:...VTC Academy       THSoft Co.,Ltd   14
Compiling and Running a Program                                                                  Where are the files      ...
Anatomy of a Java Program Comments Package Keywords Variables    – Data type Operators Control   flow If else state...
Comments          Eclipse shortcut key:          Ctrl + Shift + C          Ctrl + Shift + /          Ctrl + /VTC Academy  ...
PackageVTC Academy    THSoft Co.,Ltd   18
Keywords (reserved words)   http://en.wikipedia.org/wiki/List_of_Java_keywordsVTC Academy                  THSoft Co.,Ltd ...
BlocksA pair of braces in a program forms ablock that groups components of aprogram.  public class Test {    public static...
Data Types              byte              8 bits              short           16 bits              int            32 bits ...
Constants  final datatype CONSTANTNAME = VALUE;  final double PI = 3.14159;  final int SIZE = 3;VTC Academy      THSoft Co...
Operators+, -, *, /, %, ++, --, +=, -=, *=, /=, ^, &, |5/2 yields an integer 2.5.0/2 yields a double value 2.55 % 2 yields...
Arithmetic Expressions   3 4x         10 ( y 5)( a b c)              4   9 x                                            9(...
Shortcut Assignment Operators         Operator Example            Equivalent         +=       i+=8               i = i+8  ...
Increment and              Decrement Operatorssuffix               x++; // Same as x = x + 1;prefix               ++x; // ...
Increment and       Decrement Operators, cont.int i=10;                Equivalent to                                      ...
Variables// Compute the first arearadius = 1.0;area = radius*radius*3.14159;System.out.println("The area is “ +  area + " ...
Declaring Variables  int x;             // Declare x to be an                     // integer variable;  double radius; // ...
if ... ElseVTC Academy     THSoft Co.,Ltd   30
Displaying Text in a Message              Dialog Boxyou can use the showMessageDialogmethod in the JOptionPane class.JOpti...
Actions on Eclipse Development        environment    –   Copy folder: Java_setup_thsoft    –   Install JDK    –   JAVA_HO...
Actions on Eclipse Create, build, run welcome.java and  welcomeBox.java Rewrite demo Calcule this expression with a = b...
Actions on Eclipse Problem ax + b = 0 Problem ax^2 + bx + c = 0   Input data by user. (JOptionPane)VTC Academy         ...
Action on class Teacher    – hauc2@yahoo.com    – 0984380003    – https://play.google.com/store/search?q=thsoft+co&c=apps...
Upcoming SlideShare
Loading in...5
×

bai giang java co ban - java cơ bản - bai 1

799
-1

Published on

Bài giảng java cơ bản, bài 1/5

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
799
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

bai giang java co ban - java cơ bản - bai 1

  1. 1. Introduction to Java Programming Y. Daniel LiangEdited by Hoàng Văn Hậu – VTC Academy – THSoft co.,ltd https://play.google.com/store/apps/developer?id=THSoft+Co.,Ltd
  2. 2. Introduction Course Objectives Organization of the BookVTC Academy THSoft Co.,Ltd 2
  3. 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 3
  4. 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 projectsVTC Academy THSoft Co.,Ltd 4
  5. 5. Session 01 Introduction to Java and Eclipse What Is Java? Getting Started With Java Programming – Create, Compile and Running a Java ApplicationVTC Academy THSoft Co.,Ltd 5
  6. 6. What Is Java? Java language programming marketVTC Academy THSoft Co.,Ltd 6
  7. 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 7
  8. 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 dynamicVTC Academy THSoft Co.,Ltd 8
  9. 9. Java IDE Tools Forteby Sun MicroSystems Borland JBuilder Microsoft Visual J++ NetBean by Oracle IBM Visual Age for Java Eclipse by Sun MicroSystemsVTC Academy THSoft Co.,Ltd 9
  10. 10. Getting Started with Java ProgrammingA Simple Java Application Compiling Programs Executing ApplicationsVTC Academy THSoft Co.,Ltd 10
  11. 11. A Simple ApplicationExample 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!"); }} Source Run NOTE: To run the program, install slide files on hard VTC Academy THSoft Co.,Ltd disk. 11
  12. 12. Creating and Compiling Programs Create/Modify Source Code On command line – javac file.java Source Code Compile Source Code i.e. javac Welcome.java If compilation errors Bytecode Run Byteode i.e. java Welcome Result If runtime errors or incorrect resultVTC Academy THSoft Co.,Ltd 12
  13. 13. Executing Applications On command line – java classname Bytecode Java Java Java Interpreter Interpreter Interpreter ... on Windows on Linux on Sun SolarisVTC Academy THSoft Co.,Ltd 13
  14. 14. Example javac Welcome.java java Welcome output:...VTC Academy THSoft Co.,Ltd 14
  15. 15. Compiling and Running a Program Where are the files Welcome.java stored in thec:example directory? chapter1 Welcome.class Welcome.java~ chapter2 Java source files and class files for Chapter 2 . . . chapter19 Java source files and class files for Chapter 19 VTC Academy THSoft Co.,Ltd 15
  16. 16. Anatomy of a Java Program Comments Package Keywords Variables – Data type Operators Control flow If else statement VTC Academy THSoft Co.,Ltd 16
  17. 17. Comments Eclipse shortcut key: Ctrl + Shift + C Ctrl + Shift + / Ctrl + /VTC Academy THSoft Co.,Ltd 17
  18. 18. PackageVTC Academy THSoft Co.,Ltd 18
  19. 19. Keywords (reserved words) http://en.wikipedia.org/wiki/List_of_Java_keywordsVTC Academy THSoft Co.,Ltd 19
  20. 20. BlocksA pair of braces in a program forms ablock that groups components of aprogram. public class Test { public static void main(String[] args) { Class block System.out.println("Welcome to Java!"); Method block } } VTC Academy THSoft Co.,Ltd 20
  21. 21. Data Types byte 8 bits short 16 bits int 32 bits long 64 bits float 32 bits double 64 bits char 16 bitsVTC Academy THSoft Co.,Ltd 21
  22. 22. Constants final datatype CONSTANTNAME = VALUE; final double PI = 3.14159; final int SIZE = 3;VTC Academy THSoft Co.,Ltd 22
  23. 23. Operators+, -, *, /, %, ++, --, +=, -=, *=, /=, ^, &, |5/2 yields an integer 2.5.0/2 yields a double value 2.55 % 2 yields 1 (the remainder of the division)VTC Academy THSoft Co.,Ltd 23
  24. 24. Arithmetic Expressions 3 4x 10 ( y 5)( a b c) 4 9 x 9( ) 5 x x yis translated to(3+4*x)/5 – 10*(y-5)*(a+b+c)/x + 9*(4/x + (9+x)/y) VTC Academy THSoft Co.,Ltd 24
  25. 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%8VTC Academy THSoft Co.,Ltd 25
  26. 26. Increment and Decrement Operatorssuffix x++; // Same as x = x + 1;prefix ++x; // Same as x = x + 1;suffix x––; // Same as x = x - 1;prefix ––x; // Same as x = x - 1;VTC Academy THSoft Co.,Ltd 26
  27. 27. Increment and Decrement Operators, cont.int i=10; Equivalent to int newNum = 10*i;int newNum = 10*i++; i = i + 1;int i=10; Equivalent to i = i + 1;int newNum = 10*(++i); int newNum = 10*i;VTC Academy THSoft Co.,Ltd 27
  28. 28. Variables// Compute the first arearadius = 1.0;area = radius*radius*3.14159;System.out.println("The area is “ + area + " for radius "+radius);// Compute the second arearadius = 2.0;area = radius*radius*3.14159;System.out.println("The area is “ + area + " for radius "+radius);VTC Academy THSoft Co.,Ltd 28
  29. 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 29
  30. 30. if ... ElseVTC Academy THSoft Co.,Ltd 30
  31. 31. Displaying Text in a Message Dialog Boxyou can use the showMessageDialogmethod in the JOptionPane class.JOptionPane is one of the manypredefined classes in the Java system,which can be reused rather than“reinventing the wheel.” Source Run VTC Academy THSoft Co.,Ltd 31
  32. 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 projectVTC Academy THSoft Co.,Ltd 32
  33. 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 3 4x 10 ( y 5)( a b c) 4 9 x 9( ) 5 x x yVTC Academy THSoft Co.,Ltd 33
  34. 34. Actions on Eclipse Problem ax + b = 0 Problem ax^2 + bx + c = 0 Input data by user. (JOptionPane)VTC Academy THSoft Co.,Ltd 34
  35. 35. Action on class Teacher – hauc2@yahoo.com – 0984380003 – https://play.google.com/store/search?q=thsoft+co&c=apps Captions MembersVTC Academy THSoft Co.,Ltd 35
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×