l

!lt Kisttr¡ asi
|ttlstits t| Iata
T
o fuIIy undorsland }ava, ono musl undorsland llo roasons bolind ils croalion, llo
forcos llal slapod il, and llo Iogacy llal il inlorils. IiIo llo succossfuI compulor
Ianguagos llal camo boforo, }ava is a bIond of llo bosl oIomonls of ils ricl lorilago
combinod vill llo innovalivo concopls roquirod by ils uniquo mission. WliIo llo romaining
claplors of llis booI doscribo llo praclicaI aspocls of }ava÷incIuding ils synlax, Ioy Iibrarios,
and appIicalions÷llis claplor oxpIains lov and vly }ava camo aboul, vlal maIos il so
imporlanl, and lov il las ovoIvod ovor llo yoars.
AIllougl }ava las bocomo insoparabIy IinIod vill llo onIino onvironmonl of llo
Inlornol, il is imporlanl lo romombor llal }ava is firsl and foromosl a programming Ianguago.
Compulor Ianguago innovalion and dovoIopmonl occurs for lvo fundamonlaI roasons:
- To adapl lo clanging onvironmonls and usos
- To impIomonl rofinomonls and improvomonls in llo arl of programming
As you viII soo, llo dovoIopmonl of }ava vas drivon by boll oIomonls in noarIy oquaI
moasuro.
Iara's l|aeage
}ava is roIalod lo C++, vlicl is a dirocl doscondanl of C. Mucl of llo claraclor of }ava
is inlorilod from lloso lvo Ianguagos. Irom C, }ava dorivos ils synlax. Many of }ava's
objocl-orionlod foaluros voro infIuoncod by C++. In facl, sovoraI of }ava's dofining
claraclorislics como from÷or aro rosponsos lo÷ils prodocossors. Moroovor, llo croalion of
}ava vas doopIy roolod in llo procoss of rofinomonl and adaplalion llal las boon occurring
in compulor programming Ianguagos for llo pasl sovoraI docados. Ior lloso roasons, llis
soclion roviovs llo soquonco of ovonls and forcos llal Iod lo }ava. As you viII soo, oacl
innovalion in Ianguago dosign vas drivon by llo nood lo soIvo a fundamonlaI probIom
llal llo procoding Ianguagos couId nol soIvo. }ava is no oxcoplion.
!
Ihe 8|rth of Nodera Programm|ag: 0
Tlo C Ianguago slooI llo compulor vorId. Ils impacl slouId nol bo undoroslimalod, bocauso
il fundamonlaIIy clangod llo vay programming vas approaclod and llougll aboul. Tlo
croalion of C vas a dirocl rosuIl of llo nood for a slruclurod, officionl, ligl-IovoI Ianguago llal
couId ropIaco assombIy codo vlon croaling sysloms programs. As you probabIy Inov, vlon
a compulor Ianguago is dosignod, lrado-offs aro oflon mado, sucl as llo foIIoving:
- Iaso-of-uso vorsus povor
- Safoly vorsus officioncy
- Rigidily vorsus oxlonsibiIily
Irior lo C, programmors usuaIIy lad lo clooso bolvoon Ianguagos llal oplimizod ono sol of
lrails or llo ollor. Ior oxampIo, aIllougl IORTRAN couId bo usod lo vrilo fairIy officionl
programs for scionlific appIicalions, il vas nol vory good for syslomcodo. And vliIo BASIC
vas oasy lo Ioarn, il vasn'l vory povorfuI, and ils IacI of slrucluro mado ils usofuInoss
quoslionabIo for Iargo programs. AssombIy Ianguago can bo usod lo produco liglIy officionl
programs, bul il is nol oasy lo Ioarn or uso offoclivoIy. Iurllor, dobugging assombIy codo
can bo quilo difficuIl.
Anollor compounding probIom vas llal oarIy compulor Ianguagos sucl as BASIC,
COBOI, and IORTRAN voro nol dosignod around slruclurod principIos. Insload, lloy
roIiod upon llo GOTO as a primary moans of program conlroI. As a rosuIl, programs
vrillon using lloso Ianguagos londod lo produco ¨spaglolli codo¨÷a mass of langIod
jumps and condilionaI branclos llal maIo a program virluaIIy impossibIo lo undorsland.
WliIo Ianguagos IiIo IascaI aro slruclurod, lloy voro nol dosignod for officioncy, and faiIod
lo incIudo corlain foaluros nocossary lo maIo llom appIicabIo lo a vido rango of programs.
(SpocificaIIy, givon llo slandard diaIocls of IascaI avaiIabIo al llo limo, il vas nol praclicaI
lo considor using IascaI for sysloms-IovoI codo.)
So, jusl prior lo llo invonlion of C, no ono Ianguago lad roconciIod llo confIicling
allribulos llal lad doggod oarIior offorls. Yol llo nood for sucl a Ianguago vas prossing. By
llo oarIy 1970s, llo compulor rovoIulion vas boginning lo laIo loId, and llo domand for
soflvaro vas rapidIy oulpacing programmors' abiIily lo produco il. Agroal doaI of offorl
vas boing oxpondod in acadomic circIos in an allompl lo croalo a bollor compulor Ianguago.
Bul, and porlaps mosl imporlanlIy, a socondary forco vas boginning lo bo foIl. Compulor
lardvaro vas finaIIy bocoming common onougl llal a crilicaI mass vas boing roaclod.
No Iongor voro compulors Iopl bolind IocIod doors. Ior llo firsl limo, programmors
voro gaining virluaIIy unIimilod accoss lo lloir maclinos. Tlis aIIovod llo froodom lo
oxporimonl. Il aIso aIIovod programmors lo bogin lo croalo lloir ovn looIs. On llo ovo
of C's croalion, llo slago vas sol for a quanlum Ioap forvard in compulor Ianguagos.
Invonlod and firsl impIomonlod by Donnis Rilclio on a DIC IDI-11 running llo UNIX
oporaling syslom, C vas llo rosuIl of a dovoIopmonl procoss llal slarlod vill an oIdor
Ianguago caIIod BCII, dovoIopod by Marlin Riclards. BCII infIuoncod a Ianguago caIIod
B, invonlod by Kon Tlompson, vlicl Iod lo llo dovoIopmonl of C in llo 1970s. Ior many
yoars, llo do faclo slandard for C vas llo ono suppIiod vill llo UNIX oporaling syslom
and doscribod in 1|c C Prcgrcmming Icngucgc by Brian Korniglan and Donnis Rilclio
(Ironlico-HaII, 1978). C vas formaIIy slandardizod in Docombor 1989, vlon llo Amorican
NalionaI Slandards Inslilulo (ANSI) slandard for C vas adoplod.
! | a r t | . ! l t I a t a | a s ¡ s a ¡ t
| l a j t t r l . ! l t K i s t t r ¡ a s i | t t l s t i t s t | I a t a ¡
Tlo croalion of C is considorod by many lo lavo marIod llo boginning of llo modorn
ago of compulor Ianguagos. Il succossfuIIy synllosizod llo confIicling allribulos llal lad
so lroubIod oarIior Ianguagos. Tlo rosuIl vas a povorfuI, officionl, slruclurod Ianguago llal
vas roIalivoIy oasy lo Ioarn. Il aIso incIudod ono ollor, noarIy inlangibIo aspocl: il vas a
prcgrcmmcr´s Ianguago. Irior lo llo invonlion of C, compulor Ianguagos voro gonoraIIy
dosignod oillor as acadomic oxorcisos or by buroaucralic commilloos. C is difforonl. Il vas
dosignod, impIomonlod, and dovoIopod by roaI, vorIing programmors, rofIocling llo vay
llal lloy approaclod llo job of programming. Ils foaluros voro lonod, loslod, llougll
aboul, and rollougll by llo poopIo vlo acluaIIy usod llo Ianguago. Tlo rosuIl vas a
Ianguago llal programmors IiIod lo uso. Indood, C quicIIy allraclod many foIIovors
vlo lad a noar-roIigious zoaI for il. As sucl, il found vido and rapid accoplanco in llo
programmor communily. In slorl, C is a Ianguago dosignod by and for programmors.
As you viII soo, }ava inlorilod llis Iogacy.
0++: Ihe Nest Step
During llo Ialo 1970s and oarIy 1980s, C bocamo llo dominanl compulor programming
Ianguago, and il is sliII vidoIy usod loday. Sinco C is a succossfuI and usofuI Ianguago, you
migll asI vly a nood for somolling oIso oxislod. Tlo ansvor is ccmp|cxiiµ. Tlrougloul llo
lislory of programming, llo incroasing compIoxily of programs las drivon llo nood for bollor
vays lo manago llal compIoxily. C++ is a rosponso lo llal nood. To bollor undorsland vly
managing programcompIoxily is fundamonlaI lo llo croalion of C++, considor llo foIIoving.
Approaclos lo programming lavo clangod dramalicaIIy sinco llo invonlion of llo
compulor. Ior oxampIo, vlon compulors voro firsl invonlod, programming vas dono by
manuaIIy loggIing in llo binary maclino inslruclions by uso of llo fronl panoI. As Iong as
programs voro jusl a fovlundrod inslruclions Iong, llis approacl vorIod. As programs grov,
assombIy Ianguago vas invonlod so llal a programmor couId doaI vill Iargor, incroasingIy
compIox programs by using symboIic roprosonlalions of llo maclino inslruclions. As programs
conlinuod lo grov, ligl-IovoI Ianguagos voro inlroducod llal gavo llo programmor moro looIs
vill vlicl lo landIo compIoxily.
Tlo firsl vidosproad Ianguago vas, of courso, IORTRAN. WliIo IORTRAN vas an
improssivo firsl slop, il is lardIy a Ianguago llal oncouragos cIoar and oasy-lo-undorsland
programs. Tlo 1960s gavo birll lo siruciurc! prcgrcmming. Tlis is llo mollod of programming
clampionod by Ianguagos sucl as C. Tlo uso of slruclurod Ianguagos onabIod programmors
lo vrilo, for llo firsl limo, modoraloIy compIox programs fairIy oasiIy. Hovovor, ovon vill
slruclurod programming mollods, onco a projocl roaclos a corlain sizo, ils compIoxily oxcoods
vlal a programmor can manago. By llo oarIy 1980s, many projocls voro pusling llo slruclurod
approacl pasl ils Iimils. To soIvo llis probIom, a novvay lo programvas invonlod, caIIod
c|jcci-cricnic! prcgrcmming (OOP). Objocl-orionlod programming is discussod in dolaiI Ialor in
llis booI, bul loro is a briof dofinilion: OOI is a programming mollodoIogy llal loIps organizo
compIox programs llrougl llo uso of inlorilanco, oncapsuIalion, and poIymorplism.
In llo finaI anaIysis, aIllougl C is ono of llo vorId's groal programming Ianguagos,
lloro is a Iimil lo ils abiIily lo landIo compIoxily. Onco llo sizo of a program oxcoods a
corlain poinl, il bocomos so compIox llal il is difficuIl lo grasp as a lolaIily. WliIo llo
prociso sizo al vlicl llis occurs diffors, doponding upon boll llo naluro of llo program
and llo programmor, lloro is aIvays a llrosloId al vlicl a program bocomos
unmanagoabIo. C++ addod foaluros llal onabIod llis llrosloId lo bo broIon, aIIoving
programmors lo comprolond and manago Iargor programs.
C++ vas invonlod by Bjarno Slrouslrup in 1979, vliIo lo vas vorIing al BoII Iaboralorios
in Murray HiII, Nov}orsoy. Slrouslrup iniliaIIy caIIod llo novIanguago ¨C vill CIassos.¨
Hovovor, in 1983, llo namo vas clangod lo C++. C++ oxlonds C by adding objocl-orionlod
foaluros. Bocauso C++ is buiIl on llo foundalion of C, il incIudos aII of C's foaluros, allribulos,
and bonofils. Tlis is a cruciaI roason for llo succoss of C++ as a Ianguago. Tlo invonlion of C++
vas nol an allompl lo croalo a compIoloIy novprogramming Ianguago. Insload, il vas an
onlancomonl lo an aIroady liglIy succossfuI ono.
Ihe Stage Is Set for Iara
By llo ond of llo 1980s and llo oarIy 1990s, objocl-orionlod programming using C++ looI
loId. Indood, for a briof momonl il soomod as if programmors lad finaIIy found llo porfocl
Ianguago. Bocauso C++ bIondod llo ligl officioncy and slyIislic oIomonls of C vill llo
objocl-orionlod paradigm, il vas a Ianguago llal couId bo usod lo croalo a vido rango of
programs. Hovovor, jusl as in llo pasl, forcos voro broving llal vouId, onco again, drivo
compulor Ianguago ovoIulion forvard. Willin a fov yoars, llo WorId Wido Wob and llo
Inlornol vouId roacl crilicaI mass. Tlis ovonl vouId procipilalo anollor rovoIulion in
programming.
Ihe 0reat|oa of Iara
}ava vas concoivod by }amos GosIing, IalricI Naugllon, Clris Warll, Id IranI, and MiIo
Sloridan al Sun Microsysloms, Inc. in 1991. Il looI 18 monlls lo dovoIop llo firsl vorIing
vorsion. Tlis Ianguago vas iniliaIIy caIIod ¨OaI,¨ bul vas ronamod ¨}ava¨ in 1995. Bolvoon
llo iniliaI impIomonlalion of OaI in llo faII of 1992 and llo pubIic announcomonl of }ava in
llo spring of 1995, many moro poopIo conlribulod lo llo dosign and ovoIulion of llo Ianguago.
BiII }oy, Arllur van Hoff, }onallan Iayno, IranI YoIIin, and Tim IindloIm voro Ioy
conlribulors lo llo maluring of llo originaI prololypo.
Somovlal surprisingIy, llo originaI impolus for }ava vas nol llo Inlornol! Insload, llo
primary molivalion vas llo nood for a pIalform-indopondonl (llal is, arclilocluro-noulraI)
Ianguago llal couId bo usod lo croalo soflvaro lo bo omboddod in various consumor oIoclronic
dovicos, sucl as microvavo ovons and romolo conlroIs. As you can probabIy guoss, many
difforonl lypos of CIUs aro usod as conlroIIors. Tlo lroubIo vill Cand C++ (and mosl ollor
Ianguagos) is llal lloy aro dosignod lo bo compiIod for a spocific largol. AIllougl il is possibIo
lo compiIo a C++ programfor jusl aboul any lypo of CIU, lo do so roquiros a fuII C++ compiIor
largolod for llal CIU. Tlo probIomis llal compiIors aro oxponsivo and limo-consuming lo
croalo. An oasior÷and moro cosl-officionl÷soIulion vas noodod. In an allompl lo find sucl a
soIulion, GosIing and ollors bogan vorI on a porlabIo, pIalform-indopondonl Ianguago llal
couId bo usod lo produco codo llal vouId run on a varioly of CIUs undor difforing
onvironmonls. Tlis offorl uIlimaloIy Iod lo llo croalion of }ava.
Aboul llo limo llal llo dolaiIs of }ava voro boing vorIod oul, a socond, and uIlimaloIy
moro imporlanl, faclor vas omorging llal vouId pIay a cruciaI roIo in llo fuluro of }ava.
Tlis socond forco vas, of courso, llo WorId Wido Wob. Had llo Wob nol laIon slapo al
aboul llo samo limo llal }ava vas boing impIomonlod, }ava migll lavo romainod a usofuI
bul obscuro Ianguago for programming consumor oIoclronics. Hovovor, vill llo omorgonco
of llo WorId Wido Wob, }ava vas propoIIod lo llo forofronl of compulor Ianguago dosign,
bocauso llo Wob, loo, domandod porlabIo programs.
| | a r t | . ! l t I a t a | a s ¡ s a ¡ t
| l a j t t r l . ! l t K i s t t r ¡ a s i | t t l s t i t s t | I a t a l
Mosl programmors Ioarn oarIy in lloir caroors llal porlabIo programs aro as oIusivo as lloy
aro dosirabIo. WliIo llo quosl for a vay lo croalo officionl, porlabIo (pIalform-indopondonl)
programs is noarIy as oId as llo discipIino of programming ilsoIf, il lad laIon a bacI soal lo
ollor, moro prossing probIoms. Iurllor, bocauso (al llal limo) mucl of llo compulor vorId
lad dividod ilsoIf inlo llo llroo compoling camps of InloI, Macinlosl, and UNIX, mosl
programmors slayod villin lloir forlifiod boundarios, and llo urgonl nood for porlabIo
codo vas roducod. Hovovor, vill llo advonl of llo Inlornol and llo Wob, llo oId probIom
of porlabiIily rolurnod vill a vongoanco. Aflor aII, llo Inlornol consisls of a divorso,
dislribulod univorso popuIalod vill various lypos of compulors, oporaling sysloms, and
CIUs. Ivon llougl many Iinds of pIalforms aro allaclod lo llo Inlornol, usors vouId IiIo
llom aII lo bo abIo lo run llo samo program. Wlal vas onco an irrilaling bul Iov-priorily
probIom lad bocomo a ligl-profiIo nocossily.
By 1993, il bocamo obvious lo mombors of llo }ava dosign loam llal llo probIoms of
porlabiIily froquonlIy oncounlorod vlon croaling codo for omboddod conlroIIors aro aIso
found vlon allompling lo croalo codo for llo Inlornol. In facl, llo samo probIom llal }ava
vas iniliaIIy dosignod lo soIvo on a smaII scaIo couId aIso bo appIiod lo llo Inlornol on a
Iargo scaIo. Tlis roaIizalion causod llo focus of }ava lo svilcl from consumor oIoclronics
lo Inlornol programming. So, vliIo llo dosiro for an arclilocluro-noulraI programming
Ianguago providod llo iniliaI sparI, llo Inlornol uIlimaloIy Iod lo }ava's Iargo-scaIo succoss.
As monlionod oarIior, }ava dorivos mucl of ils claraclor from C and C++. Tlis is by
inlonl. Tlo }ava dosignors Inov llal using llo famiIiar synlax of C and ocloing llo
objocl-orionlod foaluros of C++ vouId maIo lloir Ianguago appoaIing lo llo Iogions of
oxporioncod C/C++ programmors. In addilion lo llo surfaco simiIarilios, }ava slaros somo
of llo ollor allribulos llal loIpod maIo C and C++ succossfuI. Iirsl, }ava vas dosignod,
loslod, and rofinod by roaI, vorIing programmors. Il is a Ianguago groundod in llo noods
and oxporioncos of llo poopIo vlo dovisod il. Tlus, }ava is a programmor's Ianguago.
Socond, }ava is colosivo and IogicaIIy consislonl. Tlird, oxcopl for lloso conslrainls
imposod by llo Inlornol onvironmonl, }ava givos you, llo programmor, fuII conlroI. If you
program voII, your programs rofIocl il. If you program poorIy, your programs rofIocl llal,
loo. Iul difforonlIy, }ava is nol a Ianguago vill lraining vlooIs. Il is a Ianguago for
profossionaI programmors.
Bocauso of llo simiIarilios bolvoon }ava and C++, il is lompling lo llinI of }ava as simpIy
llo ¨Inlornol vorsion of C++.¨ Hovovor, lo do so vouId bo a Iargo mislaIo. }ava las significanl
praclicaI and pliIosoplicaI difforoncos. WliIo il is lruo llal }ava vas infIuoncod by C++, il is
nol an onlancod vorsion of C++. Ior oxampIo, }ava is noillor upvardIy nor dovnvardIy
compalibIo vill C++. Of courso, llo simiIarilios vill C++ aro significanl, and if you aro a
C++ programmor, llon you viII fooI rigll al lomo vill }ava. Ono ollor poinl: }ava vas nol
dosignod lo ropIaco C++. }ava vas dosignod lo soIvo a corlain sol of probIoms. C++ vas
dosignod lo soIvo a difforonl sol of probIoms. Boll viII cooxisl for many yoars lo como.
As monlionod al llo slarl of llis claplor, compulor Ianguagos ovoIvo for lvo roasons:
lo adapl lo clangos in onvironmonl and lo impIomonl advancos in llo arl of programming.
Tlo onvironmonlaI clango llal promplod }ava vas llo nood for pIalform-indopondonl
programs doslinod for dislribulion on llo Inlornol. Hovovor, }ava aIso ombodios clangos
in llo vay llal poopIo approacl llo vriling of programs. Ior oxampIo, }ava onlancod
and rofinod llo objocl-orionlod paradigm usod by C++, addod inlogralod supporl for
muIlillroading, and providod a Iibrary llal simpIifiod Inlornol accoss. In llo finaI anaIysis,
llougl, il vas nol llo individuaI foaluros of }ava llal mado il so romarIabIo. Rallor, il vas
llo Ianguago as a vloIo. }ava vas llo porfocl rosponso lo llo domands of llo llon novIy
omorging, liglIy dislribulod compuling univorso. }ava vas lo Inlornol programming vlal
C vas lo syslom programming: a rovoIulionary forco llal clangod llo vorId.
Ihe 0# 0oaaect|oa
Tlo roacl and povor of }ava conlinuos lo bo foIl in llo vorId of compulor Ianguago
dovoIopmonl. Many of ils innovalivo foaluros, conslrucls, and concopls lavo bocomo parl
of llo basoIino for any nov Ianguago. Tlo succoss of }ava is simpIy loo imporlanl lo ignoro.
Iorlaps llo mosl imporlanl oxampIo of }ava's infIuonco is C#. Croalod by Microsofl lo
supporl llo .NIT IramovorI, C# is cIosoIy roIalod lo }ava. Ior oxampIo, boll slaro llo
samo gonoraI synlax, supporl dislribulod programming, and uliIizo llo samo objocl modoI.
Tloro aro, of courso, difforoncos bolvoon }ava and C#, bul llo ovoraII ¨IooI and fooI¨ of
lloso Ianguagos is vory simiIar. Tlis ¨cross-poIIinalion¨ from }ava lo C# is llo slrongosl
loslimoniaI lo dalo llal }ava rodofinod llo vay vo llinI aboul and uso a compulor Ianguago.
ßow Iara 0haaged the Iateraet
Tlo Inlornol loIpod calapuIl }ava lo llo forofronl of programming, and }ava, in lurn, lad a
profound offocl on llo Inlornol. In addilion lo simpIifying vob programming in gonoraI,
}ava innovalod a nov lypo of nolvorIod program caIIod llo appIol llal clangod llo vay
llo onIino vorId llougll aboul conlonl. }ava aIso addrossod somo of llo llorniosl issuos
associalod vill llo Inlornol: porlabiIily and socurily. Iol's IooI moro cIosoIy al oacl of lloso.
Iara App|ets
An cpp|ci is a spociaI Iind of }ava program llal is dosignod lo bo lransmillod ovor llo
Inlornol and aulomalicaIIy oxoculod by a }ava-compalibIo vob brovsor. Iurllormoro, an
appIol is dovnIoadod on domand, villoul furllor inloraclion vill llo usor. If llo usor
cIicIs a IinI llal conlains an appIol, llo appIol viII bo aulomalicaIIy dovnIoadod and run in
llo brovsor. AppIols aro inlondod lo bo smaII programs. Tloy aro lypicaIIy usod lo dispIay
dala providod by llo sorvor, landIo usor inpul, or provido simpIo funclions, sucl as a Ioan
caIcuIalor, llal oxoculo IocaIIy, rallor llan on llo sorvor. In ossonco, llo appIol aIIovs somo
funclionaIily lo bo movod from llo sorvor lo llo cIionl.
Tlo croalion of llo appIol clangod Inlornol programming bocauso il oxpandod llo
univorso of objocls llal can movo aboul frooIy in cyborspaco. In gonoraI, lloro aro lvo vory
broad calogorios of objocls llal aro lransmillod bolvoon llo sorvor and llo cIionl: passivo
informalion and dynamic, aclivo programs. Ior oxampIo, vlon you road your o-maiI, you aro
vioving passivo dala. Ivon vlon you dovnIoad a program, llo program's codo is sliII onIy
passivo dala unliI you oxoculo il. By conlrasl, llo appIol is a dynamic, soIf-oxoculing program.
Sucl a programis an aclivo agonl on llo cIionl compulor, yol il is inilialod by llo sorvor.
As dosirabIo as dynamic, nolvorIod programs aro, lloy aIso prosonl sorious probIoms
in llo aroas of socurily and porlabiIily. ObviousIy, a program llal dovnIoads and oxoculos
aulomalicaIIy on llo cIionl compulor musl bo provonlod from doing larm. Il musl aIso bo
abIo lo run in a varioly of difforonl onvironmonls and undor difforonl oporaling sysloms. As
you viII soo, }ava soIvod lloso probIoms in an offoclivo and oIoganl vay. Iol's IooI a bil
moro cIosoIy al oacl.
! | a r t | . ! l t I a t a | a s ¡ s a ¡ t
Secar|t,
As you aro IiIoIy avaro, ovory limo you dovnIoad a ¨normaI¨ program, you aro laIing a
risI, bocauso llo codo you aro dovnIoading migll conlain a virus, Trojan lorso, or ollor
larmfuI codo. Al llo coro of llo probIomis llo facl llal maIicious codo can causo ils damago
bocauso il las gainod unaullorizod accoss lo syslomrosourcos. Ior oxampIo, a virus program
migll gallor privalo informalion, sucl as crodil card numbors, banI accounl baIancos, and
passvords, by soarcling llo conlonls of your compulor's IocaI fiIo syslom. In ordor for }ava
lo onabIo appIols lo bo dovnIoadod and oxoculod on llo cIionl compulor safoIy, il vas
nocossary lo provonl an appIol from Iauncling sucl an allacI.
}ava acliovod llis proloclion by confining an appIol lo llo }ava oxoculion onvironmonl
and nol aIIoving il accoss lo ollor parls of llo compulor. (You viII soo lov llis is
accompIislod slorlIy.) Tlo abiIily lo dovnIoad appIols vill confidonco llal no larm viII
bo dono and llal no socurily viII bo broaclod is considorod by many lo bo llo singIo mosl
innovalivo aspocl of }ava.
Portah|||t,
IorlabiIily is a major aspocl of llo Inlornol bocauso lloro aro many difforonl lypos of
compulors and oporaling sysloms connoclod lo il. If a }ava program voro lo bo run on
virluaIIy any compulor connoclod lo llo Inlornol, lloro noodod lo bo somo vay lo onabIo
llal program lo oxoculo on difforonl sysloms. Ior oxampIo, in llo caso of an appIol, llo
samo appIol musl bo abIo lo bo dovnIoadod and oxoculod by llo vido varioly of CIUs,
oporaling sysloms, and brovsors connoclod lo llo Inlornol. Il is nol praclicaI lo lavo
difforonl vorsions of llo appIol for difforonl compulors. Tlo scmc codo musl vorI on c||
compulors. Tloroforo, somo moans of gonoraling porlabIo oxoculabIo codo vas noodod. As
you viII soon soo, llo samo moclanismllal loIps onsuro socurily aIso loIps croalo porlabiIily.
Iara's Nag|c: Ihe 8,tecode
Tlo Ioy llal aIIovs }ava lo soIvo boll llo socurily and llo porlabiIily probIoms jusl doscribod
is llal llo oulpul of a }ava compiIor is nol oxoculabIo codo. Rallor, il is bylocodo. 8µiccc!c is
a liglIy oplimizod sol of inslruclions dosignod lo bo oxoculod by llo }ava run-limo syslom,
vlicl is caIIod llo jctc Viriuc| Mcc|inc (jVM). In ossonco, llo originaI }VM vas dosignod as
an inicrprcicr |cr |µiccc!c. Tlis may como as a bil of a surpriso sinco many modorn Ianguagos
aro dosignod lo bo compiIod inlo oxoculabIo codo bocauso of porformanco concorns. Hovovor,
llo facl llal a }ava programis oxoculod by llo }VMloIps soIvo llo major probIoms associalod
vill vob-basod programs. Horo is vly.
TransIaling a }ava program inlo bylocodo maIos il mucl oasior lo run a program in
a vido varioly of onvironmonls bocauso onIy llo }VM noods lo bo impIomonlod for oacl
pIalform. Onco llo run-limo pacIago oxisls for a givon syslom, any }ava program can run
on il. Romombor, aIllougl llo dolaiIs of llo }VM viII diffor from pIalform lo pIalform, aII
undorsland llo samo }ava bylocodo. If a }ava program voro compiIod lo nalivo codo, llon
difforonl vorsions of llo samo program vouId lavo lo oxisl for oacl lypo of CIU connoclod
lo llo Inlornol. Tlis is, of courso, nol a foasibIo soIulion. Tlus, llo oxoculion of bylocodo by
llo }VM is llo oasiosl vay lo croalo lruIy porlabIo programs.
Tlo facl llal a }ava program is oxoculod by llo }VM aIso loIps lo maIo il socuro.
Bocauso llo }VM is in conlroI, il can conlain llo program and provonl il from gonoraling
| l a j t t r l . ! l t K i s t t r ¡ a s i | t t l s t i t s t | I a t a !
sido offocls oulsido of llo syslom. As you viII soo, safoly is aIso onlancod by corlain
roslriclions llal oxisl in llo }ava Ianguago.
In gonoraI, vlon a program is compiIod lo an inlormodialo form and llon inlorprolod
by a virluaI maclino, il runs sIovor llan il vouId run if compiIod lo oxoculabIo codo.
Hovovor, vill }ava, llo difforonliaI bolvoon llo lvo is nol so groal. Bocauso bylocodo las
boon liglIy oplimizod, llo uso of bylocodo onabIos llo }VM lo oxoculo programs mucl
faslor llan you migll oxpocl.
AIllougl }ava vas dosignod as an inlorprolod Ianguago, lloro is nolling aboul }ava llal
provonls on-llo-fIy compiIalion of bylocodo inlo nalivo codo in ordor lo boosl porformanco.
Ior llis roason, Sun bogan suppIying ils HolSpol loclnoIogy nol Iong aflor }ava's iniliaI
roIoaso. HolSpol providos a }usl-In-Timo (}IT) compiIor for bylocodo. Wlon a }IT compiIor
is parl of llo }VM, soIoclod porlions of bylocodo aro compiIod inlo oxoculabIo codo in roaI
limo, on a pioco-by-pioco, domand basis. Il is imporlanl lo undorsland llal il is nol praclicaI
lo compiIo an onliro }ava program inlo oxoculabIo codo aII al onco, bocauso }ava porforms
various run-limo clocIs llal can bo dono onIy al run limo. Insload, a }IT compiIor compiIos
codo as il is noodod, during oxoculion. Iurllormoro, nol aII soquoncos of bylocodo aro
compiIod÷onIy lloso llal viII bonofil from compiIalion. Tlo romaining codo is simpIy
inlorprolod. Hovovor, llo jusl-in-limo approacl sliII yioIds a significanl porformanco boosl.
Ivon vlon dynamic compiIalion is appIiod lo bylocodo, llo porlabiIily and safoly foaluros
sliII appIy, bocauso llo }VM is sliII in clargo of llo oxoculion onvironmonl.
Serr|ets: Iara oa the Serrer S|de
As usofuI as appIols can bo, lloy aro jusl ono laIf of llo cIionl/sorvor oqualion. Nol Iong
aflor llo iniliaI roIoaso of }ava, il bocamo obvious llal }ava vouId aIso bo usofuI on llo
sorvor sido. Tlo rosuIl vas llo scrt|ci. AsorvIol is a smaII program llal oxoculos on llo
sorvor. }usl as appIols dynamicaIIy oxlond llo funclionaIily of a vob brovsor, sorvIols
dynamicaIIy oxlond llo funclionaIily of a vob sorvor. Tlus, vill llo advonl of llo sorvIol,
}ava spannod boll sidos of llo cIionl/sorvor connoclion.
SorvIols aro usod lo croalo dynamicaIIy gonoralod conlonl llal is llon sorvod lo llo
cIionl. Ior oxampIo, an onIino sloro migll uso a sorvIol lo IooI up llo prico for an ilom in a
dalabaso. Tlo prico informalion is llon usod lo dynamicaIIy gonoralo a vob pago llal is sonl
lo llo brovsor. AIllougl dynamicaIIy gonoralod conlonl is avaiIabIo llrougl moclanisms sucl
as CGI (Common Galovay Inlorfaco), llo sorvIol offors sovoraI advanlagos, incIuding
incroasod porformanco.
Bocauso sorvIols (IiIo aII }ava programs) aro compiIod inlo bylocodo and oxoculod
by llo }VM, lloy aro liglIy porlabIo. Tlus, llo samo sorvIol can bo usod in a varioly of
difforonl sorvor onvironmonls. Tlo onIy roquiromonls aro llal llo sorvor supporl llo }VM
and a sorvIol conlainor.
Ihe Iara 8attwords
No discussion of }ava's lislory is compIolo villoul a IooI al llo }ava buzzvords. AIllougl
llo fundamonlaI forcos llal nocossilalod llo invonlion of }ava aro porlabiIily and socurily,
ollor faclors aIso pIayod an imporlanl roIo in moIding llo finaI form of llo Ianguago. Tlo
Ioy considoralions voro summod up by llo }ava loam in llo foIIoving Iisl of buzzvords:
l| | a r t | . ! l t I a t a | a s ¡ s a ¡ t
- SimpIo
- Socuro
- IorlabIo
- Objocl-orionlod
- Robusl
- MuIlillroadod
- Arclilocluro-noulraI
- Inlorprolod
- Higl porformanco
- Dislribulod
- Dynamic
Tvo of lloso buzzvords lavo aIroady boon discussod: socuro and porlabIo. Iol's
oxamino vlal oacl of llo ollors impIios.
S|mp|e
}ava vas dosignod lo bo oasy for llo profossionaI programmor lo Ioarn and uso offoclivoIy.
Assuming llal you lavo somo programming oxporionco, you viII nol find }ava lard lo maslor.
If you aIroady undorsland llo basic concopls of objocl-orionlod programming, Ioarning }ava
viII bo ovon oasior. Bosl of aII, if you aro an oxporioncod C++ programmor, moving lo }ava viII
roquiro vory IillIo offorl. Bocauso }ava inlorils llo C/C++ synlax and many of llo
objocl-orionlod foaluros of C++, mosl programmors lavo IillIo lroubIo Ioarning }ava.
0hject-0r|eated
AIllougl infIuoncod by ils prodocossors, }ava vas nol dosignod lo bo sourco-codo compalibIo
vill any ollor Ianguago. Tlis aIIovod llo }ava loam llo froodom lo dosign vill a bIanI
sIalo. Ono oulcomo of llis vas a cIoan, usabIo, pragmalic approacl lo objocls. Borroving
IiboraIIy from many sominaI objocl-soflvaro onvironmonls of llo Iasl fov docados, }ava
managos lo slriIo a baIanco bolvoon llo purisl's ¨ovorylling is an objocl¨ paradigm and
llo pragmalisl's ¨slay oul of my vay¨ modoI. Tlo objocl modoI in }ava is simpIo and oasy
lo oxlond, vliIo primilivo lypos, sucl as inlogors, aro Iopl as ligl-porformanco nonobjocls.
kohast
Tlo muIlipIalformod onvironmonl of llo Wob pIacos oxlraordinary domands on a program,
bocauso llo program musl oxoculo roIiabIy in a varioly of sysloms. Tlus, llo abiIily lo croalo
robusl programs vas givon a ligl priorily in llo dosign of }ava. To gain roIiabiIily, }ava
roslricls you in a fov Ioy aroas lo forco you lo find your mislaIos oarIy in program
dovoIopmonl. Al llo samo limo, }ava froos you from laving lo vorry aboul many of llo
mosl common causos of programming orrors. Bocauso }ava is a slriclIy lypod Ianguago, il
clocIs your codo al compiIo limo. Hovovor, il aIso clocIs your codo al run limo. Many
lard-lo-lracI-dovn bugs llal oflon lurn up in lard-lo-roproduco run-limo silualions aro
simpIy impossibIo lo croalo in }ava. Knoving llal vlal you lavo vrillon viII bolavo in a
prodiclabIo vay undor divorso condilions is a Ioy foaluro of }ava.
| l a j t t r l . ! l t K i s t t r ¡ a s i | t t l s t i t s t | I a t a ll
ll | a r t | . ! l t I a t a | a s ¡ s a ¡ t
To bollor undorsland lov }ava is robusl, considor lvo of llo main roasons for program
faiIuro: momory managomonl mislaIos and mislandIod oxcoplionaI condilions (llal is,
run-limo orrors). Momory managomonl can bo a difficuIl, lodious lasI in lradilionaI
programming onvironmonls. Ior oxampIo, in C/C++, llo programmor musl manuaIIy aIIocalo
and froo aII dynamic momory. Tlis somolimos Ioads lo probIoms, bocauso programmors viII
oillor forgol lo froo momory llal las boon proviousIy aIIocalod or, vorso, lry lo froo somo
momory llal anollor parl of lloir codo is sliII using. }ava virluaIIy oIiminalos lloso probIoms
by managing momory aIIocalion and doaIIocalion for you. (In facl, doaIIocalion is compIoloIy
aulomalic, bocauso }ava providos garbago coIIoclion for unusod objocls.) IxcoplionaI condilions
in lradilionaI onvironmonls oflon ariso in silualions sucl as division by zoro or ¨fiIo nol found,¨
and lloy musl bo managod vill cIumsy and lard-lo-road conslrucls. }ava loIps in llis aroa
by providing objocl-orionlod oxcoplion landIing. In a voII-vrillon }ava program, aII run-limo
orrors can÷and slouId÷bo managod by your program.
Na|t|threaded
}ava vas dosignod lo mool llo roaI-vorId roquiromonl of croaling inloraclivo, nolvorIod
programs. To accompIisl llis, }ava supporls muIlillroadod programming, vlicl aIIovs
you lo vrilo programs llal do many llings simuIlanoousIy. Tlo }ava run-limo syslom
comos vill an oIoganl yol soplislicalod soIulion for muIliprocoss synclronizalion llal
onabIos you lo conslrucl smoollIy running inloraclivo sysloms. }ava's oasy-lo-uso approacl
lo muIlillroading aIIovs you lo llinI aboul llo spocific bolavior of your program, nol llo
muIlilasIing subsyslom.
Arch|tectare-Neatra|
AconlraI issuo for llo }ava dosignors vas llal of codo Iongovily and porlabiIily. Ono of llo
main probIoms facing programmors is llal no guaranloo oxisls llal if you vrilo a program
loday, il viII run lomorrov÷ovon on llo samo maclino. Oporaling syslom upgrados,
procossor upgrados, and clangos in coro syslom rosourcos can aII combino lo maIo a
program maIfunclion. Tlo }ava dosignors mado sovoraI lard docisions in llo }ava Ianguago
and llo }ava VirluaI Maclino in an allompl lo aIlor llis silualion. Tloir goaI vas ¨vrilo
onco, run anyvloro, any limo, forovor.¨ To a groal oxlonl, llis goaI vas accompIislod.
Iaterpreted aad ß|gh Performaace
As doscribod oarIior, }ava onabIos llo croalion of cross-pIalform programs by compiIing
inlo an inlormodialo roprosonlalion caIIod }ava bylocodo. Tlis codo can bo oxoculod on
any syslom llal impIomonls llo }ava VirluaI Maclino. Mosl provious allompls al
cross-pIalform soIulions lavo dono so al llo oxponso of porformanco. As oxpIainod oarIior,
llo }ava bylocodo vas carofuIIy dosignod so llal il vouId bo oasy lo lransIalo diroclIy inlo
nalivo maclino codo for vory ligl porformanco by using a jusl-in-limo compiIor. }ava run-limo
sysloms llal provido llis foaluro Ioso nono of llo bonofils of llo pIalform-indopondonl codo.
0|str|hated
}ava is dosignod for llo dislribulod onvironmonl of llo Inlornol bocauso il landIos TCI/II
prolocoIs. In facl, accossing a rosourco using a URI is nol mucl difforonl from accossing a
fiIo. }ava aIso supporls Rcmcic Mci|c! |ntccciicn (RM|). Tlis foaluro onabIos a program lo
invoIo mollods across a nolvorI.
| l a j t t r l . ! l t K i s t t r ¡ a s i | t t l s t i t s t | I a t a l!
0,aam|c
}ava programs carry vill llom subslanliaI amounls of run-limo lypo informalion llal
is usod lo vorify and rosoIvo accossos lo objocls al run limo. Tlis maIos il possibIo lo
dynamicaIIy IinI codo in a safo and oxpodionl mannor. Tlis is cruciaI lo llo robuslnoss of
llo }ava onvironmonl, in vlicl smaII fragmonls of bylocodo may bo dynamicaIIy updalod
on a running syslom.
Ihe £ro|at|oa of Iara
Tlo iniliaI roIoaso of }ava vas nolling slorl of rovoIulionary, bul il did nol marI llo ond of
}ava's ora of rapid innovalion. UnIiIo mosl ollor soflvaro sysloms llal usuaIIy sollIo inlo a
pallorn of smaII, incromonlaI improvomonls, }ava conlinuod lo ovoIvo al an oxpIosivo paco.
Soon aflor llo roIoaso of }ava 1.0, llo dosignors of }ava lad aIroady croalod }ava 1.1. Tlo
foaluros addod by }ava 1.1 voro moro significanl and subslanliaI llan llo incroaso in llo
minor rovision numbor vouId lavo you llinI. }ava 1.1 addod many nov Iibrary oIomonls,
rodofinod llo vay ovonls aro landIod, and roconfigurod many foaluros of llo 1.0 Iibrary. Il
aIso doprocalod (rondorod obsoIolo) sovoraI foaluros originaIIy dofinod by }ava 1.0. Tlus,
}ava 1.1 boll addod lo and sublraclod from allribulos of ils originaI spocificalion.
Tlo noxl major roIoaso of }ava vas }ava 2, vloro llo ¨2¨ indicalos ¨socond gonoralion.¨
Tlo croalion of }ava 2 vas a valorslod ovonl, marIing llo boginning of }ava's ¨modorn
ago.¨ Tlo firsl roIoaso of }ava 2 carriod llo vorsion numbor 1.2. Il may soom odd llal llo
firsl roIoaso of }ava 2 usod llo 1.2 vorsion numbor. Tlo roason is llal il originaIIy roforrod
lo llo inlornaI vorsion numbor of llo }ava Iibrarios, bul llon vas gonoraIizod lo rofor lo
llo onliro roIoaso. Will }ava 2, Sun ropacIagod llo }ava producl as }2SI (}ava 2 IIalform
Slandard Idilion), and llo vorsion numbors bogan lo bo appIiod lo llal producl.
}ava 2 addod supporl for a numbor of nov foaluros, sucl as Sving and llo CoIIoclions
IramovorI, and il onlancod llo }ava VirluaI Maclino and various programming looIs. }ava
2 aIso conlainod a fov doprocalions. Tlo mosl imporlanl affoclod llo Thread cIass in vlicl
llo mollods suspend( ), resume( ), and stnp( ) voro doprocalod.
}2SI 1.3 vas llo firsl major upgrado lo llo originaI }ava 2 roIoaso. Ior llo mosl parl,
il addod lo oxisling funclionaIily and ¨ligllonod up¨ llo dovoIopmonl onvironmonl. In
gonoraI, programs vrillon for vorsion 1.2 and lloso vrillon for vorsion 1.3 aro sourco-codo
compalibIo. AIllougl vorsion 1.3 conlainod a smaIIor sol of clangos llan llo procoding
llroo major roIoasos, il vas novorlloIoss imporlanl.
Tlo roIoaso of }2SI 1.4 furllor onlancod }ava. Tlis roIoaso conlainod sovoraI imporlanl
upgrados, onlancomonls, and addilions. Ior oxampIo, il addod llo nov Ioyvord assert,
clainod oxcoplions, and a clannoI-basod I/O subsyslom. Il aIso mado clangos lo llo
CoIIoclions IramovorI and llo nolvorIing cIassos. In addilion, numorous smaII clangos
voro mado llrougloul. Dospilo llo significanl numbor of nov foaluros, vorsion 1.4
mainlainod noarIy 100 porconl sourco-codo compalibiIily vill prior vorsions.
Tlo noxl roIoaso of }ava vas }2SI 5, and il vas rovoIulionary. UnIiIo mosl of llo provious
}ava upgrados, vlicl offorod imporlanl, bul moasurod improvomonls, }2SI 5 fundamonlaIIy
oxpandod llo scopo, povor, and rango of llo Ianguago. To grasp llo magniludo of llo
clangos llal }2SI 5 mado lo }ava, considor llo foIIoving Iisl of ils major nov foaluros:
- Gonorics
- Annolalions
- Auloboxing and aulo-unboxing
l! | a r t | . ! l t I a t a | a s ¡ s a ¡ t
- Inumoralions
- Inlancod, for-oacl slyIo Inr Ioop
- VariabIo-Iongll argumonls (varargs)
- Slalic imporl
- Iormallod I/O
- Concurroncy uliIilios
Tlis is nol a Iisl of minor lvoaIs or incromonlaI upgrados. Iacl ilom in llo Iisl roprosonls
a significanl addilion lo llo }ava Ianguago. Somo, sucl as gonorics, llo onlancod Inr, and
varargs, inlroduco nov synlax oIomonls. Ollors, sucl as auloboxing and aulo-unboxing,
aIlor llo somanlics of llo Ianguago. Annolalions add an onliroIy nov dimonsion lo
programming. In aII casos, llo impacl of lloso addilions vonl boyond lloir dirocl offocls.
Tloy clangod llo vory claraclor of }ava ilsoIf.
Tlo imporlanco of lloso nov foaluros is rofIoclod in llo uso of llo vorsion numbor
¨5.¨ Tlo noxl vorsion numbor for }ava vouId normaIIy lavo boon 1.5. Hovovor, llo nov
foaluros voro so significanl llal a slifl from 1.4 lo 1.5 jusl didn'l soom lo oxpross llo
magniludo of llo clango. Insload, Sun oIoclod lo incroaso llo vorsion numbor lo 5 as a vay
of omplasizing llal a major ovonl vas laIing pIaco. Tlus, il vas namod }2SI 5, and llo
dovoIopor's Iil vas caIIod }DK 5. Hovovor, in ordor lo mainlain consisloncy, Sun docidod
lo uso 1.5 as ils inicrnc| tcrsicn numbor, vlicl is aIso roforrod lo as llo !ctc|cpcr tcrsicn
numbor. Tlo ¨5¨ in }2SI 5 is caIIod llo prc!uci tcrsicn numbor.
Iara S£ 0
Tlo novosl roIoaso of }ava is caIIod }ava SI 6, and llo maloriaI in llis booI las boon updalod
lo rofIocl llis Ialosl vorsion of }ava. Will llo roIoaso of }ava SI 6, Sun onco again docidod lo
clango llo namo of llo }ava pIalform. Iirsl, nolico llal llo ¨2¨ las boon droppod. Tlus, llo
pIalform nov las llo namo jctc S|, and llo officiaI producl namo is jctc P|ci|crm, Sicn!cr!
|!iiicn 6. As vill }2SI 5, llo 6 in }ava SI 6 is llo producl vorsion numbor. Tlo inlornaI,
dovoIopor vorsion numbor is 1.6.
}ava SI 6 buiIds on llo baso of }2SI 5, adding incromonlaI improvomonls. }ava SI 6
adds no major foaluros lo llo }ava Ianguago propor, bul il doos onlanco llo AII Iibrarios,
add sovoraI nov pacIagos, and offor improvomonls lo llo run limo. As il roIalos lo llis
booI, il is llo clangos lo llo coro AII llal aro llo mosl nolabIo. Many of llo pacIagos
lavo nov cIassos, and many of llo cIassos lavo nov mollods. Tloso clangos aro indicalod
llrougloul llo booI. In gonoraI, llo roIoaso of }ava SI 6 sorvos lo furllor soIidify llo
advancos mado by }2SI 5.
A 0a|tare of Iaaorat|oa
Sinco llo boginning, }ava las boon al llo conlor of a cuIluro of innovalion. Ils originaI roIoaso
rodofinod programming for llo Inlornol. Tlo }ava VirluaI Maclino (}VM) and bylocodo
clangod llo vay vo llinI aboul socurily and porlabiIily. Tlo appIol (and llon llo sorvIol)
mado llo Wob como aIivo. Tlo }ava Communily Irocoss (}CI) rodofinod llo vay llal nov
idoas aro assimiIalod inlo llo Ianguago. Tlo vorId of }ava las novor slood sliII for vory
Iong. }ava SI 6 is llo Ialosl roIoaso in }ava's ongoing, dynamic lislory.
l
Æs êttrtitw t| Iata
A
s in aII ollor compulor Ianguagos, llo oIomonls of }ava do nol oxisl in isoIalion.
Rallor, lloy vorI logollor lo form llo Ianguago as a vloIo. Hovovor, llis
inlorroIalodnoss can maIo il difficuIl lo doscribo ono aspocl of }ava villoul
invoIving sovoraI ollors. Oflon a discussion of ono foaluro impIios prior InovIodgo of
anollor. Ior llis roason, llis claplor prosonls a quicI ovorviov of sovoraI Ioy foaluros
of }ava. Tlo maloriaI doscribod loro viII givo you a foolloId llal viII aIIov you lo vrilo
and undorsland simpIo programs. Mosl of llo lopics discussod viII bo oxaminod in groalor
dolaiI in llo romaining claplors of Iarl I.
0hject-0r|eated Programm|ag
Objocl-orionlod programming (OOI) is al llo coro of }ava. In facl, aII }ava programs aro lo al
Ioasl somo oxlonl objocl-orionlod. OOI is so inlograI lo }ava llal il is bosl lo undorsland ils
basic principIos boforo you bogin vriling ovon simpIo }ava programs. Tloroforo, llis claplor
bogins vill a discussion of llo lloorolicaI aspocls of OOI.
Iwo Parad|gms
AII compulor programs consisl of lvo oIomonls: codo and dala. Iurllormoro, a program can
bo concopluaIIy organizod around ils codo or around ils dala. Tlal is, somo programs aro
vrillon around ¨vlal is lapponing¨ and ollors aro vrillon around ¨vlo is boing affoclod.¨
Tloso aro llo lvo paradigms llal govorn lov a program is conslruclod. Tlo firsl vay is
caIIod llo prcccss-cricnic! mc!c|. Tlis approacl claraclorizos a program as a sorios of Iinoar
slops (llal is, codo). Tlo procoss-orionlod modoI can bo llougll of as cc!c cciing cn !cic.
IrocoduraI Ianguagos sucl as C ompIoy llis modoI lo considorabIo succoss. Hovovor, as
monlionod in Claplor 1, probIoms vill llis approacl appoar as programs grov Iargor and
moro compIox.
To manago incroasing compIoxily, llo socond approacl, caIIodc|jcci-cricnic! prcgrcmming,
vas concoivod. Objocl-orionlod programming organizos a program around ils dala (llal is,
objocls) and a sol of voII-dofinod inlorfacos lo llal dala. An objocl-orionlod program can bo
claraclorizod as !cic ccnirc||ing ccccss ic cc!c. As you viII soo, by svilcling llo conlroIIing
onlily lo dala, you can acliovo sovoraI organizalionaI bonofils.
l ¡

the de facto standard for C was the one supplied with the UNIX operating system and described in The C Programming Language by Brian Kernighan and Dennis Ritchie (Prentice-Hall. Further. developed by Martin Richards. although FORTRAN could be used to write fairly efficient programs for scientific applications. For example. and FORTRAN were not designed around structured principles. it was not very good for system code. it was not practical to consider using Pascal for systems-level code. Another compounding problem was that early computer languages such as BASIC. a secondary force was beginning to be felt. the stage was set for a quantum leap forward in computer languages. high-level language that could replace assembly code when creating systems programs. trade-offs are often made. For the first time. Instead. And while BASIC was easy to learn. programs written using these languages tended to produce "spaghetti code" -a mass of tangled jumps and conditional branches that make a program virtually impossible to understand. it wasn't very powerful. For many years. they were not designed for efficiency. which led to the development of C in the 1970s. Its impact should not be underestimated. COBOL. As a result. programmers usually had to choose between languages that optimized one set of traits or the other.) So. By the early 1970s. . and perhaps most importantly. This allowed the freedom to experiment. The creation of C was a direct result of the need for a structured. But. programmers were gaining virtually unlimited access to their machines. Assembly language can be used to produce highly efficient programs. 1978). Computer hardware was finally becoming common enough that a critical mass was being reached. While languages like Pascal are structured. given the standard dialects of Pascal available at the time. It also allowed programmers to begin to create their own tools. invented by Ken Thompson. No longer were computers kept behind locked doors. BCPL influenced a language called B. Invented and first implemented by Dennis Ritchie on a DEC PDP-ll running the UNIX operating system. and the demand for software was rapidly outpacing programmers' ability to produce it. when the American National Standards Institute (ANSI) standard for C was adopted. C was formally standardized in December 1989. C was the result of a development process that started with an older language called BCPL. and its lack of structure made its usefulness questionable for large programs. debugging assembly code can be quite difficult. Yet the need for such a language was pressing. they relied upon the GOTO as a primary means of program control. but it is not easy to learn or use effectively. and failed to include certain features necessary to make them applicable to a wide range of programs. As you probably know. no one language had reconciled the conflicting attributes that had dogged earlier efforts. (Specifically. when a computer language is designed. the computer revolution was beginning to take hold. efficient.4 Part I: The Java Language The Birth of Modern Programming: C The C language shook the computer world. On the eve of C's creation. just prior to the invention of C. A great deal of effort was being expended in academic circles in an attempt to create a better computer language. such as the following: • Ease-of-use versus power • Safety versus efficiency • Rigidity versus extensibility Prior to C. because it fundamentally changed the way programming was approached and thought about.

the increasing complexity of programs has driven the need for better ways to manage that complexity. structured language that was relatively easy to learn. Prior to the invention of C. programming was done by manually toggling in the binary machine instructions by use of the front panel. but here is a brief definition: OOP is a programming methodology that helps organize complex programs through the use of inheritance. Its features were honed. To solve this problem. it is hardly a language that encourages clear and easy-to-understand programs. By the early 1980s. and polymorphism. To better understand why managing program complexity is fundamental to the creation of C++. although C is one of the world's great programming languages. Object-oriented programming is discussed in detail later in this book. a new way to program was invented. you might ask why a need for something else existed. C is a language designed by and for programmers. In short. many projects were pushing the structured approach past its limits. However. The use of structured languages enabled programmers to write. As programs continued to grow. it found wide and rapid acceptance in the programmer community. it becomes so complex that it is difficult to grasp as a totality. The result was a powerful. even with structured programming methods. While FORTRAN was an impressive first step. moderately complex programs fairly easily. consider the following. there is always a threshold at which a program becomes unmanageable. once a project reaches a certain size. allowing programmers to comprehend and manage larger programs. The 1960s gave birth to structured programming. Approaches to programming have changed dramatically since the invention of the computer. its complexity exceeds what a programmer can manage. called object-oriented programming (OOP). C quickly attracted many followers who had a near-religious zeal for it. It was designed. and rethought by the people who actually used the language. Since C is a successful and useful language. encapsulation. computer languages were generally designed either as academic exercises or by bureaucratic committees. and developed by real. assembly language was invented so that a programmer could deal with larger. reflecting the way that they approached the job of programming. This is the method of programming championed by languages such as C. The answer is complexity. It also included one other. of course. As such. high-level languages were introduced that gave the programmer more tools with which to handle complexity. C++: The Next Step During the late 1970s and early 1980s. Java inherited this legacy. efficient. nearly intangible aspect: it was a programmer's language. Throughout the history of programming. thought about. Indeed. Once the size of a program exceeds a certain point. . and it is still widely used today. The first widespread language was. this approach worked. for the first time. there is a limit to its ability to handle complexity. FORTRAN. working programmers. In the final analysis. As programs grew. increasingly complex programs by using symbolic representations of the machine instructions. As long as programs were just a few hundred instructions long. implemented. tested. As you will see. While the precise size at which this occurs differs. depending upon both the nature of the program and the programmer. C++ is a response to that need. It successfully synthesized the conflicting attributes that had so troubled earlier languages. C is different. when computers were first invented. C++ added features that enabled this threshold to be broken.Chapter 1: The History and Evolution of Java 5 The creation of C is considered by many to have marked the beginning of the modem age of computer languages. C became the dominant computer programming language. The result was a language that programmers liked to use. For example.

The problem is that compilers are expensive and time-consuming to create. It took 18 months to develop the first working version. Indeed. As you can probably guess. of course. platform-independent language that could be used to produce code that would run on a variety of CPUs under differing environments. and Mike Sheridan at Sun Microsystems. and Tim Lindholm were key contributors to the maturing of the original prototype. The invention of C++ was not an attempt to create a completely new programming language. Stroustrup initially called the new language "C with Classes. Java might have remained a useful but obscure language for programming consumer electronics." but was renamed "Java" in 1995. while he was working at Bell Laboratories in Murray Hill. the primary motivation was the need for a platform-independent (that is. attributes. Frank Yellin. Between the initial implementation of Oak in the fall of 1992 and the public announcement of Java in the spring of 1995. a second. This effort ultimately led to the creation of Java." However. demanded portable programs. Ed Frank.6 Part I: The Java Language Ct+ was invented by Bjarne Stroustrup in 1979. The trouble with C and C++ (and most other languages) is that they are designed to be compiled for a specific target. Chris Warth. the World Wide Web. because the Web. This second force was. This event would precipitate another revolution in programming. Somewhat surprisingly. once again. This is a crucial reason for the success of C++ as a language. too. architecture-neutral) language that could be used to create software to be embedded in various consumer electronic devices. In an attempt to find such a solution. Instead. and benefits. the name was changed to C++. just as in the past. it includes all of C's features. New Jersey. However. it was an enhancement to an already highly successful one. and ultimately more important. Bill Joy. the World Wide Web and the Internet would reach critical mass. Although it is possible to compile a C++ program for just about any type of CPU. About the time that the details of Java were being worked out. Because C++ is built on the foundation of C. Inc. in 1991. Within a few years. However. forces were brewing that would. object-oriented programming using C++ took hold. many different types of CPUs are used as controllers. to do so requires a full C++ compiler targeted for that CPU. in 1983. factor was emerging that would playa crucial role in the future of Java. . the original impetus for Java was not the Internet! Instead. Java was propelled to the forefront of computer language design. many more people contributed to the design and evolution of the language. Gosling and others began work on a portable. Arthur van Hoff. such as microwave ovens and remote controls. Had the Web not taken shape at about the same time that Java was being implemented. drive computer language evolution forward. Jonathan Payne. The Stage Is Set for Java By the end of the 1980s and the early 1990s. with the emergence of the World Wide Web. An easier-and more cost-efficient-solution was needed. for a brief moment it seemed as if programmers had finally found the perfect language. C++ extends C by adding object-oriented features. Patrick Naughton. it was a language that could be used to create a wide range of programs. Because C++ blended the high efficiency and stylistic elements of C with the object-oriented paradigm. The Creation of Java Java was conceived by James Gosling. This language was initially called "Oak.

the same problem that Java was initially designed to solve on a small scale could also be applied to the Internet on a large scale. Further. except for those constraints imposed by the Internet environment. and if you are a C++ programmer. portable (platform-independent) programs is nearly as old as the discipline of programming itself. While it is true that Java was influenced by C++. Java gives you. with the advent of the Internet and the Web. In addition to the surface similarities. and UNIX. As mentioned at the start of this chapter. In the final analysis. added integrated support for multithreading. Thus. the old problem of portability returned with a vengeance. Java shares some of the other attributes that helped make C and C++ successful. then you will feel right at home with Java. to do so would be a large mistake. Second. Because of the similarities between Java and C++. it had taken a back seat to other. it is tempting to think of Java as simply the "Internet version of C++. too. it was . Java also embodies changes in the way that people approach the writing of programs. However. Java is cohesive and logically consistent. Macintosh. So. Of course. If you program well. Both will coexist for many years to come. distributed universe populated with various types of computers. it became obvious to members of the Java design team that the problems of portability frequently encountered when creating code for embedded controllers are also found when attempting to create code for the Internet. because (at that time) much of the computer world had divided itself into the three competing camps of Intel. operating systems. the similarities with C++ are significant. Java was designed. For example. Java is not a language with training wheels. users would like them all to be able to run the same program. it was not the individual features of Java that made it so remarkable. However. Put differently. more pressing problems. Third. and the urgent need for portable code was reduced. If you program poorly. By 1993. While the quest for a way to create efficient. and provided a library that simplified Internet access." However. This is by intent. most programmers stayed within their fortified boundaries. Even though many kinds of platforms are attached to the Internet. and refined by real. Java has significant practical and philosophical differences. The environmental change that prompted Java was the need for platform-independent programs destined for distribution on the Internet. It is a language for professional programmers. it is not an enhanced version of C++. After all. One other point: Java was not designed to replace C++. Java was designed to solve a certain set of problems. working programmers. This realization caused the focus of Java to switch from consumer electronics to Internet programming. For example. Java is neither upwardly nor downwardly compatible with C++. Java is a programmer's language. the Internet ultimately led to Java's large-scale success. C++ was designed to solve a different set of problems. the Internet consists of a diverse. full control. computer languages evolve for two reasons: to adapt to changes in environment and to implement advances in the art of programming. Java derives much of its character from C and C++. Rather. and CPUs. tested. What was once an irritating but low-priority problem had become a high-profile necessity. the programmer. your programs reflect that.Chapter 1: The History and Evolution of Java 7 Most programmers learn early in their careers that portable programs are as elusive as they are desirable. As mentioned earlier. Java enhanced and refined the object-oriented paradigm used by C++. In fact. First. The Java designers knew that using the familiar syntax of C and echoing the object-oriented features of C++ would make their language appealing to the legions of experienced C/C++ programmers. though. your programs reflect it. It is a language grounded in the needs and experiences of the people who devised it. while the desire for an architecture-neutral programming language provided the initial spark.

Many of its innovative features.NET Framework. networked programs are. such as a loan calculator. As desirable as dynamic. In general. but the overall "look and feel" of these languages is very similar. self-executing program. They are typically used to display data provided by the server. rather than on the server. It must also be able to run in a variety of different environments and under different operating systems. Let's look more closely at each of these. an applet is downloaded on demand. For example. This "cross-pollination" from Java to C# is the strongest testimonial to date that Java redefined the way we think about and use a computer language. a program that downloads and executes automatically on the client computer must be prevented from doing harm. Applets are intended to be small programs. had a profound effect on the Internet. Java solved these problems in an effective and elegant way. Such a program is an active agent on the client computer. C# is closely related to Java. . or provide simple functions. the applet allows some functionality to be moved from the server to the client. Even when you download a program. when you read your e-mail. and concepts have become part of the baseline for any new language. Java was to Internet programming what C was to system programming: a revolutionary force that changed the world. the applet is a dynamic. both share the same general syntax. differences between Java and C#. yet it is initiated by the server. Obviously. Perhaps the most important example of Java's influence is C#. How Java Changed the Internet The Internet helped catapult Java to the forefront of programming. of course. you are viewing passive data. Furthermore. that execute locally. Java Applets An applet is a special kind of Java program that is designed to be transmitted over the Internet and automatically executed by a Java-compatible web browser. there are two very broad categories of objects that are transmitted between the server and the client: passive information and dynamic. and utilize the same object modeL There are. without further interaction with the user. support distributed programming. As you will see. Java was the perfect response to the demands of the then newly emerging. the program's code is still only passive data until you execute it. handle user input. For example. Java innovated a new type of networked program called the applet that changed the way the online world thought about content. highly distributed computing universe. In addition to simplifying web programming in general. The success of Java is simply too important to ignore. The creation of the applet changed Internet programming because it expanded the universe of objects that can move about freely in cyberspace. constructs. Created by Microsoft to support the .8 Part I: The Java Language the language as a whole. By contrast. If the user clicks a link that contains an applet. In essence. Let's look a bit more closely at each. The C# Connection The reach and power of Java continues to be felt in the world of computer language development. in tum. Java also addressed some of the thorniest issues associated with the Internet: portability and security. the applet will be automatically downloaded and run in the browser. active programs. they also present serious problems in the areas of security and portability. and Java.

the original JVM was designed as an interpreter for bytecode. or other harmful code. In essence. which is called the Java Virtual Machine (JVM). However. all understand the same Java bytecode. a virus program might gather private information. The fact that a Java program is executed by the JVM also helps to make it secure. although the details of the JVM will differ from platform to platform.) The ability to download applets with confidence that no harm will be done and that no security will be breached is considered by many to be the single most innovative aspect of Java. Trojan horse. it can contain the program and prevent it from generating . you are taking a risk. of course. The same code must work on all computers. Here is why. not a feasible solution. such as credit card numbers. This is. Thus. it is bytecode. any Java program can run on it. because the code you are downloading might contain a virus. the same mechanism that helps ensure security also helps create portability. Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system. the fact that a Java program is executed by the JVM helps solve the major problems associated with web-based programs. Translating a Java program into bytecode makes it much easier to run a program in a wide variety of environments because only the JVM needs to be implemented for each platform. For example. and passwords. the execution of bytecode by the JVM is the easiest way to create truly portable programs. in the case of an applet. In order for Java to enable applets to be downloaded and executed on the client computer safely. Rather. Portability Portability is a major aspect of the Internet because there are many different types of computers and operating systems connected to it. At the core of the problem is the fact that malicious code can cause its damage because it has gained unauthorized access to system resources. bank account balances. It is not practical to have different versions of the applet for different computers. This may come as a bit of a surprise since many modern languages are designed to be compiled into executable code because of performance concerns. operating systems.Chapter 1: The History and Evolution of Java 9 Security As you are likely aware. some means of generating portable executable code was needed. Remember. As you will soon see. (You will see how this is accomplished shortly. the same applet must be able to be downloaded and executed by the wide variety of CPUs. every time you download a "normal" program. by searching the contents of your computer's local file system. Therefore. then different versions of the same program would have to exist for each type of CPU connected to the Internet. For example. Java's Magic: The 8ytecode The key that allows Java to solve both the security and the portability problems just described is that the output of a Java compiler is not executable code. there needed to be some way to enable that program to execute on different systems. Once the run-time package exists for a given system. If a Java program were compiled to native code. and browsers connected to the Internet. If a Java program were to be run on virtually any computer connected to the Internet. Java achieved this protection by confining an applet to the Java execution environment and not allowing it access to other parts of the computer. Because the JVM is in control. it was necessary to prevent an applet from launching such an attack.

For example. The price information is then used to dynamically generate a web page that is sent to the browser. As you will see. not all sequences of bytecode are compiled=-only those that will benefit from compilation. they are highly portable. The Java Buzzwords No discussion of Java's history is complete without a look at the Java buzzwords. When a JIT compiler is part of the JVM. safety is also enhanced by certain restrictions that exist in the Java language. they are just one half of the client/ server equation. Instead. an online store might use a servlet to look up the price for an item in a database. Just as applets dynamically extend the functionality of a web browser.Time OIT) compiler for bytecode. the just-in-time approach still yields a significant performance boost. Although dynamically generated content is available through mechanisms such as CGI (Common Gateway Interface). because the JVM is still in charge of the execution environment. the servlet offers several advantages. However. with Java. the use of bytecode enables the JVM to execute programs much faster than you might expect. Thus. In general. selected portions of bytecode are compiled into executable code in real time. Furthermore. The result was the servlet. It is important to understand that it is not practical to compile an entire Java program into executable code all at once. The only requirements are that the server support the JVM and a servlet container. A servlet is a small program that executes on the server. when a program is compiled to an intermediate form and then interpreted by a virtual machine. demand basis. the portability and safety features still apply. a JIT compiler compiles code as it is needed. Not long after the initial release of Java. Java spanned both sides of the client/ server connection. other factors also played an important role in molding the final form of the language. The remaining code is simply interpreted. Sun began supplying its HotSpot technology not long after Java's initial release. the same servlet can be used in a variety of different server environments.10 Par t I: The Ja vaL a n g u age side effects outside of the system. Servlets: Java on the Server Side As useful as applets can be. HotSpot provides a Just. Servlets are used to create dynamically generated content that is then served to the client. it runs slower than it would run if compiled to executable code. For this reason. Because bytecode has been highly optimized. because Java performs various run-time checks that can be done only at run time. Even when dynamic compilation is applied to bytecode. Thus. Although Java was designed as an interpreted language. on a piece-by-piece. there is nothing about Java that prevents on-the-fly compilation of bytecode into native code in order to boost performance. The key considerations were summed up by the Java team in the following list of buzzwords: . including increased performance. servlets dynamically extend the functionality of a web server.In. Although the fundamental forces that necessitated the invention of Java are portability and security. However. Because servlets (like all Java programs) are compiled into bytecode and executed by the JVM. it became obvious that Java would also be useful on the server side. the differential between the two is not so great. during execution. with the advent of the servlet.

Java was not designed to be source-code compatible with any other language. Java frees you from having to worry about many of the most common causes of programming errors. . it checks your code at compile time. One outcome of this was a clean. Let's examine what each of the others implies. Thus. moving to Java will require very little effort. Borrowing liberally from many seminal object-software environments of the last few decades. Object-Oriented Although influenced by its predecessors. Many hard-to-track-down bugs that often tum up in hard-to-reproduce run-time situations are simply impossible to create in Java. learning Java will be even easier. Knowing that what you have written will behave in a predictable way under diverse conditions is a key feature of Java. most programmers have little trouble learning Java. pragmatic approach to objects. the ability to create robust programs was given a high priority in the design of Java. If you already understand the basic concepts of object-oriented programming. you will not find Java hard to master. are kept as high-performance nonobjects. usable.Chapter 1: The History and Evolution of Java 11 • Simple • Secure • Portable • Object-oriented • Robust • Multithreaded • Architecture-neutral • Interpreted • High performance • Distributed • Dynamic Two of these buzzwords have already been discussed: secure and portable. To gain reliability. while primitive types. At the same time. it also checks your code at run time. such as integers. This allowed the Java team the freedom to design with a blank slate. However. Best of all. because the program must execute reliably in a variety of systems. The object model in Java is simple and easy to extend. Java restricts you in a few key areas to force you to find your mistakes early in program development. Simple Java was designed to be easy for the professional programmer to learn and use effectively. if you are an experienced C++ programmer. Assuming that you have some programming experience. Robust The multiplatformed environment of the Web places extraordinary demands on a program. Because Java is a strictly typed language. Java manages to strike a balance between the purist's "everything is an object" paradigm and the pragmatist's "stay out of my way" model. Because Java inherits the C/C++ syntax and many of the object-oriented features of C++.

this goal was accomplished. Multithreaded Java was designed to meet the real-world requirement of creating interactive. This sometimes leads to problems. consider two of the main reasons for program failure: memory management mistakes and mishandled exceptional conditions (that is. In a well-written Java program. because Java provides garbage collection for unused objects." To a great extent. . Java run-time systems that provide this feature lose none of the benefits of the platform-independent code. Java helps in this area by providing object-oriented exception handling. This code can be executed on any system that implements the Java Virtual Machine. any time. the programmer must manually allocate and free all dynamic memory. try to free some memory that another part of their code is still using. deallocation is completely automatic. In fact. worse. not the multitasking subsystem. Operating system upgrades. which allows you to write programs that do many things simultaneously." and they must be managed with clumsy and hard-to-read constructs. This feature enables a program to invoke methods across a network. in CIC++. Java's easy-to-use approach to multithreading allows you to think about the specific behavior of your program. The Java run-time system comes with an elegant yet sophisticated solution for multiprocess synchronization that enables you to construct smoothly running interactive systems. Most previous attempts at cross-platform solutions have done so at the expense of performance. (In fact. run-time errors). Arch itectu re-N eutra I A central issue for the Java designers was that of code longevity and portability. it will run tomorrow-even on the same machine. Distributed Java is designed for the distributed environment of the Internet because it handles TCP lIP protocols. all run-time errors can-and should-be managed by your program. Java enables the creation of cross-platform programs by compiling into an intermediate representation called Java bytecode. One of the main problems facing programmers is that no guarantee exists that if you write a program today. run anywhere. the Java bytecode was carefully designed so that it would be easy to translate directly into native machine code for very high performance by using a just-in-time compiler. Java supports multithreaded programming. Their goal was "write once. To accomplish this. As explained earlier. Memory management can be a difficult. accessing a resource using a URL is not much different from accessing a file. Interpreted and High Performance As described earlier. forever. and changes in core system resources can all combine to make a program malfunction.12 Par t I: The Ja vaL a n g u age To better understand how Java is robust. Java virtually eliminates these problems by managing memory allocation and deallocation for you. For example.) Exceptional conditions in traditional environments often arise in situations such as division by zero or "file not found. The Java designers made several hard decisions in the Java language and the Java Virtual Machine in an attempt to alter this situation. tedious task in traditional programming environments. Java also supports Remote Method Invocation (RMI). processor upgrades. because programmers will either forget to free memory that has been previously allocated or. networked programs.

For example. power. and it was revolutionary. it was nevertheless important. and reconfigured many features of the 1. The Evolution of Java The initial release of Java was nothing short of revolutionary. enhancements.1 were more significant and substantial than the increase in the minor revision number would have you think. In addition. With Java 2. This makes it possible to dynamically link code in a safe and expedient manner. consider the following list of its major new features: • Generics • Annotations • Autoboxing and auto-unboxing . J2SE 5 fundamentally expanded the scope. and additions. it added the new keyword assert. Despite the significant number of new features. Thus. but then was generalized to refer to the entire release. and a channel-based I/O subsystem.0. This release contained several important upgrades. Java continued to evolve at an explosive pace.1. and stop() were deprecated. It also made changes to the Collections Framework and the networking classes.0. The next release of Java was J2SE 5. resume(). Java 1. The features added by Java 1. chained exceptions.0 library. in which small fragments of bytecode may be dynamically updated on a running system. Sun repackaged the Java product as J2SE (Java 2 Platform Standard Edition). Soon after the release of Java 1. which offered important. The next major release of Java was Java 2. For the most part. To grasp the magnitude of the changes that J2SE 5 made to Java. The most important affected the Thread class in which the methods suspend(). and the version numbers began to be applied to that product.1 both added to and subtracted from attributes of its original specification. It may seem odd that the first release of Java 2 used the 1.3 contained a smaller set of changes than the preceding three major releases. Unlike most other software systems that usually settle into a pattern of small.3 are source-code compatible. Unlike most of the previous Java upgrades. such as Swing and the Collections Framework. but it did not mark the end of Java's era of rapid innovation.2 version number. version 1. it added to existing functionality and "tightened up" the development environment. Java 2 also contained a few deprecations. Java 1. Java 2 added support for a number of new features. It also deprecated (rendered obsolete) several features originally defined by Java 1. programs written for version 1." The creation of Java 2 was a watershed event. In general. incremental improvements. where the "2" indicates "second generation.2 and those written for version 1. and range of the language. marking the beginning of Java's "modern age. but measured improvements.4 maintained nearly 100 percent source-code compatibility with prior versions.1 added many new library elements." The first release of Java 2 carried the version number 1. the designers of Java had already created Java 1. The release of J2SE 1. numerous small changes were made throughout. and it enhanced the Java Virtual Machine and various programming tools.3 was the first major upgrade to the original Java 2 release.4 further enhanced Java.2. This is crucial to the robustness of the Java environment. Although version 1. redefined the way events are handled. The reason is that it originally referred to the internal version number of the Java libraries.C hap t e r 1: The His tor y and E v 0 I uti 0 n 0 f Ja v a 13 Dynamic Java programs carry with them substantial amounts of run-time type information that is used to verify and resolve accesses to objects at run time. J2SE 1.

for-each style for loop • Variable-length • Static import • Formatted I/O utilities • Concurrency arguments (varargs) This is not a list of minor tweaks or incremental upgrades. Java has been at the center of a culture of innovation.6. The Java Community Process OCP) redefined the way that new ideas are assimilated into the language. and the developer's kit was called JOK 5. Many of the packages have new classes. First. dynamic history. introduce new syntax elements. Java SE 6 The newest release of Java is called Java SE 6. Java SE 6 builds on the base of J2SE 5. The applet (and then the servlet) made the Web come alive. . but it does enhance the API libraries. Java SE 6 is the latest release in Java's ongoing. adding incremental improvements. Each item in the list represents a significant addition to the Java language.5 as its internal version number. it is the changes to the core API that are the most notable. alter the semantics of the language. Sun decided to use 1. In all cases. the release of Java SE 6 serves to further solidify the advances made by J2SE 5. The importance of these new features is reflected in the use of the version number "5. the enhanced for. in order to maintain consistency. notice that the "2" has been dropped. Sun once again decided to change the name of the Java platform. the impact of these additions went beyond their direct effects. Annotations add an entirely new dimension to programming. and varargs. Java SE 6 adds no major features to the Java language proper. The world of Java has never stood still for very long. which is also referred to as the developer version number. such as generics. Instead. The "5" in J2SE 5 is called the product version number.5 just didn't seem to express the magnitude of the change. In general. Standard Edition 6. the platform now has the name Java SE. However. Thus. As it relates to this book. As with J2SE 5. With the release of Java SE 6. Thus. such as autoboxing and auto-unboxing.14 Par t I: The Ja vaL a n g u age • Enumerations • Enhanced. The internal. and offer improvements to the run time. and the official product name is Java Platform. and the material in this book has been updated to reflect this latest version of Java. the new features were so significant that a shift from 1. These changes are indicated throughout the book. developer version number is 1. A Culture of Innovation Since the beginning. Some." The next version number for Java would normally have been 1. However. it was named J2SE 5. Sun elected to increase the version number to 5 as a way of emphasizing that a major event was taking place. They changed the very character of Java itself. Its original release redefined programming for the Internet. and many of the classes have new methods. the 6 in Java SE 6 is the product version number.5.4 to 1. The Java Virtual Machine OVM) and bytecode changed the way we think about security and portability. Others. add several new packages.

they work together to form the language as a whole. Object-oriented programming organizes a program around its data (that is. code). Often a discussion of one feature implies prior knowledge of another. you can achieve several organizational benefits.CHAPTER An Overview of Java s in all other computer languages. this interrelatedness can make it difficult to describe one aspect of Java without involving several others. objects) and a set of well-defined interfaces to that data. Rather. Furthermore. a program can be conceptually organized around its code or around its data. Therefore. was conceived. In fact. called object-oriented programming. Most of the topics discussed will be examined in greater detail in the remaining chapters of Part I. the second approach. all Java programs are to at least some extent object-oriented. The first way is called the process-oriented model. As you will see." These are the two paradigms that govern how a program is constructed. this chapter begins with a discussion of the theoretical aspects of OOP. Two Paradigms All computer programs consist of two elements: code and data. some programs are written around "what is happening" and others are written around "who is being affected. OOP is so integral to Java that it is best to understand its basic principles before you begin writing even simple Java programs. However. by switching the controlling entity to data. That is. An object-oriented program can be characterized as data controlling access to code. The process-oriented model can be thought of as code acting on data. For this reason. A Object-Oriented Programming Object-oriented programming (OOP) is at the core of Java. 15 . The material described here will give you a foothold that will allow you to write and understand simple programs. This approach characterizes a program as a series of linear steps (that is. as mentioned in Chapter 1. Procedural languages such as C employ this model to considerable success. this chapter presents a quick overview of several key features of Java. To manage increasing complexity. However. the elements of Java do not exist in isolation. problems with this approach appear as programs grow larger and more complex.

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.