Java Basic

Share Embed Donate


Short Description

Download Java Basic...

Description

m

Java Basic Chapter - 1m m "hat is Programming?m  mm   m mm  mm m  mm m   mmmm mm  m m   m m   mm  m m m m m m   mm   mm   mm m mm 

m m m  m  m  mm m

 m mmm  m  m  mm m  m m mmm

m   mmmm mm  m  m m  mm mm mm 

 mm mm m m m! mm mmmm  m "m "hat is Java?m #m mm  m$   m m  m   mmm m%    m mm m   mmm m mmmm m m mm mmm&m m m   m m m mm  m    m m    m'  m&m m  m!  m mmmmm   mm   m mm m   m  m  m mm (( mm m )  m*++m m  m  mmm$ m  m m   m m  m mm m   m m   mmm   mm m  m*, mm mm m%    m

  m m- m%m  m mm  mm # m.   m    mm  m m   m m  mmm  mm  m    m   mm  mmmm m m  m  mmmm  mm  m m m  m   m m  m m  m  m    m   m& mmm (( mmm m   m m m  mm/m0m m mm m m     mm m  m m#m m m ((1m m#m m m 

m   mmm m #m m    mm* m*++ m

 m m m m   m mm m m   mm  m m m m  mmm  m  m2m / m3 m 4mm mm  m  m m m m m  m' mm#m 5 m%  m6#5%7m m  m m   m m

m mm m   m

  m 8 ! m  m  m m9,:m m ;m "here Java is used? m     mm  m mm#m m mm&  m JSP ¬m8m9m m m#mm m  m mm  mm  m9%8m m m  m  m  m   mm mm m Java Appletsm¬m m m mmm#mmm  m mmmmm m m m  mmmm m mm 

mm  m mm mm  m   m

m   m   m m  !m    m mm mm  mm m J2EEm¬mm m#m"m)  m)  mm  mm m   mm m m  m  m:%8m   m    m m m mm m JavaBeansm¬m m m  m m5  m0  m mm  m m   mm  mm   m  mm m m m m   m   m m  mm m  !m m    m#m m  m mm*m m  mmm   m  mm

  m&m

 m

mm  m m m m  m m m   m  m  m    m m& mm

m m/$ m/  m m6//7m  m mm  m

m //m m

  m

  m   m   m  m mmm m

m

m

Jobile Java - 0   mmm    m#m m m  mm m   m   m   

m m m% m&  m?  m m6%&?7m  m#m mm   m  m 

m  m m  m   m mm   m?m   m#m   m   m    m mmmm m m   m  m mm m m m m  m m  m m mm mm    m  m m %m mm m m   m m

   mm m  m   m mm  m  mm  m mmm m  mm    m   m

m   m m  m m m- m m5  mm  m#m   m  m#m  m m m  m mm   m  m%&?m   mmmmmmmmm #m   m m   mm m   m   mm mm m   m m   m    m  m  m m mm  mm m  mm  m  mm  m m  m   m m   mm m#m   m m  mm  m m   m m

  m%;m  m  m5 m  m;? m   m m m Java Releasesm

’he Creation of Java )

#m m   mm# m.   m m- m* m m) m@  m m%m  mm  m%    m& m m (( m&mm Am  mm  mm m m  m m  m m  

m 

 m2/ 4mm m  m2#4m m ((1m0 mm  m   mm/m mm

m m (("m mm  m   mm#m mm  mm ((1 m mm m   mmm   m m  mmm  m0

m# mm m9 m#  m  m@ mB

 m mm 8  mmm   mmm mmm  mm#m m   mm m %    m m ((Cm-mm#m m m mmm   mm m m   m   m   mmm m  m m m m  mmm m mmm   mm  m  mm #m   mmm

^    m J  m  m   m  m m  m    m  m   m  m m   m    m  ! "#$ $$%%      m & # 'm  ! "#$ $$%%  ( Jm & # ('m  ! " ) % $%%     m & 'm  ! "#$ $$%% & #'mm m

 m m m m m m m m m

m

m

m    ) *% & * 'm    ) *%  & *  'm    ) *% & * 'm

   m    m  m

m

+m

m

[ownloading J[ (Java) m

m m#?Dm6#m?  mD7m¬m #?Dm mm m   mm  mm  m%    m#m?  mDmm#?Dm

 m m m  m m  mm    mmmm  m%    m#5%m   m m mmm mm  mm#?Dmm   m$m  m   mEm$m  mm m mmm#5%m  mEm#?Dm  mm mm #?Dm m  m m#m"m  mm  m mm  m#"%) m#")mEm#"))m&mmm  mm   m#m m mm    m#")m Acronyms:m J[ mm#m?  mDm JVJmm#m m  m [ownload J[ You can download J[ from www.javasoft.com/j2sem Installing Javam [ownloading and Installing J2SE Software on "indows Platformm m   m#")mm   m mhttp://www.java.sun.com/j2sem m   m#")m m m  m& m m mmm  m$  F1FFC  1AC!m$m" mm6#?D7m

 mm    mmm  m@ mD  m mm$m?  mm m#?D m?   m $m m

mm    mm$m"m mmm  m mm  m m#"%) m#")m m#"))m mmmm   mm$ m mm  m mm    mm#"))m / mmm    mm$" m mm   mmm mm 

mm& mm

 m   mm 

m  mmm 

mm$ m   m   m mm  mmmm mm 

m#?Dm  mm  m  m Step 1m

m

m

? m

 mm#?Dm  m   m  mm!  m!  mm' m*   mmmm  m m m8  m m  mm m/ mm   m mm m m

m m   m mm

 mm !m mm m m m m m Step 2m m  m m  m m m

 m m

Step 3m *  m mm  m mm  mm 

 m  mmGc:\jdk1.5.0_06Gm m  m mm 

 m  m m m m m

m

m

m  m

 m mmG/DGm mm

  m mmG/DGm m 

 m >m m m m

Step 4 & mm !m m 

m  mmm 

 mm m m  m mm

 m  >m m

Step 5m *  m m !m m 

mm#")m m mm  m-!m  m  mm m    >*  m mmG-!Gm m

m

m

Step 6 / mm 

 m m   mm  mmm  m  m   mm 

 m-mmm 

 

m 

 m#")m mm  m& 

m  mm

 m  m   m m mm m m m m  m >m *  m mmG@  Gm mm!mmm 

m Configuring the installation on windows machine:m & m m  mm

m m m   mmm  m   m mmm$m  m m  m  m  mm   m m  mm$m   m .mmm   m  m m  m

 m mG m Gm mmmm  mmm m m m m m m m m m

m

m  m mGc:\jdk1.5.0_06Gmmm >m

m  m

 m mm mm mm  m

 m mG/DGm m Understanding Java S[ [irectory Structurem  m   m    mm? m m m  mmS[ m6m?  mD7mm

 m m  m$  1m m  m mH Hm  mm m  m    m m m  m 

 m m$m mm m

m m   m m  m mm  m  m

m S[ [irectory Structure:m

m Subdirectories of the S[ :m ’      m

m

m

Bin directorymmm m  m  m

m    m mm   m m  mmm mm mm  m  mm#m  m [emo directory -  m  m    m m   m m  mm  m  mm Include directory m&m   m

m m  m mmH*Hm m  mm   mmm

 m*m  m mm#mm Jre directorym-  mm m m$mm mmmm  mmmm mmm#m  mm#m3 m)   m6#3)7mm?Dm  mm   m  mm#3) m m

   m mm$mm  m Lib directory m m mm m m  mm   m mm   m  m mH m  m  m [ocs directory m&m mm  m  mmm?  mDmm   mmm mm#m    mm  m  m m m  m  m Files of the S[ :m 6                 m REA[JE.html : m$  1m  m  m m m mm   mm  m  mm?Dm  m mmm m m m   m

m  m'  m m m    m   m m   m

m  H mmm$  1m scr.zip: mIm m mm 

  mm mmm  mm m m   mm  mmHIHm !  m   mm  m m   mm  m  mm?Dm&m m   mm! mm  mm   mm  m  mmmJ&m mmm "riting Hello "orld Java programm #m mmm  m m  m mm m  mm  mm m   m#m    mm m m   m m  mm m m m m m m9

m  mm mm  mmmm9

m mmm  mm  m!m m m m m  mm$ m mm 

m mm  mm   m m  m9

m mm mm m mm $m mm  m0m  m mmmm$m  m mm!m m  m$m mm

 m  m m  m

m

m

mFor Examplem hello world !=(not equal to) Hello "orldm mm

 m  m mm m mm mm9

m mmm

Ú m  mm mmm ÚmÚmm  m  m mmm      m  m mmm m

m mm m m  mmm   mmm mm m& m m! mmm  m m m mmGC:\javatutorial\exampleGm  mm m m  mm mm

 m m mm mm mmm$m!  mm Hello"orld.javam -m mm  mmm  mm9

 $mm.mmm  mmm m  mm m6m mm  m*>K$ K! L7m m mm

 m  mm  m m>m C:\javatutorial\example>javac Hello"orld.javam javacm mm  m mm$m8 m#m  m  mm m8 m m   m  mmmm$m m  m   mm/ mm   m m 

  mm m  m

mm  mmm mHello"orld.class. mm mmm mm

 m  m m

 m>m C:\javatutorial\example>java Hello"orldm Bm

m mm

 m  m mm  mm Hello "orld!m 9m mm  m mmmm  >m m m m

m

m

m m & m m   mmm   mmmm m m mm9

m m mmmmmmmmmmmmmmm   mPmG Gm mmmmmmmmmmmmmmmm mmmmmmmmmmm  m;>m mmmmmmmmmmm  mQ>m mmmmmmmmmmm  m1>m mmmmmmmmmmmmmmm   mPmG Gm mmmmmmmmmmmmmmmm mmmmmmmmmmm  mC>m mmmmmmmmmmm  mR>m mmmmmmmmmmm  mA>m mmmmmmmmmmmmmmm   mPmGGm mmmmmmmmmmmmmmmm mmmmmmmmmmm  m(>m mmmmmmmmmmm  m >m mmmmmmmmmmm  m >m m

m

mmmmmmmmmmmmmmmmm   mPmG Gm mmmmmmmmmmmmmmmmmm mmmmmmmmmmmm  >m mmmmmmmmmmmmmmmmm   mPmG0 m% Gm mmmmmmm'm mmmmmmm   6G m m mmGm+m   m+mGG7m mmm'm 'm m m

  

m





m

Chapter ± 7m Ñ )0 mmmmmmmmmmmmmmm m mmmmm mm m mmmmm m m  mm m m m mm !  )0m m mmmm!Úmm Ú mmÚmÚ   mmÚÚ mmÚ m Ú  mm mÚ mmmm  m   mÚ  m m  Ú Ú  m %%%%-% 0mm mm m! mmmm mmm mÚ  m  mm!Úm mmmmmmmmmmmm  Ú m  $%% 0mmmmmm  m! mmmm mÚ  m m  mm mm m mmmmmmm" m m Úm mmm m  mm m1  .$   0 mmm m! mm Ú mmÚ mm mÚ  m   2) 0   mm m mm m m     mm m mm

m mm , %  )0   m m mm   m mm!Úmm  mm! m mm mm mm mm m m mmÚm m mmmÚ m 2) 0m Ú mÚ  m  ÚmÚmm m  m  m  mmmmmmm  m mm m     Ú  m mmmmmm m

m

m

m

m mm $ , %  )0 m m mm  mm m m!ÚmmmÚm Ú m   m m!Úmm m Ú m #20 m m mmmmmmmmm m  m

m m ! m m2) 0 m  ÚmÚ m# $ mm m m mm ÚmÚmm  m  mm m mmmm mmmm mmmmm m mmmmmm      m mmmmmmm mm m m mm m mm m

m m

Nested Loops 8m

mm m   m#m

 m  mmm   mm m m mm m  m m@m!  mm mmmm   mfor  >m m m

m

m XXm mmm   m

m  mm m  m   m m   mmm m  mmm  m!" m##mm m m!" m##m



    $ $m      m %m %m %m mm   mm mm m  m>m m m m m m m m m m m m

Using break & m# mmbreak  m mm  m@  m mmm  mm  mm  m ' m mmswitch  m  mm  mm  mm!mm m mm  mm  m m m2  I 4mmmmm  mm  mm!   mm

Using break to Exit a Loop 0m  mbreak mm  m m m  mmm  m  mm    m !  m m m  m  m mm mmm m mmbreak  m m    m  mm  mm m m  m mm   m  mmm !m  m

 mm m9m mm  m! >m

WWm,  mmm!mm m

 m08m mOm   m  m m 6 m MN7mm Om 6 mPmV m++7mm m Om 6mPPm 7mmWWm mm

mmm m m

m

m    6G>mGm+m7m 'm    6G8m  G7m 'm 'm m  mm  mm

 m>m m >mm >m m >m"m >m;m >mQm >m1m >mCm >mRm >mAm >m(m 8m  m

Using continue  mm m  mm m m m mmm mm mmm mm   m   mm mm m   mm mmm  m m m mm m  m  m m m m  mmm$ m mm mmm  mmm Y m mmcontinue  m m  m m  m& mwhile  mdo-while  mmcontinue  m

  m   mmm  m   mmm    m!  mm   mm m & mmfor  m   m m mmm m mmmfor  m m mmm

   m!  m@m

mm  m m  m  m m  m 9m m m! mmm  mcontinue m  mm  mmm  m m  m  >m WWm? m   m

 m*  mm Om   m  m m 6 m MN7Nm mm

m

Om 6 mPmV m++7mm Om   6m+mGmG7m m6Z"mPPm7m   m    6GG7m 'm 'm

'm

m

m  m  m  mmš mm  mmi  m m&mm mm m    mm  m m   mm m 9m mmmm m>m m m m "m;m Qm1m CmRm Am(m m 9m m m! mmm  mcontinue m mm  m     m mmmm(m m WWm,  m   mmm  m

 m*  8 mm Om   m  m m 6 m MN7mm Om >mm6 mPmV m++7mm Om 6 m$Pm$V m$++7mm Om 6$mLm7m Om    67m

  mm 'm   6GmGm+m6m[m$77m 'm 'm    67m 'm 'm m m m

m

m

m mcontinue  m m m! m  mm m   mj  m    mm m !m mmm m   mim9m mmmm m>m m m m m"mQm m;mCm(m mQmAm "m Cm m1m m 1m"m"1m mCm "m Am"Qm;m;Cm mRm Qm" m"Am;1mQ"mQ(m mAm Cm"Qm;"mQmQAm1CmCQm m(m Am"Rm;CmQ1m1QmC;mR"mA m

):)3*&)m>m ;m Checking whether a year is leap or not ?m ;m Listing out leap years between certain period ?m ;m Preparing table of a number by using loop ?m ;m Finding out the prime number ?m ;m Prime Number in Java ?m m  m$ m  m m m m  m mm   mmmm\ mm  m m m m  m m m6 mm 

m  mmm  7 m m m mm mmm mm  m  m mm  mm m m  mm  m m@m!  m  m  m mm  mmm   m m  mm >m   m mm &m  m  m m  mmm ' ( m  mmm ' ( m      m#m m  m m  m mm mmm m m m  m mmm mmm m m m !m m   m m  mm m m -!&  m -!? m @m!  mm

 m  m m  m m mmm  mm m mm mmm   m m m   >m   m mPm m  6  7m  m mPmm  m6  -!& 677mm Om m+Pm  !& 67m 'm

m

m

Creating Scanners  m  m   mm mm

 mmmm  >m m$   m m

m m   m mm >m mm mmm    m mm

 >m   m mPm m  m6 m 7m "mm mmm\  m mm

 >m   m mPm m  m6 m@ 6G  !G77m

m m m

m

m

m

m

Chapter ± 8m

&    m*   m m

 m mmm mm#m&m mm   m   m m mm m#m

 m m m  mm   mm m m mm m$ m m   mm

 m mm  mm$   m m m#m m  mm m m  m mm#mm mm    m mm

 m 0  mm

 m m m   mm# m m mm !mm  m

mm  m mm9 mm

mm    mmm  m   mmm

 m m  mmm

 m  mm   mm m$  mBm

m m  mm m    m mmthis  &    mm#m*   m m

 m m  mmm  mmm mm  m  m$  m m   m m m  m m#m

 m$  m!mm m m m   mm m

 mm

 m  m

  m m m mm  mmmm m$ m % mm  mm mmm

 mm mm  mm m$ mmm m    m  m#m m mm  m  mm  m  m* m  mmm

 Y m

   m$ mm  m mm$ Y m  m  m% m  mm mm  m m m m$m m m ’he General Form of a Class  mm  mm

 mm 

m m! mm m mBm m mm   mm mmm   m mm  mm m mm m mm  m

  mm

  m m  mm m  m m  m

  m   mm mm

m  mm

 Ym

 m   mm  mm m m 

 m m 

 mm mmmclass  mm

  mmm m  mmm m  mm 

mm  m!  mm m  mm*   m  m6 m 

m 7m m mm  !mm   m  mmmmclass   m m  m>m m

 m

  Om  |   #ë m  |   #ë %m   WWmm  |   #ë )m  |  "  6|  # 7m m Om WWm mm m 'm  |  "  %6|  # 7mm Om WWm mm m 'm

m

m WWmm  |  "  )6|  # 7mm Om WWm mm m 'm 'm mclassm mm

 m  m  !>m V

 m  L

 V

 m Lm V! m

 LmV   m

 Lm Om WWm?  mm*   m6*  m 7m V m 

 m6 m m-  7Lm V m 

 m6 m m-  7Lm V& m

 m 

 Lm V   m  m 

 Lm V   m 

 Lm V m  Im   Lm 'm 0 m m m! m  mm/$  m m*   mmm*m

 mm   m;m m  m

  m m mm mm

 m   mmm  m5 67m   m

 m*mm Om m m  m  m m  m m m  mm m   m m5 67mm mmmmmmmmmmmmmmmmOm m m  m6  m[m m[m7m m 'm 'm è          (   m m

   mm  mm mmm$ m  m

 mmm m6 7 m

 mm  mmmm  mm$ m 6m$ 3 m7mBm 

mm mm m$ mm  mm$ m

 mmm m 6 7 m

 mmm mmm m m m m   m m >m$ - -6 m " m;7m

m

m r ! | 

/$   mPmQm

/$  mPmQm

/$ mPmQm

/$  67m

           m m

 m  m m m m m m mm mm m    m  m

m$  m  mm

 m mm 

mm mmm  m mm   m  mmm   m m m

 m  mm

mm$  mmm

 m9 m m m$ m   mm mmm

 m   mm  m

m$  mmm

 mm  m

 mm

 m mm  mm m mm

 m  m m    m  mm mm m   m$ m mm

 m m  m  mm 

  m mm m$  mmm

 m! m&m m 

 m  m  m m

          *  m m  mm*  m  m  mm  mm m m  mmm

 m*  m  mm m  mm m  m  mm#m m@m!  m m mm $  %m mm

 m mBm  m 

m    m mm  mm  m  m

     &  m  m  mm mmm$ m) m

 m mm m m mmm m )m$ m mm mm m   mmm  m  m mm$ m m$ m m  mmm

  m m m m mmm m  m  m mm$ mm m  m m m$ m   mmm  mm

m 

mm m  m  m m m m m$ mm mm  mm m  m m m  mmm    m Ê             m

))  ,EÚ   J

 & 6 &,EÚ , Ú Ú$ M   Ú #     &     &   &&   $#Ú

Ú # ,#))

Ú    $#Ú

Ú  > ,# ))

Ú  &     ## ,#  -  $#Ú#    # ,#(())  - -

m

m  $#ÚÚ #

ÚD    $#Ú

Ú         "   # $  !>#  # EÚ !(## ,#    "   # $  !>#  # EÚ !     (# > ,#   - -  /m -mm*m$  mPmm -mm*m$  mPmm Final Variable, Jethods and Classes & m#mm  mm m m m

  m m  m/ m m m  m m m  mm

  m 5  m   m m m  mm   m  mBm  Ym  m mmm  m m6 mm

  7mm  m

 m  Ymm!  m m  m

 mm mm 

  m m m  mm  m   mm  m

  m m m m& m&m m

 mm  mmm mI m  m m m mm  m mm mm  m m  Ymm  m m m

 m m   m mmm mm mm  m m

m  m mm  mm Introduction to Java Objects m/$ m*  m mm m

 mm

m

  m m#m mmm$ m

 m mm ' m  67m 67m 67m 

67m    67m

 67m  mobjectm m m  mmm

 m  m  mm mmm mm mm m mm m  mmm

 m m m  mm   mmm m mmm

 mm   mm  m$  mmm

 m m 

 m   m m$ m    m m mm

m

m  m$ m m  mm mm m$ mm m  m m  m mm& m# m$  m

 m mm   mm  m m  mm  m m  m * m  mmm

 mm m  mm  m  mmm m m  m m  mm m) mmm m m$  mm m mm  m  m  m m!  m  m   mm    mmm$ m&mm mm m m$ mmm

 m mmm  m m   mm m$  mm m m

 mmmm$ mm  m mnew operatorm m  m m 

 m   m m$ mm  m m$ m  m  mm mm m$  mm mm mmm  mm$ mm mm  mm   mmm$ m mm  mmm mm 0 m m m! m  mm  mm*m$  mm  mm mm   m

 m*mOm m m  m  mPm m m  m mPm m m  mmPm m m   m m5 67mm mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmOm m m mmmmmmmmmmm m6  m[m m[m7m m mmmmmmmmmmmmmmmmmmmmmm'm mmmmmmmmmmmmmmmmm  m  m m 6 MNm 7mm mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmOm m m mmmmmmmmmmmm*m /$mWWm* mm*m3 m m m mmmmmmmmmmmm /$mPm m*67mWWm* m m/$ mm*m m m mmmmmmmmmmmm   6G5 mm*m m>mGm+m /$5 677m m mmmmmmmmmmmmmmmmmmmmm'm m mmmmmmmmmmmmmmmmmmmmmmmmm'm m m m m m m m m m m X)m *mm + mm +m,'m  m -m +mm,'. m )Xm

m,'mm

m

m m m& +m m++ m m  +m %m XXm/+m m  m m mm m,' m

m,'.mm m  m   m m   mmm m ,'m'mm &m,'mXX m   mm'm m mm XXm mm m'0m   mm ' & +mm" m ' ++ mm1 m '  +mm"2m XXm  mmm'm mm' & +m)m' ++ m)m'  +m      $3mm$m#mm %m %m

"hat Are Objects #m m m  m m  m0mmm$  ¬m m m mm      m  m m m m mm 

  mm  m6m 7m m  m6m 7m m   m   m mm  m m   

m   m  mmm m   m  m m  m mm   mm  mm  m mm mm  m m

  mm m    m/$  mm m  mmm  m

 m?  m   m  mm   m

 m' m m$  mmm  m

 mmm   m m mH m   Hm  m/$  m mm ! m  m mm m  mm I m   mm m

×      m  I m mm  mm   m m$ m mm ' mm m mmm  mm   m mm m m  m mm mmmmm m m  mmmmm$m

 m  I m mmm  IW   Im$m$  m m W  mm m  m /m! m

 >m Ú K  $

  >  $

   >   $#ÚK   > 7   >   & >  > 

m

m  &  >   >  - -  m m  mm  m m   mm I m  m m m m m m   m m  mm  m m   m >m  $  E     J   Ú K  $    J  $

  >  $

   >   $#ÚK   > 7   >   & >  >   &  >   >  - - /$  Im m m! m

 m  mmmm$ m  I m m#mm /$  Im  I mm   I mm  I m$m$ m mmWm mmmm m  $  E   L,# $#    $  E   ,EÚ ,# $#    $  E   9, 7,EÚ  E ,EÚ ,# $#   # #  " L,# $#   6L,# $#  >   # 6,EÚ ,# $#     # 6 ,EÚ E  # Ú   -Ú

Ú& 9,m ";"mm 3  mm 6 ";"7>m 1 RA"Qm  mm  m  mtest( )  m   mm mm m  m m m mm   m  m m m mm m mm m m mmm m  mdoublemm mmmm  mmtest( )  m mm m mm m

 ' m mm    m  m m m m m mm m m  m   m  m m   m m m 

 m#m  mmm m mm  m  mm 

m m m mm H m m9 m m m  m m  mm! m& m m

  m#H m mm    m  m mm m m  m   m@m!  m

  mm

 m>m XXÀ  | 



||                   |   |    XX         |      #     |   !"""  XX       |           |  -     !"       |     %&        '        '..

 

 ()#*)

 XX /    

 (*+*XX /    

m

m    mm  mm

 m>m -m mm m m>m m"mm &  m 6  7m>mAAmm &  m 6  7m>m ";"m

Jethod Overriding &mm  Ym m m

 m   mm m mm  m m mm  m

 m  m m m  m

 m' m m  m m 

 m/  m "hile overriding we have to fallow rules:m 1m& mm   mm m  m mY m mm m &m& mm  mmm  mm   mmm m mm m ,  m Qm  mm m m mm m0mm 1m  m  m  m m mm  m

 m Example:m

 mmOm  m-m-67O'm'm

 m m! mOm  m-m-67O'm'm (or)m

 m*m! mm Om   m0WW& m-67O'm 'm

m

@m-m

 m0WW& m m  m m mm

  m

m

9 m m  mm  m mm mmm  mm  m

 m$  m m

Example:m m$[m

 mm Om   m$ m 67Om m m$ m'm 'm

 m*m! mm Om   m/$ m 67Om m m/$ m'm 'm

 m*m! mm Om

m

m   m m 67Om m2 4m'm 'WW m Qm*)m  m 67m m*m  m m >   m'>$ >m m 1mm m*)m m 2m  m m  Ymm  m 3mm m m m mm mm  m  m m mm m  m mm

 m

  m 4m m  m    m

 m  m m m

 m5  m  mm*)m m

 mmOm  m m 67O'm'm

 m*m! mmOm  m m 67O'm'm Parent classm-------------------------------- Child classm   mm  m   mm  m  m  mm   m  m   m mm m   m  m  m m [m m   m m  m mm  m 

mm m m  m mm   m

 6m  m   m  m m m  m m  7m [m m  m m  mm  m m  mm  mmm  m  m

 m m   mm m   m m

 mm Om   m m 67m Om m'm m'WW  m  m   m

 m*m! mm Om   m  m 67mm 'WW  m  m m 5.m m  mm Immm*  )!  m  m m  mm m m mm , *  )!  m Example>mBase or parent classm>m   m m 67 m&/)!  m

[erived or child classm>m   m m 67 m@ - )!  mWW  m   m m 67 m)!  mL*)m   m m 67 m3 )!  mWW  m

m

m

m  m mm   I m mm     I m m m m

m

m  m m mm mm  m m m m m

m

m  m mm    m mm  m m

m

m

m  Ym mm  m mm  m  m mm    m mm  m  m  mm *)mm

m

 m  m m mm! m

mm    mm#5%m  m mm3 mm/$ m 9 m/  m m m! mm2   m  4mm280  4m6?  m% m   7m

m

&mm Y m

 m m  mm  mm m  m

 m$ mm  mm mm m

 mm 

m m m

 m m* m

 m   m mm m

 mm 

m m  m m

 m m

Jethod Hiding>m  m m!  m m m  m! mm mEm  m

 m m mm 

 m m  m& m m m  mm m   mm mm  m m  m mm mm Ex:m

 mm Om  m m!P m  mP"m 'm

 m*m! mm Om  m m!P m  mP"m 'm

 m m Om   m  m m 6 MNm7m Om m mP m*67m    6!+4 4+7mWW  "m *m P m*67m    6 !+4 4+ 7mWW  "m m P m67m    6 !+4 4+ 7mWW  "m

m

m

'm 'm

m

m

m  Ym m mm  m

 m0mm  m!  m m m m  m

 m

m

5 m   mm mm  m m  m mm mm

m

Chapter ± 10 Inheritance &  m m mmm     mm$   m m  mm

 m m  mm   m

   m,  m   mm  m mm  m

 mm   m m  mmm mm  m m m

 m  m mm  m m mm   m

  m m  m m  mmm 'mmm& mm  m m# mm

 mm m  m m 

 mm | 

m

 mm  mm  m m 

 m m 

 mm 

 m mm   I m  mmm 

 m&m  m

mmm   m  m m m   mmm 

 m m m m m 'm   m m &  m mm  m   m m#mm

 mmm! mm

 m6 

 mm  m

 mm 

 7mm m

 m6 

 mm  m

 mm 

 7m& m# m   m m  mmm  >m 1. Class inheritancemm mm m

 m m m!  mm m

 m mmm m m  m mm mm  m

 m  mm  m m m  m mmm  m

 m#m m

 mm

 mmm m m m

 m m   m

 m &  m 2. Interface inheritancemm mm m

 mm  mm m \  m mmm m   mmm mm  mm mm

 mm   m m  m2   m 4m6m m    mmmm7mm  m#m  m  m  m  m & m# m mm mm  mm m   mm  m  m  m  !m@m

 m   m#m  mm m! m mm  m  m#m  mm  m   m m   m

 m  

  m! m 

  m Om WWm  m

 m m! m m  m m WWm mmm m

 m 'm   m

 m

  m   m   mm Om WWm

 m  m m   mmm m WWm m   mmm  m

m

m 'm m m  m% m

 m0 mm Om m m!m   m m67mOmm'm   m m67mOmm'm 'm m

 m? m! m0 mm Om m mm   m m67m mOmm W[m m   mm0 67m[Wmm 'm   m m67m mOmm mPm67mm mm

'm

'm & m# mm  m

 m' \m mmm  mm6\ mm 7m m  mmm  m  m

 mmm m

 m    mm  mm&m m mmm  m m m  mm mmm

  m mm m mm m m  mm*++m Extends keyword mextends  mm#m m m m  m m  m  mm#m&   mm 

 m  mm

 m 

 m   extendsm m&m mm mm   mm m

 mmm 

 m m  mm mm mm  m m   mmm  m 

mm mm

 m m m m mm#mm& m# mm

 m mm 

 mmjava.lang.Objectmm @m!  m*  m:m! m

 mBmm m    mmm  m mm mm

 mB m mm  m mm

 mBm mm mmm

 m!  m m   mm mmmH! Hm mm

m

m   m

 mmOm mm  m m m 'mm

 m0m! mmOm mm  m m  67mOm mm ++m mm'm 'mm

m& m m!  mm mm

 m m m mm0m

m m   mm m 

 m mm mm

  m  m mm  mmm m m

 m extends  m m m  m m m  m 

 mm  m mmm    m @m  >mm   m%&  mOm mm¬¬¬¬m 'mm m   m%&  m! m&  mOm mm¬¬¬¬¬¬m mm'mm

SUPER EY"OR[ msuperm mm m   m mm$m m  mD mm  

m   m m mm   m  m  mmm  m m$m m

 m  msuperm m   mm

 m>mm m mm m m m$m m  m mmm 

 mmm

 mm m m m m   m m  m mmm m m mm    m  m m  mm 

mm   mmm 

 m  mm m

 m Example to use the super keyword to call the constructor of the superclass in the base class:m

m

m   m

 m*  m Om   mClass16 m7m Om 67m 'm m mmm  !msuper.() is used tommm 

mmm mmm 

 m m m m

 m mm m mm mmm m m m m   m mm  mm 

mm mm m   m m m m

 m m mm  mmm m  mm 

 m mm 

 m Example to use the super keyword with a method:m   m

 mClass1 Om   m m F% 67m Om  m   F F% 67m 'm m Order of Construction under Inheritance -mm mm   m m$  mm  m m

 m   m m 

 m    mm m mmm  m

 m   m m!  m m$  mm    m  m m   mm mm$ m  mmm/$ m

 mm/$ 67m   m m  m



 m   mm9 mm  m 

mm 

 m   m!   m  mm  m m  m m  m mm mm\ mm  m mm   m @m!  m m#m!  m$  m mmm$  )!  m

 m&mmm m m!  m

 m m)!  mmmmm m

 >m m

m

m   m

 m)!  m! m)!  mm Om   m)!  67mm Om 67mmWWm 

m)!  67 m m  m 

m/$ 67m 'm   m)!  6 m 7mm Om 6 7mmWWm 

m)!  6 7 mm m mm m

 m 'm   m)!  m6 mF  7mm Om  6G47mmWWm

 m   m m m 

m 6 7m    6F  7m 'm 'm m

m

m

Chapter ± 11 Abstract Base Classes  m  m

 m mm

 mm  m mmm m   m  \ mm 

 m mmm m  m m  m m m m m6 m m   7mm 

 m m' mm mm  m m m m m   m9  m m   m

 m m  m m  mm   mm  mm  m mm m

 m m   m  m

 m   

  mmm Om WWm  m

 m mm  m m  m m   m  m m    m6m  m7m mWWmm  m m$ m m

 m m 'm   m

 m  

  m! m   

  m Om   m m    m6  7m Omm   m m'm mWWmm m   m 'm &m mm mmmmm  m m$ mm m  m>m   

  m$mPm m  

  67mmWWm)33/3m  mmPm m *   6 m m 7m 67m m

Instance of operator minstanceof m m m  m>m *   m | m 9 m*  m m  mmm

 m m |  mm

 mm&m*  mmm   mmm  m m  m mm   m m mminstanceof m  mmtruem/  m m  m  falsem minstanceof  mm mm mmm  m m mm  m m m$ m m

 mm   minstanceof>m XXm.   m   m  mm

m*mm mm  mmmm %mm m m

m,mm mm  mmmm %mm

m-m'  m*m mm  m4m %mm

m.m'  m*m mm  m4mm %mm

m(   5mm m mm  m   m m   mmm m mm *mmm &m*mm

m

m ,mmm &m,mm -m mm &m-mm .m mm &m.mm m   m*mm      $mm   mm*$mm m   m,mm      $mm   mm,$mm  m   m-mm      $ mm   mm-$mm  m   m*mm      $ m  mm  m m*$mm m   m-mm      $m  mm  m m-$mm      mm XXm m mm  m mm *mmm mm mXXm*m m m mm      $m &mm m $mm m   m.mm      $mm   mm.$mm      mm mm mXXm*m m m mm      $m &mm m $mm m   m.mm      $m  mm  m m.$mm mm      $m   mm  m m.$mm m   m*mm      $m  mm  m m*$mm 6m17 m6mm      mm XXmm m  mm  m m5 mm m   m5 mm      $mmm  m m5 $mm m   m5 mm      $mmm  m m5 $mm

m

m  m   m5 mm      $ mmm  m m5 $mm  m   m5 mm      $ mmm  m m5 $mm m %mm %m mmm mm m  m>m m m  mmm m m  mm0mm

m m  mm*mm

m  mm  mmmm m m mm mm m m  mm?mm m m mm mm m  mm  mm?mm m  mm  mmmm mmm  mm/$ mm mmm  mm/$ mm

mmm  mm/$ mm mmm  mm/$ m minstanceof m Hm   mm m m   m 

 mm mmmm $ mm mmm m9 mm  mmm  m mHm m  I m   mmm m$  mmm  !m

 m m m m

Using final to Prevent Overriding  m m  m m mm#Y m m m mm

mm m m m

m mm mmm

 mm  

mm mm m  m  mfinal  mm mmm mm m 

 m% m 

 m mfinal  m m  mm

 m m

  mfinal>m

 mmOm   m m67m mOm    6G m mm  m G7m 'm 'm

 m0m! mmm Om m

m

m  m67mm OmWWm)33/3m 0  

 m  m m m  m6m 7m mm  m   mm mm m  m@m!  m  m m$m m m  m  mm&W/ mm  m m$ m m m mmmm  mmm-m& m.,&m   mH m'm  mm mm mm  m mm mGGm6 m  7 m  mm m  m m  m  mmm   mmm m   m/ mmm mm m mm  m 

 mG  G m m  m

m  m  m mm m   mmm   m  m   m m m mm m

 m m 

  m mm mm m

 m m mmm  m@m!  mmmmm

 m m 

 mG5 G m m m m  mmm5 m

 m m#?Dm9 m m m m  m#?Dm m$ m mm m mmm5 m

 m6$ 5 7mmm5 m

 m  mm  m mG5 Gmmm  mmm m m  m m   5 mm mm  mm  mm  m m  m m mm    m I m m  m 

 m m   m,    mm

 mm m

m m m m m m m  m  m m$m  m mm  m m m  mmmm m 

 m9

 $ m mm mmm m m mm mworldm@ m m mmm m mm  mm packagemmm mmm mm mm m6worldm m m  7m mmmm  m  mmm  mm   mm m

  m mm  m m  m  mm9

 m

 m >m ((   "  m package world;m m   m

 m9

 mOm mm  m  m m 6 MNm 7mOm mmmm   6G9

m G7m mm'm 'm / m mm m mm  mm mmm

 m mm m   m    mm   m m mmm

 m& mm   mmmmworldm  m m' m m  m  m mm mm  mworldm mmm9

 $m mm

m

m Setting up the CLASSPA’H @mm"mmmm m m m*>mmm$ m mm*89m >m m*89P*>Km m mm*89mm mm"m   mm6 7m m*>Km  mm ->m&mm  mm m mm?/mm,-&: mmmm mmm6 7m mm6 m 7mm  mm m m  mmm  m  m mmmm m  m& mm*89mm

 m  mmm    m  m#m

m mm

 m m m mm*>m  mmmm  m  m m

m  mm mm6    7mm mm  m   m m  mmm

 m  m  m m   m  m   m9

 m

 mm$ mmmm m  m mmm  >m *>K K$ m9

 $m &mmmm m m9

 m  mjava Hello"orld mm

mmm

 m>m +N6 ?E  O P   2L #

1 &  

E    ;    ; E  + 

 E  Ú# " Ú# ;   Ú# ; E  + 

E   54; ;   54; ; E  +Q 

E   54; ;  ÚÚR 54; ; E  +S 

E   54; ; R# 54; ; E  +TI 

E  Ú# ".ÚÚ    K >

1 &  

E   54; ;   54; ; E  +T 

E    ;     ; E  +T 

# Ú; #Ú&R.$$ ;    ; #Ú&E  +QS 

E    ;     ; E  +I  m  m mm mm9

 m

 m   mmm m m&mm mm m mmm m

m#5%mm mfully-qualified class name6 9

 7m  mm m  m

 m m69

 7m *>K L$m 9

 m *>K L9

m m ->mfully-qualified class namem mm mmm$m

 mm

  m m m m m$ m   mm   mmm mm*>K K9

 $mm *>K

  K K9

 $m/m*89m m  mmm   mm mmm m

  mmm m m

   m  ;. K.DOÊ!0   m#m

m mm$m

  mmm  m  m mC:\myclassesm  m  m  mm mG?mmmm mm9

 mmm  mmm m m

 m m ¬Gmm m m-/mm  m m9

 mm m m  m mm 

m

 mm  m m mm*89m@m!  m +N? ;. K.DO+N

m

m  +N? ;. K.DOXX       ;. K.DO+N  +N?Ú6   Ê!0  12   3  4   3  4    +N6 ?Ú  Ê!012   3  4   3  4  

è ,  )5  mm"m m m mm mm  m

  m  m m mm m?

mm

'  m

 m m@m!  m  6 O P & P 66 O P   6  O 1 & 1 66  O 1   & > & 1  O >     mm m  $  m  m  $  6 0XX           d    $  6  0XX           d     $  E  # 0XX      3      $  E  # O & XX    è           !

mmÚmmmmmÚ mm  m m # mÚ m mm  O P & P 6O P  XX  "   #   $   O 1 & 1 6O 1  XX  "   #    %    -mmm  m 

m  m

  m  m mm m  mm mmm mm  Hm m m

  mm  mmm  mmm mmm@m!  mmmm  m mm  m m mm9

 m

 mm mm9

% m

 m A Short Package Example m D mm   m    m m mm  mm m  m >m WWmm  m m

 m% m

 m0  m Om  m m  m m 0  6 m m  m7mm Om

m

m mPm m  mPmm 'm  m 67mm Om 6 V7m   6GLmG7m    6 m+mG>m]Gm+m 7m 'm 'm

 m

 0  mm Om   m  m m 6 m MN7mm Om 0  m  MNmPm m0  M;Nm

 MNmPm m0  6GDm#m@  G m ";";7m

 M NmPm m0  6G

m

G m 1R"7m

 M"NmPm m0  6Gm#   G m ";;7m 6 mPmV;m++7m  MN 67m 'm 'm m *

m m mAccountBalance.java  mmm mm  m 

 mJyPackm -! m  mm m%m mmm   m.class  m m m mmJyPack  m mm!  mmAccountBalance

 m  mm

 m  m  >m $m% 

 0  m 3 mm

m  mmm mm  mmJyPack  mm! m m  m 6    mm  m m mmmmm m   m mm   m   mm  mmmJyPack7m  m!   mAccountBalance  m mmmm mJyPackm m mmm

 mm!  mm  mm mm  m m m  m  >m $m

 0  m AccountBalance  mm'  mm m m m m m m

m

m

m

Class ± 13 Exeception handling ¦! |mm m!   m m 

m ! | mm  mm  m m m m m

 m  mmm!  m? mmm!  mm mm

 m mm m m mm m mmm  m mmmm mmmmmmmm  m mmm mmO'm  m m  mm m  m  67m  m)!  m mm   mm  m mmmm   m m  mmm  m  67m  m)mm

 m  mmm!  m mm   m$ m m mm  mmm m 

 m mmm & mm

 m! m  mm

m mmmm!  m  m  mm  m m$mm  m! m mm m  mmm  mm mm&mm m mm  m! m m6mmm(m7m mmm m mm)  r ¦! |m$ mm !% 67m  mm  mmmm

 m   m Code of the program : m | E   0  | 8Ú$  O   |        + +!(D& Ú# D&   >  m D& 2   D& 2 !1"D& !))>6

m D& 2   D& 2 !1"D& !m -m -m

mm # %-% m m  mm    m  I m mm  mm  

 mm

 mm  m   m mm  m m m  mm mm m m m  m

 mm  m  mmmm & m  m   I m   m   mm m  mm m mm mm  m$ m  m m m m mm  mm  mm  mm$ H m m  I m  m  mmm m  m mm m  mm m m m    m mm  m Ú  mm Ú m

mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm |  

6   7  ( XX   

  

6  /     

! | 7  *

m

m  

6  XX 

6    

m

m

m mm # %-% m m  mm    m  I m mm  mm  

 mm

 mm  m   m mm  m m m  mm mm m m m  m

 mm  m  mmmm & m  m   I m   m   mm m  mm m mm mm  m$ m  m m m m mm  mm  mm  mm$ H m m  I m  m  mmm m  m mm m  mm m m m    m mm  m Ú  mm Ú m

mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm |  

6   7  ( XX   

  

6  /     

! | 7  *  

6  XX 

6    

m

m

m J %m / mmm m   m m  m   m  m mmmm  mm m m

m

  mm mm#m mm

 mmmm mm mm mmmm wait67m mnotify67m mnotifyall67m m

mm / $ % %% m  m mm   m m  m m m m m m mm mm/ m mm  m m  mm mm9mm mmm*,mm m  m mm H mmmm 6 m7m m m & m# m m   m  m mm prioritiesm mmmminteger value m mm m m m  mm!  m   mm mm m mmready-to-runm m

  mmm  mmthread schedulerm  mm*,mmm mm mm  m  m mmm  mm m  mm m6  mm mmm   m’hread.JIN_PRIORI’Y7mm m 6 mm mmm   m’hread.JAX_PRIORI’Y7mm  mm m 16’hread.NORJ_PRIORI’Y7mmm mm

3 m

  %)% m mm!m mm m m #%&'()(*m m  m m mm m m #+&'()(*m mm m mm m

m

m m  m m mm m mm  m mm m m %)(#&'()(*m m  m m mm m m mmmmmmmmm mmm mm mm

mJ  $m

  %)% m mmmmmmmm m' mm  mm mmm mmmmm mm m ' mm  mm m mm  mm#m m m  mm  m mmmm mm  mmmm m m m  m  m mm mmm!  mm m  m   mm  m mmm  mmm!  m& m#m m   mpreemptive schedulingm m m  m&mm m!  mmm mmmmm m

mm mm  m mm m  m   mm higher prioritym mm!  m/ mmm mmm mmm mmm mmmm!  mmm*,m mmround-robinm m m  m m m m   m   m mmmm m

  mmm mmtime-slicem ’hread Schedulerm & mm   mm  m   m 

m  m mmmm

 m  >m m

Preemptive scheduling ? &mm m m mmmm m  m  m m

 mm  m m mmm m mmm  m m mm

m

’ime-Sliced (Round-Robin) Scheduling ? m  m m m

 mmm! mmm ! m mm   mm m  m m   mmm m mm mm m m  m m

Bm  m m mm H mmm mmm m  m  mmsetPrioritym m8 m  m mm m mmmmmm m mm # m 2 $m mm#   m m mm)  m mm m

m

m mm m mm)% %$ m

mm! % m mmmÚ Ú  m mmÚ '  #%&'()(* m mm%Ú ' m mm     m%mm  Ú  %

m mm     m' mm Ú m mm m mm m

m mm# m 2 $m mm#   m m mm)  m mm m mm m m )% %$ m mm! % m mmmÚ Ú  m mmÚ '  #+&'()(* m mm%Ú ' m mm     m%mm  Ú  %

m mm     m' mm Ú m mm m mm m

m )%' m mm)%% %$  m  mmm mm# m ,#  # mm m mm# m ,#  # mm m mm m

m

m m  mmm m m mm m$ m  mm mm   m m m m   m  m m mm m$ m  mm mm m m m  m m  m m[eadlockm

m

m

8 m mm  m mm m  m mmm   m   m m

 m>m

m & m m mm m mmPrintingmEmI/O  m   mmmm0m’hread1  m mprintermmm m mmmm’hread2 m  m’hread2m  mmkeyboardmm m mmmm  m& m m  mm*,m  m  m mm   m   m

 m  m m m  m m!  m  mm mm   mmmm ’he following program demonstrates the deadlock situation:m | 2 2  |        !2 !  !; Ú'! 1"D&   1"D&  7 1"D&   1"D&  7 - -  1"D&  5 D&      1"D&  7       -  |   #      

6    

6   "   # $  ( - -

m

m - - - 1"D&  5 D&      1"D&  7        -  |   #      

6    

6   "   # $  ( - - - - -m

m m

m

m

m

     File I/O "hat is Java I/O? Introductionm m#m& W/m6&W/7m mmmjava.iom mm2  m m   mm  m m m

  mm mm m mm mm

  m mm mm m   m

  m m   mm  m m m 

  m m

m mmm m m m mm  mmm m mm   mmInputStreamm OutputStreammmm

  m

  m mm m mm  mm  mm m mmm  m   m m$m m  mm  m  mm m m

  m mm m  m  m  >m

m InputStream:m

m

m

mInputStream

 m m  mm  mm m  m mmm mmm mm m m  m m m  m  mmmfile mmstring mmmemorymmm   mm m&m m m  m

 mm   mm m  mm

m m  mmm  mmm m m m m 

m  m mm mmBm  m!   m

 mm mmmclose( ) mm mmm

  m   m mm$ m m m mmm m 

  m  mmmInputStream

 m  mm  m mm m m  m >m

m & m m  mmm/$ m

 m) m

 mmm&  m  mmm$m  m m   mmm  m m mm OutputStream:m m/m

 m mm   mm& mm m  mm mm mmm mm m m  m mm m   m mm  m  mm  m  m mm  mm   mm m    mm m8m m m  m mm m m 

m  m mm

mmBm  m!   m

 m mm mmmclose( )m mm mmm

  m   m  mm$ m mm 

  m m

  m  mmmOutputStream

 m  mm  m mm m  m  m >m

m

m

m /m m m  mmm/$ m

 m) m

 mmm/ m  mmm $m m m   mmm  m m How Files and Streams "ork:m #m  mstreamsmm m&W/m mm mm m m  mm m   mm  m@m!  m mInputStreamm  m mm mmm  m mmmm   mm m  OutputStream  m mm mmm   mmmm  m mm   mmmm!m m mm m m mmmmm!m  mmm mmcharacterm mm m  m m m  mmm m  m mmmmm m  mmm mmbinarym m m m  mmm&W/m  m  mm  m mm m m

m m Classes and Interfaces of the I/O Streams  

 m   mm

  m  mmmjava.iom m  m mm m m m Reading ’ext from the Standard Input Standard Streams:m

m

m

  m mmmm  mm m m   m0m   mm m mmm  m mmmmm   mm m m&W/m m m  m m#m m  mm  m >m

#$ $1)0mÚÚm m# %Úmm mmm mmm   m m #$ $)0mÚÚm m#  mÚm mmmmmmm  m m #$ $ 0mÚÚm m#  Úmm mmmmmmm  m m

 m$  mm   m 

m m m m  mmm  m!   mStandard Outputm Standard Error,mmmmmm mmm  m mmm mm  mm  m    System.inm mmm mm m m  m m mm m  m& m mm  m  mmSystem.inm mmInputStreamReaderm m m m InputStreamReader inp = new InputStreamReader(system.in);m "orking with Reader classes:m #m  mm   m&W/m   mm  m!mmmm mmm m mm

 m  mmReaderm

 m m  mm m mm m  m mmjava.iom m&m  m  m m  m

 mm  m  m  mm m mmm 

 m m  m mread(char[], int, int)  mclose()mm3 m

 m mm I m mm 

  mm m

 m m  mm

  mmmjava.io.Readerm

 m

m

m

m

9 m m 

  m m mmm m m mm mm   m   m     mmm InputStreamReader:m  m& 3 m mm mmm  mm  m  mmm mbytesm m    mm mUnicode characters 

  mmm  m m m m

 m m

  mmmm m m mm m mInputStreamReader mm  m m & mm  mm& 3 m mm m m  !mm& 3 m m m >m InputStreamReader = new InputStreamReader(system.in)m BufferedReader : m mBufferedReaderm

 m mm 

 mmmReaderm

 m&m m   m m mm mmm  m mmbufferm  m mmmm Immm   mmm  m Im mm  mm m m mm!m  m   0 3 m   m munbufferedm m mmbuffered m  mm m!  m mm  m m$ m m  mmm   mmm m m

 m @m! mm    mmm0 3 m

 m  m >m

w!! $^ $ &,   !$mm mÚÚ mm mmm m m m w!! $^ $ &^ $ %"%-'0$mm mÚÚ m mmm m mmmmÚm m BufferedReader

 m  m m   m mmm   m  m m  m m m m

m m m mmIOException mm m&W/mm

 m

J  $m m m m m Ú mÚm  mm m  m m  m m

m

^   /) m m m m m m  m

  %)% m m(mm mÚÚmm m(mÚÚm mm mm  m m m(mm  mm! mm  mm Ú mmmm m m

m

mmÚ  m m

mmm

  m m$ mm m m

mm mm

  mmmm m   m m mm mm m m | E   0m  | 4   9,  |       9,  m mO m m  1  m m & m m K

& m m  m

  %)% m m( mmm m! m m( mmmmmm  m  m mmm  mmmÚ m m( m mmm mmÚ m m( mmm mm m m( mmm mÚ m m( m mm m m  m mm  m m mm  m m( mmm m m( mmm m D m ÚÚ m m$mm m m mm mÚ

>6L m )!Ú mm m Create a File m | E   0  | 

L |       9,6N! " 8 N!& Ú

  &Ú# Ú "! - - -m m m

m

m

m Read the Filem | E   0 L4   |         )),$ & &

 &  ))Ú $    L9$#     L9$#  ! 8  8 ! ))@  & EÚ  2

9$#   2

9$#   2

9$#     G#4  G#4  9$#  4      ; ))4 L;G";    ; ; :  ))K  &Ú     &Ú    "   # $   ; - ))  &$#    Ú   - mm

% 6 % ! 7 ,% 6 % &!%  '8 w!! $6 %  7 ,w!! $6 % &! '8m 8 m m m m! mm mm!m mmm m  mmFile"riter  m Buffered"riter

 m | E   0  | LP   |       9,6L   :8    "   # $  !L  "8 !  "  8  -     LP    LP  V  G#P  #  G#P      # 6   ;   # Ú    "   # $  !LÚ

#ÚÚ#"! -

m

m - -m m m Appending to a Filem

Here is the code of java program to write text to a file:m | E   0 LP   |         ))

 LP    LP  ! #  8 !7 # G#P  #  G#P      # 6  !O M  ! ))  & # $#     # Ú   -
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF