0% found this document useful (0 votes)
13 views

Unit 1 JAVA

PSLP Unit 4

Uploaded by

Shelly Garg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
13 views

Unit 1 JAVA

PSLP Unit 4

Uploaded by

Shelly Garg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 37
Tava ik a geneal-purpoce, object owented Prageamming Janquage developed by sun Memsystems af Us dh gat. Ths fanguage usar Wltiatly called “Dak” but sor ‘venamad * Tava"! i In 1948. Tava was clesi ed for the developmant of saftwae for consumed electrnicndevices tike TWs, microwave ovens and remote conbele. The main goal was 40 crate a la near which Ie ‘strople, portable The most striking feateve of tte Language | that tt it platform - + Tava Ih the fist prograrming fanguage sthat it not tied to ang pauticular hadwae or operating siptem Pregrarns developed in Tava can be executed anywhee on any system. Tava Peatures ') Gomgited_and_Thtexpreted Tava combines both abfroachss of corpilation and Intupretation. en irshuctons, Bytecode axe mot machine IvshucHont and thee! Seve Wn second stage, Tava Interpreter qpnerata machine cede that can directly executed by te machine that is sunning Taya program. 2) Seanity As you ausare, crew dime that you download a “normal” program, you ue N. Prot £0 java, most users cli not duunlcad exeusdable programs Frequently and those who did geanned Hern for vituses prior 40 execution. When yeu See te java- compatible Wieb browses, ort can althout feat ff vival Infection. 3) RAS SR Teneo arab Tava, programs can be Janeth, anyistee and analtne - Changes and. up, ades in obealirg force any Changes i) java programs This ta Ve main reason java become a poputar arquage {ox progratenitrg on internet. Tava ensures portability tn duo Usays. Fivat, Tava compiles | inshuctlors that can be Tmplemanted on ary any machine. Secondly, tte jou machine ~ Independent: ) Object -Ovented Tava is a tee object - oviented Lanquage. Almost eras tra in Tava ts an abject. AU preqram Tava comes uith an IPaeKages), that we can Wwe In our programs by Inheutance- 5) Rebust - Tava b a vobust Language. 4b provides rang safe quacs to ensue vyeliabla code, Sf has shick compile time and ~wun tea checking fo data types. “Te better understand how java is vobust, consider tua of tHe rain veasons bey prqram failure: ) . 2) Memon eae ds a difficult, tedious tosk tn traditional propeamining envivonmants. “Tava nl Biminates thee prodlermt by managing ynernewy ee > Exceptional condiHons in traditlonal envimonmants aulse in situatlone Such as divisten by cus oy fila not found’ and Hey must be managed. Java helbs in Ws auea by providing Object ovlertted|, exceplion handling. 6) “Distributed - Tava te designed for the cistibubed envivnnunt of te Trtesnet, because Ut handles Ter|tP protocols. it has tte abluty +0 shase both » Tava applicators can oben and access objects on Thternet as easly cx they can do Ina Local yemote system. Tava achive tHs using a package called Remote Method Invecalten (temt). 4) Muliittreadled: Multithreaded means t - Taya Subberts mullithreaded Programs . This meat that we need not wait fer tHe Application to Hnish one tak befove beginning another. for eq. e 4 8) tilat bulermance ava beitormance ts impressive for an Interpreted fenquage che to he wie of Inlermediate bytecode ava " by compiling into an tntemeciate Tebrearentation Called Tava bytecode. This code can be Intespreted on any aystem thak provides a Tava i\iviual Machine: The java bytecode was € Into native code tor high betormance by Ustig just-in-time Compiles. 4) Dynamic:and Extensible 5 Tava is a dynamite Language. Java is capable of dynamically - Tava can also deumine He type of class Ahmugh a query» moatirg it posdble to either Alynaninni catty Mok or abort le program, clfending on He “vespone. Tava programs subpart Rinellon “cote tn ether anqaagas SueHawicandcres thee functions cu Known as native metheds. Native methods are Linked cyramically at runtime. (s) cS Tava ig a smatt and simple banquage. SF you already undestand the basic concebts of object-erlented programming » Leaning jee is easier. sunvees gf unviliable Cole ae not pak of java. Fev 4q- Tava doe not Cthers: 2! also eliminates cbeuater oveiteading and muliiple “Inheuitanee: N) ava hpplets ard “applications Tava can be used to create two tba of froqranu: applicalens: are apilete. An application ts a progam thal unt om yout computer intanek ond executed by a java~ compalibla Web browser. An applet bs actually a. Hing java fmgqrarn, aesmse Hennchaerte;: just die sansimage, sound le or video clip, Ambedant Note fox Peinters Tava does or allow pointers. Tava can not ator pointers, because clelng so oould allow axa applets to Difference between Tava _and © Taya tha Got Bike c but tHe majov cliffeene behween Tava and ¢ is that java ts an object-oriented fanguage and has vnechanism to define classes and objects. 1) Tava doe not Include He C unique, Shatemant keywords sive} and typedef. 2) Tae does vot conlain te datatypes stud an Union 3) Tava dloes not detine “tHe Wype modifiers Reyusards die” W) Tava dees not subbort an explidt pointer tube. S) Tava dow not have a [prebrecessor and thuefore we can't We fdefine, Hlnclude and sifdet statements ©) Tava vrequives that tHe Void Reyword ox done 19 ¢- 4) Seva addi new operator such ax Ynstanceat and yyy. 2) Tava addi Labelled break and continue statements. o) Tava acd yna ny features “requbed Yor object oriented ‘Pregrarorming Ditfuence belween Tava and Cr+ Tava ts a tue object - owlented Aargucie vohile CHP Is bast cally C wlth oblect-ovented extention Crp has maintained backwoud Compatibility usith c. 9 ts thaefose possible to write an old style preqrarm and sun tt successfully under C44- “Tava appears to be simllas to cry owly extension past of cH © Tava does not support opuatoy overloading - @® Tava does mot have template classes as in crt. ® Tava does not support ynubtiple Inhaitence of claves Ths done by “interface” ® Tova does - Every’ vatlable and methed Is declaied within a class and forme bak of that class. © Tara does not we pointers. ®@ Tava has ~eplaced the cleshucloy functon with /a findiexc) function hue Class Example2 public state void main (Shing angst) % tat num; mum = loo’, System. out. prindden (¥TWs1's num:"-4+num) 5 Num = num #2; Syprem. out. print (“The value of num #2 13”)) Siptem. ouk. prinidn (min; 3 a Output This (s nurn:ls0 Tle Valur ot num *2 Is 200 “Tyr (Tava Vivtudl Machine) te the core of +e Tava ecosystern, and males It possible for Tava-baed software programs to follow He “ waite once, wun anyeshate” approach. Nou can unite joe code on one machine, and ‘un it onany otha machine uslng He dvn. TM was » Howe ves, ovek tHe Hime, many other fang wages such as Scala, Kotlin and Crroevy were adopted on te java platform. alt tree Languages oe Collectively called Ivm Sanguoges . Vixtual Machine - A virtual machine ik a virtual vebreentation af a Physical Computes. A ingle phypical machine can run multiple vivksal) Machines, each wih thele own Obuading cystern ane applications: The virkiot machines are feolated from each othex. Taya Virtual Machine + on programming Panguog es Uke Gand c#y, the code {2 hat compited {nie plattorm~ specie machine code. Thee Aanguages ate called compiled: Aerguags . . the On the other hand, in Languagzs Uke . computer executtes He «tyuhuetions elivectty withouk Reig to compile therm. Thue Larguagts ate called interpreted Languags. Java wer o combinatlon of both Languages translators. (2. compiles cond \nteapreter Tava uses a comblnatton of boty techniquss- Tava cecle is fiat complied to byte code to generate a clas fie. This claw file is then Interpreted by ‘He Tava Virtual Machine for urdeting Platform: The same class Hle can be exerted on any version of TVM vranning on any patton and Opeserting system. How it te similar wlth virtual machine ? Strvitar to virtual machines, the Tvm creates an Isolated space ‘on host machine Tht sbace can be wed to execute joe programa repedte of He ltform ox obeating sytem of ttermachine Tava Virtual Machine Pychitectute ' The VM comtists of three com porants: @ Class loades When you compile a java source file, His conveited into bye code as a -clau file: When You Fay to tue thin chau in your program, ‘The ‘laut loader oad it in te memory, The | fivst clas to be Loaded into remory ie wualiy te d ¢ class at Minima temmmeTeTE “The @ ct three pha ty te claw loacling process 4 0) aang, inky and inlabeaton leading:- Loading Involves taking tie i of a day ov interface with a pactaular name and qenesting Available tn jee “THs Ib armoh clam loadess ot fs aupuclan of @xlentlon clas leades and Loads He \ j and so on: Thue Package cut preient in vtejax file and otter core Libraites Priest in giravactonel Jre]b diveclory - N ©) Extension Clas loader. “This is suukclaw gb te Boutshap clan loader and supeclaus of Applicaton claw doader Wis Loads the extensions of standard Tava Libraie which axe pruent in the frava Home] jve] Lib]enk divectory ) Application Claus Loacles* Tha is final claw Loades and the Subclan of Extewslon clan loader Wo Loads the filer braent an He claw path. The Twn uses tte classloader: boadClauc) method for Loading He clas Into maumery - “4 process. Unking a clan oy Intuface involves a dlenants: and clebendlenctess a} program toqethen . Unking involves folowle 5 Stebs : Y Mt cheeks te Shuchue comectness of tte .cleu Hle- @) Preparation — on Hs phae, Tym a clu ov (aaa ol oes @) Resclution- dn ts phase, s chivect references Mies o dau |s Leadecl into mamory, it undeigoes te Lin Proent in tte auntime constant pool. For eg iF you have references to other clases or constant 5 “They ae vesabrec} iw AHS phae as i velesences . TniHaticaton Involves ov Interface (Known as 3 tn abore eq: vailablu Uke amwers and score ou placed in He The opuand shack contalns tHe d to pafowm He mattematical cateutatons of sublraclen and Avision: @ Progrrarn_ Count ex (Pc) Registers: tle he mah fai Ho td he alten fe ey * Once the Tnshucton ts exeutted, the . © Native Method stacles: The Tym containg stack -thal supports mative methocli. There methecls ae unttten In a Language other than He Towa, such ai Gander: Once the byte code has been Loaded inte te main mlm and The executon Ine handles \ this b the code preent tn each clay. “a yeosg - : loweves, betove errscul ag te Program, the bytecode needs to a So NESS rr eantfeetomsegine Execution Engine d Garbage. wre Interpreter Covapile, Collector © Tnteipreten: the interpreter veack and eweuter te bytecode lrubuctions Une by Line. Due to the Line by Line execution tHe Interprctes is comparatively slower (2) tar Complles: The TIT Compiles ovecoma the dieaclvamlage of te interpreter. The €xe auton endre ficst Uses the interpreter Some vebeated code, Ht user He TIT complies. The TIT compiles then compiles the entire bytecade and Changes It 40 native machine code. The TET compiles, har He folloving comporents : 4 = geneetes intermediate code 2 Code Optiniices~ optinicas the lnlermediate code fov better peformane. 3. Target Code Generator converts intermediate code to native machine tode- ‘Profiles find tne habshots (code thah ik excused -vebeatedly) @ Gaurkage Callector- The Gaibage ccllector (4c) collects and semove “Unvefewnad Oblets fromthe heap asta. at te process op vedoining ae vuntinne unused ynfm automatically by clectwyly tem. St Involves. tux phases! q os A Matk- In tHe deb, tHe Ge | es 2. Sureeb- in ts skeb, tHe Ge . arr ; Geabage allecHom is clone! autermalically by He TvM of veqular nteavals and doe mot need to be handled seprately. The UVM contalnt 2 diffent tybe of gesbage collectors: 4. Seal GC 2. Poxabldl Ge 3 Gasbage Fleck (4) 4c AM sometnus, It ts mecessaty to we mative (non= java) cocle . Upr eq: cfert)- This can be tn caret whee we need to Interact with hardwae, or to overcome tte mm Yranagernant . Tava subpodts the exeutton of native cede via. THT. TINT acs asa ( tor otter Programing Aanguages such at e+ and soon: Rai Re aa Nolive Method Ubvailes ae Ubvaies that ove comtten In other Pregorming Rarguagis, cuuch as Cress avel acembly: Thue Libraies © native Ubvaier can be loaded Seough TNT. The Tava Virtual Machine (TVtH) ts a softwate began that executes Tova byteccde. Tava bytecode ty a plattewn— independent Intermectiate ‘ebreentation oP gaya Prgqrams. at ts generated by } fl 4 s1 and ts stored in .clow filer, jaya compiles The Tym Is both an interpreter and an emulatoy. Mt hitespreke As an emulator, He tum provides a plattorm- inde pendent €mivonnunt for java program to run. This meant that te Tava 4 rreqasd Less of the underkying hadware or opuating systems Example + Fava source programe (ie: Hello java) can be tltiem and compiled on one computes (soy window) 4o produce bytececde (say hello.clos). Now, the life code can be yun on any computes that has java intupretes - Tava Developmant Wie (TDK) is a soffwaie development envivsnmunt used tor developing ova applications and applets. at includes the , oo (sR), ¢ ep eter |loacles (Tava), and other twols needed in Tava cleveloprunt . —> The Tava Runtime Environment (TeE)sis an implimantation of Tm. Sls a type of settoase package that provider claw Morales of Tava, WM and Natioussottereomponants) for vunning He in \ora Praqrammmdrg TRE ls vesborsible for creating an envieonmant for He exeustion d the code. TRE just Like Applications written TDK IS lis platfown=dependent. 9+ means that for Creu LH event platfcrm, you vequive a ittesnt tRe. The Isa platform - Independent abshack machine +h helps in exeuuting He Tava bytecode. Tt does mot comist of any teal for softaoie developmunt.. Tit = Only tre vuntime envionment ‘that helbe fn executing tHe java byteode. Tum enabls a wes fo mun applicaHons on theiy device ox in O doud enionment. Tv alo bovide some bale Hons Like git ced sty ween ony

You might also like