SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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 EmbeddedBruno 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 ÜberblickBenjamin Schmid
 
Java design pattern tutorial
Java design pattern tutorialJava design pattern tutorial
Java design pattern tutorialAshoka Vanjare
 
Java - Remote method invocation
Java - Remote method invocationJava - Remote method invocation
Java - Remote method invocationRiccardo Cardin
 
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"Baltasar Ortega
 
JavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityJavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityDanHeidinga
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the DomainVictor Rentea
 
8 most expected java interview questions
8 most expected java interview questions8 most expected java interview questions
8 most expected java interview questionsPoonam Kherde
 
Pal gov.tutorial1.session1 2.conceptualdatamodelingusingorm
Pal gov.tutorial1.session1 2.conceptualdatamodelingusingormPal gov.tutorial1.session1 2.conceptualdatamodelingusingorm
Pal gov.tutorial1.session1 2.conceptualdatamodelingusingormMustafa Jarrar
 
Undergrad Interfaces Lecture 2008
Undergrad Interfaces Lecture 2008Undergrad Interfaces Lecture 2008
Undergrad Interfaces Lecture 2008Stacy Branham
 
#JavaOne What's in an object?
#JavaOne What's in an object?#JavaOne What's in an object?
#JavaOne What's in an object?Charlie Gracie
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in javakim.mens
 
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]David Buck
 
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.2007Arun Kumar
 
Extreme Interview Questions
Extreme Interview QuestionsExtreme Interview Questions
Extreme Interview QuestionsEhtisham Ali
 
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]David Buck
 
Design pattern application
Design pattern applicationDesign pattern application
Design pattern applicationgayatri thakur
 

Was ist angesagt? (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
 

Andere mochten auch

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 kg0000931
 
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 ifis
 
9781285852744 ppt ch02
9781285852744 ppt ch029781285852744 ppt ch02
9781285852744 ppt ch02Terry Yoast
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Languagejaimefrozr
 
Exception handling
Exception handlingException handling
Exception handlingRaja Sekhar
 
String handling session 5
String handling session 5String handling session 5
String handling session 5Raja Sekhar
 

Andere mochten auch (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
 

Ähnlich wie 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
 
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...Mr. Akaash
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkMohit Belwal
 
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 solutionsQUONTRASOLUTIONS
 
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.pdfakankshasorate1
 
Fun with bytecode weaving
Fun with bytecode weavingFun with bytecode weaving
Fun with bytecode weavingMatthew
 
It pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_enIt pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_enGeorge Birbilis
 
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?calltutors
 
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'smomin6
 
J2ee strutswithhibernate-140121221332-phpapp01
J2ee strutswithhibernate-140121221332-phpapp01J2ee strutswithhibernate-140121221332-phpapp01
J2ee strutswithhibernate-140121221332-phpapp01Jay Palit
 
Владимир Иванов. Java 8 и JVM: что нового в HotSpot
Владимир Иванов. Java 8 и JVM: что нового в HotSpotВладимир Иванов. Java 8 и JVM: что нового в HotSpot
Владимир Иванов. Java 8 и JVM: что нового в HotSpotVolha Banadyseva
 
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...Indu32
 

Ähnlich wie 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...
 

Kürzlich hochgeladen

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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 GraphThiyagu K
 
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 ConsultingTechSoup
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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 . pdfQucHHunhnh
 

Kürzlich hochgeladen (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
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"
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
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
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
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
 

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