JAVA - #2 שיעור 

1.  Comments    //      /* … */
     byte : 8-bit     short : 16-bit     int : 32-bit     long : 64-bit
     int number, max=100;
     octal : 016       hex : 0xBB
     float : 32-bit     double : 64-bit
     23.8     1.56e2     2.345E4
     + - * / %
     =    +=    -=    *=    /=    %=
     ++     --     int j=0,k;     k=j++;
     a=(b=12);
     ==    >    <    >=    <=   !=
     int a,b=12,c;    c=a+b;

2. char     16-bit Unicode
    boolean     true , false
    &&     ||     !       &  |  !  ^    ?:
    int a=1, b=2, d=3;   char c;     c=a+b+d;
                                           c=(char) a;        type casting 

3. Arrays  0..n-1
     int [] buffer = new int[10];     buffer.length
     int [] holder = {0,0,0,0,0};
     char [] letters = {'a','b','c','d','e','f'};
     int [][]table = {{1,3},{2,13},{9,2},{10,15}};
     char[][] scoreCard = new char[14][];
     scoreCard[0] = new char [numBatters];
     scoreCard[0][7] = 'g';
     scoreCard.length     scoreCard[0].length

4. Strings
     String name, user="Ploni Almoni";
      name = "David";         name = "Meodaroch";
      name.length()
     int [] link = new int[5];
     link[0] = 11;   link[1] = 22;    link[2] = 33;
     number = link.length;
     String[] family = {"Eliezer","Chaim","Rivka","Moshe"};

5.  String pcFile = userId + "." + extension;
     length()          integer
     charAt(2)         char                exception
     indexOf("ne")     integer
     lastIndexOf("ab") integer
     substring(2,5)    String
     equals()

6. {....}
    if ( .... )   {  .... }    if  ( ... )  { ... } else { ... }
    if ( a == 1)              if (count>=1)  {
       found = true;             count++;
     else                        name = "Osnat";
       i++;                     } else {
     if (a==1)                    blabla--;
        found = true;              name = "Aaron";
                                }
7. switch (id) {
       case 'a': nid = 3;
                 break;
       case 'b': nid = 19;
                 otherVar = 12;
                 break;
       case 'c': nid=25;
                 link++;
                 break;
      default:   x+=4;
                 break;
    }

8. while ( ... )   { ... }                    break, continue
       do { ...}   while ( ... )
       for (int i=0; i<10; i++) { ... }
       for (int i=start + newList; i<=sum; i+=2) { ... }

      for (int i=0; i<scoreCard.length; i++) {
          for (int j=0; j<scoreCard[i].length; j++)
              System.out.println(scoreCard[i][j]);
          System.out.println();
      }

      boolean nimza = false;
      String name = "Ploni";
      int counter=0, index, total=50;
      while (counter < total ) {
          if (table[counter].equals(name)) {
             nimza = true; index = counter; break; }
          counter++;
      }

תכנות מונחה עצמים



עצם    =    שם מזהה    +    מצב  .1
state       +      identifier  =  object


עוטף :    מצב    +   התנהגות                                 מסר       .2
message            behavior   +    state : encapsulates

תיאור האוביקט      מאפיינים = שדות + שיטות    .3
 new        methods          features      class : template 

                 משתני מופע .4
 instance   variables

                                      הסתרת מידע          מימשק .5
 interface    information hiding
implementation : messages + arguments               
robi.up()               Robot                               

ירושה       פרוטוקול .6
extends             protocol    inheritance
subclass   --    superclass                
super.p           super.func                

חבילה .7
import       package

8.  abstract class      abstract methods

:תכנות מונחה עצמים .9

שיקוף עולם הבעיה    --    המודל  טבעיות.1          
עמידות העיצוב    --    המודל  גמישות.2          
ירושה  --    ברכיבי תוכנה  שימוש חוזר.3          

10.  class libraries:    1) java.lang (language foundation class)
          package        2) java.io (I/O class library)
                         3) java.awt (Abstract Window Toolkit, GUI)
                         4) java.util (utility class library: date, tables)
                         5) java.net (network interface library)
                         6) java.applet (applet implementation)
               abstract class       abstract method

11. import java.lang.*;
  java.util.Date d = new java.util.Date();
  java.awt.Point p = new java.awt.Point(1,2);

  import java.util.Date;
  import java.awt.*;
  Date d = new Date();
  Point p = new Point(1,2);