The Java Tutorial» by wrn10268

VIEWS: 0 PAGES: 6

									                                    -                                                  µ                                                            -                µ                     1

                                                                                                            (
                                      -                                 µ
                                                                                                        *
                                                                                                        *
                                                                                                                     µµ
                                                                                                                     µµ          µ +
                                                                                                                                 µ +
                 (                µ                               µµ    µ( )

                                                                                                        *
                                                                                                        *
                                                            µ                                                    µ                                 µµ        µ +
                                                                                                                 µ                                 µµ        µ +

                                                                                                        ,, ( (                         µµ
                                                                                                                                       µµ         µ +
                                                                                                                                                  µ +
                                                                                                        Java
                                                                                                         Java




    -                µ                                                          µ   , ! , Slide 1   -            µ                                                           µ   , ! , Slide 2




                 (                                                                                                   µµ
                              *:               15%
                                                                                                                  µµ
                              µ :              85%
                                                                                                    •4              5 % ,
                                                                                                    "             3    Java 2"
        •*                                      µµ                                                              (    *    &µ


                         ::
                                                                                                    • «The Java Tutorial»
        ••   2
             2                    +&
                                  +&     3
                                         3                        3
                                                                  3
                                3
                                3    3
                                     3                      3
                                                            3
                 +
                 +                    µµ
                              µ
                              µ

    -                µ                                                          µ   , ! , Slide 3   -            µ                                                           µ   , ! , Slide 4




                                      internet                                                                                   +µ

                                                                                                    H       &% 3 (               3 I        ...
=                                                       µ       µ & µ                                   •                    (      Java
         &% µ                         +&        :                                                       •   $                        µ     (            µ%   ,           ,             )
                                                                                                        •                    +µ       µ &(
        www.math.ntua.gr/~symvonis                                                                      •   "                %
                                                                                                        •   $+                    µ% 3 (int, String, char, …)
                                                                                                        •            %                ,      %          C
                 &                         +        µ                                                   •   D + µ
        “                     -           !"   #$ %µ'()         *+ %'$'%,-./”                           •   BlueJ




    -                µ                                                          µ   , ! , Slide 5   -            µ                                                           µ   , ! , Slide 6




                                                                                                    µ                    ,       "# , $ µ%                   " & µ               , "
                                -                                                 µ                                                      -                   µ                  1

                         (µ                                                                                     (µ         (         %        )
1

2
        [inheritance]
                     3

                     µ
                                             µ (

                                µ( [polymorphism]                 ?
                                                                                                   8
                                                                                                   9    4        (
                                                                                                                               µ +

                                                                                                        [GUI - Graphical User Interface]
                                                                                                                                         +
                                                                                                                                              µµ 3
                                                                                                                                                                 !
3 *                               µ%     +       [abstract                                         10 Applets and GUIs (             %       ..)
        classes]                       3       [interfaces]
                                                                                                   11 GUIs (    %   ..)
4                    %        [exceptions]
                                                                                                   12          C
5                        µ(            µ
                         µµ 3
6 *                                          µ% 3
        [collection classes]
7        *                                   µ% 3
        (        %        ..)
    -            µ                                                        µ    , ! , Slide 7       -        µ                                                    µ    , ! , Slide 8




                                                                                               *                     µ (             [inheritance]




                                                                                                            $                                µ (         ;
                                             µ       1:
             *                      µ (             [inheritance]
                                                                                                                     4                   µ           ;



    -            µ                                                        µ    , ! , Slide 9   -            µ                                                    µ   , ! , Slide 10




                              µ …                                                              DoME: 5                               (

                                                                                               •            3           µ% 3
                                                                                                       – CD: title, artist, # tracks, playing time, got-it,
                                                                                                         comment
          DoME: Database of Multimedia
          DoME: Database of Multimedia                                                                 – Video: title, director, playing time, got-it, comment
                 Entertainment
                  Entertainment                                                                •          + 3
                 ((                     µ
                                        µ        µ CDs
                                                 µ CDs        videos.)
                                                               videos.)                        •          I




-                µ                                                        µ   , ! , Slide 11   -            µ                                                    µ   , ! , Slide 12




                                                                                                   µ            ,        "# , $ µ%                 " & µ              , "
                     -                                                 µ                                                    -                   µ                  1

 m                                                                                  *                     µ%                µ%          [encapsulated data]




                                                                                             µ        CD                            µ      Video


               CD
               CD                               Video
                                                Video




                                                                                         D   µ%                                 &           µ


 -         µ                                                   µ   , ! , Slide 13    -       µ                                                      µ   , ! , Slide 14




 "%&                                                                                 $                µ         database


           µ    CD                              µ      Video


                                                !




     "%&       "         +       "   3          &        µ


 -         µ                                                   µ   , ! , Slide 15    -       µ                                                      µ   , ! , Slide 16




                                                                                                            class Video {
                             class CD {
                                                                                                                String title;
                                String title;
                                                                                                                String director;
                                String artist;
                                                                                                                String comment;
                                String comment;
*              Java                                                                                             Video(String theTitle, String theDirector)

(CD)
                                 CD(String theTitle, String theArtist)
                                 {                                                  *       Java                {
                                                                                                                    title = theTitle;
                                      title = theTitle;
                                      artist = theArtist;                           (Video)                         director = theDirector;
                                                                                                                    comment = “ ”;
                                      comment = “ “;
       2µ                        }
                                                                                                                }

       ( (      !)                                                                                              void setComment(String newComment)
                                 void setComment(String newComment)
                                                                                                                { … }
                                 { … }
                                                                                                                String getComment()
                                 String getComment()
                                                                                                                { … }
                                 { … }
                                                                                                                void print()
                                 void print()
                                                                                                                { … }
                                 { … }
                                 …
                                                                                                                …
                             }
                                                                                                            }

 -         µ                                                   µ   , ! , Slide 17    -       µ                                                      µ   , ! , Slide 18




                                                                                         µ        ,        "# , $ µ%             " & µ                   , "
                              -                                                           µ                                                         -                      µ                  1

                                  class Database {
                                                                                                      "                          µ
                                      CD[] myCDs;
                                      Video[] myVideos;
                                      …
                                                                                                                             C                                CD      Video
*       Java                                                                                          ••                     C                                CD      Video
                                                                                                      ••               %%
(Database)
                                      void print()
                                      {
                                          for(int i=0; i<myCDs.length; i++)
                                          {                                                           ••   D
                                                                                                           D      + µ
                                                                                                                   + µ                               C
                                                                                                                                                     C
                                               myCDs[i].print();
                                          }
                                                                                                           Database
                                                                                                           Database
                                          for(int i=0; i<myVideos.length; i++)                        ••   D
                                                                                                           D           (&
                                                                                                                        (&                    +µ
                                                                                                                                              +µ      +
                                                                                                                                                      +       µ …)
                                                                                                                                                              µ …)
                                          {
                                               myVideos[i].print();
                                          }
                                      }

                                      …
                                  }



 -           µ                                                              µ       , ! , Slide 19    -            µ                                                           µ   , ! , Slide 20




2                                         +       :                 µ (                               $                           3                3

                                                                Item
                                                                 Item                                2 '# %                 & [subclasses]
                                                                                                           µ                                                  Item
                                                                                                                                                               Item
                                                                                                       :  '#                %     &
                                                                                                     [superclasses].                                      #



                                                       CD
                                                       CD                 Video
                                                                          Video
     µ           :«               »                                                                                                          CD
                                                                                                                                             CD                            Video
                                                                                                                                                                           Video
         "            #       $
                 %        &



                                                                                                              CD: title, artist, # tracks, playing time, got-it, comment
                                                                                                              Video: title, director, playing time, got-it, comment
 -           µ                                                              µ       , ! , Slide 21    -            µ                                                           µ   , ! , Slide 22




 m µ%&                        3                             3
2 '# %     &
      µ                                                     Item                                                                                   Item
                                                                                                                                                    Item
µ          :                                                 Item
                                                                                    $%
'# %    &.                                                                  $%




                                  CD
                                  CD                                    Video
                                                                        Video                                          MusicCD                 Video               VideoGame
                                                                                                                       MusicCD                 Video               VideoGame
                                                  $%                            !        $%
                                              &        $%                                     $%



     CD: CD(), getArtist(), setComment(), print()
     Video: Video(), getDirector(), setComment(), print()
 -           µ                                                              µ       , ! , Slide 23    -            µ                                                           µ   , ! , Slide 24




                                                                                                          µ                 ,      "# , $ µ%                  " & µ                 , "
                       -                                     µ                                                 -              µ                     1

              %                                                           m

                            Item
                             Item
                                                                              *                     H                        4     %
                                                                                  [base class]       [superclass]             [parent]


        MusicCD
        MusicCD            Video
                           Video             Game
                                             Game                                  (µ                H
                                                                              [derived class]           [subclass]            [child]




                                 VideoGame
                                 VideoGame      BoardGame
                                                BoardGame

-         µ                                          µ   , ! , Slide 25   -            µ                                           µ     , ! , Slide 26




                  µ                            µ (                        *                Java µ                          µ (
                                                                              class Item
                                                                              {
                                                                                     ...
                                                                              }
                                                                              class MusicCD extends Item
                                                                              {
                                                                                     ...
    •                        C                                                }
    •                  µ                                                      class Video extends Item
                                                                              {
    •         +                                                                      ...
                                                                              }
    •             µ(       [extendability]




-         µ                                          µ   , ! , Slide 27   -            µ                                           µ     , ! , Slide 28




                                                                          D                µµ             3     [Class diagram]


                                                                              Database
                                                                              Database

                                                                                                                   Item
                                                                                                                    Item




                                                                                                    MusicCD
                                                                                                    MusicCD                Video
                                                                                                                           Video



-         µ                                          µ   , ! , Slide 29   -            µ                                           µ     , ! , Slide 30




                                                                              µ            ,     "# , $ µ%           " & µ                , "
                        -                                         µ                                                    -              µ                     1

D               µµ                      µ% 3   [Object diagram]                                                    (             [client])


                                                                               void list()
                                                                               {
                                                                                  for (int i = 0; i < myItems.length; i++)
                                                                                  {
                                                                                     myItems[i].print();
                                                                                  }
                                                                               }




-           µ                                             µ   , ! , Slide 31   -             µ                                               µ   , ! , Slide 32




                    µ                            µ (                                             µC µ &(               [Overriding, redefinition]




                                                                               $         (           µ :

    •                          C                                                   •   2 µ%&               print
                        !                                                                        µ          +    MusicCD     Video




-           µ                                             µ   , ! , Slide 33   -             µ                                               µ   , ! , Slide 34




2 µ%&                       “print”
                '
        print
                                  + 3   :
                             CD: Triple J Hottest 100 (79 min)
                                 artist: sampler, 33 tracks
                                 double CD - great!



                !
        print
                            + 3    :
                        Video: The Matrix (102 min)
                            director: Fred Smith
                            (not seen yet)
-           µ                                             µ   , ! , Slide 35   -             µ                                               µ   , ! , Slide 36




                                                                                   µ             ,          "# , $ µ%      " & µ                  , "

								
To top