SlideShare ist ein Scribd-Unternehmen logo
1 von 78
Downloaden Sie, um offline zu lesen
CHAPTER 2
BASIC PROGRAMMING
CONCEPTS

Mr.Warawut Khangkhan
e-Mail: awarawut@hotmail.com
Social Media: www.facebook.com/AjWarawut
Mr.Warawut Khangkhan   Chapter 2 Basic Programming Concepts
                                 Basic Programming Concepts
                       PROGRAMMING IN
                       STRUCTURED

                       JAVA
                                                      2
Mr.Warawut
             Chapter 1 Java & OOP
 Khangkhan
                                    3
Mr.Warawut Khangkhan   Chapter 2 Basic Programming Concepts
                       Chapter 2 Basic Programming Concepts
                              VARIABLE
                              DATA &
                                                      4
JAVA




                                              Mr.Warawut
                                               Khangkhan
     F F       a-z, A-Z, _, $          F
                   F




                                                  Chapter 2 Basic Programming Concepts
                           a-z, A-Z, _, $
           F           F     F   F ˈ
(Case Sensitive)
 F               (Reserved Word)
Literal Words (True, False, Null)


                                              5
Mr.Warawut
                           Chapter 2 Basic Programming Concepts
               Khangkhan
                                                                  6
F RESERVED WORD
(DECLARATION)




                                       Mr.Warawut
                                        Khangkhan
  ˈ      F                 F   (Data
 Type)       F




                                           Chapter 2 Basic Programming Concepts
      dataType varName [= value];

dataType =       F
varName =
value    = F
                                       7
F




                           Mr.Warawut
                            Khangkhan
String name;
float score;




                               Chapter 2 Basic Programming Concepts
char grade;



String name = “Warawut”;
float score = 85.5f;
char grade = ‘A’;
                           8
Mr.Warawut Khangkhan   Chapter 2 Basic Programming Concepts
                                 Basic Programming Concepts
                                          DATA TYPE
                                                      9
F          (DATA TYPE)




                                                 Mr.Warawut
                                                  Khangkhan
Primitive Data Type -          F
               F       F




                                                   Chapter 2 Basic Programming Concepts
Class Type –
Interface
Array Type –       F       ˈ       F F   F   ˈ




                                                 10
F
(PRIMITIVE DATA TYPE)




                                Mr.Warawut
                                 Khangkhan
 F             (Integer)
 F




                                  Chapter 2 Basic Programming Concepts
             (Floating Point)
 F           (Character)
 F       F     (Boolean)




                                11
INTEGER TYPE




                                                Mr.Warawut
                                                 Khangkhan
Data Type Size     Range
          (Byte)




                                                  Chapter 2 Basic Programming Concepts
byte      1        -128 to +127
short     2        -32,768 to +32,767
int       4        -2,147,483,648 to
                   +2,147,483,647
long      8        -9,223,372,036,854,775,808
                   to
                   +9,223,372,036,854,775,807

                                                12
EX. INTEGER TYPE




                         Mr.Warawut
                          Khangkhan
byte A = 65;
short B = 32767;




                           Chapter 2 Basic Programming Concepts
int C = 2147286444;
long D = 21472864448L;
long E = 21472864438l;




                         13
FLOATING POINT TYPE




                                             Mr.Warawut
                                              Khangkhan
Data Type Size   Range
          (Byte)




                                               Chapter 2 Basic Programming Concepts
float     4      -3.40292347E+38 to
                 +3.40292347E+38
double    8      -1.79769313486231570E+308
                 to
                 +1.79769313486231570E+308

float a   =   200;
float b   =   200.5f; // 200.5F;
double    c   = 300;                         14

double    d   = 300.7d; // 300.7D;
CHARACTER TYPE




                               Mr.Warawut
                                Khangkhan
Data Type Size   Range
          (Byte)




                                 Chapter 2 Basic Programming Concepts
char      2      0 to 65,535


char c = ‘A’;
char cInt = 65;



                               15
Mr.Warawut
                          Chapter 2 Basic Programming Concepts
              Khangkhan
                                                                 16
EX. PROGRAMMING
CHARACTER TYPE
BOOLEAN TYPE




                                       Mr.Warawut
                                        Khangkhan
 F               F
     F2 F   F                  ˈ   F




                                         Chapter 2 Basic Programming Concepts
                true   false


boolean b1 = false;
boolean b2 = true;


                                       17
STRING TYPE




                                  Mr.Warawut
                                   Khangkhan
     Java       F   F
 F          F




                                    Chapter 2 Basic Programming Concepts
                        (class)

String name = “Warawut”;
String langProg = “Java”;



                                  18
Mr.Warawut Khangkhan   Chapter 2 Basic Programming Concepts
                                 Basic Programming Concepts
                                          CONSTANT
                                                      19
F         (CONSTANT)




                                     Mr.Warawut
                                      Khangkhan
     F F           F




                                       Chapter 2 Basic Programming Concepts
 final dataType varName [= value];

dataType =     F
varName =
value    = F
                                     20
Mr.Warawut
                          Chapter 2 Basic Programming Concepts
              Khangkhan
                                                                 21
EX. PROGRAMMING
CONSTANT
Mr.Warawut
                          Chapter 2 Basic Programming Concepts
              Khangkhan
                                                                 22
EX. PROGRAMMING
CONSTANT
Mr.Warawut Khangkhan   Chapter 2 Basic Programming Concepts
                                 Basic Programming Concepts
                                          OPERATOR
                                                      23
(OPERATOR)




                                                 Mr.Warawut
                                                  Khangkhan
        F (Expression)           F
          F         F    F   ,       , ˆ F




                                                   Chapter 2 Basic Programming Concepts
F               F            (Operator)      F
    F
               num1 + num2

              a = (b - c) * d
                                                 24
(OPERATOR)




                                           Mr.Warawut
                                            Khangkhan
              F (Assignment
Operators)




                                             Chapter 2 Basic Programming Concepts
                   F (Arithmetic
Operators)
                 (Comparison
Operators)
                   F (Logical Operators)
             (Unary Operators)
               (Bitwise Operators)         25
ASSIGNMENT
OPERATORS




                          Mr.Warawut
                           Khangkhan
Operator   Description
=           F




                            Chapter 2 Basic Programming Concepts
+=                  F
-=            F
*=              F
/=                F
%=                    F
                          26
ASSIGNMENT
OPERATORS




                                          Mr.Warawut
                                           Khangkhan
    F               F   F    F        F
a   = 30    a   =   30           30




                                            Chapter 2 Basic Programming Concepts
a   += 5    a   =   a + 5        35
a   -= 10   a   =   a - 10       25
a   *= 2    a   =   a * 2        50
a   /= 5    a   =   a / 5        10
a   %= 5    a   =   a % 5         0
                                          27
ARITHMETIC OPERATORS




                               Mr.Warawut
                                Khangkhan
Operator Description Example
   +                 a + b




                                 Chapter 2 Basic Programming Concepts
   -                 a - b
   *                 a * b
   /                 a / b
   %                 a % b

                               28
COMPARISON
OPERATORS




                                   Mr.Warawut
                                    Khangkhan
Operator Description Example
  ==        F             a == b




                                     Chapter 2 Basic Programming Concepts
   !=         F F         a != b
   >              F       a > b
  >=                F F   a >= b
   <      F F             a < b
  <=       F F          F a <= b
                                   29
LOGICAL OPERATORS




                                   Mr.Warawut
                                    Khangkhan
Operator   Description   Example
  &&       and           a && b




                                     Chapter 2 Basic Programming Concepts
   ||      or            a || b
   !       not           !a




                                   30
LOGICAL OPERATORS




                                  Mr.Warawut
                                   Khangkhan
a   b a && b   a || b   !a   !b
T   T   T        T       F    F




                                    Chapter 2 Basic Programming Concepts
T   F   F        T       F    T
F   T   F        T      T     F
F   F   F        F      T     T

T – True
F – False
                                  31
UNARY OPERATORS




                                                     Mr.Warawut
                                                      Khangkhan
Operator   Description Format   Example    Execute
   ++            F    Postfix   a = b++    a=b
                                           b=b+1




                                                       Chapter 2 Basic Programming Concepts
                      Prefix    a = ++ b   b=b+1
                                           a=b
             F        Postfix   a = b--    a=b
    --                                     b=b-1
                      Prefix    a = --b    b=b–1
                                           a=b




                                                     32
UNARY OPERATORS




                               Mr.Warawut
                                Khangkhan
a = 5;
System.out.println(a);
System.out.println(a);




                                 Chapter 2 Basic Programming Concepts
                           5
System.out.println(a++);
System.out.println(a++);   5
System.out.println(++a);
System.out.println(++a);   7
System.out.println(a);
System.out.println(a);     7
System.out.println(--a);
System.out.println(--a);   6
System.out.println(a--);
                  (a--
System.out.println(a--);   6
System.out.println(a);
System.out.println(a);     5
                               33
BITWISE OPERATORS




                                            Mr.Warawut
                                             Khangkhan
Operator    Description
   <<       left shift              F




                                              Chapter 2 Basic Programming Concepts
   >>       right shift
   &        bitwise AND
    |       bitwise OR
    ^       bitwise XOR
 ˈ                F
                                            34

(Operand)     F       Integer   Character
BITWISE OPERATORS




                                    Mr.Warawut
                                     Khangkhan
a    b    a & b     a | b   a ^ b
1    1      1        1        0




                                      Chapter 2 Basic Programming Concepts
1    0      0        1        1
0    1      0        1        1
0    0      0        0        0

1 – Open (True)
0 – Close (False)
                                    35
BITWISE OPERATORS




                                  Mr.Warawut
                                   Khangkhan
   F a = 01000001, b = 00100001
 a&b




                                    Chapter 2 Basic Programming Concepts
   a    0 1 0 0 0 0 0 1
               &
   b    0 0 1 0 0 0 0 1


        0 0 0 0 0 0 0 1           36
BITWISE OPERATORS




                                      Mr.Warawut
                                       Khangkhan
       F a = 01000001, b = 00100001
 a|b




                                        Chapter 2 Basic Programming Concepts
  a       0 1 0 0 0 0 0 1
                 |
  b       0 0 1 0 0 0 0 1


          0 1 1 0 0 0 0 1             37
BITWISE OPERATORS




                                   Mr.Warawut
                                    Khangkhan
    F a = 01000001, b = 00100001
 a^b




                                     Chapter 2 Basic Programming Concepts
   a     0 1 0 0 0 0 0 1
                ^
   b     0 0 1 0 0 0 0 1


         0 1 1 0 0 0 0 0           38
BITWISE OPERATORS




                                     Mr.Warawut
                                      Khangkhan
 a << 2




                                       Chapter 2 Basic Programming Concepts
   a      0 0 1 0 0 0 0 1


          1 0 0 0 0 1 0 0

  If x = 8 then y = x << 2 is that
  y = 8 * 22 = 32
                                     39
BITWISE OPERATORS




                                      Mr.Warawut
                                       Khangkhan
 b >> 3




                                        Chapter 2 Basic Programming Concepts
   b      0 1 0 0 0 0 0 1


          0 0 0 0 1 0 0 0

  If x = 32 then y = x >> 2 is that
  y = 32 / 22 = 8
                                      40
Mr.Warawut Khangkhan   Chapter 2 Basic Programming Concepts
                       Chapter 2 Basic Programming Concepts
                              OPERATOR OF
                              PRCEDENCE
                                                      41
Mr.Warawut
               Chapter 2 Basic Programming Concepts
 Khangkhan
                                                      42
             F

                             F

                                           F
                             F
    F
             F
             (Operand)
                         F




                                                  F
    ˈ



                                   F
1    ( ), [ ]                                         L   R
2    ++, --, !, ~                                     R   L




                                                              Mr.Warawut
                                                               Khangkhan
3    *, /, %                                          L   R
4    +, -                                             L   R
5    <<, >>, >>>                                      L   R




                                                                Chapter 2 Basic Programming Concepts
6    <, <=, >, >=                                     L   R
7    ==, !=                                           L   R
8    &                                                L   R
9    ^                                                L   R
10   |                                                L   R
11   &&                                               L   R
12   ||                                               L   R
13   ?:                                               L   R
14   =, +=, -=, *=, /=, %=, <<=, >>=, >>>=, &=, ^=,   R   L
     !=                                                       43
Mr.Warawut
                                   Chapter 2 Basic Programming Concepts
                    Khangkhan
                                                                          44
                         25

                                         25
a = 5, b = 2, c = 10

                         70

                                         70
                                         (a + b) * c = ?
                         a+b*c=?
a = 5, b = 2, c = 10, d = 3




                                  Mr.Warawut
                                   Khangkhan
a+b*c+d=?               73   28




                                    Chapter 2 Basic Programming Concepts
(a + b) * c + d = ?     73   28

(a + b) * (c + d) = ?   73

a + (b * c) + d = ?     28
                                  45
Mr.Warawut Khangkhan   Chapter 2 Basic Programming Concepts
                       Chapter 2 Basic Programming Concepts
                              CONVERSION
                              DATA TYPE
                                                      46
F




                                         Mr.Warawut
                                          Khangkhan
Implicit Type Conversion -       F   F




                                           Chapter 2 Basic Programming Concepts
Explicit Type Conversion -   F
 F




                                         47
Mr.Warawut
                         Chapter 2 Basic Programming Concepts
             Khangkhan
                                                                48
                         F F
                         ˈ
IMPLICIT TYPE

                F
CONVERSION
                ˈ
                F
                         F
                F
EXPLICIT TYPE
CONVERSION




                                                         Mr.Warawut
                                                          Khangkhan
       F       F   ˈ   F
           F                       ˈ       F F




                                                           Chapter 2 Basic Programming Concepts
 valNameResult = (dataType) valName

valNameResult =                        F             F
dataType      =            F
valName       =                F                 F
                                                         49
Mr.Warawut
                                 Chapter 2 Basic Programming Concepts
                     Khangkhan
                                                                        50
EX. CODE EXPLICIT TYPE
CONVERSION
EXPLICIT TYPE
CONVERSION




                                                                                 Mr.Warawut
                                                                                  Khangkhan
                               F                 F                           F
      F          ˈ                                      F       Java




                                                                                   Chapter 2 Basic Programming Concepts
          F                F               F
(Character)          F ˈ                                    F        F
     F ˈ                               F             (Method)
(Class) Wrapper                    ˈ           class             F       F
              (Primitive Data Type)

                                                                                 51
F METHOD F                    CLASS
 WRAPPER




                                                                         Mr.Warawut
                                                                          Khangkhan
Class     Primitive   Method     F      F ˈ    Method     F        F ˈ
Wrapper   Data Type




                                                                           Chapter 2 Basic Programming Concepts
Integer   int         Integer.parseInt( )      Integer.toString( )
Float     float       Float.parseFloat( )      Float.toString( )
Double    double      Double.parseDouble( ) Double.toString( )




                                                                         52
Mr.Warawut
                               Chapter 2 Basic Programming Concepts
                   Khangkhan
                                                                      53
EX. CODE CLASS WRAPPER
Mr.Warawut Khangkhan   Chapter 2 Basic Programming Concepts
                                 Basic Programming Concepts
                              DATA OUTPUT
                              & INPUT
                                                      54
F     F
 PRINTLN




                                               Mr.Warawut
                                                Khangkhan
  Method println( ) print( )      F
   F Object out Class System




                                                 Chapter 2 Basic Programming Concepts
System.out.println(arg1 + arg2 + … + arg_n);
                     or
 System.out.print(arg1 + arg2 + .. + arg_n);

arg1, arg2, arg_n = ˈ F       F

                                               55
F
ARGUMENT




                                            Mr.Warawut
                                             Khangkhan
 b         cursor          1




                                              Chapter 2 Basic Programming Concepts
  f    F     F
 n             F
 r         cursor      F
 t
  ’              ‘
 ”               ”
                
 xxx               Ascii F 065    A       56


uxxx                Unicode F u0008   F
Mr.Warawut
             Chapter 2 Basic Programming Concepts
 Khangkhan
                                                    57
F     F               PRINTF




                                                  Mr.Warawut
                                                   Khangkhan
  Method printf( )   F
   F Object out Class System




                                                    Chapter 2 Basic Programming Concepts
System.out.printf(Control_String, arg1 + arg2
               + … + arg_n);

Control_String =             F                ,

                         F
arg1, arg2, arg_n = ˈ F          F                58
Mr.Warawut
                           Chapter 2 Basic Programming Concepts
               Khangkhan
                                                                  59
METHOD




                                          exponential
                  F




                                                            F
                  F




                                                        F
         PRINTF


                           %d




                           %u
                           %c



                           %e
                           %s
                           %f
Mr.Warawut
                           Chapter 2 Basic Programming Concepts
               Khangkhan
                                                                  60
                                         F
                                         F
                                               F F F
                                         F
                                               F F
    METHOD PRINTF



                                         F

                                                       F
                    F




                                               F
                               F
                                    F
                           F




                                               F
                                         F ˈ
                           F
                               F




                                                       )
                           +
                           -




                                                       .(
F

                    F
Mr.Warawut
             Chapter 2 Basic Programming Concepts
 Khangkhan
                                                    61
F     F
JOPTIONPANE




                                             Mr.Warawut
                                              Khangkhan
Class JOptionPane        F
Graphic Mode                     Popup




                                               Chapter 2 Basic Programming Concepts
Window       F Dialogbox
MessageDialog        F     method
showMessageDialog( ) F         F
   F Class JOptionPane F F Object
Class JOptionPane F         F import class
    package javax.swing F     project

                                             62
F     F
 JOPTIONPANE




                                                   Mr.Warawut
                                                    Khangkhan
   JOptionPane.showMessageDialog(
  Parent_Window, Message, Title, Type);




                                                     Chapter 2 Basic Programming Concepts
Parent_Window = ˈ               F F     F
                                            F ˈ
                   null               Dialog box
                           F
Message = ˈ F                  Dialog box
Title = ˈ F            F        Title bar          63
F        F
    JOPTIONPANE




                                               Mr.Warawut
                                                Khangkhan
Type = ˈ              Dialog box
F         F




                                                 Chapter 2 Basic Programming Concepts
    • ERROR_MESSAGE -                  F
    • INFORMATION_MESSAGE -
      F
    • PLAIN_MESSAGE -              F
              F        F
    • QUESTION_MESSAGE -
    • WARNING_MESSAGE -                    F   64
Mr.Warawut
             Chapter 2 Basic Programming Concepts
 Khangkhan
                                                    65
F
DECIMALFORMAT




                                               Mr.Warawut
                                                Khangkhan
 ˈ
         F F   F                           F




                                                 Chapter 2 Basic Programming Concepts
                   Class DecimalFormat
     F
     import package java.text      F
Project




                                               66
F
 DECIMALFORMAT




                                                        Mr.Warawut
                                                         Khangkhan
DecmialFormat df = new DecimalFormat(arg);
      String str = df.format(payment);




                                                          Chapter 2 Basic Programming Concepts
arg = ˈ                        F              F
      • 0            0     F
      • “#”                        F F0           ˈ 0
           F
        • “,” ˈ
df = ˈ    object         class       F                  67

str = ˈ          F   F                    F
Mr.Warawut
             Chapter 2 Basic Programming Concepts
 Khangkhan
                                                    68
F    F
INPUTSTREAMREADER




                                          Mr.Warawut
                                           Khangkhan
Class InputStreamReader        ˈ
 F     Class BufferedReader




                                            Chapter 2 Basic Programming Concepts
   F     1         F Method readLine( )
     ˈ    F     F     (String)
 F import package java.io F


                                          69
F
 INPUTSTREAMREADER




                                                           Mr.Warawut
                                                            Khangkhan
InputStreamReader rd = new InputStreamReader(System.in);
      BufferedReader stdin = new BufferedReader(rd);




                                                             Chapter 2 Basic Programming Concepts
                             or
      BufferedReader stdin = new InputStreamReader(
            new InputStreamReader(System.in));

reader = ˈ  object   class InputStreamReader
stdin = ˈ  object  class BufferedReader




                                                           70
Mr.Warawut
             Chapter 2 Basic Programming Concepts
 Khangkhan
                                                    71
F            F                SCANNER




                                                              Mr.Warawut
                                                               Khangkhan
             F                 F           ˈ F
 F




                                                                Chapter 2 Basic Programming Concepts
     F               Scanner       F   F     object   class
Scanner          F
import package java.util



                                                              72
SCANNER




                                              Mr.Warawut
                                               Khangkhan
   Scanner sn = new Scanner(System.in);




                                                Chapter 2 Basic Programming Concepts
sn = ˈ  object            F   class Scanner
System.in = ˈ F                   F F
              F   F           ˂         F
Method
•nextInt( )           F            Integer
•nextFloat( )         F            Float
•nextDouble( )        F            Double     73


•nextLine( )          F             String
Mr.Warawut
             Chapter 2 Basic Programming Concepts
 Khangkhan
                                                    74
F     F
JOPTIONPANE




                                           Mr.Warawut
                                            Khangkhan
  F Method showInputDialog( )       F
   ˈ F     F     (String)




                                             Chapter 2 Basic Programming Concepts
       F     JOptionPane F    F   object
class JOptionPane F
import package javax.swing



                                           75
JOPTIONPANE




                                                  Mr.Warawut
                                                   Khangkhan
     JOptionPane.showInputDialog(
  Parent_Window, Message, Title, Type);




                                                    Chapter 2 Basic Programming Concepts
Parent_Window = ˈ              F F     F
                                           F ˈ
                   null              Dialog box
                          F
Message = ˈ F                 Dialog box
Title = ˈ F           F        Title bar          76
JOPTIONPANE




                                           Mr.Warawut
                                            Khangkhan
Type = ˈ          Dialog box
F         F




                                             Chapter 2 Basic Programming Concepts
    • ERROR_MESSAGE -              F
    • INFORMATION_MESSAGE -
      F
    • PLAIN_MESSAGE -          F
              F    F
    • QUESTION_MESSAGE -
    • WARNING_MESSAGE -                F   77
Mr.Warawut
             Chapter 2 Basic Programming Concepts
 Khangkhan
                                                    78

Weitere ähnliche Inhalte

Andere mochten auch

Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languagesVarun Garg
 
The Basics of programming
The Basics of programmingThe Basics of programming
The Basics of programming692sfrobotics
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C BasicsBharat Kalia
 
Introduction to Programming Languages
Introduction to Programming LanguagesIntroduction to Programming Languages
Introduction to Programming Languageseducationfront
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programmingRoger Argarin
 
Basic Programming Concept
Basic Programming ConceptBasic Programming Concept
Basic Programming ConceptCma Mohd
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 
Computer programing
Computer programingComputer programing
Computer programingJT Taylor
 
System software lecture infs429
System software lecture infs429System software lecture infs429
System software lecture infs429Edmund Sowah
 
Introduction to basic programming
Introduction to basic programmingIntroduction to basic programming
Introduction to basic programmingJordan Delacruz
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04hassaanciit
 
Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)mujeeb memon
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming ConceptsJussi Pohjolainen
 
C programming basics
C  programming basicsC  programming basics
C programming basicsargusacademy
 

Andere mochten auch (20)

Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
 
The Basics of programming
The Basics of programmingThe Basics of programming
The Basics of programming
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
Introduction to Programming Languages
Introduction to Programming LanguagesIntroduction to Programming Languages
Introduction to Programming Languages
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programming
 
Basic Programming Concept
Basic Programming ConceptBasic Programming Concept
Basic Programming Concept
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
 
Basic programming
Basic programmingBasic programming
Basic programming
 
Computer programing
Computer programingComputer programing
Computer programing
 
Computer Programing
Computer ProgramingComputer Programing
Computer Programing
 
Programing techniques
Programing techniquesPrograming techniques
Programing techniques
 
System software lecture infs429
System software lecture infs429System software lecture infs429
System software lecture infs429
 
Introduction to basic programming
Introduction to basic programmingIntroduction to basic programming
Introduction to basic programming
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
 
Data type
Data typeData type
Data type
 
C programming basics
C  programming basicsC  programming basics
C programming basics
 
Programing Fundamental
Programing FundamentalPrograming Fundamental
Programing Fundamental
 

Mehr von Warawut

Database design
Database designDatabase design
Database designWarawut
 
Business Computer Project 4
Business Computer Project 4Business Computer Project 4
Business Computer Project 4Warawut
 
Object-Oriented Programming 10
Object-Oriented Programming 10Object-Oriented Programming 10
Object-Oriented Programming 10Warawut
 
Object-Oriented Programming 9
Object-Oriented Programming 9Object-Oriented Programming 9
Object-Oriented Programming 9Warawut
 
Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8Warawut
 
Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7Warawut
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6Warawut
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6Warawut
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5Warawut
 
Management Information System 4
Management Information System 4Management Information System 4
Management Information System 4Warawut
 
Object-Oriented Programming 5
Object-Oriented Programming 5Object-Oriented Programming 5
Object-Oriented Programming 5Warawut
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3Warawut
 
Management Information System 3
Management Information System 3Management Information System 3
Management Information System 3Warawut
 
Business Computer Project 2
Business Computer Project 2Business Computer Project 2
Business Computer Project 2Warawut
 
Chapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemChapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemWarawut
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4Warawut
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1Warawut
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MISWarawut
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3Warawut
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1Warawut
 

Mehr von Warawut (20)

Database design
Database designDatabase design
Database design
 
Business Computer Project 4
Business Computer Project 4Business Computer Project 4
Business Computer Project 4
 
Object-Oriented Programming 10
Object-Oriented Programming 10Object-Oriented Programming 10
Object-Oriented Programming 10
 
Object-Oriented Programming 9
Object-Oriented Programming 9Object-Oriented Programming 9
Object-Oriented Programming 9
 
Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8
 
Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5
 
Management Information System 4
Management Information System 4Management Information System 4
Management Information System 4
 
Object-Oriented Programming 5
Object-Oriented Programming 5Object-Oriented Programming 5
Object-Oriented Programming 5
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3
 
Management Information System 3
Management Information System 3Management Information System 3
Management Information System 3
 
Business Computer Project 2
Business Computer Project 2Business Computer Project 2
Business Computer Project 2
 
Chapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemChapter 2 Strategy & Information System
Chapter 2 Strategy & Information System
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MIS
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1
 

Kürzlich hochgeladen

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
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
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
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
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
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
 
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).pptxVishalSingh1417
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
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
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 

Kürzlich hochgeladen (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
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
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
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
 
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
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
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
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 

Object-Oriented Programming 2

  • 1. CHAPTER 2 BASIC PROGRAMMING CONCEPTS Mr.Warawut Khangkhan e-Mail: awarawut@hotmail.com Social Media: www.facebook.com/AjWarawut
  • 2. Mr.Warawut Khangkhan Chapter 2 Basic Programming Concepts Basic Programming Concepts PROGRAMMING IN STRUCTURED JAVA 2
  • 3. Mr.Warawut Chapter 1 Java & OOP Khangkhan 3
  • 4. Mr.Warawut Khangkhan Chapter 2 Basic Programming Concepts Chapter 2 Basic Programming Concepts VARIABLE DATA & 4
  • 5. JAVA Mr.Warawut Khangkhan F F a-z, A-Z, _, $ F F Chapter 2 Basic Programming Concepts a-z, A-Z, _, $ F F F F ˈ (Case Sensitive) F (Reserved Word) Literal Words (True, False, Null) 5
  • 6. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 6 F RESERVED WORD
  • 7. (DECLARATION) Mr.Warawut Khangkhan ˈ F F (Data Type) F Chapter 2 Basic Programming Concepts dataType varName [= value]; dataType = F varName = value = F 7
  • 8. F Mr.Warawut Khangkhan String name; float score; Chapter 2 Basic Programming Concepts char grade; String name = “Warawut”; float score = 85.5f; char grade = ‘A’; 8
  • 9. Mr.Warawut Khangkhan Chapter 2 Basic Programming Concepts Basic Programming Concepts DATA TYPE 9
  • 10. F (DATA TYPE) Mr.Warawut Khangkhan Primitive Data Type - F F F Chapter 2 Basic Programming Concepts Class Type – Interface Array Type – F ˈ F F F ˈ 10
  • 11. F (PRIMITIVE DATA TYPE) Mr.Warawut Khangkhan F (Integer) F Chapter 2 Basic Programming Concepts (Floating Point) F (Character) F F (Boolean) 11
  • 12. INTEGER TYPE Mr.Warawut Khangkhan Data Type Size Range (Byte) Chapter 2 Basic Programming Concepts byte 1 -128 to +127 short 2 -32,768 to +32,767 int 4 -2,147,483,648 to +2,147,483,647 long 8 -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 12
  • 13. EX. INTEGER TYPE Mr.Warawut Khangkhan byte A = 65; short B = 32767; Chapter 2 Basic Programming Concepts int C = 2147286444; long D = 21472864448L; long E = 21472864438l; 13
  • 14. FLOATING POINT TYPE Mr.Warawut Khangkhan Data Type Size Range (Byte) Chapter 2 Basic Programming Concepts float 4 -3.40292347E+38 to +3.40292347E+38 double 8 -1.79769313486231570E+308 to +1.79769313486231570E+308 float a = 200; float b = 200.5f; // 200.5F; double c = 300; 14 double d = 300.7d; // 300.7D;
  • 15. CHARACTER TYPE Mr.Warawut Khangkhan Data Type Size Range (Byte) Chapter 2 Basic Programming Concepts char 2 0 to 65,535 char c = ‘A’; char cInt = 65; 15
  • 16. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 16 EX. PROGRAMMING CHARACTER TYPE
  • 17. BOOLEAN TYPE Mr.Warawut Khangkhan F F F2 F F ˈ F Chapter 2 Basic Programming Concepts true false boolean b1 = false; boolean b2 = true; 17
  • 18. STRING TYPE Mr.Warawut Khangkhan Java F F F F Chapter 2 Basic Programming Concepts (class) String name = “Warawut”; String langProg = “Java”; 18
  • 19. Mr.Warawut Khangkhan Chapter 2 Basic Programming Concepts Basic Programming Concepts CONSTANT 19
  • 20. F (CONSTANT) Mr.Warawut Khangkhan F F F Chapter 2 Basic Programming Concepts final dataType varName [= value]; dataType = F varName = value = F 20
  • 21. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 21 EX. PROGRAMMING CONSTANT
  • 22. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 22 EX. PROGRAMMING CONSTANT
  • 23. Mr.Warawut Khangkhan Chapter 2 Basic Programming Concepts Basic Programming Concepts OPERATOR 23
  • 24. (OPERATOR) Mr.Warawut Khangkhan F (Expression) F F F F , , ˆ F Chapter 2 Basic Programming Concepts F F (Operator) F F num1 + num2 a = (b - c) * d 24
  • 25. (OPERATOR) Mr.Warawut Khangkhan F (Assignment Operators) Chapter 2 Basic Programming Concepts F (Arithmetic Operators) (Comparison Operators) F (Logical Operators) (Unary Operators) (Bitwise Operators) 25
  • 26. ASSIGNMENT OPERATORS Mr.Warawut Khangkhan Operator Description = F Chapter 2 Basic Programming Concepts += F -= F *= F /= F %= F 26
  • 27. ASSIGNMENT OPERATORS Mr.Warawut Khangkhan F F F F F a = 30 a = 30 30 Chapter 2 Basic Programming Concepts a += 5 a = a + 5 35 a -= 10 a = a - 10 25 a *= 2 a = a * 2 50 a /= 5 a = a / 5 10 a %= 5 a = a % 5 0 27
  • 28. ARITHMETIC OPERATORS Mr.Warawut Khangkhan Operator Description Example + a + b Chapter 2 Basic Programming Concepts - a - b * a * b / a / b % a % b 28
  • 29. COMPARISON OPERATORS Mr.Warawut Khangkhan Operator Description Example == F a == b Chapter 2 Basic Programming Concepts != F F a != b > F a > b >= F F a >= b < F F a < b <= F F F a <= b 29
  • 30. LOGICAL OPERATORS Mr.Warawut Khangkhan Operator Description Example && and a && b Chapter 2 Basic Programming Concepts || or a || b ! not !a 30
  • 31. LOGICAL OPERATORS Mr.Warawut Khangkhan a b a && b a || b !a !b T T T T F F Chapter 2 Basic Programming Concepts T F F T F T F T F T T F F F F F T T T – True F – False 31
  • 32. UNARY OPERATORS Mr.Warawut Khangkhan Operator Description Format Example Execute ++ F Postfix a = b++ a=b b=b+1 Chapter 2 Basic Programming Concepts Prefix a = ++ b b=b+1 a=b F Postfix a = b-- a=b -- b=b-1 Prefix a = --b b=b–1 a=b 32
  • 33. UNARY OPERATORS Mr.Warawut Khangkhan a = 5; System.out.println(a); System.out.println(a); Chapter 2 Basic Programming Concepts 5 System.out.println(a++); System.out.println(a++); 5 System.out.println(++a); System.out.println(++a); 7 System.out.println(a); System.out.println(a); 7 System.out.println(--a); System.out.println(--a); 6 System.out.println(a--); (a-- System.out.println(a--); 6 System.out.println(a); System.out.println(a); 5 33
  • 34. BITWISE OPERATORS Mr.Warawut Khangkhan Operator Description << left shift F Chapter 2 Basic Programming Concepts >> right shift & bitwise AND | bitwise OR ^ bitwise XOR ˈ F 34 (Operand) F Integer Character
  • 35. BITWISE OPERATORS Mr.Warawut Khangkhan a b a & b a | b a ^ b 1 1 1 1 0 Chapter 2 Basic Programming Concepts 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 1 – Open (True) 0 – Close (False) 35
  • 36. BITWISE OPERATORS Mr.Warawut Khangkhan F a = 01000001, b = 00100001 a&b Chapter 2 Basic Programming Concepts a 0 1 0 0 0 0 0 1 & b 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 36
  • 37. BITWISE OPERATORS Mr.Warawut Khangkhan F a = 01000001, b = 00100001 a|b Chapter 2 Basic Programming Concepts a 0 1 0 0 0 0 0 1 | b 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 1 37
  • 38. BITWISE OPERATORS Mr.Warawut Khangkhan F a = 01000001, b = 00100001 a^b Chapter 2 Basic Programming Concepts a 0 1 0 0 0 0 0 1 ^ b 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0 38
  • 39. BITWISE OPERATORS Mr.Warawut Khangkhan a << 2 Chapter 2 Basic Programming Concepts a 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 If x = 8 then y = x << 2 is that y = 8 * 22 = 32 39
  • 40. BITWISE OPERATORS Mr.Warawut Khangkhan b >> 3 Chapter 2 Basic Programming Concepts b 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 If x = 32 then y = x >> 2 is that y = 32 / 22 = 8 40
  • 41. Mr.Warawut Khangkhan Chapter 2 Basic Programming Concepts Chapter 2 Basic Programming Concepts OPERATOR OF PRCEDENCE 41
  • 42. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 42 F F F F F F (Operand) F F ˈ F
  • 43. 1 ( ), [ ] L R 2 ++, --, !, ~ R L Mr.Warawut Khangkhan 3 *, /, % L R 4 +, - L R 5 <<, >>, >>> L R Chapter 2 Basic Programming Concepts 6 <, <=, >, >= L R 7 ==, != L R 8 & L R 9 ^ L R 10 | L R 11 && L R 12 || L R 13 ?: L R 14 =, +=, -=, *=, /=, %=, <<=, >>=, >>>=, &=, ^=, R L != 43
  • 44. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 44 25 25 a = 5, b = 2, c = 10 70 70 (a + b) * c = ? a+b*c=?
  • 45. a = 5, b = 2, c = 10, d = 3 Mr.Warawut Khangkhan a+b*c+d=? 73 28 Chapter 2 Basic Programming Concepts (a + b) * c + d = ? 73 28 (a + b) * (c + d) = ? 73 a + (b * c) + d = ? 28 45
  • 46. Mr.Warawut Khangkhan Chapter 2 Basic Programming Concepts Chapter 2 Basic Programming Concepts CONVERSION DATA TYPE 46
  • 47. F Mr.Warawut Khangkhan Implicit Type Conversion - F F Chapter 2 Basic Programming Concepts Explicit Type Conversion - F F 47
  • 48. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 48 F F ˈ IMPLICIT TYPE F CONVERSION ˈ F F F
  • 49. EXPLICIT TYPE CONVERSION Mr.Warawut Khangkhan F F ˈ F F ˈ F F Chapter 2 Basic Programming Concepts valNameResult = (dataType) valName valNameResult = F F dataType = F valName = F F 49
  • 50. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 50 EX. CODE EXPLICIT TYPE CONVERSION
  • 51. EXPLICIT TYPE CONVERSION Mr.Warawut Khangkhan F F F F ˈ F Java Chapter 2 Basic Programming Concepts F F F (Character) F ˈ F F F ˈ F (Method) (Class) Wrapper ˈ class F F (Primitive Data Type) 51
  • 52. F METHOD F CLASS WRAPPER Mr.Warawut Khangkhan Class Primitive Method F F ˈ Method F F ˈ Wrapper Data Type Chapter 2 Basic Programming Concepts Integer int Integer.parseInt( ) Integer.toString( ) Float float Float.parseFloat( ) Float.toString( ) Double double Double.parseDouble( ) Double.toString( ) 52
  • 53. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 53 EX. CODE CLASS WRAPPER
  • 54. Mr.Warawut Khangkhan Chapter 2 Basic Programming Concepts Basic Programming Concepts DATA OUTPUT & INPUT 54
  • 55. F F PRINTLN Mr.Warawut Khangkhan Method println( ) print( ) F F Object out Class System Chapter 2 Basic Programming Concepts System.out.println(arg1 + arg2 + … + arg_n); or System.out.print(arg1 + arg2 + .. + arg_n); arg1, arg2, arg_n = ˈ F F 55
  • 56. F ARGUMENT Mr.Warawut Khangkhan b cursor 1 Chapter 2 Basic Programming Concepts f F F n F r cursor F t ’ ‘ ” ” xxx Ascii F 065 A 56 uxxx Unicode F u0008 F
  • 57. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 57
  • 58. F F PRINTF Mr.Warawut Khangkhan Method printf( ) F F Object out Class System Chapter 2 Basic Programming Concepts System.out.printf(Control_String, arg1 + arg2 + … + arg_n); Control_String = F , F arg1, arg2, arg_n = ˈ F F 58
  • 59. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 59 METHOD exponential F F F F PRINTF %d %u %c %e %s %f
  • 60. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 60 F F F F F F F F METHOD PRINTF F F F F F F F F F ˈ F F ) + - .( F F
  • 61. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 61
  • 62. F F JOPTIONPANE Mr.Warawut Khangkhan Class JOptionPane F Graphic Mode Popup Chapter 2 Basic Programming Concepts Window F Dialogbox MessageDialog F method showMessageDialog( ) F F F Class JOptionPane F F Object Class JOptionPane F F import class package javax.swing F project 62
  • 63. F F JOPTIONPANE Mr.Warawut Khangkhan JOptionPane.showMessageDialog( Parent_Window, Message, Title, Type); Chapter 2 Basic Programming Concepts Parent_Window = ˈ F F F F ˈ null Dialog box F Message = ˈ F Dialog box Title = ˈ F F Title bar 63
  • 64. F F JOPTIONPANE Mr.Warawut Khangkhan Type = ˈ Dialog box F F Chapter 2 Basic Programming Concepts • ERROR_MESSAGE - F • INFORMATION_MESSAGE - F • PLAIN_MESSAGE - F F F • QUESTION_MESSAGE - • WARNING_MESSAGE - F 64
  • 65. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 65
  • 66. F DECIMALFORMAT Mr.Warawut Khangkhan ˈ F F F F Chapter 2 Basic Programming Concepts Class DecimalFormat F import package java.text F Project 66
  • 67. F DECIMALFORMAT Mr.Warawut Khangkhan DecmialFormat df = new DecimalFormat(arg); String str = df.format(payment); Chapter 2 Basic Programming Concepts arg = ˈ F F • 0 0 F • “#” F F0 ˈ 0 F • “,” ˈ df = ˈ object class F 67 str = ˈ F F F
  • 68. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 68
  • 69. F F INPUTSTREAMREADER Mr.Warawut Khangkhan Class InputStreamReader ˈ F Class BufferedReader Chapter 2 Basic Programming Concepts F 1 F Method readLine( ) ˈ F F (String) F import package java.io F 69
  • 70. F INPUTSTREAMREADER Mr.Warawut Khangkhan InputStreamReader rd = new InputStreamReader(System.in); BufferedReader stdin = new BufferedReader(rd); Chapter 2 Basic Programming Concepts or BufferedReader stdin = new InputStreamReader( new InputStreamReader(System.in)); reader = ˈ object class InputStreamReader stdin = ˈ object class BufferedReader 70
  • 71. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 71
  • 72. F F SCANNER Mr.Warawut Khangkhan F F ˈ F F Chapter 2 Basic Programming Concepts F Scanner F F object class Scanner F import package java.util 72
  • 73. SCANNER Mr.Warawut Khangkhan Scanner sn = new Scanner(System.in); Chapter 2 Basic Programming Concepts sn = ˈ object F class Scanner System.in = ˈ F F F F F ˂ F Method •nextInt( ) F Integer •nextFloat( ) F Float •nextDouble( ) F Double 73 •nextLine( ) F String
  • 74. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 74
  • 75. F F JOPTIONPANE Mr.Warawut Khangkhan F Method showInputDialog( ) F ˈ F F (String) Chapter 2 Basic Programming Concepts F JOptionPane F F object class JOptionPane F import package javax.swing 75
  • 76. JOPTIONPANE Mr.Warawut Khangkhan JOptionPane.showInputDialog( Parent_Window, Message, Title, Type); Chapter 2 Basic Programming Concepts Parent_Window = ˈ F F F F ˈ null Dialog box F Message = ˈ F Dialog box Title = ˈ F F Title bar 76
  • 77. JOPTIONPANE Mr.Warawut Khangkhan Type = ˈ Dialog box F F Chapter 2 Basic Programming Concepts • ERROR_MESSAGE - F • INFORMATION_MESSAGE - F • PLAIN_MESSAGE - F F F • QUESTION_MESSAGE - • WARNING_MESSAGE - F 77
  • 78. Mr.Warawut Chapter 2 Basic Programming Concepts Khangkhan 78