SlideShare uma empresa Scribd logo
1 de 35
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
Introduction
 Course Objectives
 Organization of the Book




VTC Academy       THSoft Co.,Ltd   2
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
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              4
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       5
What Is Java?
 Java        language programming market




VTC Academy              THSoft Co.,Ltd     6
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
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   8
Java IDE Tools
 Forteby Sun MicroSystems
 Borland JBuilder

 Microsoft       Visual J++
 NetBean        by Oracle
 IBM         Visual Age for Java
 Eclipse       by Sun MicroSystems



VTC Academy               THSoft Co.,Ltd   9
Getting Started with Java
                    Programming
A     Simple Java Application
 Compiling        Programs
 Executing        Applications




VTC Academy             THSoft Co.,Ltd    10
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!");
  }
}

               Source                       Run
                                   NOTE: To run the program,
                                       install slide files on hard
 VTC Academy            THSoft Co.,Ltd
                                       disk.                         11
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 result


VTC Academy      THSoft Co.,Ltd                                                     12
Executing Applications
 On command line
  – java classname


                                    Bytecode




        Java          Java                                   Java
     Interpreter   Interpreter                            Interpreter
                                                  ...
    on Windows      on Linux                            on Sun Solaris




VTC Academy                      THSoft Co.,Ltd                          13
Example
  javac Welcome.java

  java Welcome

  output:...




VTC Academy       THSoft Co.,Ltd   14
Compiling and Running a Program
                                                                  Where are the files
                                     Welcome.java
                                                                  stored in the
c: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
Anatomy of a Java Program
 Comments
 Package
 Keywords
 Variables    – Data type
 Operators
 Control   flow
 If else statement



 VTC Academy           THSoft Co.,Ltd   16
Comments




          Eclipse shortcut key:
          Ctrl + Shift + C
          Ctrl + Shift + /
          Ctrl + /
VTC Academy                    THSoft Co.,Ltd   17
Package




VTC Academy    THSoft Co.,Ltd   18
Keywords (reserved words)
   http://en.wikipedia.org/wiki/List_of_Java_keywords




VTC Academy                  THSoft Co.,Ltd             19
Blocks
A pair of braces in a program forms a
block that groups components of a
program.
  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
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   21
Constants
  final datatype CONSTANTNAME = VALUE;

  final double PI = 3.14159;
  final int SIZE = 3;




VTC Academy      THSoft Co.,Ltd          22
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            23
Arithmetic Expressions
   3 4x         10 ( y 5)( a b c)              4   9 x
                                            9(         )
     5                   x                     x    y

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                  24
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                25
Increment and
              Decrement Operators
suffix
               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
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
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        28
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
if ... Else




VTC Academy     THSoft Co.,Ltd   30
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.”
               Source                    Run

 VTC Academy            THSoft Co.,Ltd         31
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     32
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     y




VTC Academy                THSoft Co.,Ltd           33
Actions on Eclipse
 Problem ax + b = 0
 Problem ax^2 + bx + c = 0

   Input data by user. (JOptionPane)




VTC Academy          THSoft Co.,Ltd     34
Action on class
 Teacher
    – hauc2@yahoo.com
    – 0984380003
    – https://play.google.com/store/search?q=thsoft+co&c=apps

 Captions
 Members




VTC Academy                  THSoft Co.,Ltd                     35

Mais conteúdo relacionado

Mais procurados

A Importância do JavaFX no Mercado Embedded
A Importância do JavaFX no Mercado EmbeddedA Importância do JavaFX no Mercado Embedded
A Importância do JavaFX no Mercado Embedded
Bruno Borges
 
Next Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
Next Generation Java - Ceylon, Kotlin, Scala & Fantom im ÜberblickNext Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
Next Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
Benjamin Schmid
 
Pal gov.tutorial1.session1 2.conceptualdatamodelingusingorm
Pal gov.tutorial1.session1 2.conceptualdatamodelingusingormPal gov.tutorial1.session1 2.conceptualdatamodelingusingorm
Pal gov.tutorial1.session1 2.conceptualdatamodelingusingorm
Mustafa Jarrar
 
Undergrad Interfaces Lecture 2008
Undergrad Interfaces Lecture 2008Undergrad Interfaces Lecture 2008
Undergrad Interfaces Lecture 2008
Stacy Branham
 
Extreme Interview Questions
Extreme Interview QuestionsExtreme Interview Questions
Extreme Interview Questions
Ehtisham Ali
 

Mais procurados (20)

A Importância do JavaFX no Mercado Embedded
A Importância do JavaFX no Mercado EmbeddedA Importância do JavaFX no Mercado Embedded
A Importância do JavaFX no Mercado Embedded
 
Next Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
Next Generation Java - Ceylon, Kotlin, Scala & Fantom im ÜberblickNext Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
Next Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
 
Java design pattern tutorial
Java design pattern tutorialJava design pattern tutorial
Java design pattern tutorial
 
Java interview question
Java interview questionJava interview question
Java interview question
 
Java - Remote method invocation
Java - Remote method invocationJava - Remote method invocation
Java - Remote method invocation
 
Suse Studio: "How to create a live openSUSE image with OpenFOAM® and CFD tools"
Suse Studio: "How to create a live openSUSE image with  OpenFOAM® and CFD tools"Suse Studio: "How to create a live openSUSE image with  OpenFOAM® and CFD tools"
Suse Studio: "How to create a live openSUSE image with OpenFOAM® and CFD tools"
 
JavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityJavaOne 2016: Life after Modularity
JavaOne 2016: Life after Modularity
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
 
8 most expected java interview questions
8 most expected java interview questions8 most expected java interview questions
8 most expected java interview questions
 
Pal gov.tutorial1.session1 2.conceptualdatamodelingusingorm
Pal gov.tutorial1.session1 2.conceptualdatamodelingusingormPal gov.tutorial1.session1 2.conceptualdatamodelingusingorm
Pal gov.tutorial1.session1 2.conceptualdatamodelingusingorm
 
Undergrad Interfaces Lecture 2008
Undergrad Interfaces Lecture 2008Undergrad Interfaces Lecture 2008
Undergrad Interfaces Lecture 2008
 
#JavaOne What's in an object?
#JavaOne What's in an object?#JavaOne What's in an object?
#JavaOne What's in an object?
 
Java Technicalities
Java TechnicalitiesJava Technicalities
Java Technicalities
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in java
 
Let's talk about Certifications
Let's talk about CertificationsLet's talk about Certifications
Let's talk about Certifications
 
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
 
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
 
Extreme Interview Questions
Extreme Interview QuestionsExtreme Interview Questions
Extreme Interview Questions
 
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
 
Design pattern application
Design pattern applicationDesign pattern application
Design pattern application
 

Destaque (13)

JavaYDL5
JavaYDL5JavaYDL5
JavaYDL5
 
01slide
01slide01slide
01slide
 
kg0000931 Chapter 1 introduction to computers, programs part ia
kg0000931 Chapter 1 introduction to computers, programs part ia kg0000931 Chapter 1 introduction to computers, programs part ia
kg0000931 Chapter 1 introduction to computers, programs part ia
 
Java cơ bản java co ban
Java cơ bản java co ban Java cơ bản java co ban
Java cơ bản java co ban
 
JavaYDL18
JavaYDL18JavaYDL18
JavaYDL18
 
05slide
05slide05slide
05slide
 
9781285852744 ppt ch02
9781285852744 ppt ch029781285852744 ppt ch02
9781285852744 ppt ch02
 
07slide
07slide07slide
07slide
 
10slide
10slide10slide
10slide
 
13slide graphics
13slide graphics13slide graphics
13slide graphics
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
Exception handling
Exception handlingException handling
Exception handling
 
String handling session 5
String handling session 5String handling session 5
String handling session 5
 

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

Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
Pratima Parida
 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
Pratima Parida
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutions
QUONTRASOLUTIONS
 
Java Standard edition(Java ) programming Basics for beginner's
Java Standard edition(Java ) programming Basics  for beginner'sJava Standard edition(Java ) programming Basics  for beginner's
Java Standard edition(Java ) programming Basics for beginner's
momin6
 
J2ee strutswithhibernate-140121221332-phpapp01
J2ee strutswithhibernate-140121221332-phpapp01J2ee strutswithhibernate-140121221332-phpapp01
J2ee strutswithhibernate-140121221332-phpapp01
Jay Palit
 
Владимир Иванов. Java 8 и JVM: что нового в HotSpot
Владимир Иванов. Java 8 и JVM: что нового в HotSpotВладимир Иванов. Java 8 и JVM: что нового в HotSpot
Владимир Иванов. Java 8 и JVM: что нового в HotSpot
Volha Banadyseva
 

Semelhante a bai giang java co ban - java cơ bản - bai 1 (20)

Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
 
1- java
1- java1- java
1- java
 
01slide
01slide01slide
01slide
 
Javalecture 1
Javalecture 1Javalecture 1
Javalecture 1
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
Java Cloud and Container Ready
Java Cloud and Container ReadyJava Cloud and Container Ready
Java Cloud and Container Ready
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutions
 
java_bba_21_vision academy_final.pdf
java_bba_21_vision academy_final.pdfjava_bba_21_vision academy_final.pdf
java_bba_21_vision academy_final.pdf
 
Fun with bytecode weaving
Fun with bytecode weavingFun with bytecode weaving
Fun with bytecode weaving
 
It pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_enIt pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_en
 
Java bcs 21_vision academy_final
Java bcs 21_vision academy_finalJava bcs 21_vision academy_final
Java bcs 21_vision academy_final
 
C++ vs Java: Which one is the best?
C++ vs Java: Which one is the best?C++ vs Java: Which one is the best?
C++ vs Java: Which one is the best?
 
Java introduction
Java introductionJava introduction
Java introduction
 
Java Standard edition(Java ) programming Basics for beginner's
Java Standard edition(Java ) programming Basics  for beginner'sJava Standard edition(Java ) programming Basics  for beginner's
Java Standard edition(Java ) programming Basics for beginner's
 
J2ee strutswithhibernate-140121221332-phpapp01
J2ee strutswithhibernate-140121221332-phpapp01J2ee strutswithhibernate-140121221332-phpapp01
J2ee strutswithhibernate-140121221332-phpapp01
 
OOPS JAVA.pdf
OOPS JAVA.pdfOOPS JAVA.pdf
OOPS JAVA.pdf
 
Владимир Иванов. Java 8 и JVM: что нового в HotSpot
Владимир Иванов. Java 8 и JVM: что нового в HotSpotВладимир Иванов. Java 8 и JVM: что нового в HotSpot
Владимир Иванов. Java 8 и JVM: что нового в HotSpot
 
java basic ppt introduction, The Java language is known for its robustness, s...
java basic ppt introduction, The Java language is known for its robustness, s...java basic ppt introduction, The Java language is known for its robustness, s...
java basic ppt introduction, The Java language is known for its robustness, s...
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Último (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

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

  • 1. 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
  • 2. Introduction  Course Objectives  Organization of the Book VTC Academy THSoft Co.,Ltd 2
  • 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. 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 4
  • 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 5
  • 6. What Is Java?  Java language programming market VTC Academy THSoft Co.,Ltd 6
  • 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. 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 8
  • 9. Java IDE Tools  Forteby Sun MicroSystems  Borland JBuilder  Microsoft Visual J++  NetBean by Oracle  IBM Visual Age for Java  Eclipse by Sun MicroSystems VTC Academy THSoft Co.,Ltd 9
  • 10. Getting Started with Java Programming A Simple Java Application  Compiling Programs  Executing Applications VTC Academy THSoft Co.,Ltd 10
  • 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!"); } } Source Run NOTE: To run the program, install slide files on hard VTC Academy THSoft Co.,Ltd disk. 11
  • 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 result VTC Academy THSoft Co.,Ltd 12
  • 13. Executing Applications  On command line – java classname Bytecode Java Java Java Interpreter Interpreter Interpreter ... on Windows on Linux on Sun Solaris VTC Academy THSoft Co.,Ltd 13
  • 14. Example javac Welcome.java java Welcome output:... VTC Academy THSoft Co.,Ltd 14
  • 15. Compiling and Running a Program Where are the files Welcome.java stored in the c: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. Anatomy of a Java Program  Comments  Package  Keywords  Variables – Data type  Operators  Control flow  If else statement VTC Academy THSoft Co.,Ltd 16
  • 17. Comments Eclipse shortcut key: Ctrl + Shift + C Ctrl + Shift + / Ctrl + / VTC Academy THSoft Co.,Ltd 17
  • 18. Package VTC Academy THSoft Co.,Ltd 18
  • 19. Keywords (reserved words) http://en.wikipedia.org/wiki/List_of_Java_keywords VTC Academy THSoft Co.,Ltd 19
  • 20. Blocks A pair of braces in a program forms a block that groups components of a program. 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. 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 21
  • 22. Constants final datatype CONSTANTNAME = VALUE; final double PI = 3.14159; final int SIZE = 3; VTC Academy THSoft Co.,Ltd 22
  • 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 23
  • 24. Arithmetic Expressions 3 4x 10 ( y 5)( a b c) 4 9 x 9( ) 5 x x y 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 24
  • 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 25
  • 26. Increment and Decrement Operators suffix 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. 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. 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 28
  • 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. if ... Else VTC Academy THSoft Co.,Ltd 30
  • 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.” Source Run VTC Academy THSoft Co.,Ltd 31
  • 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 32
  • 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 y VTC Academy THSoft Co.,Ltd 33
  • 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. Action on class  Teacher – hauc2@yahoo.com – 0984380003 – https://play.google.com/store/search?q=thsoft+co&c=apps  Captions  Members VTC Academy THSoft Co.,Ltd 35