0% found this document useful (0 votes)
440 views101 pages

BioJava Book

Uploaded by

rednri
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
440 views101 pages

BioJava Book

Uploaded by

rednri
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 101

Java and Bio Java

A Students Handbook

SUBRATA SINHA

Copyright 2010 Subrata Sinha All rights reserved.

ISBN: 14 !!11!22 ISBN"1#: !$%"14 !!11!22

DEDICATION
I &ould li'e to dedi(ate )y boo' to )y )other* S)t. +ripti Sinha* )y ,ather Shri Bi-oy .u)ar Sinha.

CONTENTS
Section A : Java Chapter 1 Introdu!tion to OO" and Java Chapter # Basi!s o$ Java Chapter % Introdu!in& C'asses Chapter ( "a!ka&es Chapter ) Inheritan!e Chapter * E+!eption Hand'in& Chapter , -u'tithreaded "ro&ra..in& Chapter / App'ets Chapter 0 Strin& Hand'in& Chapter 11 2i'e Hand'in& Chapter 11 Event Hand'in& Section B: Biojava Chapter 1# Introdu!tion to Bio3ava Chapter 1% A'phabets and s4.bo's Chapter 1( Basi! Se5uen!e -anipu'ation Chapter 1) "roteo.i!s Chapter 1* Se5uen!e I6O Section C: Solved Problems Chapter 1, E+er!ise So'utions o$ Java "rob'e.s Chapter 1/ E+er!ise So'utions o$ Bio Java

SUBRATA SINHA

vi

AC7NO89ED:-ENTS
I &ould li'e to a('no&ledge )y (ollegaes * students /or their (onstant help and support..

Chapter 1
INTRODUCTION TO OOP AND JAVA

0aradig) o/ 0rogra))ing. +&o 0rogra))ing 0aradig)s are 0ro(edure 1riented 0rogra))ing and 1b-e(t 1riented 0rogra))ing. 0ro(edure 1riented 0rogra))ing 0aradig): In 0ro(edure 1riented 0rogra))ing20103 approa(h the proble) is vie&ed as a Se4uen(e o/ things to be done su(h as reading*(al(ulating and printing. A nu)ber o/ /un(tions are &ritten to a((o)plish this tas'.+he pri)ary /o(us is on /un(tions or pro(edures. In a )ulti /un(tion progra) * )any i)portant data ite)s are pla(ed as global * so that they )ay be a((essed by all the /un(tions. 5a(h /un(tion )ay have its o&n lo(al data. 6lobal data are )ore vulnerable to an inadvertent (hange by a /un(tion. In a large progra) it is very di//i(ult to identi/y &hat data is used by &hi(h /un(tion. Another serious dra&ba(' &ith 0ro(edural approa(h is that it does not )odel real &orld proble)s very &ell.+his is be(ause /un(tions are a(tion oriented.

SUBRATA SINHA

So)e Chara(teristi(s o/ 0ro(edure 1riented 0rogra))ing 1. 5)phasis is on doing things 2algorith)s3* 2. 7arge progra)s are divided into s)aller progra)s 'no&n as /un(tions. #. 8ost o/ the /un(tions share global data. 4. 9ata )ove openly around the syste) /ro) /un(tion to /un(tion. :. ,un(tions trans/or) data /ro) one /or) to another. .5)ploys top do&n approa(h in 0rogra) design. Object Oriented Programming Paradigm 110 treats data as a (riti(al ele)ent in the progra) develop)ent and does not allo& it to /lo& /reely around the syste).It ties data )ore (losely to the /un(tions that operate on it* and prote(ts it /ro) a((idental )odi/i(ation /ro) outside /un(tions.110 allo&s de(o)position o/ a proble) into a nu)ber o/ entities (alled ob-e(ts and then builds data and /un(tions around these ob-e(ts.+he data o/ an ob-e(t (an be a((essed only by the /un(tions asso(iated &ith that ob-e(t. ;o&ever /un(tion o/ one ob-e(t (an a((ess the /un(tions o/ other ob-e(ts. So)e o/ the /eatures o/ 110: 1. 5)phasis is on data rather than pro(edure. 2. 0rogra)s are divided into &hat are 'no&n as ob-e(ts. #. 9ata Stru(tures are designed su(h that they (hara(teri<e the ob-e(ts. 4. ,un(tions that operate on the data o/ an ob-e(t are tied together in the data stru(ture. :. 9ata is hidden and (an not be a((essed by e=ternal /un(tions. . 1b-e(t )ay (o))uni(ate &ith ea(h other through /un(tions. $. Ne& data and /un(tions (an easily be added &henever ne(essary. %. ,ollo&s botto) up approa(h in progra) design.

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

9e/inition o/ 1b-e(t 1riented 0rogra))ing: An approa(h that provides a &ay o/ )odulari<ing progra)s by (reating partitioned )e)ory area /or both data and /un(tions that (an be used as te)plates /or (reating (opies o/ su(h )odules on de)and. 9e/inition /ro) 5.Balagurus&a)y Features of OOP: 5n(apsulation : +he &rapping up o/ data and /un(tions into a single unit 2(alled (lass3 is 'no&n as en(apsulation.1nly /un(tions in side the &rap (an use the data . +hese /un(tions provide the inter/a(e bet&een ob-e(ts data and the progra). +his is also 'no&n as data hiding or in/or)ation hiding.

Abstra(tion: Abstra(tion re/ers to the a(t o/ representing essential /eatures &ithout in(luding the ba('ground details or e=planations. Sin(e (lasses use the (on(ept o/ abstra(tion * they are 'no&n as Abstra(t 9ata +ype.

SUBRATA SINHA

Inheriten(e: Inheritan(e provides the idea o/ reusability o/ (ode. +his )eans that &e (an add additional /eatures to an e=isting (lass &ithout )odi/ying it. +his is possible by deriving a ne& (lass /ro) the e=isting one. +he ne& (lass &ill have the (o)bined /eatures o/ both (lasses. 0oly)orphis) : 0oly)orphis) is another i)portant (on(ept o/ oop in &hi(h one ob-e(t behaves di//erently in di//erent situation. It is i)ple)ented by one inter/a(e* )ultiple )ethod this )eans that it is possible to design a generi( inter/a(e to a group o/ related a(tivities.

Class and Objects Class is a ,unda)ental >nit o/ 9esign in 110. Class is a >serde/ined 9ata +ype &hi(h a(ts as a te)plate to (reate ob-e(ts. Class is also 'no&n as Abstra(t 9ata +ype as it i)ple)ents the Abstra(tion in 110. Class has )e)ber variables2'no&n as attributes3 and 8e)ber /un(tions2'no&n as )ethods3 &rapped together. 1b-e(ts are nothing but an instan(e o/ a (lass.All )e)bers o/ (lass e=(ept (lass )e)bers appear in the ob-e(t &hen &e (reate an ob-e(t /ro) that (lass. ,or e=a)ple ?a) is an instan(e o/ a (lass ;u)an. 5verything &hat a hu)an has or hu)an (an do @?a)A has or (an do the sa)e. 7i'e ;u)an has attributes eye*nose*hands*legs2attributes3 and ;u)an (an See*S)ell*Brite*Bal'2)ethods3. So &hen ?a) is an instan(e o/ ;u)an he &ill have everything and (an do erything &hat a ;u)an (an do. Be (an not do any thing &ith ;u)an * but &e (an deal &ith @?a)A. Si)ilarly &e have to (reate ob-e(ts /ro) a (lass then only &e &ill be able to deal &ith the ob-e(t o/ that (lass.

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

In Cava &e (an not (reate ob-e(ts /ro) so)e (lass li'e Abstra(t Class* in that (ase &e inherit another (lass /ro) that abstra(t (lass and (reate ob-e(ts /ro) it.

INTROD CTION TO !"#" "ND IT$ %N#IRON&%NT Cava is a si)ple* sa/e *1b-e(t 1riented*interpreted or dyna)i(ally opti)i<ed*byte (ode* ar(hite(ture neutral*garbage (olle(ted*)ultithreaded progra))ing language &ith a strong typed e=(eption handling )e(hanis) /or &riting distributed* dy)na)i(ally e=tensible progra)s. ;o& Cava Co)piles and Interprets Code:

Cava 0rogra)s are &ritten using any standard +e=t 5ditor. ,ile is then saved &ith an e=tension .-ava. +his /ile is 'no&n as Sour(e Code. Sour(e Code is then Co)piled &ith Cava Co)piler2-ava(3. 1n(e the /ile is (o)piled * &e get a .(lass /ile &hose na)e is sa)e as .-ava /ile. +his is 'no&n as byte (ode. Byte Code is then interpreted using a Cava Interpreter* &hi(h is an i)plantation o/ Cava Dirtual 8a(hine. Byte Code is a 0lat/or) neutral Code. So a Cava 0rogra) (an be run on any plat/or) provided the CD8 is installed in the )a(hine.

SUBRATA SINHA

F%"T R%$ OF !"#" Si)ple: +he language Synta= is based on the /a)iliar progra))ing language li'e CECFF. 1b-e(t 1riented:All /eatures o/ 1b-e(t 1riented 0rogra))ing is available * e=(ept 8ultiple Inheriten(e is not dire(tly possible in Cava* rather it is i)ple)ented through inter/a(es. Ar(hite(ture Neutral: +he Cava Co)piler generates an inter)ediate byte (ode &hi(h does not depend on any ar(hite(ture o/ a (o)puter. 0ortable +ype: +he si<e o/ data types are al&ays sa)e irrespe(tive o/ the syste) ar(hite(ture. 9istributed:CavaGs net&or'ing (apabilities are both strong and easy to use.Cava appli(ations are (apable o/ a((essing ob-e(ts a(ross the net* via >?7s as easy as a lo(al /ile syste). Se(ure:Sin(e Cava is )ostly used in net&or' environ)ent * a lot o/ e)phasis has been pla(ed on se(urity to enable (onstru(tion o/ virus /ree and ta)per /ree syste). 8ultithreaded:8ultithreading is the ability o/ one progra) to do )ore than one tas' at on(e. !a'a "pplication #s !a'a "pplet Ans : Cava progra)s (an be either applets or appli(ations. Co))on bet&een applets and appli(ations: 1. Both are (o)posed o/ /iles &ith .(lass e=tension 2. Both re4uire CD8 on the userGs syste).

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

9i//eren(es bet&een applets and appli(ations: 1. Applets (an be e)bedded in ;+87 pages and (an be vie&ed in bro&ser. 2. Appli(ations are e=e(uted /ro) (o))and line &ith boot utility* su(h as 8i(roso/tGs CDie&.e=e #. Applet (an not a((ess /ile or syste) servi(es &here as appli(ation (an. "rchitecture of !a'a +he ar(hite(ture o/ Cava is based on the /ollo&ing /our di//erent te(hnologies. 5a(h o/ these te(hnologies is de/ined by Sun 8i(rosyste)s separately: Cava progra))ing language Cava (lass /ile Cava Appli(ation 0rogra))ing Inter/a(e Cava Dirtual 8a(hine Hou &rite sour(e /iles by using the Cava progra))ing language. +hese sour(e /iles get (o)piled to (lass /iles that (ontain byte(odes. +hese (lass /iles get e=e(uted on a CD8. Hour progra) (an a((ess the syste) resour(es by invo'ing the )ethods in (lass /iles that i)ple)ent the Cava A0I. CD8 and Cava A0I put together )a'e up the Cava 0lat/or). Cava progra)s (an run on di//erent 'inds o/ (o)puters be(ause the Cava plat/or) itsel/ is i)ple)ented in the so/t&are. Cava progra)s (an e=e(ute on any (o)puter that has the Cava plat/or) i)ple)ented on it.

!a'a #irtual &achine Cava Dirtual 8a(hine is an abstra(t spe(i/i(ation that de/ines /eatures that )ust be i)ple)ented by every CD8 but leaves (ertain (hoi(es to the designers. ,or e=a)ple* all CD8s )ust e=e(ute byte(odes but they (an use

SUBRATA SINHA

any te(hni4ue to e=e(ute the). 5a(h appli(ation e=e(utes inside so)e sort o/ an i)ple)entation o/ the CD8 spe(i/i(ation. CD8 (ontains the /ollo&ing (o)ponents: +he (lass loader subsyste) +he (lass loader subsyste) loads the (lass /iles o/ your progra) and Cava A0I. Class loaders (an be o/ t&o types* pri)ordial (lass loader or (lass loader ob-e(ts. 0ri)ordial (lass loader is a part o/ the CD8 i)ple)entation that loads (lasses usually /ro) the lo(al dis'. A Cava appli(ation )ight install ne& (lass loaders to load (lasses in (usto) &ays* su(h as do&nloading (lass /iles a(ross a net&or'. ,or ea(h (lass that is loaded* CD8 'eeps tra(' o/ the loader that &as used to load the (lass /ile. Bhen the loaded (lass /ile invo'es the )ethods o/ another (lass /ile* the CD8 re4uests the re/eren(ed (lass. ,or e=a)ple* i/ a (lass na)ed 5)ployee is loaded using a loader na)ed 0ayroll7oader and i/ the 5)ployee (lass re/eren(es the 7eave (lass then* CD8 re4uests the 0ayroll7oader to load the 7eave (lass. 5a(h (lass loader that your appli(ation uses e=ists in a separate na)e"spa(e. +hus (lasses loaded by di//erent (lass loaders e=ist in di//erent na)e"spa(es and (an a((ess ea(h other only i/ the appli(ation allo&s the) to do so. 5a(h (lass loader ob-e(t (reated by an appli(ation )ust ensure that it loads (lasses only /ro) trusted pa('ages. +he (lass /ile veri/ier +he (lass /ile veri/ier (he('s the internal stru(ture o/ ea(h o/ the loaded (lass /ile to see i/ they are sa/e to be used. It does the veri/i(ation in t&o phases: Internal (he('s Sy)boli( ?e/eren(es veri/i(ation +he e=e(ution engine +he e=e(ution engine e=e(utes the byte(odes by (onverting the byte(odes into the native )a(hine (ode. +he i)ple)entation o/ the e=e(ution engine (an be di//erent on di//erent CD8s. 1ne 'ind o/ CD8 (an e=e(ute the byte(odes line by line. 1ne 'ind o/ CD8 (an (a(he the native )a(hine
/

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

(ode o/ a )ethod the /irst ti)e the )ethod is invo'ed. +he se(ond ti)e the )ethod is invo'ed the CD8 need not do the (onversion again. +his &ay it &or's /aster.

!a'a $ecurit( &odel:

Se(urity be(o)es )ore i)portant in the s(enario o/ Internet and applets be(ause* a (lient is allo&ing an e=ternal progra) to be e=e(uted on his )a(hine &hi(h has undoubted (apabilities o/ atta('ing the (lientGs )a(hine. Cava a(hieve the se(urity via a Se(urity 8odel. +his )e(hanis) is (alled @Sand Bo=A . 5very applet runs in the (onte=t o/ a sand bo=.1n the (lients (o)puter the sand bo= ensures that untrusted2and possibly )ali(ious3. Cava applets are only allo&ed a((ess to a li)ited set o/ (apabilities.

SUBRATA SINHA

In Sand Bo= 8odel* the CD8 per/or)s a series o/ level (he('s to ensure sa/e e=e(ution o/ applets on the (lientGs )a(hine. +he (lass loader*byte(ode veri/ier and the se(urity )anager &or' together to ensure that 1. 1nly the proper (lasses are loaded. 2. ea(h (lass is in proper /or)at #. >ntrusted (lasses are not allo&ed to e=e(ute dangerous instru(tions. 4. >ntrusted (lasses are not allo&ed to a((ess the syste) resour(es.

!D) and !R% Sun 8i(rosyste)s provides t&o prin(ipal so/t&are produ(ts in the Cava+8 0lat/or)* Standard 5dition 2Cava+8 S53 /a)ily: Cava S5 ?unti)e 5nviron)ent 2C?53 +he C?5 provides the libraries* Cava virtual )a(hine* and other (o)ponents ne(essary /or you to run applets and appli(ations &ritten in the Cava progra))ing language. +his runti)e environ)ent (an be redistributed &ith appli(ations to )a'e the) /ree"standing. Cava S5 9evelop)ent .it 2C9.3 +he C9. in(ludes the C?5 plus (o))and"line develop)ent tools su(h as (o)pilers and debuggers that are ne(essary or use/ul /or developing applets and appli(ations. $tandard !D) Tools and tilities Basi( +ools 2-ava(* -ava* -avado(* apt* appletvie&er* -ar* -db* -avah* -avap* e=t(he('3

11

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

Se(urity +ools 2'eytool* -arsigner* poli(ytool* 'init* 'list* 'tab3 Internationali<ation +ools 2native2as(ii3 ?e)ote 8ethod Invo(ation 2?8I3 +ools 2r)i(* r)iregistry* r)id* serialver3 Cava I97 and ?8I"II10 +ools 2tna)eserv* idl-* orbd* servertool3 Cava 9eploy)ent +ools 2pa('200* unpa('2003 Cava 0lug"in +ools 2ht)l(onverter3 Cava Beb Start +ools 2-ava&s3 Cava 8onitoring and 8anage)ent Console 2-(onsole3 Cava Beb Servi(es +ools

*"$IC TOO+$ +ool Na)e Cava( -ava Brie/ 9es(ription +he (o)piler /or the Cava progra))ing language. +he laun(her /or Cava appli(ations. In this release* a single laun(her is used both /or develop)ent and deploy)ent.. +he old deploy)ent laun(her* -re* is no longer provided. A0I do(u)entation generator. Annotation pro(essing tool. ?un and debug applets &ithout a &eb bro&ser. Create and )anage Cava Ar(hive 2CA?3 /iles.

-avado( . apt appletvie&er -ar

11

SUBRATA SINHA

-db Cavah )ethods. Cavap 5=t(he('

+he Cava 9ebugger. C header and stub generator. >sed to &rite native Class /ile disasse)bler >tility to dete(t Car (on/li(ts.

S5C>?I+H +117S +hese se(urity tools help you set se(urity poli(ies on your syste) and (reate apps that (an &or' &ithin the s(ope o/ se(urity poli(ies set at re)ote sites. Tool Name .eytool Carsigner 0oli(ytool Brief Description 8anage 'eystores and (erti/i(ates. 6enerate and veri/y CA? signatures. 6>I tool /or )anaging poli(y /iles.

1#

Chapter ,
JAVA AN!UA!" BASICS

"nal(-ing the main./ method 0ith its signature 8ain )ethod should al&ays be used as /ollo&s : publi( stati( void )ain2 String sIJ 3 +he )ain23 )ethod should be Kpubli(G be(ause the CD8 has to a((ess it. +he )ain23 )ethod should be stati( be(ause * it should be e=e(uted even be/ore an instan(e o/ the (lass is available*&hi(h )eans to say that the )ain23 )ethod should be a (lass )ethod and not an instan(e )ethod. 8ain23 )ethod is (alled by the CD8 and there in not anything &hi(h the CD8 e=pe(ts in return /or (alling the )ain )ethod. ;en(e you need to de(lare the return value to be void. ,inally the para)eters &hi(h the )ain )ethod a((epts is an array o/ String values.+he CD8 uses this array to store any (o))and line para)eters* &hi(h are given at the ti)e o/ e=e(ution o/ the progra). !a'a +anguage To1ens +here are ,ive types o/ +o'ens:.ey&ords* identi/iers* literals* separators and operators. "2 )e(0ords:: .ey&ords are available abstra(t (ase (lass do /inal /uture boolean (ast (onst double /inally generi( brea' (at(h (ontinue else /loat goto byte (har de/ault e=tends /or i/

1%

SUBRATA SINHA

i)ple)ents int ne& pa('age rest super thro& var

i)port inter/a(e null private return s&it(h thro&s void

inner instan(eo/ long native operator outer prote(ted publi( short stati( syn(hroni<ed this transient try volatile &hile

*2 Identifier : Na)es /or (lasses*ob-e(ts*variables*(onstants* labels*)ethods. Identi/ier is (hoosen by 0rogra))er ?ules /or na)ing identi/ier Start &ith letter or unders(ore or dollar sign but not &ith digit. >se upto 2:: Chara(ters 9onGt >se .ey&ords

7egal identi/ier Na)e: 9ealer1* (ounter* =*;otCavaL*dealerMid*se4M1*se41* +otalBudget1/Cune200% Illegal identi/ier Na)e: 19ealer*9ealerNid*9ealer id* dealer"id* 2#4 C2 +iterals :>sed /or entering e=pli(it values /or variables or (onstants. +hese )ay be nu)eri(*Boolean* (hara(ter or string. @;ello BorldA * * 2:$7 * #.4, D2 $eparators : 0arentheses Bra(es 23 OP
1(

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

Ba('ets Se)i(olon Co))a 0eriod %2 Operators

IJ Q * .

Arith)eti( 1perators : F * " * R * E * S Arith)rti( Assign)ent 1perators :FT * RT * "T * ET * ST In(re)entE9e(re)ent 1perator:FF*"" Bit&ise Arith)eti( 1perator: N * U * V * W Co)parison 1perators : T T * XT*Y * Z * YT * ZT 7ogi(al Co)parison 1perators : NN * UU * X

!a'a Data T(pes Cava has eight pri)itive data types byte int /loat 1 byte 4 bytes 4 bytes short long double (har 2 bytes % bytes % bytes 2 bytes

boolean 1 byte

"rra(s $ingle Dimensional "rra(

1)

SUBRATA SINHA

Arrays in Cava (an be de(lared in t&o /or)s ,or) 1 : type arrayna)eIJQ ,or) 2: type IJ arrayna)eQ 5=a)ples : int aIJQ intIJ aQ Initiali<ation o/ Single 9i)ensional Array: int aIJTO11*#2*44*::*##PQ So although si<e is not spe(i/ied* but a/ter initiali<ation the si<e o/ array &ill be :.

EE0rogra) to use array : A((ept 10 nu)bers and display the sa)e i)port -ava.util.RQ (lass +estArray O publi( stati( void )ain2String sIJ3 O int aIJTne& intI10JQ S(anner s(Tne& S(anner2Syste).in3Q

1*

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

Syste).out.println2[5nter the nu)bers[3Q /or2int iT0QiY10QiFF3 O aIiJTs(.ne=tInt23Q P Syste).out.println2[Hou have entered: [3Q /or2int iT0QiY10QiFF3 O Syste).out.println2aIiJ3Q P P P

Array 7ength: In -ava all arrays store the allo(ated si<e in a variable na)e length*Be (an obtain the length o/ the array a using a.length. int asi<eTa.lengthQ

T0o Dimensional "rra(: Be )ay (reate t&o di)ensional array as /ollo&s int aI JI JTne& intI#JI4JQ 9ouble di)ensional array (an also be initiali<ed as single di)ensional array as /ollo&s:

1,

SUBRATA SINHA

int aI2JI#JTO0*0*0*1*1*1P 1? as int aI JI JTOO0*0*0P*O1*1*1PPQ 1? as int aI JI JTO O0* 0* 0P O1* 1* 1P PQ

5=a)ple :0rogra) to use double di)ensional array i)port -ava.util.RQ (lass +est9oubleArray O publi( stati( void )ain2String sIJ3 O int aI JI JTne& intI#JI#JQ int bI JI JTne& intI#JI#JQ int (I JI JTne& intI#JI#JQ S(anner s(Tne& S(anner2Syste).in3Q Syste).out.println2[5nter the ele)ents o/ ,irst #=# )atri=[3Q /or2int iT0QiY#QiFF3 O

1/

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

/or2int -T0Q-Y#Q-FF3 O aI i JI - JTs(.ne=tInt23Q P P Syste).out.println2[+he 8atri= is as /ollo&s:[3Q /or2int iT0QiY#QiFF3 O /or2int -T0Q-Y#Q-FF3 O Syste).out.print2aIiJI-JF[ [3Q P Syste).out.println23Q P P P

\. Bhat are ,lo& Controls in Cava ]

A. Conditional : i/"else * s&it(h"(ase 7ooping : &hile * do * /or 5=(eption : try*(at(h*/inally

10

SUBRATA SINHA

Chapter 3
INTRODUCIN! C ASS"S

Declare Classes Class is de(lared &ith 'ey&ord (lass. +he synta= o/ &hi(h is given belo&Q (lass Y(lassna)eZ O A((ess"Spe(i/ier 9atatype Yattributena)eZQ A((ess"spe(i/ier ?eturn"type )ethodna)e2para)eter list3 O State)entsQ

#1

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

P P "dding and "ccessing &ethods 4Properties 8ethod (an be added as sho&n above. A((essing )ethods a3 Stati( )ethods (an be a((essed through (lass na)e* using (lassna)eYdotZ)ethodna)e 5=a)ple: Integer.parseInt23Q b3 Non stati( )ethods are a((essed by the ob-e(t o/ the (lass * using ob-e(tna)eYdotZ)ethodna)eQ 5=a)ple: S(anner s(Tne& S(anner2Syste).in3 int =Ts(.ne=tInt23Q 0roperties or attributes (an be a((essed in the sa)e &ay as )ethods are a((essed.

(lass +estAttribute O stati( int aQ int bQ +estAttribute23 O aT:Q bT Q P publi( stati( void )ain2String sIJ3 O +estAttribute ob-Tne& +estAttribute23Q

#1

SUBRATA SINHA

Syste).out.println2[Dalue o/ a[F+estAttribute.a3Q EEbut stati( a (an be a((essed by (lassna)e or ob-e(t na)e Syste).out.println2[Dalue o/ a[F+estAttribute.a3Q EEbut stati( a (an be a((essed by (lassna)e or ob-e(t na)e Syste).out.println2[Dalue o/ b[F ob-.b3Q EE non stati( b (an not be a((essed by (lass na)e P P PR%DICT T5% R%"$ON 657 T5% COD% *%+O6 8I#%$ $ C5 O TP T (lass +estAttribute O stati( int aQ int bQ +estAttribute2int =*int y3 O aT=Q bTyQ P publi( stati( void )ain2String sIJ3 O +estAttribute ob-1Tne& +estAttribute2:*$3Q +estAttribute ob-2Tne& +estAttribute2!*103Q Syste).out.println2[Dalue o/ a: [Fob-1.a3Q Syste).out.println2[Dalue o/ b: [F ob-1.b3Q Syste).out.println2[Dalue o/ a: [Fob-2.a3Q Syste).out.println2[Dalue o/ b: [F ob-2.b3Q P P 1utput: Dalue o/ a: Dalue o/ b: Dalue o/ a: Dalue o/ b:

! $ ! 10

Reason is static attributes is common for all objects of the class, thats why it is also known as class variables

##

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

Non static attributes is known as object variables or instance variables. \. Stati( Ds Non stati( 8e)bers Ans: S+A+IC 858B5?SEC7ASS N1N S+A+IC 858B5?S 858B5?SEINS+ANC5 858B5?S +hese )e)bers are asso(iated &ith (lass itsel/ rather than individual ob-e(ts*stati( variables and stati( )ethods are also re/erred as (lass variable and (lass )ethods 12 $tatic #ariables +hese are asso(iated &ith individual ob-e(ts they are re/erred as instan(e variable and instan(e )ethods.

#ariables4Class 12 Non $tatic #ariables4Instance #ariables Non stati( variables also 'no&n as instan(e variables are used in (on-un(tion &ith instan(e2ob-e(ts3 o/ a (lass.5very ti)e the (lass is instantiated a ne& (opy o/ Instan(e variables are (reated.

Stati( variables are used &hen &e &ant to have a variable (o))on to all instan(es o/ a (lass.8ost (o))on e=a)ple is to have a variable that (ould 'eep a (ount o/ ho& )any ob-e(ts o/ a (lass have been (reated. Cava (reates only one (opy /or a stati( variable* &hi(h (an be used even i/ the (lass is never a(tually instantiated.

,2 $tatic &ethods

&ethods4Class ,2 Non $tatic methods4Instance methods Non stati( )ethods also 'no&n as instan(e )ethods are used in (on-un(tion &ith instan(e2ob-e(ts3 o/ a (lass.

7i'e stati( variables stati( )ethods (an also be (alled &ithout using ob-e(ts.+hey are also available /or use by other (lasses.8ethods that are o/

#%

SUBRATA SINHA

general utility but do not dire(tly a//e(t an instan(e o/ that (lass are usually de(lared as (lass )ethods. Stati( )ethods has so)e restri(tions a3 +hey (an only (all other stati( )ethods b3+hey (an only a((ess stati( data. (3+hey (an not re/er to this or super in any &ay. 5=a)ple : Integre.parseInt23

Constructor Constru(tors are used to assign initial values to instan(e variables o/ the (lass. A de/ault (onstru(tor &ith no argu)ents &ill be (alled auto)ati(ally by the Cava Dirtual 8a(hine 2CD83. Constru(tor is al&ays (alled by ne&

#(

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

operator. Constru(tor are de(lared -ust li'e as &e de(lare )ethods* e=(ept that the (onstru(tor don^t have any return type. Ex-1. Design a class for Dealer. Dealer has dealarId,DealerName,dealerAddress. Initiali e the constructor and !rite a method to displa" the details. attributes like attributes in

(lass 9ealer O private String dealerI9Q private String dealerNa)eQ private String dealerAddressQ publi( 9ealer23 O dealerI9T[9I9001[Q dealerNa)eT[Carol[Q dealerAddressT[21 ?o(' St.* NH* : 41$[Q P publi( void display9etails23 O Syste).out.println2[9ealer I9 is [FdealerI93Q Syste).out.println2[9ealer na)e is [FdealerNa)e3Q Syste).out.println2[9ealer address is [FdealerAddress3Q P publi( stati( void )ain2String argsIJ3 O 9ealer dealer1b-Tne& 9ealer23Q dealer1b-.display9etails23Q P P Instead o/ (alling the (onstru(tor &ith the (lass na)e* use the 'ey&ord this. +he (o)piler )at(hes [this[ &ith a (onstru(tor &ith the appropriate nu)ber and types o/ para)eters* and (alls it.

publi( (lass +i)e1/9ay1d O publi( int hourQ publi( int )inuteQ

#)

SUBRATA SINHA

publi( +i)e1/9ay1d2int h* int )3 O hour T hQ )inute T )Q P publi( +i)e1/9ay1d2int h3 O this2h* 03Q P P Passing parameters in Constructor Ex-# Design the same class so as to pass the data of dealer through main and in constructor (lass 9ealer O private String dealerI9Q private String dealerNa)eQ private String dealerAddressQ publi( 9ealer2String id*String na)e*String address3 O dealerI9TidQ dealerNa)eTna)eQ dealerAddressTaddressQ P publi( void display9etails23 O Syste).out.println2[9ealer I9 is [FdealerI93Q Syste).out.println2[9ealer na)e is [FdealerNa)e3Q Syste).out.println2[9ealer address is [FdealerAddress3Q P publi( stati( void )ain2String argsIJ3 O 9ealer dealer1b-Tne& 9ealer2[9001[*[Su-ay[*[8ar&ary 0atty[3Q

#*

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

dealer1b-.display9etails23Q P P Constructor o'erloading Constru(tor (an be overloaded provided they should have di//erent argu)ents be(ause CD8 di//erentiates (onstru(tors on the basis o/ argu)ents passed in the (onstru(tor. publi( (lass +i)e1/9ay1( O publi( int hourQ publi( int )inuteQ publi( +i)e1/9ay1(2int h* int )3 O hour T hQ )inute T )Q P publi( +i)e1/9ay1(2int h3 O hour T hQ )inute T 0Q P P

5="# 9esign the sa)e (lass so that >ser (an enter the re(ord /or 9ealer 2>sing Co))and 7ine Argu)ent3

#,

SUBRATA SINHA

(lass 9ealer O private String dealerI9Q private String dealerNa)eQ private String dealerAddressQ publi( 9ealer2String id*String na)e*String address3 EE 0ara)eteri<ed (onstru(tor O dealerI9TidQ dealerNa)eTna)eQ dealerAddressTaddressQ P publi( void display9etails23 O Syste).out.println2[9ealer I9 is [FdealerI93Q Syste).out.println2[9ealer na)e is [FdealerNa)e3Q Syste).out.println2[9ealer address is [FdealerAddress3Q P publi( stati( void )ain2String argsIJ3 O 9ealer dealer1b-Tne& 9ealer2argsI0J*argsI1J*argsI2J3Q dealer1b-.display9etails23Q P P

Ex-$ Design the same class so that %ser can enter the record for Dealer &!ithout %sing 'ommand (ine Argument) i)port -ava.io.RQ (lass 9ealer O private String dealerI9Q private String dealerNa)eQ private String dealerAddressQ publi( 9ealer2String id*String na)e*String address3

#/

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

O dealerI9TidQ dealerNa)eTna)eQ dealerAddressTaddressQ P publi( void display9etails23 O Syste).out.println2[9ealer I9 is [FdealerI93Q Syste).out.println2[9ealer na)e is [FdealerNa)e3Q Syste).out.println2[9ealer address is [FdealerAddress3Q P publi( stati( void )ain2String argsIJ3 O Bu//ered?eader brTne& Bu//ered?eader2ne& InputStrea)?eader2Syste).in33Q String =T[ [*yT[ [*<T[ [Q try O
Syste).out.println2[5nter the 9ealer Id: [3Q =Tbr.read7ine23Q Syste).out.println2[5nter the 9ealer Na)e : [3Q yTbr.read7ine23Q Syste).out.println2[5nter the 9ealer Address :[3Q

<Tbr.read7ine23Q P (at(h25=(eption e3OP 9ealer dealer1b-Tne& 9ealer2=*y*<3Q dealer1b-.display9etails23Q P

#0

SUBRATA SINHA

Ex * %sing +canner 'lass to ,ead Data -rom .e" /oard&0uch Easier than %sing Input+tream,eader 'lass) i)port -ava.util.RQ (lass ?ead9ata O publi( stati( void )ain2String sIJ3 O S(anner s(Tne& S(anner2Syste).in3Q int ?ollNoQ String Na)eQ /loat 8ar'sQ Syste).out.println2[5nter a ?oll No[3Q ?ollNoTs(.ne=tInt23Q Syste).out.println2[5nter a Na)e[3Q Na)eTs(.ne=t23Q Syste).out.println2[5nter the 8ar's[3Q 8ar'sTs(.ne=t,loat23Q Syste).out.println2[?oll No : [F?ollNo3Q Syste).out.println2[Na)e : [FNa)e3Q Syste).out.println2[8ar's : [F8ar's3Q P P Ex 1 Design the Dealer 'lass, ,ead Data %sing +canner 'lass i)port -ava.util.RQ (lass 9ealer O private String dealerI9Q private String dealerNa)eQ private String dealerAddressQ publi( 9ealer2String id*String na)e*String address3 O dealerI9TidQ

%1

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

dealerNa)eTna)eQ dealerAddressTaddressQ P publi( void display9etails23 O Syste).out.println2[9ealer I9 is [FdealerI93Q Syste).out.println2[9ealer na)e is [FdealerNa)e3Q Syste).out.println2[9ealer address is [FdealerAddress3Q P publi( stati( void )ain2String argsI J3 O S(anner s(Tne& S(anner2Syste).in3Q String =T[[*yT[[*<T[[Q Syste).out.println2[5nter the 9ealer Id : [3Q =Ts(.ne=t7ine23Q Syste).out.println2[5nter the 9ealer Na)e : [3Q yTs(.ne=t7ine23Q Syste).out.println2[5nter the 9ealer Address :[3Q <Ts(.ne=t7ine23Q 9ealer dealer1b-Tne& 9ealer2=*y*<3Q dealer1b-.display9etails23Q P P

%1

( INHERITENCE

Inheritan(e lets you (reate a ne& (lass based on an e=isting (lass. +hen the ne& (lass inherits the /ields* (onstru(tors and )ethods o/ the e=isting (lass. A (lass that inherits /ro) an e=isting (lass is (alled a derived (lass* (hild (lass or sub(lass. A (lass that another (lass inherits is (alled base (lass* parent (lass or super (lass. A sub (lass (an override a )ethod /ro) the super (lass &ith its o&n version o/ the )ethod. Inheritan(e )ay ta'e di//erent /or)s: 1. Single inheritan(e2only one super (lass3 2. 8ultiple inheritan(e2several super (lasses3 I)ple)ented &ith inter/a(e #. ;ierar(hi(al inheritan(e2one super (lass* )any sub(lasses3 4. 8ulti level inheritan(e29erived /ro) a derived (lass3 %9ample: $ingle Inheritence i)port -ava.util.RQ (lass 0rodu(t O /loat pri(eQ void a((ept23 O S(anner s(Tne& S(anner2Syste).in3Q Syste).out.println2[5nter the pri(e:[3Q pri(eTs(.ne=t,loat23Q P void display() { System.out.println("Price:"+price); } }

%#

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

(lass Boo' e=tends 0rodu(t O String +itleQ void a((ept+itle23 O S(anner s(Tne& S(anner2Syste).in3Q Syste).out.println2[5nter the title:[3Q +itleTs(.ne=t7ine23Q P void display+itle23 O Syste).out.println2[+itle:[F+itle3Q P P (lass Boo'+est O publi( stati( void )ain2String sIJ3 O Boo' bTne& Boo'23Q b.a((ept23Q EE (alling a((ept23 &hi(h is a(tually inherited /ro) produ(t b.a((ept+itle23Q b.display23Q EE (alling display23 &hi(h is a(tually inherited /ro) produ(t b.display+itle23Q P P Teacher : Bhat happens &hen &e de/ine a )ethod in sub (lass &ith sa)e na)e as in super (lass ]

%%

SUBRATA SINHA

$tudent: 8ethod &hi(h is inherited /ro) super (lass &ill be over ridden by the sub (lass )ethod. i)port -ava.util.RQ (lass 0rodu(t O /loat pri(eQ void a((ept23 O S(anner s(Tne& S(anner2Syste).in3Q Syste).out.println2[5nter the pri(e:[3Q pri(eTs(.ne=t,loat23Q P void display23 O Syste).out.println2[0ri(e:[Fpri(e3Q P P (lass Boo' e=tends 0rodu(t O String +itleQ void a((ept23 O S(anner s(Tne& S(anner2Syste).in3Q Syste).out.println2[5nter the title:[3Q +itleTs(.ne=t7ine23Q P void display23 O Syste).out.println2[+itle:[F+itle3Q P P (lass Boo'+est O publi( stati( void )ain2String sIJ3 O Boo' bTne& Boo'23Q b.a((ept23Q b.display23Q

%(

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

P P Teacher : +he output sho&s only +itle o/ Boo' 2a((ept and display3 $tudent : 1h no___ I never &anted that XXXXXXX I &anted to get the (odes o/ parent (lass )ethods e=e(uted even a/ter overriding Teacher : +hen you (an use super

sing super 1. >sing super to (all super (lass (onstru(tor A sub(lass (onstru(tor (an (all the super (lass (onstru(tor by (alling super2para)eter list3Q 2. +he se(ond /or) o/ super a(ts so)e &hat li'e this * e=(ept that it al&ays re/ers to the super (lass o/ the sub (lass in &hi(h it is used. +his usage has the /ollo&ing general /or): super.)e)ber ;ere* )e)ber (an be a )ethod or a attribute

i)port -ava.util.RQ (lass 0rodu(t O /loat pri(eQ void a((ept23 O S(anner s(Tne& S(anner2Syste).in3Q Syste).out.println2[5nter the pri(e:[3Q pri(eTs(.ne=t,loat23Q P void display23 O

%)

SUBRATA SINHA

Syste).out.println2[0ri(e:[Fpri(e3Q P P (lass Boo' e=tends 0rodu(t O String +itleQ void a((ept23 O super.a((ept23Q S(anner s(Tne& S(anner2Syste).in3Q Syste).out.println2[5nter the title:[3Q +itleTs(.ne=t7ine23Q P void display23 O super.display23Q Syste).out.println2[+itle:[F+itle3Q P P (lass Boo'+est O publi( stati( void )ain2String sIJ3 O Boo' bTne& Boo'23Q b.a((ept23Q b.display23Q P P Teacher : Are you getting the super (lass )ethods e=e(uted] $tudent : Hes * I a) getting. But do I have to &rite al&ays super &hen I over&rite a )ethod] Teacher : No* 1nly &hen you &ant super (lass )ethods should e=e(ute /ro) sub (lass )ethod.

%*

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

%9ample of 5ierarchial Inheritence Consider a 0rodu(t (lass is already e=isting and you need to (reate a Boo' (lass and a So/t&are Class /ro) it.2;ierar(hi(al Inheritan(e3 (lass 0rodu(t O double pri(eQ void set0ri(e2double =3 O pri(eT=Q P void get0ri(e23 O return pri(eQ P P No& the Boo' (lass and So/t&are (lass need to be designed* Both the (lass is a &ill need the /eatures o/ 0rodu(t (lass. So in both these (lass &e donGt have to again de(lare pri(e attribute and set0ri(e23 and get0ri(e23 )ethod. Be )ust inherit these /ro) the produ(t (lass* as /ollo&s (lass Boo' e=tends 0rodu(t O String AuthorQ void setAuthor2String <3 O AuthorT<Q P String getAuthor23 O return AuthorQ P P (lass So/t&are e=tends 0rodu(t O String DersionNoQ void setDersionNo2String y3 O DersionNoTyQ P String getDersionNo23 O return DersionNoQ P P

%,

SUBRATA SINHA

7et us no& use these sub (lass (lass +est O publi( stati( void )ain2String aIJ3 O Boo' bTne& Boo'23Q b.set0ri(e22003Q b.setAuthor2@Balagurus&a)yA3Q Syste).out.println2@Boo' 0ri(e isA F b.get0ri(e233Q Syste).out.println2@Boo' Author isA F b.getAuthor233Q So/t&are s Tne& So/t&are23Q s.set0ri(e2:0003Q s.setDersionNo2@C9.1. A3Q Syste).out.println2@So/t&are 0ri(e isA F s.get0ri(e233Q Syste).out.println2@So/t&are Dersion isA F s.getDersionNo233Q P P

%/

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

"bstract Classes An abstra(t (lass is a (lass that (an be inherited by other (lasses but that you (anGt use to (reate an ob-e(t. +o de(lare an abstra(t (lass* (ode the abstra(t 'ey&ord in the (lass de(laration. An abstra(t (lass (an (ontain /ields* (onstru(tors and )ethods -ust li'e other super (lasses. In addition * an abstra(t (lass (an (ontain abstra(t )ethods. +o (reate an abstra(t )ethod * you (ode the abstra(t 'ey&ord in the )ethod de(laration and you o)it the )ethod body. Abstra(t )ethods (an not have private a((ess. ;o&ever* they )ay have prote(ted or de/ault2no a((ess )odi/ier3.Bhen a sub(lass inherits an abstra(t (lass* all abstra(t )ethods in the abstra(t (lass )ust be overridden in the sub(lass. An abstra(t (lass doesnGt have to (ontain abstra(t )ethods. ;o&ever *any (lass that (ontain an abstra(t )ethod )ust be de(lared as abstra(t.
abstract class Product { abstract void display();
// an abstract method dont have any method body its upto subclass to de!ine the body

void !n() { System.out.println(""ello #orld"); } } public class $oo% extends Product { // sub class must implement the abstract method(override abstract method) void display() { System.out.println("$oo% de!ined abstract method o! Product"); } public static void main(Strin& s'() { $oo% b)ne* $oo%(); b.!n(); b.display();

%0

SUBRATA SINHA

} }

Final Classes +o prevent a (lass /ro) being inherited* you (an (reate a /inal (lass by (oding the /inal 'ey&ord in the (lass de(laration.+o prevent sub(lasses /ro) being overriding a )ethod o/ a super (lass* you (an (reate a /inal )ethod by (oding the /inal 'ey&ord in the )ethod de(laration.In addition all )ethods in a /inal (lass are auto)ati(ally /inal )ethods. a3 ,inal Class (an not be e=tended b3 ,inal )ethods (an not be overridden Test yourself and see the error: i/ final class inheritence /inal (lass ABCO P (lass 95, e=tends ABC OP Output: +rror: cannot inherit !rom !inal ,$ii) final method overriding (lass ABC O /inal void /n23 O Syste).out.println2[;ello[3Q P P (lass 95, e=tends ABC O

(1

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

void /n23 O Syste).out.println2[;i[3Q P P Output: 5rror: /n23 in 95, (an not override /n23 in ABCQoverridden )ethod is /inal "bstract #s Final A3 Abstra(t (lass (an only be inherited but (an not be instantiated* But ,inal (lass (an not be inherited but (an be instantiated. B3 Abstra(t )ethods )ust be overridden but /inal )ethod (an not be over ridden C3 /inal variables (an not be )odi/ied.It )ust be initiali<ed on de(laration. Nor)ally de(lared as /inal /loat 0IMDA7>5T#.14Q 9e(lared in (apital letters. Abstra(t variable do not e=ist.

(1

SUBRATA SINHA

CHA"TER ) "O9=-OR"HIS0oly)orphis) is the (apability o/ an a(tion or )ethod to do di//erent things based on the ob-e(t that it is a(ting upon. +his is the third basi( prin(iple o/ ob-e(t oriented progra))ing. 1verloading* overriding and dyna)i( )ethod binding are three types o/ poly)orphis). 1verloaded )ethods are )ethods &ith the sa)e na)e signature but either a di//erent nu)ber o/ para)eters or di//erent types in the para)eter list. %9: Design a class sho0ing method o'erloading2 (lass 8ath O int add2int a*int b3 O int <Q <TaFbQ return <Q P double add2double a*double b3 O double <Q <TaFbQ return <Q P publi( stati( void )ain2String sIJ3 O 8ath ob-Tne& 8ath23Q Syste).out.println2[Su) o/ +&o integers is[Fob-.add2:*$33Q Syste).out.println2[Su) o/ +&o /loat is[Fob-.add2:.:*$.$33Q P P

(#

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

5=" 9esign a (lass sho&ing (onstru(tor overloading. (lass Const1ver O Const1ver2int =*int y3 O Syste).out.println2[,rist Integer :[F=3Q Syste).out.println2[Se(ond Integer :[Fy3Q P Const1ver2String &*String <3 O Syste).out.println2[,rist String: [F&3Q Syste).out.println2[Se(ond String: [F<3Q P publi( stati( void )ain2String sI J3 O Const1ver ob-1Tne& Const1ver2#*:3Q Const1ver ob-2Tne& Const1ver2[Subrata[*[Sinha[3Q P P 1verridden )ethods are )ethods that are rede/ined &ithin an inherited or sub(lass. +hey have the sa)e signature and the sub(lass de/inition is used. ZZZZ9is(ussed in previous se(tion 9yna)i( 2or late3 )ethod binding is the ability o/ a progra) to resolve re/eren(es to sub(lass )ethods at runti)e. As an e=a)ple assu)e that three sub(lasses 2Co&* 9og and Sna'e3 have been (reated based on the Ani)al abstra(t (lass* ea(h having their o&n spea'23 )ethod. Although ea(h )ethod re/eren(e is to an Ani)al 2but no ani)al ob-e(ts e=ist3* the progra) is &ill resolve the (orre(t )ethod re/eren(e at runti)e. 7et^s ta'e a loo' at the /ollo&ing e=a)ple:

(%

SUBRATA SINHA

(lass Ani)al O void &hoA)I23 O Syste).out.println2[I a) a generi( Ani)al.[3Q P P (lass 9og e=tends Ani)al O void &hoA)I23 O Syste).out.println2[I a) a 9og.[3Q P P (lass Co& e=tends Ani)al O void &hoA)I23 O Syste).out.println2[I a) a Co&.[3Q P P (lass Sna'e e=tends Ani)al O void &hoA)I23 O Syste).out.println2[I a) a Sna'e.[3Q P P (lass ?unti)e0oly)orphis)9e)o O publi( stati( void )ain2StringI J args3 O Ani)al re/1 T ne& Ani)al23Q Ani)al re/2 T ne& 9og23Q Ani)al re/# T ne& Co&23Q Ani)al re/4 T ne& Sna'e23Q re/1.&hoA)I23Q re/2.&hoA)I23Q re/#.&hoA)I23Q re/4.&hoA)I23Q P P +he output is I a) a generi( Ani)al. I a) a 9og. I a) a Co&. I a) a Sna'e.

((

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

In the e=a)ple* there are /our variables o/ type Ani)al 2e.g.* re/1* re/2* re/#* and re/43. 1nlyre/1 re/ers to an instan(e o/ Ani)al (lass* all others re/er to an instan(e o/ the sub(lasses o/Ani)al. ,ro) the output results* you (an (on/ir) that version o/ a )ethod is invo'ed based on the a(tually ob-e(t^s type. In Cava* a variable de(lared type o/ (lass A (an hold a re/eren(e to an ob-e(t o/ (lass A or an ob-e(t belonging to any sub(lasses o/ (lass A. +he progra) is able to resolve the (orre(t )ethod related to the sub(lass ob-e(t at runti)e. +his is (alled the runti)e poly)orphis) in Cava. +his provides the ability to override /un(tionality already available in the (lass hierar(hy tree. At runti)e* &hi(h version o/ the )ethod &ill be invo'ed is based on the type o/ a(tual ob-e(t stored in that re/eren(e variable and not on the type o/ the re/eren(e variable. Creating Your Own Pac age pac%a&e .yPac%a&e; public class .y.ath { protected int s/uare(int a) { return a0a; } } Steps: 1. -reate a sub directory .yPac%a&e in your home directory. 2. Save the !ile .y.ath.3ava in your .yPac%a&e subdirectory. 4. -ompile your .y.ath.3ava and veri!y your .class !ile is there in .yPac%a&e subdirectory or not. 5o* &o bac% to home directory and try to use your o*n pac%a&e. !nheriting from your own pac age import .yPac%a&e.0; class 6our.ath e7tends .y.ath { public static void main(Strin& s'() { 6our.ath ym)ne* 6our.ath(); System.out.println(ym.s/uare(8)); }
()

SUBRATA SINHA

"ccess #pecifiers : 5n(apsulation lin's data &ith the (ode that )anipulates it. ;o&ever en(apsulation provides another i)portant attribute: a((ess (ontrol. +hrough en(apsulation you (an (ontrol &hat parts o/ a progra) (an a((ess the )e)bers o/ a (lass. ;o& aa )e)bers (an be a((essed is deter)ined by the a((ess spe(i/ier. CavaGs a((essspe(i/ier are publi(*private and prote(ted. Cava also de/ines a de/ault a((ess level. 0ubli( : A variable or )ethod de(lared as publi( has the &idest possible visibility and a((essible every&here. 9e/ault : is not a((essible in both sub (lass or non sub(lass in other pa('age. But de/ault (an be a((essed /ro) the sub (lass or non sub(lass o/ sa)e pa('age. 0rote(ted: A((essible every &here e=(ept non sub(lass o/ other pa('age. 0rivate prote(ted : 1nly in the sa)e (lass or sub (lass in sa)e pa('age. 0rivate: 1nly in the sa)e (lass.
Same class S,.+ P,-9,:+ Sub class in same pac%a&e 5on sub class in same pac%a&e 6es 6es 6es ;<"+= P,-9,:+ Sub class in other pac%a&e 5on sub class in other pac%a&e 6es 5o 5o

Public Protected >e!ault !riendly or

6es 6es 6es

6es 6es 6es

6es Yes 5o

(*

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7 Private Protected Private 6es 6es 5o 6es 5o

6es

5o

5o

5o

5o

5$:

P=;<+-<+> .+.$+= ,--+SS+?$?@?<6 ",S ,@=+,>6 $++5 <+S<+> ?5 P=+A?;BS +C,.P@+ ;D P,-9,:+

CHA"TER * E>CE"TION HAND9IN:


An exception is an event* &hi(h o((urs during the e=e(ution o/ a progra)* that disrupts the nor)al /lo& o/ the progra)^s instru(tions. Bhen an error o((urs &ithin a )ethod* the )ethod (reates an ob-e(t and hands it o// to the runti)e syste). +he ob-e(t* (alled an exception ob2ect* (ontains in/or)ation about the error* in(luding its type and the state o/ the progra) &hen the error o((urred. Creating an e=(eption ob-e(t and handing it to the runti)e syste) is (alled thro!ing an exception. A progra) (an use e=(eptions to indi(ate that an error o((urred. +o thro& an e=(eption* use the thro& state)ent and provide it &ith an e=(eption ob-e(t ` a des(endant o/ +hro&able ` to provide in/or)ation about the spe(i/i( error that o((urred. A )ethod that thro&s an un(aught* (he('ed e=(eption )ust in(lude a thro&s (lause in its de(laration. Thro0able Class and Its $ubclasses +he ob-e(ts that inherit /ro) the +hro&able (lass in(lude dire(t des(endants 2ob-e(ts that inherit dire(tly /ro) the +hro&able (lass3 and indire(t des(endants 2ob-e(ts that inherit /ro) (hildren or grand(hildren o/ the +hro&able (lass3. +he /igure belo& illustrates the (lass hierar(hy o/ the +hro&able (lass and its )ost signi/i(ant sub(lasses. As you (an see* +hro&able has t&o dire(t des(endants: 5rror and 5=(eption.

(,

SUBRATA SINHA

%rror Class Bhen a dyna)i( lin'ing /ailure or other hard /ailure in the Cava virtual )a(hine o((urs* the virtual )a(hine thro&s an 5rror. Si)ple progra)s typi(ally do not(at(h or thro& 5rrors. %9ception Class 8ost progra)s thro& and (at(h ob-e(ts that derive /ro) the 5=(eption (lass. An 5=(eption indi(ates that a proble) o((urred* but it is not a serious syste) proble). 8ost progra)s you &rite &ill thro& and (at(h 5=(eptions as opposed to 5rrors. +he Cava plat/or) de/ines the )any des(endants o/ the 5=(eption (lass. +hese des(endants indi(ate various types o/ e=(eptions that (an o((ur. ,or e=a)ple*IllegalA((ess5=(eption signals that a parti(ular )ethod (ould not be /ound* and NegativeArraySi<e5=(eption indi(ates that a progra) atte)pted to (reate an array &ith a negative si<e. 1ne 5=(eption sub(lass* ?unti)e5=(eption* is reserved /or e=(eptions that indi(ate in(orre(t use o/ an A0I. An e=a)ple o/ a runti)e e=(eption isNull0ointer5=(eption* &hi(h o((urs &hen a )ethod tries to a((ess a )e)ber o/ an ob-e(t through a null re/eren(e. A progra) (an (at(h e=(eptions by using a (o)bination o/ the try* (at(h* and /inally blo('s. +he tr( bloc1 identi/ies a blo(' o/ (ode in &hi(h an e=(eption (an o((ur. +he catch bloc1 identi/ies a blo(' o/ (ode* 'no&n as an e=(eption handler* that (an handle a parti(ular type o/ e=(eption.

(/

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

+he finall( bloc1 identi/ies a blo(' o/ (ode that is guaranteed to e=e(ute* and is the right pla(e to (lose /iles* re(over resour(es* and other&ise (lean up a/ter the (ode en(losed in the try blo('. +he try state)ent should (ontain at least one (at(h blo(' or a /inally blo(' and )ay have )ultiple (at(h blo('s. +he (lass o/ the e=(eption ob-e(t indi(ates the type o/ e=(eption thro&n. +he e=(eption ob-e(t (an (ontain /urther in/or)ation about the error* in(luding an error )essage. Bith e=(eption (haining* an e=(eption (an point to the e=(eption that (aused it* &hi(h (an in turn point to the e=(eption that (aused it* and so on.

i)port -ava.util.RQ (lass +estArith5=(eption O publi( stati( void )ain2String aaIJ3 O int a*b*(Q S(anner s(Tne& S(anner2Syste).in3Q Syste).out.println2[5nter the value o/ a[3Q aTs(.ne=tInt23Q bTs(.ne=tInt23Q try O (TaEbQ
EE this state)ent )ay raise Arith)eti(5=(eption i/ b value entered is <ero

P (at(h2Arith)eti(5=(eption ob-3 O Syste).out.println2[9ivision by aero...[3Q P /inally O Syste).out.println2[+han' Hou...,inally e=e(uted al&ays[3Q P P P

(0

SUBRATA SINHA

5o0 to Thro0 %9ceptions Be/ore you (an (at(h an e=(eption* so)e (ode so)e&here )ust thro& one. Any (ode (an thro& an e=(eption: your (ode* (ode /ro) a pa('age &ritten by so)eone else su(h as the pa('ages that (o)e &ith the Cava plat/or)* or the Cava runti)e environ)ent. ?egardless o/ &hat thro&s the e=(eption* it^s al&ays thro&n &ith the thro& state)ent. As you have probably noti(ed* the Cava plat/or) provides nu)erous e=(eption (lasses. All the (lasses are des(endants o/ the +hro&able (lass* and all allo& progra)s to di//erentiate a)ong the various types o/ e=(eptions that (an o((ur during the e=e(ution o/ a progra). Hou (an also (reate your o&n e=(eption (lasses to represent proble)s that (an o((ur &ithin the (lasses you &rite. In /a(t* i/ you are a pa('age developer* you )ight have to (reate your o&n set o/ e=(eption (lasses to allo& users to di//erentiate an error that (an o((ur in your pa('age /ro) errors that o((ur in the Cava plat/or) or other pa('ages. Hou (an also (reate (hained e=(eptions. ,or )ore in/or)ation* see the Chained 5=(eptions se(tion. The thro0 $tatement All )ethods use the thro& state)ent to thro& an e=(eption. +he thro& state)ent re4uires a single argu)ent: a thro&able ob-e(t. +hro&able ob-e(ts are instan(es o/ any sub(lass o/ the +hro&able (lass. ;ere^s an e=a)ple o/ a thro& state)ent. thro& so)e+hro&able1b-e(tQ 7et^s loo' at the thro& state)ent in (onte=t. +he /ollo&ing pop )ethod is ta'en /ro) a (lass that i)ple)ents a (o))on sta(' ob-e(t. +he )ethod re)oves the top ele)ent /ro) the sta(' and returns the ob-e(t. publi( 1b-e(t pop23 O 1b-e(t ob-Q i/ 2si<e TT 03 O thro& ne& 5)ptySta('5=(eption23Q P

)1

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

ob- T ob-e(tAt2si<e " 13Q set1b-e(tAt2si<e " 1* null3Q si<e""Q return ob-Q P +he pop )ethod (he('s to see &hether any ele)ents are on the sta('. I/ the sta(' is e)pty 2its si<e is e4ual to 03* pop instantiates a ne&5)ptySta('5=(eption ob-e(t 2a )e)ber o/ -ava.util3 and thro&s it. +he Creating 5=(eption Classes se(tion in this (hapter e=plains ho& to (reate your o&n e=(eption (lasses. ,or no&* all you need to re)e)ber is that you (an thro& only ob-e(ts that inherit /ro) the -ava.lang.+hro&able (lass. Note that the de(laration o/ the pop )ethod does not (ontain a thro&s (lause. 5)ptySta('5=(eption is not a (he('ed e=(eption* so pop is not re4uired to state that it )ight o((ur. Creating 7our O0n %9ception Class +he e=a)ple given belo& is /or (reation o/ a ne& 5=(eption (lass NegativeAge5=(eption* &hi(h is done by inherting /ro) 5=(eption (lass. NegativeAge5=(eption (lass has one (onstru(tor (ontaning a 8essage @Negative Age 5=(eptionA* Its supposed to get (alled &hen this e=(eption is raised. And its raised &hen &e thro& an ob-e(t o/ that (lass* as done in (he('Age23 )ethod2using thro& state)ent3. (he('Age23 )ethod is de/ined and its (apable to thro& an e=(eption ob-e(t 2&hi(h is done by thro&s state)ent3. As &e 'no& that (he('Age23 )ethod )ay raise negative age e=(eption i/ user supplies negative value* so &e put the (alling o/ (he('Age23 )ethod in try blo(' and in (at(h state)ent * &e (at(h NegativeAge5=((eption. i)port -ava.util.RQ (lass NegativeAge5=(eption e=tends 5=(eption O NegativeAge5=(eption23 O Syste).out.println2[Negative Age 5=(eption[3Q P P

)1

SUBRATA SINHA

(lass +estDoter O void (he('Age2int age3 thro&s NegativeAge5=(eption O i/2ageY03 O thro& ne& NegativeAge5=(eption23Q P else i/2ageZT0 NN ageY1%3 O Syste).out.println2[Invalid Doter Age[3Q P else O Syste).out.println2[Dalid Age[3Q P P publi( stati( void )ain2String aIJ3 O +estDoter tvTne& +estDoter23Q S(anner s(Tne& S(anner2Syste).in3Q Syste).out.println2[5nter a age:[3Q int =Ts(.ne=tInt23Q try O tv.(he('Age2=3Q P (at(h2NegativeAge5=(eption nve3 O P P P ;uestions and "ns0er of %9cetion 5andling \uestion: Is the /ollo&ing (ode legal]

)#

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

try O P /inally O P Ans&er: Hes* it^s legal ` and very use/ul A try state)ent does not have to have a (at(h blo(' i/ it has a /inally blo('. I/ the (ode in the try state)ent has )ultiple e=it points and no asso(iated (at(h (lauses* the (ode in the /inally blo(' is e=e(uted no )atter ho& the try blo(' is e=ited. +hus it )a'es sense to provide a /inally blo(' &henever there is (ode that )ust al&ays be e=e(uted. +his in(lude resour(e re(overy (ode* su(h as the (ode to (lose IE1 strea)s.

;uestion: Bhat e=(eption types (an be (aught by the /ollo&ing handler] (at(h 25=(eption e3 O P Bhat is &rong &ith using this type o/ e=(eption handler]

"ns0er: +his handler (at(hes e=(eptions o/ type 5=(eptionQ there/ore* it (at(hes any e=(eption. +his (an be a poor i)ple)entation be(ause you are losing valuable in/or)ation about the type o/ e=(eption being thro&n and )a'ing your (ode less e//i(ient. As a result* your progra) )ay be /or(ed to deter)ine the type o/ e=(eption be/ore it (an de(ide on the best re(overy strategy.

)%

SUBRATA SINHA

;uestion: Is there anything &rong &ith this e=(eption handler as &ritten] Bill this (ode (o)pile] try O

P (at(h 25=(eption e3 O

P (at(h 2Arith)eti(5=(eption a3 O

P "ns0er: +his /irst handler (at(hes e=(eptions o/ type 5=(eptionQ there/ore* it (at(hes any e=(eption* in(luding Arith)eti(5=(eption. +he se(ond handler (ould never be rea(hed. +his (ode &ill not (o)pile.

;uestion: 8at(h ea(h situation in the /irst list &ith an ite) in the se(ond list. a. intIJ AQ b. AI0J T 0Q (. +he CD8 starts running your progra)* but the CD8 (an^t /ind the Cava plat/or) (lasses. 2+he Cava plat/or) (lasses reside in (lasses.<ip or rt.-ar.3 d. A progra) is reading a strea) and rea(hes the end o/ strea) )ar'er. Be/ore (losing the strea) and a/ter rea(hing the end o/ strea) )ar'er* a progra) tries to read the strea) again.

1 error

)(

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

2 (he('ed e=(eption # (o)pile error 4 no e=(eption

"ns0er:

a. # 2(o)pile error3. +he array is not initiali<ed and &ill not (o)pile. b. 1 2error3. (. 4 2no e=(eption3. Bhen you read a strea)* you e=pe(t there to be an end o/ strea) )ar'er. Hou should use e=(eptions to (at(h une=pe(ted behavior in your progra). d. 2 2(he('ed e=(eption3.

CHA"TER , A""9ET

An applet is a (ontainer (o)ponent that resides on an ;+87 page &ith in the bro&ser.5very applet is a sub(lass o/ -ava.applet.Applet (lass. +hus every applet inherits a large a)ount o/ /un(tionality /ro) Applet* also /ro) the super (lasses o/ Applet i.e -ava.a&t.Co)ponent*-ava.a&t.Container and -ava.a&t.0anel.

"pplet 5eirarch(: 1b-e(t Co)ponent Container 0anel Applet


))

SUBRATA SINHA

So i/ &e inherit /ro) Applet (lass * /eatures o/ all super (lass is also inherited auto)ati(ally to our (lass.

$ife Cycle of an "pplet:


+here are /our )ethods in the Applet (lass that give the /ra)e&or' on &hi(h &e (an build an applet. +hey are init23* start23* stop23* destroy23. Initiali-ation : An applet is initiali<ed &henever a (all to the init23 )ethod is )ade by the progra). +his )ethod &or's )u(h li'e a (onstru(tor in an -ava appli(ation.It is auto)ati(ally (alled by the syste) &hen Cava laun(hes the applet /or the /irst ti)e.Co))on a(tions in the init )ethod in(lude pro(essing 0A?A8 values and adding user inter/a(e (o)ponents.

$tarting: An applet is said to have started &henever a (all to the start23 )ethod. +his )ethod is auto)ati(ally (alled a/ter -ava (alls init23 )ethod.It is also (alled &henver the user returns to the page (ontaining the applet a/ter having gone o// to the other pages.+his )eans that the start )ethod (an be (alled repeatedly* unli'e the init23 )ethod.A sub(lass o/ Applet should override this )ethod i/ it has any operation that it &ants to per/or) ea(h ti)e the &eb page (ontaining it is visited. $topping: An applets e=e(ution is stopped &hen a (all to stop )ethod is )ade. +his )ethod is auto)ati(ally (alled &hen the user )oves o// the page on &hi(h the applet sits.

)*

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

Destro(ing: Cava gurantees to (all destroy23 )ethod &hen the bro&ser shuts do&n nor)ally.

0aint23 : paint )ethod is (alled auto)ati(ally &hen applet begins its e=e(ution and also ea(h ti)e its out put is redra&n.

Displa(ng a $imple Te9t on an "pplet i)port -ava.applet.RQ i)port -ava.a&t.RQ publi( (lass ;elloApplet e=tends Applet O publi( void init23 O P publi( void paint26raphi(s g3 O g.dra&String2[;ello Borld[*:0*1003Q P P

),

SUBRATA SINHA

Co)pile the above progra). But do not try to interpret it. +he applet &ill be interpreted either by the bro&ser or you (an use appletvie&er. So (reate a ht)l /ile and e)bed the .(lass /ile in it . Yht)lZ Ybody bg(olorT[blue[ Z Yapplet (odeT;elloApplet heightT#00 &idthT#00ZYEappletZ YEbodyZ YEht)lZ Save the above /ile as ht)l &ith a na)e o/ your (hoi(e. So suppose &e have given the na)e 8yApplet.ht)l +hen run applet by &riting : appletvie&er 8yApplet.ht)l in (o))and pro)pt

+he output &ill loo' li'e:

)/

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

Demonstrating the method of an applet


)0

SUBRATA SINHA

i)port -ava.applet.RQ i)port -ava.a&t.RQ publi( (lass ;elloApplet e=tends Applet O publi( void init23 O Syste).out.println2[Applet is initiali<ed[3Q P publi( void start23 O Syste).out.println2[+his is /ro) start )ethod[3Q P publi( void stop23 O Syste).out.println2[+his is /ro) stop )ethod[3Q P publi( void destroy23 O Syste).out.println2[Applet is destroyed[3Q P P

*1

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

Creating %&! using "pplet


*1

SUBRATA SINHA

i)port -ava.applet.RQ i)port -ava.a&t.RQ i)port -ava.a&t.event.RQ publi( (lass ;elloApplet e=tends Applet i)ple)ents A(tion7istener O +e=t,ield t=1Tne& +e=t,ield2103Q +e=t,ield t=2Tne& +e=t,ield2203Q Button btTne& Button2[Cli('[3Q String )sgQ publi( void init23 O add2t=13Q add2bt3Q add2t=23Q bt.addA(tion7istener2this3Q P publi( void a(tion0er/or)ed2A(tion5vent ae3 O t=2.set+e=t2[6ood 8orning X 8r. [Ft=1.get+e=t233Q P P

*#

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

*%

SUBRATA SINHA

Creating an "nimated "pplet with Threading: '()ample of *ultiple !nheritence in +ava through ,unna-le interface)
import 3ava.applet.0; import 3ava.a*t.0; import 3ava.a*t.event.0; public class "ello,pplet e7tends ,pplet implements =unnable { <hread t)null; Strin& ms&)", Simple .;vin& $anner"; int a; public void init() { a)4EE; } public void start() { t)ne* <hread(this); t.start(); } public void run() { !or(;;) { a)aF1; i!(a))F12E) { a)4EE; } repaint(); try { t.sleep(1E); } catch(+7ception e) {} } } public void paint(:raphics &) { &.dra*Strin&(ms& a 1EE); } }

Create a "pplet 0ith 8 I components capable of handling e'ents

*(

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7 import 3ava.applet.,pplet; import 3ava.a*t.0; import 3ava.a*t.event.0; public class .y,pplet e7tends ,pplet implements ,ction@istener { <e7tDield t71)ne* <e7tDield(1E); <e7tDield t72)ne* <e7tDield(1E); <e7tDield t74)ne* <e7tDield(1E); <e7tDield t7G)ne* <e7tDield(1E); $utton b)ne* $utton(",>>"); $utton b1)ne* $utton(".B@"); public void init() { add(t71); add(t72); add(b); add(b1); b.add,ction@istener(this); b1.add,ction@istener(this); add(t74); add(t7G); } public void actionPer!ormed(,ction+vent e) { int 7 y H; 7)?nte&er.parse?nt(t71.&et<e7t()); y)?nte&er.parse?nt(t72.&et<e7t()); i!(e.&etSource()))b) { H)7+y; t74.set<e7t(Strin&.value;!(H)); } i!(e.&etSource()))b1) { H)70y; t7G.set<e7t(Strin&.value;!(H)); } } }

CHA"TER /

2I9E HAND9IN:

!NT,OD&CT!ON TO .!$( !NP&T "ND O&TP&T

*)

SUBRATA SINHA

+here are t&o types o/ ,iles : +e=t /ile and Binary ,ile +e=t ,ile : A /ile that (ontains (hara(ters* all data is stored as (hara(ters &ith one (hara(ter per byte on dis'. ,ields are separated by tabs and ?e(ords are separated by ne&lines. Binary ,ile: A /ile that )ay (ontain (hara(ters as &ell as other non" (hara(ter data types that (anGt be read by a te=t editor. +o handle IE1 operations Cava uses strea)s . Be (an thin' o/ a strea) as the /o& o/ data /ro) one lo(ation to another. ,or instan(e an output strea) (an /lo& /ro) the internal )e)ory o/ an appli(ation to a dis' /ile 2 i.e /or Briting to a ,ile or Console or to a net&or' Conne(tion 3 and an input strea) (an /lo& /ro) dis' /ile to internal )e)ory2i.e /or ?eading /ro) a ,ile or ?eading /ro) a .eyboard or /ro) a net&or' (onne(tion3 +here are t&o types o/ strea) : Chara(ter strea) : >sed to trans/er te=t data to or /ro) IE1 devi(e Binary strea) : >sed to trans/er binary data to or /ro) an IE1 devi(e.

**

!NT,OD&CT!ON TO .!$(# "ND D!,(CTO,!(#

Cava provides a ,ile (lass that &e (an use to per/or) so)e basi( operations on /iles and dire(tories. ,ile Class : present in the pa('age -ava.io 1ne Constru(tor o/ /ile (lass : ,ile2String path3 path na)e. : (reates a /ile ob-e(t that re/ers to the spe(i/ied

8ethods that (he(' the ,ile 1b-e(t: e=ists23 : returns true value i/ the path na)e e=ists (an?ead23 : returns true value i/ the path na)e e=ists and progra) (an read /ro) it. (anBrite23 : returns true value i/ the path na)e e=ists and progra) (an &rite to it. is9ire(tory23 : returns true value i/ the path na)e e=ists and re/ers to a dire(tory. is,ile23 : returns true value i/ the path na)e e=ists and re/ers to a /ile. 8ethods that get in/or)ation about a ,ile 1b-e(t: getNa)e23:returns the na)e o/ the /ile or dire(tory as a String ob-e(t. getAbsolute0ath23: returns the path na)e as represented in the (onstru(tor as a String ob-e(t. length23: returns the length o/ /ile in bytes as a long type. last8odi/ied23 : returns a long value representing the ti)e in )illise(onds that the /ile &as last )odi/ied. list,iles23: I/ the ob-e(ts re/ers to a dire(tory* this )ethods returns an array o/ ,ile ob-e(ts /or the /iles and subdire(tories o/ this dire(tory. list23 : returns /iles and subdire(tories. 8ethods that &or' &ith ,ile 1b-e(ts: set?ead1nly23 : 8a'e the ob-e(t read only. 8'dirs23 : Create a dire(tory delete23 : delete the /ile or dire(tory 2i/ it is e)pty3.

*,

SUBRATA SINHA

Code that creates a director( if it does not alread( e9ists String strTA(:bSubratabAQ ,ile /Tne& ,ile2str3Q i/2 /.e=ists23 TT /alse 3 /.)'dir23Q
Code that creates a file if it does not already e)ists Strin& str)I-:JSubrataJproducts.t7tI; Dile !)ne* Dile(str); i!( K !.e7ists() ) !.create5e*Dile() ; Code that displays information a-out a file System.out.println(LDile 5ame : L + !.&et5ame()); System.out.println(L,bsolute Path : L + ! .&et,bsolutepath() ); System.out.println(L?s *ritable: L + !.can#rite());

*/

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

CHA"TER 0 THREAD

CONC RR%NT PRO8R"&&IN8 6IT5 T5R%"D$ In (on(urrent progra))ing* there are t&o basi( units o/ e=e(ution: pro(esses and threads. In the Cava progra))ing language* (on(urrent progra))ing is )ostly (on(erned &ith threads. ;o&ever* pro(esses are also i)portant. Processes A pro(ess has a sel/"(ontained e=e(ution environ)ent. A pro(ess generally has a (o)plete* private set o/ basi( run"ti)e resour(esQ in parti(ular* ea(h pro(ess has its o&n )e)ory spa(e.

Threads <hreads are sometimes called lightweight processes. $oth processes and threads provide an e7ecution environment but creatin& a ne* thread re/uires !e*er resources than creatin& a ne* process.

, thread is a sin&le se/uential !lo* o! control *ithin a pro&ram., thread o!ten completes a speci!ic tas%. $y de!ault a 3ava application uses a sin&le thread called main thread. "o*ever some pro&rams can bene!it by usin& t*o or more threads to allo* di!!erent parts o! the pro&ram to e7ecute simultaneously.;n a computer that has 3ust one -PB the threads donMt actually e7ecute simultaneously.?nstead a part o! the Nava Airtual .achine called the thread scheduler alternately lets portions o! each thread e7ecute.<his &ives the
*0

SUBRATA SINHA

appearance that all o! the tas%s are runnin& at the same time and this can ma%e an application *or% more e!!iciently.

&ses of thread

/0 <o improve the per!ormance o! applications *ith e7tensive ?/; operations. 10 <o improve the responsiveness o! :B? applications. 20 <o allo* t*o or more users to run serverFbased applications simultaneously.

Thread $ife Cycle:

,1

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

Thread *ethods

void start') -auses this thread to be&in e7ecution; the Nava Airtual .achine calls the run method o! this thread. static void sleep'long millis) -auses the currently e7ecutin& thread to sleep (temporarily cease e7ecution) !or the speci!ied number o! milliseconds sub3ect to the precision and accuracy o! system timers and schedulers. static yield') -auses the currently e7ecutin& thread ob3ect to temporarily pause and allo* other threads to e7ecute. void setPriority'int newPriority) -han&es the priority o! this thread. ?t ta%es .?5OP=?;=?<6 (1) 5;=.OP=?;=?<6(8) and .,COP=?;=?<6(1E) as parameter.

Two ways to create a thread ,n application can subclass <hread providin& its o*n implementation o! run as in the "ello<hread e7ample:
!nherit the Thread class:
,1

SUBRATA SINHA

public class "ello<hread e7tends <hread { public void run() { System.out.println(""ello !rom a threadK"); }

public static void main(Strin& ar&s'() { "ello<hread ht)ne* "ello<hread(); ht.start(); } }

,#

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

!mplement ,unna-le !nterface : <he =unnable inter!ace

de!ines a sin&le method run meant to contain the code e7ecuted in the thread. <he =unnableob3ect is passed to the <hread constructor as in the "ello=unnable e7ample: public class "ello=unnable implements =unnable { public void run() { System.out.println(""ello !rom a threadK"); } public static void main(Strin& ar&s'() { "ello=unnable hr)ne* "ello=unnable(); <hread t)ne* <hread(hr); t.start(); } }
,%

SUBRATA SINHA

start#$ met%od int&rn calls r&n met%od 3or ing with *ultiple Threads : , demo pro&ram *hich sho*s ho* multiplr thread e7ecutes simultaneously.

class <hread;ne e7tends <hread { public void run() { !or( ; ; ) System.out.println("<hread ;ne ............K"); } } class <hread<*o e7tends <hread { public void run() { !or( ; ; ) System.out.println("<hread <*o............K"); } }

,(

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

class <hread<hree e7tends <hread { public void run() { !or( ; ; ) System.out.println("<hread <hree............K"); } }

public class .ulti<hread { public static void main(Strin& s'() { <hread;ne t1 ) ne* <hread;ne();

,)

SUBRATA SINHA

<hread<*o

t2 ) ne* <hread<*o();

<hread<hree t4 ) ne* <hread<hree(); t1.start(); t2.start(); t4.start(); } }

(hapter /ive te=t here.

,*

* CHA"TER NA-E
Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert
,,

SUBRATA SINHA

(hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert

,/

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

(hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here. Insert (hapter si= te=t here.

,0

, CHA"TER NA-E
Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter

/1

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here.

/1

SUBRATA SINHA

Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here. Insert (hapter seven te=t here.

/#

/ CHA"TER NA-E
Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here.

/%

SUBRATA SINHA

Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight

/(

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here. Insert (hapter eight te=t here.

/)

0 CHA"TER NA-E
Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here.

/*

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here.

/,

SUBRATA SINHA

Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here. Insert (hapter nine te=t here.

//

11 CHA"TER NA-E
Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert
/0

SUBRATA SINHA

(hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert

01

INTRODUCTION TO JA;A AND BIO JA;A < A STUDENTS HANDBOO7

(hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here. Insert (hapter ten te=t here.

01

ABOUT THE AUTHOR


Insert author bio te=t here. Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here Insert author bio te=t here

0#

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy