[Go to site: main page, start]

0% found this document useful (0 votes)
8 views15 pages

Java

The document discusses the fundamentals of object-oriented programming (OOP), highlighting key concepts such as objects, classes, encapsulation, inheritance, and polymorphism. It emphasizes the advantages of OOP, including improved software quality, reduced maintenance costs, and enhanced programmer productivity. The document also outlines the communication between objects and the benefits of using OOP in various applications, particularly in complex systems.

Uploaded by

koushikmalla378
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
8 views15 pages

Java

The document discusses the fundamentals of object-oriented programming (OOP), highlighting key concepts such as objects, classes, encapsulation, inheritance, and polymorphism. It emphasizes the advantages of OOP, including improved software quality, reduced maintenance costs, and enhanced programmer productivity. The document also outlines the communication between objects and the benefits of using OOP in various applications, particularly in complex systems.

Uploaded by

koushikmalla378
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
© Scanned with OKEN Scanner 2 Proraeing mth. A Pina object Pascal, C++, an extension of C language, is the most popular OOF language today. Ct + 2iiSteally a procedural language ich object oriented extension. The latest one added this Tis ie dava, & pare objectortented language. (OBJECT-ORIENTED PARADIGM “The major objective of objectortented approach is 0 eliminate some ofthe flaws encountered in the procedural approdch, OOP treats data na a eritioal element in the program development snd ‘SoeL not allow i to low freely around the system. Te thes data more closely to the functions that ‘Sperate on itand protests from unintentional modification by other functions: OOP allows ws to decompose problem into @ number of entities called Objects and then build date and fonctions (known as methods ii-Java) sound these tethoda make up an object (ace Pigs 11), Fett Metin Mo ‘ovject = Date + Methods “The data of an object san be accedsed only by the methods associated with that objcot. However, methods of one object ean aoooss the methods of other objects: Some ofthe feature o clgoot oviented paradigm a ae <= ‘ + Bmpheale son deta rather then prooedrs: + Programs are divided into whac ure hnown as Object, Data structures are designed such shat they Sharactavine the objects Methods dhat operate on the data of an object are ted together ithe data structure Data in hidden and cannot be sensed by external Fncerons Objects may communtoate with each ether throw sneshee © Scanned with OKEN Scanner Fc of Oct Oieted Pgs ig. eral tom appre rar dei, in sill means diferent things to diferent people. Tes therctore important to have a Working On of object-oriented programming before we preecd further cpt definition of objsetarienied programming ir Object-oriented programming $a ior hort daca nd fants tnt eam ie eda emplaces for oreating copies oF sesh ‘modules on demand, This means shat am oigect ie considered t0 be a partitioned urea of zmemory partitions are indepondant, the objects can te weed in varoty of different progeams shout ZT sasic concerts oF OBJECT-ORIENTED PROGRAMMING As mentioned earlier, objeceoricnted Ina term, which ts interpreted diferently by different People. Tris dhorotors nescsany to understand some of the concepts used extensively In Shiccrorented programming. We sal now dase the Beer ‘Soneapes of OOP which form Objects and Classes Objects are the hasie runtime entitiss in an object-oriented tem. They may represent a Pasa a place: a bank necoumtsa table of data or any tems tha the progeam may handle: They Rutplalue eepresent uotredefined data types uch as vectors and lies Any programming problem Iiauyzed! in terme of objects and the ature of communteation between them, Program Shjccts should be chosen such thu they match closely with the realworld abjects. As potted eee esi ctjcct takes up space Im che memory and has an sacoeiated address hike a reoord in'Pascal, or seructure fn C Fae eS ttted, the objects internet by sending meses to one another. For eee Se inscotine are swe objects ina banking program. then the customer SERRE GESTS guemtage to the mosoat objece requesting for the balance. Each object ‘Sonate dasa and code to manipulate the data, Objects ned bythe objects jon thats papulariy- ued to represent and dowite " of data nd codeotan abject os = Ce te ofas a dats ye! aid an object a wariable” ofthat data type. Ones « = contain data and code to manipulate that data. "The entire set fined data ype using the coneapt ofa clas. A ‘Sen defined. we can ereive any number of objects belonging to that [rassoctared wath the dats of pe ‘Of simular ype. For extimpl Bach object, (Sy are created. Aclass is thus eolleetion of ‘mango, apple and orange are members of the class TC © Scanned with OKEN Scanner 4 Programing wih Je: A Pinor az) Peron objec satay Methods m0 Representation of on object Classes are uscrdefined data types and behave like the builtin types of @ programming Tanguage. For example, he syntax used to oreate an object eno different than the synta used to frente an integer object in C. If fruit has been defined as 4 class, then the statement will ereate an object mango belonging to the class fruit Data Abstraction and Encapsulation Thera Data encapsulation is the most staking outside world and only those methods, which are Wrapped in the class, cana ‘methods provide the interface between the object's data and the programy, This insulation of ch data from direct access by the program is ealled data hiding. Enenpralation wales peectole ‘objeots coe treated like ‘black bones", each performing a specie task watkeus ane eoncee internal implementation (see Fig. 1.3). ves Fe Dasa Information “out Method Encopsulation—Objects os “black boxes” © Scanned with OKEN Scanner Sst proportion the bjashint neva eet Inheritance: hertango Is the proweet by which ohjets of one cane gee th Scales iirc support te onc ral ia robiniea pact acini nsec case Fig. 124, the principle Behind tne ware of divtaon a that ‘hentia oh te Sass ts heh rtlor of objects of ‘For example, se ed =u ‘Bird ‘Robin ‘Swattow ‘Penguin Kiwi | noon, ce mechanism Ie that ie allows the programmer to reuse a class that is almost, but not exactly, what he wants, nd te taltor the © Scanned with OKEN Scanner - 6 osrnmng mh soe: A Primer tn much away that it dose not introduce any tndesirable side effocts nto the rest ofthe lassen IRSISI. the Uorned claus ix known nx eubelae' = 2h ete defines ony toe foto dat ar wa ot, With the we of ‘Sich Glass woul have to exp Polymorphism , eo eer temples an operation’ nay exhibit different behaviour in di ree ee orn dems Upon tne topes OF data used In the operation, For example, sae Je penation of ation. For two nuraber, the operation will enerate a surn. If the Sears ne obese, then the operation would produce a third string by concatenation. Fi PPE fakerater that sine fanotion name wan be used to handle different number and differnt Jase teteiments, This is something aamilar to a particular word having, several diforent ‘Moanings depending on the context. me - Daw) Gin oie Daou Taso] Daw ere Daw boo Baw eine | hmerptim Polymorphism plays an important role in allowing objoots having diferent tncernal strwctres to share the same external interface. This monn that a keneral class of operations may be “cessed in the sare manner even though specie actions sasociated with cnch operation may ASidior Polymorphinm is extensively waed in implementing inheritance Dynamic Binding Binding rofors to the inking of « procedure call to the sod be éXecuted in response to the [Dynamio binding means that the code associated with a give intil the time of the call ae runtime. Ie ie associated with polyaorphism aid procedure call associated with a polymorphic reference depunde on the dynamic type of that © Scanned with OKEN Scanner rae ‘Pactual of ect Oiotg Programing 7 Consider the provedure “draw” in Fig. 1.8. By inheritance, every objdot will have this rocedure. Ics agritnm f, however, untae to each object snd the yaw procedure wl he Fedefined in each clas that dotinn the object As rune, the sede matching the oljost ander Survent reference will by called, : Message Communication An object-oriented program consats of net of objects that communicate with exch otter The Process of programming inn objeetortnted langage, therfore, waves the folowing basic 1. Creating classes that define objects and their behaviour. 2. Creating objects from clas definitions Establishing communteation among objects Objects communicate with one another by sending and receiving information much the xame ‘way a people pass messages to one another as shown in Fig. 1-6. The concept of message Pass mses waster so talk about balling systems that siretly model or simalate their fata Neowork of objects communicating between them © Scanned with OKEN Scanner 1 Pegramming wth Jo: A Pinar cforexecution of a procedure, and therefore will inwske 5 A rmgseage for an object is arecuier object that generates the desired rexslt, as show i method (procedure) in the receiving Fig 17, = ele O- Message triggers 0 method Message passing involves speeifing the name of the object, the name of the method (moseago and the information to be sent. For example, consider the statement Bnpioyee. salary (name) Hore, Employee is the object, salary is the message and name is the parameter that contains Information: Employee-saiary (name) + Objects have a life cyele. They ean be created and destroyed. Communication with an object is feasible as long as tts alve 73 > BENEFITS OF OOP ©OP offers several bonefies to both the program designer and the user. Object-orientation ‘Sontributes ¢o the solution of many problems associated with the developmen: sud sentinco sofware products, The new technology promises greater programmer produccsicn, better ‘Gualiey of sofeware and lessor maintenance cost. The principal advantages fee, + Through Inherltance, we con ciginate redundant cole and extend the uno of exiting + WWe-can build programs from the standard working modules that communicate with ane nother, rather than having to start writing the code from soratch. This leads te savin of cvalopment time and higher productiviy. “ 3 © Scanned with OKEN Scanner ‘Pundeeniat of yet Onented Programing 9 + The principe of data hiding helps the programmer to bulld secure progess that cannot bead ty cae rote pot programs ene + Ieis possible to have multiple objects to coexist without any interferenee > Ici possible to map objects inthe problem domain to thse objects inthe progam + Ici cary to partition die work in project based on objects ‘The data-centered design approach enables us to capture more details of a model ia an implementable form, Olect-oriented sytoms can be easily upgraded from small to larje syste Message passing teeliniques for communication between objects make the interface descriptions with external systems much simpler, +¢ Software complexity can be easily managed. While it 1s possible to Incorporate all hose features in an objectoriented system, their Importance depends on the type of the project and the preference of the programmer. There re number of issues that need to be tekled to reap some of the benehts stated above. For Instance, class libraries must be gvailable for reure- The technology ie still developing ad. ‘current products may be superseded quickly, Strst controls and protosols need to be developed rouse Ix not to be compromised: "A. software that te eam to use is hard co build. Ie ix hoped that the obj programming languages like G+ and Java would help manage his problem oriented GED arruications of oor OOP is one of the programming burewords today. There appears tobe a great deal of excitement ind interest among software engineers In using OOP. Applications of OOP are beginning to gai importance in many arens. The most popular application of object oriented programming, up € ow, haw becn in the area of user interface desig such as windows, There are hundreds of ‘Sindowing systems developed using OOP techniques ‘Kcal-business systems are often much more complex and contain many more objects with complicated attributes and methods, OOP is useful ta this type of applications beats Tecan Simplify a complex problem. The promising areas for applioation of OOP includes Realtime systems Simulation and modelling Object-oriented databases Hypertext, hypermedia “ALand expert systems nd expertext ‘oworks and parallel programming Decision support and office automation systems CIM/CAD/CAD wyaterm Iie believed that the richness of OOP environment will enable the sofeware industry to Improve not only the quality of software systems but also sts productiwity. Object-oriented © Scanned with OKEN Scanner 10° Programming wih Jove: A Pome crane ssi sotto change the way software engineers wll think, naj and implement systems in the future, a SUMMARY lwalts called objects but also to take advantage of creamer ipter, we have Introduced the baste concen o Programming which include * Encapsulation, + Inheritance, and Boonpaulaton Boman: Object Orlented Paradigin, Clas, Object. Method, Absersction, Bnoupsulation, ata Hiking, Inheritance, Reuasbili Pobmorphiaas Beets Nene REVIEW QUESTIONS 1a meat thi re the major aves facia the oftware nduory cody? 13 Ruel discuss the software evolution during the period trom tone ee wane, | 1S oat ananleetorlented programming? How iste diferent tnom che recon creoriented programoning® 1 Mow are dats and methods organized in an objcotoriented program? Te Dn are umlaue advantages of an object-oriented pogeammion pam 1.6 Distinguish betwoon the fol (2) Objects and classes (@) Data abstraction and data enoapeut (©) Inheritance and polymorphic (2) Dynamic binding snd meneage passing 1.7. What kinds of things can bocome objects nr bope 1.8 Deseribe inheritance as applied to OOF. 1.9 Lista few arcas of application of OOF reclinotogy. wind terme © Scanned with OKEN Scanner ‘Fundementas of Obect-Crientod Programing 14 State whether the following statements are TRUE or FALSE. () In conventional, procedure-oriented programming, all date are shi ) Th ‘emphasis of procedure-ori than on data. (©) One of the striking features of object-oriented programming is the division of programs into objects that reprexent real-world entities @ Wrapping up of data of different types into a single unit is known as (©) One problem with OOP is that once a class is created, 1 6 © Inheritance means the ability to reuse the date values of one object by other objects: (2) Polymorphism is extensively used in implementing inheritance, (h) Object-oriented programs are executed much faster than coaventional programs. @ Objectoriented systems can scale up better from small to large. G)_ Object-oriented approach cannot be used to create databases, fed by all algorithms rather ented programming. is « never be changed. © Scanned with OKEN Scanner Chapter 2 Java Evolution 2 Java HistoRY fava in 4 gencralpurpote, ohjootortented programming language developed by Sun Microsystems of USA in 1991, Oriinally called Oak by Tames Gosting onc ofthe korn ol {he ste; Tava war desiined for the dewiOpment of soltware for consumer theteenig devices like Fs, VCRs, toners and such other ciecrronie machines This geal fad eee ypaiene seam to make the lguade simple, portable and highly reliable he inded Patric, Nauineondiacowered that the casting Inadeies (C++ had limitations in terms of both reliability and portability. ors thay ‘ew language Jaw on Cand Cot but removed e murbber ee eat ‘onsidored as sources of problense and thus made ane io ppomerul language Table 2. lise some important seston ‘simple, rellable, portable, wid nthe devolopment ofa Table 2.1 Java Hlertones $time Your Devclopment| x99 ‘wher emorng the pow of ung the mont popular oecariened language C++ rov2 Phot Kn at cn Peta yh emo 1903 Theor Wile Web VW apnea Inteynet tn a graphial ih emevommenc, The Graan pr, tamara the ented developing Weh apniete (ny programs) wang the new oases Te se es a © Scanned with OKEN Scanner ‘Tale 2.1 Contimed) Tiernet” Holegs domemated the power fate mow tngunges ue making inane 190s ° Bakems rome "aves vet some fal anaga_Jav. Jost namie and 4 208 a SSoronyn. Many poRTar companion eluding Netsoape and Microsoft announced Perpame gta Sa oem nt teagan Sons ated shone “The most striking feature ofthe language i that Iie a plagormnewtrallanguaite, Java the first programming language that is not tied to any particu’ Hardware or operating system. Proglam developed in tava can be executed anywhere on any systems. We ean call Tava a8 technology because it has browghe ma fendamental shit im how we develop and ie programs. Nothing like this has happened to the sofeware industry before, JAVA FEATURES Inventors of Java wanted to design a language which could offer solutions to some of the probleme sneountered in modern programming. They wanted the language to be not only Fehiable, portable and distributed bu also simple, compact and interactive. Sun Micromysteme ‘euoribor Java with the following atributes: + Game sd aerated + object Oriented 2 Discribuced Familia, Simple and Small Multithreaded and Interaeuve Nigh Performance Dynamic and Exzensible [Although the above appears to be alist of buzzwords, they aptly deseribe the fall potential of oa eee oe see features have made Java the fret application language of the World Wile Sea Ati alto become the premier language Yor feneral purpose stand-alone applications Compiled and Interpreted Unuilly 4 computer language is either compiled or interpreted, Java combines both these Vaal eae soaking Java a saastagermzrem, Purse Sava Somipiter translates source code Ferenc tnown as bytecode iniructions. Bytecodes are not machine tastructions and See ete asoond stage, Java interpreter gencratex machine code that can be directly © Scanned with OKEN Scanner hine that is running the Java program. We ean thus say that ‘compiled and an interpreted language. latform-Independent and Portable " ‘The most significant contribution of Jn over other languages is its portability, Java proeams ‘can be easily moved from one computer matem to another, anywhere and anytini: Chases aed parades in operating systoms; processors sm sjstem nosouraer wall not force any chases Java programa, This Is the reason why Java has bebome a popular langage for prograrnuning on Internet which interconnects different hinds of systema worldwide. We cam dowload favy spplet from a remote computer onto our local system via Internet and execute It local, Th ‘MAKE Uie Taternet an extension of the imer's Gaslo Haier providing: practically wnlonied ‘humber of accessible applets and appliesions lava ensures portability in two ways. Firat, Java compiler generates bytecode indertions {hat san be fmplemented on any machine. Secondly: tho sist of the primitive date tees ee shachinesindependant = Object-Oriented Java is a true object-oriented language, Almost everything in Java is an object, All program code gr data reside within objcots an lassen: Java Gomes with an exteasne rev ee in mackedes, that we ean us in our programa by inheritance, The object mooel ia hae aa Robust and Secure Java is a robust language. It provides many safeguards to ensure rellable code. It hax strict compile time and run time checking for daea types, Tis deeigned ae a ea et ‘Hingunge Felieving the progsammers virtually all memory heeeeeeesee oe earease-coliected eorporates the concept of exception handling which captures sien ero ttem ava also Flak of crashing he petcin shee ss scouts botomcs an lmporta Incernet. Threat ofvirasos wd a nuyue for language thet ts used for profeamming on viruses with am applct- Tie absence of 10F Rain access to memory locations withent wenes Diseributed Java is designed as a distributed langage for erating ap alny’co share bah ata nd program, Sava tpi Sh pena eres he ‘om nent easly a they one ot 9 Fal shatem hie eka gee remene obeets ‘ultple rote locations to sollaborate and work eter i an aalble ron © Scanned with OKEN Scanner Love Botton 16 imple, Small and Familiar Java isa small and simple language. Many features of C and C++ that are either redundant oF sources of unreliable code are not part of Java, Por cxany [pointers Preprocessor header files, goto statement ‘and many ethers ies operator xerloading and multiple isheritanes, For Tiore detaled compariaon of lava with G and Co , Familiarity is another striking feature of Java. To make the languase look existing programmers, twas modelled on Cand C++ languages, Java uses many constructs of G and C4" and therefore,-Java code "looks like » C4'+" ode. in fase. Java ie spied Multithreaded and Interactive S in le tasks simultaneously. Java supports multithreaded A TT eee oat tan one teat bolas Beginning another: For exam bile soraling mpage ansiat te ‘same time download an applet froma distant computer, This feature rca tnyproves the Interactive performance of graphical applications. “The Java runtime comes with tools that support multiprocess sychronizat smoothly running interactive store High Performance Java performance is impressive for an interproted language, mainly duc vo the use of Intermedinee bytcoode. According £0 Sun, va speed ts comparable ta the nase C/E +. Sav ‘rohitecture is also designed to reduce overheads during suntime. Further, the incorporation of ‘multithreading enhanoes the overall encoution spead of Java Programe Dynamic and Extensible Java ia a dynamic language. Java ix capable of dina Joking ta now clase ibraties, Imvthodas and objects: tava cont als determine the pe of clase-theail # ave ‘eae reiterate or ore the progr deranding on ts osponce These languages. Native methods are linked demavnleally at functions. Sitcione fancetons. availa 35.7 Howsava Dirrers FROM CAND C++ Altnouah Java wn mone aterC and z+ langues ier om Cand + © Scanned with OKEN Scanner

You might also like