SlideShare una empresa de 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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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
 

Similar 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
 
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
 

Similar 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

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
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.pptxAreebaZafar22
 
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.pdfAdmir Softic
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 

Último (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
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
 
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
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

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