Docstoc

PBO Pertemuan 3

Document Sample
PBO Pertemuan 3 Powered By Docstoc
					                                                                    10/15/2012




 PEMROGRAMAN BERORIENTASI OBJECT
                  INTRODUCTION TO JAVA PROGRAMMING
                                    I Made Suartana, S.Kom, M.Kom




A QUICK TOUR OF JAVA
 Materi:
        Platform.
  Java Platform
  Elements dasar bahasa pemrograman Java:
        Variabel
        Nama konstata
        Flow Control

              Object.
     Class dan Object
    Bagaimana mengcompile dan melakukan
     exekusi program java(menggunakan JCreator).




                                                                            1
                                                             10/15/2012




INTRO JAVA

   Arsitektur Java Dibagi atas Tiga Bagian, Yaitu:
      Enterprise J
     E      i Java   (J2EE)
      Standar Java (J2SE)
      Micro Java (J2ME)




JAVA PLATFORM
   Java Platform terdiri dari 3 komponen:
       1. Bahasa Pemrograman Java.
       2. Packages Java .
       3. Java Virtual Machine (JVM) / JRE.

   Bahasa Pemrograman Java – Disingkat Java.
       Sintaksis.
   Packages Java.
       Kumpulan class pada java.
   Java Virtual Machine.
       Virtual mesin sebagai environmen untuk menjalankan
        program java (JRE).




                                                                     2
                                                                                10/15/2012




                                               PACKAGES IN JAVA




PACKAGES JAVA

    java.applet                              java.io
        Applet class                              System.out.print
    java.awt                                 java.lang
        Windows, buttons, mouse,                  length method for arrays;
         etc.                                       exceptions
    java.awt.image                           java.net
        image processing                          sockets
    java.awt.peer                            java.util
        GUI toolkit                               System.getProperty


                       See http://java.sun.com/reference/api/
                                 for the current APIs




                                                                                        3
                               10/15/2012




EXAMPLE JAVA PACKAGE -1-




                           7




EXAMPLE JAVA PACKAGE -2-




                           8




                                       4
                                      10/15/2012




EXAMPLE JAVA PACKAGE -3-




                                 9




                    GETTING STARTED




                                              5
                                                                           10/15/2012




LET’S START WITH “HELLO WORLD”
public class Hello
{
      /**
       * Program Java My first
       */
      public static void main( String[] args ){

                      //menampilkan String Hello world pada layar
                      System.out.println(“Hello world”);

      }
}




      Java programs are built from classes.




JAVA COMMENTS
   Comments in Code – enable to write descriptive text.
          /
           /* Comment type 1 – This text is ignored by the compiler */ /
          // Comment type 2 – The text up to the end of line is ignored
          /** Documentation comment is extracted by javadoc tool */




                                                                                   6
                                                        10/15/2012




JAVA IDENTIFIER

   Identifier (variabel, method, class, )
     Case
    C           ii
            sensitive
     Start with
        Alphabet

        “_”

        “$”



     keyword   Java




JAVA KEYWORDS
        abstract        boolean          break
        byte            case             catch
        char            class            const
        continue        default          do
        double          else             extends
        final           finally          float
        for             goto             if
        implements      import           instanceof
        int             interface        long
        native          new              package
        private         protected        public
        return          short            static
        super           switch           synchronized
        this            throw            throws
        transient       try              void
        volatile        while




                                                                7
                                                                                                                  10/15/2012




VARIABLES
   Java has build-in primitives to support boolean, character, integer and
    floating-point values.
     -----------------------------------------------------------------------------------------
      boolean               either true or false                                             boolean b = true;
     ------------------------------------------------------------------------------------------
      char                 16-bit Unicode 1.1 character                                       char ch = ‘J’;
     ------------------------------------------------------------------------------------------
      byte                 8-bit integer (signed) byte bt = 127;
      short                 16-bit integer (signed) short sh = 32767;
      int                  32-bit integer (signed) int i = 2147483647;
      long                 64-bit integer (signed) long l = 9223372036854775807L;
     -------------------------------------------------------------------------------------------
      float                32-bit floating-point (IEEE 754-1985) float f = 1.0f;
      double               64-bit floating-point (IEEE 754-1985) double d = 1.e-1;
     -------------------------------------------------------------------------------------------




NUMERIC OPERATORS IN JAVA
           Prec Operator Description                                                         Example
           1            ++                    Increment by 1(or 1.0)                         k++
           1            --                    Decrement by 1(or 1.0)
                                                ec e e        (o . )                         k--
           1            +                     Unary plus                                     +value
           1            -                     Unary minus                                    -value
           2            *                     Multiplication                                 x * y
           2            /                     Division                                       x / y
           2            %                     Modulo                                         x % y
           3            +                     Addition                                       x + y
           3            -                     Subtraction                                    x - y
           5            <                     Less than                                      x < y
           5            >                     Greater than                                   x > y
           5            <=                    Less than/equal                                x <= y
           5            >=                    Greater than/equal                             x >= y
           6            ==                    Equals (identical values)                      x == y
           6            !=                    Is not equal to                                x != y
           13           op=                   op assignment(+ =, - =, *=, etc)               x += y




                                                                                                                          8
                                                                                   10/15/2012




BITWISE AND LOGIC OPERATORS
    Prec   Operator Type           Description                  Example
    1      ~            Integral   Unary bitwise complement     ~x
    1      !            Logical    Unary logical complement     !b
    4      <<           Integral   Left shift                   x << 2
    4      >>           Integral   Right shift (keep sign)      x >> 5
    4      >>>          Integral   Right shift (zero fill)      x >>> 3
    5      instanceof   Obj type   Tests class membership       o instanceof X
    6      ==           Object     Equals (same object)         x == y
    6      !=           Object     Unequal (different object)   x != y
    7      &            Integral   Bitwise AND                  x&y
    7      &            Logical    Logical AND                  b1 & b2
    8      ^            Integral   Bitwise XOR                  x ^ y
    8      ^            Logical    Logical XOR                  b1 ^ b2
    9      |            Integral   Bitwise OR                   x | y
    9      |            Logical    Logical OR                   b1 | b2




BITWISE AND LOGIC OPERATORS (CONTINUED)
    Prec Operator Type                 Description                      Examp.
    10     &&           Logical        Logical AND (conditional)        b && c
    11     ||           Logical        Logical OR (conditional)         b1 || b2
    12     ?:           Logical        Conditional (ternary)            b?x:y
    13     =            Variable,any   Assignment                       x=1
    13     <<=          Binary         Left shift with assignment       x <<= 2
    13     >>=          Binary         Right shift with assignment      x =>> 3
    13     >>>=         Binary         Right shift, zero fill, assign   x =>> 4
    13     &=           Binary         Bitwise AND with assign          x &= y
    13     &=           Logical        Logical AND with assign          b1 &=b2
    13     |=           Binary         Bitwise OR with assignment       x |= y
    13     |=           Logical        Logical OR with assignment       b1 |=b2
    13     ^=           Binary         Bitwise XOR with assignment      x ^= y
    13     ^=           Logical        Logical XOR with assignment      b1 ^=b2




                                                                                           9
                                                      10/15/2012




FLOW OF CONTROL
   Flow of control is the term used for describing
                                          program.
    which statements are executed in a program

   Flow statements are:
     if– else
     for
     switch
     do – while
     While




IF, IF-ELSE, IF ELSE –IF ELSE
            1.     if (boolean-expression) {
                            statements;
                   }

            2.     if (boolean-expression) {
                            statements;
                   } else {
                            statements;
                   }

            3.     if (boolean-expression) {
                              statements;
                   } else if (boolean-expresion ) {
                              statements;
                   } else {
                              statements;
                   }




                                                             10
                                                      10/15/2012




FOR STATEMENT
   A for statement should have the following form:
        for (initialization; condition; update) {
              statements;
        }

    Ex:
                   0,
          for (k = 0 flag; k < 10 && flag; k++ ) {
                ...
          }




WHILE, DO - WHILE STATEMENTS
   while, do-while and for control looping are
    classified as iteration statements.

          while (condition) {
               statements;
          }

          do {
                statements;
          } while (condition);




                                                             11
                                                                     10/15/2012




SWITCH
   The switch is classified as a selection statement.
    switch (integral-selector) {
         case integral-value1:
                 statements;
         break;
         default:
                 statements;
    }
    .




                                                         EXECUTION




                                                                            12
                                                  10/15/2012




TOOLS

 Java Standard Edition
 Editor
     Text Editor
     Integrated Development Environment (IDE)




   This course use




                                   CREATE CLASS




                                                         13
                       10/15/2012




EXAMPLE

   Class Kalkulator




                              14

				
DOCUMENT INFO
Shared By:
Categories:
Tags: oop. java
Stats:
views:31
posted:11/14/2012
language:
pages:14