Java in Hindi Updated

February 1, 2017 | Author: NikhilPaliwal | Category: N/A
Share Embed Donate


Short Description

Download Java in Hindi Updated...

Description

Java in Hindi BccFalna.com 097994-55505

Kuldeep Chand

This EBook is not Just Core Java, but also includes some concepts of Advance Java like Basics of JDBC, Event Driven Programming, GUI development with AWT and Basics of Java Networking too. In Java, all GUI development like SWT/Swing, JavaFX etc… are totally based on AWT. So, learning AWT helps very much in learning GUI Development using Java. So, in this EBook, I have covered GUI Development from and covered AWT and Event Driven Programming with Good Detail in Last Chapter. So that, after reading this EBook, you can start developing GUI Applications using Java easily. Even Applets are out of market now, but I have included it frequently in this EBook to easily using and understanding GUI Development. Basics. I have covered each Java Programming Concept with hundreds of example programs. So, it would be very easy to learn Java with this EBook.

Java in Hindi

Kuldeep Chand BetaLab Computer Center Falna

1 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Programming Language JAVA in Hindi Copyright © 2011 by Kuldeep Chand All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editors: Kuldeep Chand Distributed to the book trade worldwide by Betalab Computer Center, Behind of Vidhya Jyoti School, Falna Station Dist. Pali (Raj.) Pin 306116 e-mail [email protected] or visit http://www.bccfalna.com For information on translations, please contact Betalab Computer Center, Behind of Vidhya Jyoti School, Falna Station Dist. Pali (Raj.) Pin 306116 Phone 97994-55505 The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, the author shall not have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this book.

2 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

This book is dedicated to those who really wants to be a

ProfessionAl Developer

3 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Index of Contents

4 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Table of Contents Java – Basics and Programming Fundamentals ....................................................... 13 Features of JAVA .................................................................................................. 17 Small and Simple ............................................................................................... 17 Object Oriented .................................................................................................. 17 Distributed .......................................................................................................... 18 Compiled and Interpreted .................................................................................. 18 Robust and Safe ................................................................................................ 19 Architecture Neutral / Platform Independent / Portable / Byte Coded ................ 19 Garbage Collective ............................................................................................ 20 High Performance .............................................................................................. 20 Multithreaded and Interactive ............................................................................. 20 Dynamic and Extensible .................................................................................... 20 Java – Working ...................................................................................................... 22 Java Platform ......................................................................................................... 23 The Essentials: .................................................................................................. 24 Applets: .............................................................................................................. 24 Networking: ........................................................................................................ 24 Internationalization: ............................................................................................ 24 Security: ............................................................................................................. 25 Software components: ....................................................................................... 25 Object serialization: ............................................................................................ 25 Java Database Connectivity (JDBC): ................................................................. 25 Program ................................................................................................................. 25 Procedural Techniques and OOPS ....................................................................... 27 The Object-Oriented Approach .............................................................................. 29 Difference Between C++ and Java ........................................................................ 31 Preprocessor ...................................................................................................... 31 Pointers .............................................................................................................. 32 Structure and Union ........................................................................................... 32 Functions ........................................................................................................... 33 Multiple Inheritance ............................................................................................ 33 Strings ................................................................................................................ 34 goto Statement ................................................................................................... 34 Operator Overloading ........................................................................................ 34 Automatic Type Casting ..................................................................................... 34 Variable Number of Arguments .......................................................................... 35 Command Line Argument .................................................................................. 35 Programming – The Basic Concept ....................................................................... 36 System Software: ............................................................................................... 37 Application Software: ......................................................................................... 37 Computer Architecture ....................................................................................... 37 Hardware Programming ..................................................................................... 39 Software Programming ...................................................................................... 40 Language ............................................................................................................... 40 Java Compiler (javac) ........................................................................................ 41 Java Interpreter (java) ........................................................................................ 42 Structure of Java Programs ................................................................................... 43 Documentation Section ...................................................................................... 43 Package Statements .......................................................................................... 43 Import Statements .............................................................................................. 44

5 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Interface Statements .......................................................................................... 44 Main Method Class ............................................................................................ 44 Definition – The Applet and Application ................................................................. 44 Java - Applications ............................................................................................. 45 First Application in Java ..................................................................................... 45 Compiling Java Source File ............................................................................... 46 Running Java Application .................................................................................. 48 Anatomy of Java Application .............................................................................. 48 Comments in Java ............................................................................................. 48 Java – Applet ......................................................................................................... 51 Applet – Local and Remote ................................................................................ 51 Clients and Servers ............................................................................................ 52 Difference – Applet and Application ...................................................................... 53 Preparation – The Applet Writing ....................................................................... 53 System Package – Predefined (Built-In) Library of Java Classes ...................... 54 Using – The System Packages ......................................................................... 55 Keyword / Reserve Word ................................................................................... 56 Building – The Applet Code ............................................................................... 57 Applet Package – The Applet Class .................................................................. 57 OOPS and OOPL – The Definition ........................................................................ 58 Problem – The Definition ....................................................................................... 58 Data – Value OR a Set of Values .......................................................................... 59 Integer ................................................................................................................ 59 Float ................................................................................................................... 59 Character ........................................................................................................... 59 Object – The Definition .......................................................................................... 59 Objects – Based on Problem ................................................................................. 60 Abstraction – The Problem Simplifying Process .................................................... 60 Abstract Data Type - Logical Representation of a Real World Object ................... 61 Attributes – The Data Members of The Class .................................................... 62 Behaviors – The Methods of The Class ............................................................. 62 Problem Design (OOPS) v/s Problem Implementation (OOPL) ............................ 63 Encapsulation – The Unitizing Process of Attributes and Behaviors ..................... 64 Class – A Logical Specification of Problem Related Object .................................. 65 Identifier Naming System ...................................................................................... 70 Java – Graphical User Interface and Graphics Management ................................ 72 Web Page – The Part of Website .......................................................................... 72 HTML Tags for Web Pages ................................................................................... 74 Comment Section .............................................................................................. 74 Head Section ..................................................................................................... 75 Body Section ...................................................................................................... 75 Adding Applet in HTML File ................................................................................... 75 Applet Architecture – The Event Based GUI Application Program ........................ 76 First Applet in Java ................................................................................................ 82 GUI – The Event Driven Programming System ................................................. 84 Components of an Event ....................................................................................... 86 Event Object ...................................................................................................... 86 Event Source ..................................................................................................... 87 Event Handler .................................................................................................... 87 Java Fundamentals – Core Concepts ....................................................................... 91 Constants .............................................................................................................. 91 Variables ................................................................................................................ 93

6 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Naming Constants and Variables – The Identifiers ............................................... 93 “Java” Characterset ............................................................................................... 95 “Java” Tokens ........................................................................................................ 95 Keywords ;k Reserve Words .............................................................................. 96 Identifiers ........................................................................................................... 96 Literal ................................................................................................................. 97 Variables ............................................................................................................ 99 Operators ......................................................................................................... 100 Precedence Of Operators ................................................................................ 105 Data Types .......................................................................................................... 106 Identifier (Variable / Constant) Declaration ...................................................... 107 Value Initialization ............................................................................................ 108 Garbage Values ............................................................................................... 109 Integer Data Types .......................................................................................... 109 Floating – Point Data Types ............................................................................. 110 Boolean Data Type .......................................................................................... 111 Character Data Type ........................................................................................ 111 Variable Scope .................................................................................................... 118 Code Block .......................................................................................................... 118 Type Casting ....................................................................................................... 118 Arrays .................................................................................................................. 121 Array Memory Allocation .................................................................................. 122 Array Initialization ............................................................................................. 122 Strings ................................................................................................................. 129 String Methods ................................................................................................. 131 StringBuffer Class ............................................................................................ 136 Command Line Arguments .................................................................................. 138 Wrapper Classes ................................................................................................. 140 Control Statements .............................................................................................. 152 Program Control ............................................................................................... 153 Types Of Control Statement ............................................................................ 153 Compound Statement or Block ........................................................................ 154 Increment and Decrement ............................................................................... 164 Loops ................................................................................................................... 166 for Loop ............................................................................................................ 167 Assignment Operators ..................................................................................... 170 Nesting of Loop ................................................................................................ 171 while Loop ........................................................................................................ 176 do while Loop ................................................................................................... 178 Jump Statements ................................................................................................. 180 break Statement ............................................................................................... 180 continue Statement .......................................................................................... 182 return Statement .............................................................................................. 183 Drawing Graphics ................................................................................................ 183 Applet Canvas .................................................................................................. 183 Colors ............................................................................................................... 185 Drawing Shapes ............................................................................................... 186 Drawing Line and Rectangles .......................................................................... 186 Drawing Circles and Ellipses ........................................................................... 187 Drawing Arcs .................................................................................................... 188 Drawing Polygons ............................................................................................ 188 Building Graphical User Interface ........................................................................ 193

7 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Abstract Windowing Toolkit .............................................................................. 194 Components ..................................................................................................... 194 Panel Class – The Panel Container ................................................................. 196 Push Button Control ......................................................................................... 196 Label Control .................................................................................................... 199 Rectangles and Windows ................................................................................ 204 GUI Components – On The Absolute Placement ................................................ 204 Handling Multiple-Button Events ......................................................................... 206 Java OOPS – Object Oriented Programming Concept ........................................... 212 Class and Objects ............................................................................................... 212 Attributes .......................................................................................................... 216 Declaring Objects ............................................................................................. 224 new Operator – A Closer Look ......................................................................... 225 Object Reference ............................................................................................. 226 Abstract Data Types ........................................................................................ 238 Adding Methods to Box Class .......................................................................... 241 Methods Overloading .......................................................................................... 253 this Keyword ........................................................................................................ 254 Automatic Garbage Collection ............................................................................. 256 Finalize() Method ................................................................................................. 256 Methods Overloading .......................................................................................... 257 Constructors ........................................................................................................ 261 Arguments Passing ............................................................................................. 266 Pass By Value .................................................................................................. 266 Pass By Reference .......................................................................................... 267 Access Controls ................................................................................................... 269 public and private Access Specifier ................................................................. 270 static Data Members and Methods ...................................................................... 273 final Keyword ....................................................................................................... 276 Nested and Inner Classes ................................................................................... 276 GUI Application Of Java ...................................................................................... 278 Java Application – The Frame Class ............................................................... 279 Java Inheritance – Code Reusability ....................................................................... 285 Reusability ........................................................................................................... 285 Inheritance and Program Design ......................................................................... 286 Composition: A “Has a” Relationship ............................................................... 286 Inheritance: A “Kind of” Relationship ............................................................... 287 Superclass and Subclass .................................................................................... 289 Implementing Inheritance .................................................................................... 291 Method Overriding ............................................................................................... 299 Constructors and Inheritance .............................................................................. 302 Multilevel Hierarchy ............................................................................................. 311 Constructor Calling Convention ........................................................................... 311 Dynamic Method Dispatch – The Run Time Polymorphism ................................ 312 Abstract Classes .................................................................................................. 317 Final Classes ....................................................................................................... 322 Java Interfaces – Multiple Inheritances ................................................................... 326 Declaring Interfaces ............................................................................................. 327 Extending Interfaces ............................................................................................ 328 Implementing Interfaces ...................................................................................... 330 Java Exception – Error Handling ............................................................................. 336 Compile Time Errors ............................................................................................ 336

8 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Run Time Errors .................................................................................................. 337 Exceptions ........................................................................................................... 338 Exception Types .............................................................................................. 341 try and catch Block – The Exception Handling Process .................................. 341 Multiple catch Blocks ....................................................................................... 343 Nested try Statement ....................................................................................... 347 The throw Keyword .......................................................................................... 347 The throws Keyword ........................................................................................ 349 The finally Code Block ..................................................................................... 349 Types of Exceptions – The Java Built – In Exceptions Classes .......................... 352 java.lang Exceptions ........................................................................................ 352 java.io Exceptions ............................................................................................ 354 java.net Exceptions .......................................................................................... 354 The java.awt Exceptions .................................................................................. 354 The java.util Exceptions ................................................................................... 355 Creating Own Exception Sub Class .................................................................... 355 Java Package – Code Reusability .......................................................................... 358 Naming Conventions ........................................................................................... 359 Creating Packages .............................................................................................. 360 Java Multithreaded Programming ........................................................................... 369 Java Thread Model .............................................................................................. 370 Thread Priorities .................................................................................................. 371 The Thread Class and the Runnable Interface .................................................... 371 The Main Thread ................................................................................................. 371 Two Kinds of Threads .......................................................................................... 374 Converting a Class to a Thread ....................................................................... 374 Deriving a Class From Thread ......................................................................... 389 Thread Exception ................................................................................................ 393 Thread Scheduling – Setting Thread Priority ....................................................... 394 Establishing Thread Priority ............................................................................. 395 Daemons ............................................................................................................. 399 The ThreadGroup ................................................................................................ 400 Thread States – The Life Cycle of a Thread ........................................................ 402 NEWBORN State ............................................................................................. 403 RUNNABLE State ............................................................................................ 403 RUNNIG State ................................................................................................. 404 BLOCKED State .............................................................................................. 405 DEAD State ...................................................................................................... 405 Synchronization ................................................................................................... 407 Deadlock .............................................................................................................. 408 Java Networking ...................................................................................................... 410 World Wide Web (WWW) Concepts .................................................................... 410 Distributed Programs ........................................................................................... 410 Protocol ............................................................................................................... 411 IP Address ....................................................................................................... 411 Host .................................................................................................................. 412 Hostname ......................................................................................................... 412 IETF (Internet Engineering Task Force) .......................................................... 413 Internet ............................................................................................................. 413 Intranet ............................................................................................................. 413 Packet .............................................................................................................. 413 Protocol ............................................................................................................ 413

9 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Protocol Stack .................................................................................................. 414 Router .............................................................................................................. 414 Sockets ............................................................................................................ 414 Internet Protocols ................................................................................................ 414 TCP/IP Network Architecture ........................................................................... 414 IPv4 And IPv6 .................................................................................................. 416 URL Class ........................................................................................................... 417 Socket Class ........................................................................................................ 417 Reliable ............................................................................................................ 417 Ordered Stream ............................................................................................... 418 ServerSocket Class ......................................................................................... 418 DatagramSocket Class ........................................................................................ 418 Unreliable ......................................................................................................... 418 Connectionless ................................................................................................ 419 Ports .................................................................................................................... 419 Client/Server Technology Fundamentals ............................................................ 421 Client/Server Architecture ................................................................................ 421 Client/Server Communication .......................................................................... 422 Identifying a Computer ..................................................................................... 423 Testing A Program Without A Network ............................................................ 426 Socket Introduction .............................................................................................. 426 Creating A Simple Server and Client ................................................................... 428 Socket Transmission Modes ............................................................................... 432 Reading From a Socket and Writing To a Socket................................................ 434 Working With URL ............................................................................................... 437 What Is a URL .................................................................................................. 437 Creating and Manipulating URL ....................................................................... 438 Java RMI – Remote Method Invocation .................................................................. 444 RMI Applications .................................................................................................. 444 Advantage of Dynamic Code Loading ................................................................. 445 Remote Interfaces, Objects and Methods ........................................................... 445 Creating Distributed Application Using RMI ........................................................ 446 Design and Implement the components of Distributed Application .................. 446 Compile Sources and Generate Stubs ............................................................ 447 Make Classes Network Accessible .................................................................. 447 Start The Application ........................................................................................ 447 Creating RMI Server ............................................................................................ 448 Designing A Remote Interface ......................................................................... 448 RMI Technology .................................................................................................. 450 Java Database Management .................................................................................. 452 Database Management System Software ........................................................... 452 Database Connectivity ......................................................................................... 453 ODBC Application Programming Interface ( ODBC API)..................................... 453 JDBC Application Programming Interface ( JDBC API)....................................... 454 JDBC Driver Manager ...................................................................................... 455 JDBC-ODBC Bridge ......................................................................................... 455 Installing The ODBC Driver ................................................................................. 455 Connection to A Database ................................................................................... 458 Querying A Database .......................................................................................... 460 Using The Statement Object ............................................................................ 461 The Statement Object ...................................................................................... 461 The ResultSet Object ....................................................................................... 462

10 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Using PreparedStatement Object .................................................................... 465 The PreparedStatement Object ....................................................................... 465 Passing INPUT Parameter At Runtime ............................................................ 465 Java AWT – Abstract Windowing Toolkit ................................................................ 472 Event Driven Programming System .................................................................... 472 Components of an Event ..................................................................................... 473 Event Object .................................................................................................... 474 Event Source ................................................................................................... 474 Event Handler .................................................................................................. 475 Event Handling Mechanism – Double Approach ................................................. 475 The JDK 1.02 Event Model .............................................................................. 475 Delegation Event Handling Model .................................................................... 476 Event Classes .................................................................................................. 477 Event Listeners ................................................................................................ 479 Using The Delegation Event Model - Handling An Event .................................... 483 The ActionEvent Class ..................................................................................... 484 Handling Mouse Events ................................................................................... 493 Handling Keyboard Events .............................................................................. 499 Adapters ........................................................................................................... 503 Inner Classes and Anonymouse Inner Classes for Simplifying Adapter Classes ......................................................................................................................... 509 Window Fundamentals of JAVA .......................................................................... 514 Container Class ............................................................................................... 514 Panel Class ...................................................................................................... 515 Window Class .................................................................................................. 515 Frame Class ..................................................................................................... 515 Canvas Class ................................................................................................... 515 Frame Windows ................................................................................................... 516 Closing a Frame Window ................................................................................. 517 User Interface Control Fundamentals .................................................................. 519 Adding and Removing Controls ........................................................................... 520 Labels .............................................................................................................. 520 Buttons ............................................................................................................. 521 Check Boxes .................................................................................................... 522 Choice Controls ............................................................................................... 523 List Control ....................................................................................................... 524 Scroll Bars ........................................................................................................ 526 TextField Control .............................................................................................. 528 TextArea Control .............................................................................................. 530 CheckboxGroup Control .................................................................................. 531 Layout Manager ............................................................................................... 531 Menu Bars and Menus ..................................................................................... 536 Dialog Boxes .................................................................................................... 542 FileDialog Class ............................................................................................... 547 Explicit Event Handling .................................................................................... 549 Extending Buttons ............................................................................................ 550 Extending Checkbox ........................................................................................ 552 Fonts Handling In Java .................................................................................... 554 Last but not Least. There is more… ........................................................................ 558

11 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Java Basics and Programming Fundamentals

12 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Java – Basics and Programming Fundamentals

vkt ge ns[k ldrs gSa Internet o Mobiles dk fdruk foLrkj gks pqdk gSA vkt Internet bruk c< pqdk gS fd nqfu;k dh tks Hkh tkudkjh pkfg,] Internet ij ml tkudkjh dks izkIr fd;k tk ldrk gSA vkt bl Internet dh otg ls nqfu;k fcYdqy NksVh lh gks xbZ gSA ge tc pkgsa ftlls pkgsa ckr dj ldrs gSa ;k Online Meeting dj ldrs gSaA nqfu;k dh yxHkx lkjh phtsa vkt Internet ls tqMh gqbZ gSaA Internet ij vkt ge dsoy Texts gh ugha iwjs Multimedia dks ns[krs gSa] ftlesa Sound, Video, Animation, Graphics vkfn tks dqN Hkh gks ldrk gS] lc gSA ysfdu vkt ge ftl rjg dk Internet ns[k ik jgs gSa] dqN le; igys rd Internet ,slk ugha FkkA Multimedia dh fofHkUu phtksa dks Internet ij lEHko cukus esa Java dk cgqr cMk lg;ksx jgk gSA okLro esa Java dk fodkl dsoy Internet ds fy, fd;k x;k Fkk] ysfdu vkt bldk iz;ksx dsoy Internet ds WebPages cukus ds fy, gh ugha gksrk gS] cfYd vkt ;s cMs&cMs Standalone Application Software o Distributed Application Develop djus dh lcls vklku o mi;ksxh Hkk’kk gSA ftruh vklkuh ls ge Java dk iz;ksx djds ,d Distributed System Create dj ldrs gSa] mruh vklkuh ls fdlh Hkh vU; Hkk’kk dk iz;ksx djds ge Internet ds fy, cMs Software Develop ugha dj ldrs gSaA vkius Hkh yksxksa dks ;s dgrs lquk gksxk fd Computer Programming dkQh dfBu dke gSA ;s gj fdlh ds cl dh ckr ugha gSA Computer Programmer cuus ds fy, MCA, B-Level tSls Degree Level Courses vkSj gtkjksa :i, ds Hardware o Software dh t:jr gksrh gSA lkFk gh ogh Programmer cu ldrk gS ftldk fnekx Computer dh rjg dke djrk gks ;kuh cgqr rst gksA tks ?k.Vksa fdlh leL;k dk lek/kku izkIr djus ds fy, /kS;ZiwoZd cSB ldrk gksA vkfn&vkfnA ,d vPNk Programmer cuus ds fy, ;s lHkh ckrsa t:jh gksrh Fkha ysfdu rc] tc Programmer fdlh Assembly Language ;k Cobol, Pascal vkfn tSlh fdlh Language esa Programming djuk lh[krk FkkA Java ds lkFk blls fcYdqy mYVk gSA Java esa Programming lh[kuk ftruk vklku gS] murk “kk;n gh fdlh Language dks lh[kuk gksA blesa cl dqN Basic Concepts /;ku gksa] rks cgqr gh vklkuh ls dksbZ Hkh vko”;drkuqlkj Program cuk ldrk gS vkSj mls Use dj ldrk gSA lkFk gh og vius Application dks Internet ij Hkh mruh gh vklkuh ls pyk ldrk gS ftruk vius Lo;a ds Computer ijA

ge Programming dks bruk Hard blfy, ekurs gSa D;ksafd ,slk gesa vU; Programmers us dgk gSA ;s Programmers dh Monopoly gS rkfd mUgsa vPNh Payment izkIr gks ldsA ;fn lHkh yksx ,slk dgus yxsa] fd Programming cgqr gh ljy dke gS] rks D;k Programmers dks fdlh Program ds fy, mrus iSls feysaxs ftrus vkt fey jgs gSaA “kk;n ugha] blhfy, lHkh Programmers dgrs gSa fd Programming lcls dfBu dke gSA gekjs ns”k esa yksx Computer Programming dks blfy, dfBu le>rs gSa] D;ksafd mUgsa mudh Hkk’kk esa fy[ks gq, Matter izkIr ugha gksrsA nwljh ckr ;s fd Computer dks Bhd ls rHkh le>k tk ldrk gS] tc English ij vPNh idM gksA ysfdu ,slk t:jh ugha gSA Computer Programmer cuus ds fy, vPNh English mruh t:jh ugha gS ftruh rF;ksa dks le>us o le>kus dh ;ksX;rk dh t:jr gSA

13 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Programming lh[kus ds fy, lcls igyh pht ;s r; djuh gksrh gS fd vkf[kj fdl Language ls Programming dh “kq:vkr dh tk,A gkykafd lHkh Languages esa yxHkx dqN rF; leku gh gksrs gSaA tSls Data Types, Operators, Conditional and Looping Statements vkfn] yxHkx lHkh Languages esa FkksMs cgqr vUrj ds vykok leku gh gksrs gSa vkSj mUgsa Use djus dk rjhdk dHkh dkQh gn rd lHkh Languages esa leku gksrk gSA

;fn vkius “C” Language esa ;k “C++” Language esa FkksMh cgqr Programming dh gS vkSj Programming ds Basic Concepts vkidks Clear gSa] rks Java vkids fy, vkxs cuk o lh[kuk ljy gksrk gS ysfdu fQj Hkh ge Java ls Programming lh[kuk “kq: dj ldrs gSaA ;s vius vki esa gh ,d iw.kZ Language gSA Java lh[kus ds ckn Hkh fdlh Hkh vU; Language dks mruh gh vklkuh ls lh[kk tk ldrk gS ftruh vklkuh ls fdlh vkSj Language dks lh[kus ds ckn Java dks lh[kk tkrk gSA High Level Programming Languages ds fodkl dh ;fn ckr djsa] rks UNIX Operating System ds fy, ,d Hkk’kk dk fodkl fd;k x;k Fkk] ftldk uke “C” Language fn;k x;kA bl Hkk’kk dk fodkl eq[; :i ls Operating System UNIX dks Develop djus ds fy, fd;k x;k FkkA UNIX Operating System Develop gks tkus ds ckn UNIX Operating System ds fy, Applications Software dks Develop fd;k tkus yxkA

pwafd “B” Language dk fodkl ,d System Software dks Develop djus ds fy, fd;k x;k Fkk] blfy, fofHkUu Programmers dks bl Language esa UNIX ds fy, Application Software fy[kus esa ijs”kkuh vkrh FkhA blfy, bl “B” Language dks vkSj ljy cuk;k x;k rkfd Programmers bl Language esa Application Programs Develop dj ldsaA bl Developed Language dks “C” Language uke fn;k x;kA “C” Language “kq:vkr esa dkQh mi;ksxh lkfcr gqbZ ysfdu ftl rjg ls gj pht esa fodkl gksrk gS] mlh rjg ls Computer Technology esa Hkh fodkl gqvkA /khjs&/khjs Application Software brus cMs o tfVy gksus yxs] fd “C” Language esa Develop fd, x, Programs dks Manage o Maintain djuk dkQh dfBu gks x;kA lkFk gh tSls&tSls le; chrrk x;k] Software dh tfVyrk Hkh cnkj cukus ds fy, fd;k tk jgk Fkk] rkfd fofHkUu izdkj ds Equipments dks Artificial Intelligence iznku dh tk ldsA gkykafd ,slk rks ugha gks ldk] ysfdu tkok ,d Dynamic Internet Programming Language ds :i esa dke vkus yxhA Java dk fodkl djus okys yksx ftl Project ij dke dj jgs Fks] os mlesa “C++” Language dk iz;ksx dj jgs Fks] tks fd “C” Language dk gh fodflr :i gSA ysfdu os tks djuk pkgrs Fks] oSlk “C++” ds iz;ksx ls ugha dj ik jgs FksA blfy, mUgksaus ,d ubZ Language Develop dhA bl Language dks mUgksaus “C” o “C++” ds vk/kkj ij gh Develop fd;k gSA os Java dks ,d cgqr gh ljy Language cukuk pkgrs Fks] blfy, mUgksaus “C” o “C++” dh lHkh vklku Concepts dks T;ksa dk R;ksa mi;ksx esa fy;k vkSj tfVy Concepts dks NksM fn;kA

mUgksaus Java Language ds Programming Syntax dks Hkh yxHkx oSls gh mi;ksx esa fy;k ftl rjg ls “C” o “C++” esa fy;k tkrk gSA lkFk gh mUgksaus dbZ vU; Languages ds Concepts dk Hkh iz;ksx tkok esa fd;k rkfd blesa fdlh Hkh izdkj dk Software vklkuh ls cuk;k tk lds vkSj Software iwjh rjg ls fo”oluh; cusA bl rjg ls Java dsoy “C” o “C++” dk Modified Version gh ugha gS] cfYd dbZ vU; Languages ds Concepts ij vk/kkfjr ,d iw.kZ Programming Language gSA gkykafd blds T;knkrj Syntax o Coding Procedures “C” o “C++” Language ds vuqlkj gSa] blfy, bls “C++” Language dk Modified Version Hkh dgk tk ldrk gSA tSls&tSls t:jr cs fcuk] vxyh Generation dh Languages dks le>uk dkQh eqf”dy gSA gkykafd tkok dk fodkl ftl dke ds fy, fd;k tk jgk Fkk] ml dke ds fy, tkok mi;ksxh ugha cu ik;kA ysfdu tc tkok ds Developers us ns[kk fd bl Language dk iz;ksx Internet dh Interactive Programming esa dkQh mi;ksxh lkfcr gks ldrk gS] rc mUgksaus bl Language dks Internet ds fy, Develop djuk “kq: fd;kA os ftl Platform Independent Equipment Technology ij dke dj jgs Fks] og rduhd Internet ds fy, mi;ksxh lkfcr gks xbZA

16 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Features of JAVA

Java dsoy ,d Programming Language gh ugha gS cfYd ;s ,d Platform Hkh gSA tc Sun Microsystems us November 1995 esa Java dks nqfu;k ls ifjfpr djok;k rc Company ds Cofounder Bill Joy us Java dh fuEu ifjHkk’kk nh Fkh fd Java ,d Small, Simple, Safe, Object-Oriented, Interpreted ;k Dynamically Optimized, Byte-Coded, Architecture-Neutral, Garbage-Collected, Multithreaded Programming Language gS ftlesa Distributed, Dynamically Extensible Programs fy[kus ds fy, ,d Strongly Typed Exception-Handling Mechanism gSA tkok ds bUgha xq.akksa dks tkok ds Features Hkh dgrs gSaA

Small and Simple Java ,d NksVh vkSj ljy Hkk’kk gS ftls vklkuh ls lh[kk tk ldrk gSA tkok dks bl rjg ls Design fd;k x;k gS fd bls dksbZ Hkh Programmer vklkuh ls lh[k lds vkSj Computer Programming ds Internal Functionality dks tkus fcuk Hkh T;knk ls T;knk Efficient Program Develop dj ldsA ;fn fdlh Programmer dks fdlh Hkh Programming Language dk FkksMk Hkh Kku gS] rks og cgqr gh vklkuh ls o tYnh ls Window Based Application o Internet Based Distributed Application (Applets) Develop djuk lh[k ldrk gSA tc tkok dks igyh ckj Release fd;k x;k Fkk] rc og dkQh NksVh Hkk’kk FkhA ysfdu vkt ;s dkQh cMh Hkk’kk cu pqdh gS vkSj lHkh izdkj ds Applications dks Efficiently Develop djus esa l{ke gSA ;s Language C/C++, Simula, Ada tSlh dbZ vU; Languages ls izsfjr gS] ysfdu bldh T;knkrj Coding C++ Language ds leku gh gSA blfy, fdlh C/C++ Programmer dks tkok lh[kus esa dksbZ dfBukbZ ugha gksrh gSA bl Language esa C o C++ ds vPNs Features dks Use dj fy;k x;k gS tcfd bu Languages ds Confusing rFkk Typical Features dks NksM dj muds LFkku ij vf/kd ljy Concepts dks Include dj fy;k x;k gSA tSls C++ ds Operator Overloading o Pointer tSls Concepts dks tkok esa NksM fn;k x;k gS] tcfd Multithreading tSlh Advance Technique dks Add dj fy;k x;k gSA Object Oriented Java esa gj pht Object o Class ds :i esa ifjHkkf’kr gS] ftls Object Oriented Programming Concept dgk tkrk gSA OOPS gesa Abstraction and Encapsulation, Polymorphism vkSj Inheritance tSls Features iznku djrk gS] ftlls ge ,d leL;k dks mlh rjg ls Computer esa Logically Organize dj ldrs gSa] ftl rjg ls leL;k Real World esa Actually ;k Physically Organized jgrh gSA tkok esa cgqr lkjh t:jh Classes igys ls gh Packages ds Form esa gesa izkIr gksrh gS] ftUgsa fcuk Rewrite fd, ge T;ksa dk R;ksa Use dj ldrs gSaA

17 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Distributed Java ds Programs Network ij ;kuh Web Pages ij Hkh Execute gksrs gSaA blfy, bls Distributed Language dgk tkrk gSA Distribution dk eryc ;s gksrk gS fd Java ds Program fdlh Hkh Platform ij Run gks ldrs gSaA ge tkurs gSa fd vkt dbZ rjg ds Operating Systems miyC/k gSa vkSj vyx&vyx yksx viuh t:jr o bPNk ds vuqlkj vyx&vyx Operating Systems dk iz;ksx djrs gSaA dksbZ Windows Operating System Use djrk gS rks dksbZ Linux rks dksbZ MacOS ;k OS/2 Use djrk gSA ;s lHkh vyx&vyx Platform dgykrs gSaA ;fn ge Windows Based Computer ij dksbZ Program “C” ;k Visual Basic tSlh Hkk’kk esa Create djrs gSa] rks os Program mu lHkh Computers ij vklkuh ls Run gksrs gSa tks Windows dks Use djrs gSaA ysfdu ;fn bUgha Programs dks Linux ;k MacOS ij Execute djus dh dksf”k”k dh tk, rks ;s Program ml Operating System ij Execute ugha gksrsA bu Platforms ds fy, Program dks okil bUgha Platform okys Computers ij Compile djuk iMrk gSA tcfd Java ds lkFk ,slk ugha gSA tkok esa ge fdlh Hkh Platform ij Program Create djds Compile djsa] os Program lHkh vU; Platforms ij leku :i ls Execute gksrs gSaA ;kuh Java ds Programs dks fofHkUu Platforms ij Distribute fd;k tk ldrk gSA blfy, Java dks Distributed Language dgk tkrk gSA tkok dks bl izdkj ls Design fd;k x;k gS fd ge blesa ,sls Applications Develop dj ldsa] tks Internet ij py ldsA bl Language esa ;s Ability gS fd ;s Data o Program nksuksa dks Internet ij fofHkUu Computers ij Share dj ldrk gSA tkok Applications Remote Objects dks Hkh mruh gh vklkuh ls Access o Open dj ldrs gSa] ftruh vklkuh ls os Local Computer ds Objects dks Open o Access djrs gSaA tkok ,slh Networking dh lqfo/kk iznku djrk gS fd fofHkUu Remote Locations ij fLFkr fofHkUu Programmers ,d gh Single Project ij leku le; ij ,d lkFk dke dj ldrs gSaA Compiled and Interpreted T;knkrj vU; Languages ds Programs ;k rks Compile gksrs gSa ;k fQj Interpreted gksrs gSaA ysfdu Java ds Programs Compile Hkh gksrs gSa vkSj Interpreted HkhA Java ds Programs dks lcls igys Compile fd;k tkrk gSA Java ds Program Compile gksus ds ckn lh/ks gh Machine Language esa Convert ugha gksrs gSa] cfYd ;s Source Code o Machine Code ds chp dh fLFkfr esa Convert gksrs gSa ftls Bytecodes dgk tkrk gSA bu Bytecodes dks tc fdlh Hkh Platform ij Run djuk gksrk gS rc ;s Bytecodes ml Computer ds Platform ds vuqlkj Interpreted gks dj iwjh rjg ls ml Machine ds vuqlkj Machine Code esa Convert gksrs gSa vkSj ml Platform ij Execute gks ldrs gSaA

18 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Robust and Safe Java ds Programs esa Errors vkus dh lEHkkouk vU; Languages dh rqyuk esa fcYdqy de gksrh gSA blfy, Java ds Programs dks Robust dgk tkrk gSA blds Compiler esa fofHkUu izdkj ls Generate gksus okyh Errors dks Handle djus ds fy, dbZ Built-In rjhds Develop dj fn, x, gS vkSj tkok dks bl rjg ls Design fd;k x;k gS] fd ,d ckj lgh rjhds ls Compiled Program esa dHkh Hkh Error vkus dh lEHkkouk ugha jgrh gSA ftruh Hkh Errors vkuh gksrh gSa] os lHkh Program Development o Testing ds le; gh vk tkrh gSa] ftUgsa Handle dj fy;k tkrk gSA blesa Compile Time o Runtime nksuksa LFkkuksa ij fofHkUu izdkj ds Errors ds fy, fofHkUu Data Types dh Checking gksrh gSA fofHkUu izdkj ds Objects }kjk yh tkus okyh Memory dks ;s Lo;a gh Release dj nsrk gS] ftlls gesa bl ckr dh fpUrk djus dh t:jr ugha gksrh gS] fd geus lHkh Unrequited Objects dks Destroy djds mudh Memory dks Release fd;k ;k ughaA tkok esa Exception Handling ds fy, Hkh lqfo/kk iznku dh xbZ gS] ftldk iz;ksx ge Serious Errors dks Trap djus o mUgsa Solve djus ds fy, dj ldrs gSa] ftlls gekjs Program dh vkSj lqj{kk gks tkrh gSA tc ge Internet dh ckr djrs gSa] rc Security dkQh ek;uk j[krh gSA tkok Lo;a gh fofHkUu izdkj ds Memory Management o Memory Access ls lEcaf/kr dke djrk gS] blfy, ;s dHkh Hkh Memory o mlesa Stored Data dks xyr rjhds ls Access djus dh NwV ugha nsrk gSA bl otg ls Applet }kjk fdlh Computer esa Virus vkus dh lEHkkouk gh ugha gksrh gSA D;ksafd tkok esa Pointers dh lqfo/kk ugha gS tks Directly Memory dks Access dj lds] blfy, ge fdlh Hkh Computer dh Memory dks Directly Access ugha dj ldrs gSaA lkFk gh tkok Applets dHkh fdlh Client Computer ds Resources dks Access ugha djrs gSa] blfy, tkok Applets dHkh Hkh Clients ds Computer ;k mlds Data dks uqdlku ugha igqapk ldrs gSaA Architecture Neutral / Platform Independent / Portable / Byte Coded Java ds Bytecodes fofHkUu izdkj ds Processors o Operating Systems ij leku :i ls Run gks ldrs gSaA blfy, bls Architecture Neutral or Portable dgk tkrk gSA tkok ds Programs dks dsoy ,d gh ckj Develop djuk gksrk gSA ,d ckj bls Develop djus ds ckn bls fdlh Hkh Computer ij fdlh Hkh Platform ij Run fd;k tk ldrk gSA ;fn Operating System, System Resources ;k Processor esa Change fd;k tkrk gS] rc Hkh gesa tkok ds Program esa fdlh izdkj dk Change djus dh t:jr ugha gksrh gSA ;gh tkok ds lcls T;knk Popular gksus dh eq[; otg gS] ftlls ge tkok dk iz;ksx Internet Programming ds fy, djds World Wide Web ij Run gksus okys Applications Develop djrs gSa vkSj fofHkUu Computers dks vkil esa Interconnected djrs gq, World Wide Web ij dke djus ds fy, ,sls Programs dks Use djrs gSaA

19 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ge tkok Applet dks Remote Computer ls Download dj ldrs gSa vkSj fQj mls vius Computer ij Run dj ldrs gSaA bl izdkj dh lqfo/kk gksus ls ,d User dks mlds ?kj ij gh fofHkUu izdkj ds Applications o Applets izkIr gks tkrs gSa] ftUgsa og Use djuk pkgrk gSA tkok nks rjhdksa ls Portable gksrk gS% ,d rks tkok Compiler Byte Codes Instructions Generate djrk gS] ftls fdlh Hkh Computer ij Implement fd;k tk ldrk gS vkSj nwljk tkok ds Primitive ;k Basic Data Types Machine ij fuHkZj ugha gksrs gSa cfYd tkok Platform ij fuHkZj gksrs gSaA ;kuh fdlh Hkh Compute ij tkok ds lHkh Data Types dh Size leku gksrh gS] pkgs ge Pentium Computer ij tkok Program dks Use djsa] pkgs AMD ijA

Garbage Collective Java ,d Programmer dks Memory Manage djus dh lqfo/kk iznku ugha djrk gS cfYd t:jr ds vuqlkj Lo;a gh Memory Management djrk gSA blfy, Programmer }kjk Memory Management ds le; fdlh nwljs Data dks uqdlku igqapkus dh lEHkkouk ugha gksrh gSA blfy, ;s Language “C” o “C++” tSlh Hkk’kkvksa dh rqyuk esa vf/kd lqjf{kr ;k Secure Language gSA High Performance Java ds Program Interpreted Mode esa Run gksrs gSa ysfdu fQj Hkh vU; Interpreted Based Languages dh rqyuk esa Java dh Speed o Performance cgqr vPNh gksrh gSA blfy, bls High Performance Language dgk tkrk gSA Multithreaded and Interactive Java ;s lqfo/kk iznku djrk gS fd ,d gh Software Program ds fofHkUu Hkkxksa dks ,d gh le; esa ,d lkFk Run fd;k tk ldrk gSA blfy, bls Multithreaded Language dgk tkrk gSA mnkgj.k ds fy, ekuyks fd ge fdlh Program ls Audio Sound rks lqu gh jgs gSa] lkFk gh mlh Program esa Scroll Bars dks Hkh Use dj jgs gSaA fdlh Window esa ,d rjQ dksbZ Movie Clip rks Play gks gh jgk gS] lkFk gh ge fdlh vU; Movie Clip dks Open djus ds fy, Open Dialog Box esa fdlh nqljh Movie Clip dks Hkh [kkst jgs gSaA bl rjg ls ,d gh Program ds fofHkUu fgLlksa dk ,d gh le; esa ,d lkFk Run gksuk Multithreaded Concept ds dkj.k gh lEHko gksrk gSA Dynamic and Extensible Java esa ,d gh Program ds dbZ Versions dks ,d lkFk Maintain fd;k tk ldrk gSA blfy, bls Dynamic Language Hkh dgk tkrk gSA ;kuh tkok ,d Dynamic Language gSA tkok esa fdlh Program ds fy, Required Classes tkok ds Program ds Run gksrs le; mlesa Link gks ldrh gS vkSj tSls gh ml Class dk dke lekIr gksrk gS] og Class

20 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Lo;a gh Memory ls Release gks tkrh gSA bl izfØ;k dks Dynamic Process dgk tkrk gSA tkok ,d Query }kjk ;s Hkh Determine dj ldrk gS fd Program ds Run Time esa mlls dkSulh Class Link gks jgh gSA lkFk gh og Program ds Run Time esa Hkh fdlh Hkh Dynamic Class ;k Dynamic Link Library ls Link gks ldrk gS vkSj Run Time lqfo/kkvksa dks izkIr dj ldrk gSA bl izfØ;k dks Dynamic Linking Hkh dgrs gSaA tkok gesa vU; Languages ds Methods dks Hkh tkok esa Use djus dh lqfo/kk iznku djrk gSA bu Methods dks Native Methods dgrs gSa vkSj ;s Program ds Run Time esa Dynamically Link gks dj viuk dke djrs gSaA ;kuh ge tkok esa vU; Languages dh lqfo/kkvksa dks Use djds tkok ds Program dh {kerkvksa dks cus ;ksX; Machine Language esa Convert dj ldsA Interpreter ,d ,slk Program gS tks fdlh Hkh Program dh Source File ds gj Statement ;k Code dh gj Line dks Computer dh Machine Language esa Convert djds Computer dks crkrk gS fd mls D;k djuk gSA

dqN Languages esa ,d vU; Software ftls Compiler dgrs gSa dk iz;ksx djds Source Code File dks Machine Language esa Convert djrk gSA bu nksuksa esa vUrj dsoy bruk gS fd Interpreter Source File ds gj Line ;k gj Statement dks Computer ds le>us ;ksX; Binary Language esa Convert djrk gS vkSj ;fn fdlh Statement esa dksbZ Error gks rks ml Line ;k Statement ls vkxs Interpret ugha gksrkA tcfd Compiler ,d ,slk Program gksrk gS tks iwjs Program dks ,d lkFk Machine Language esa Convert djrk gSA ;fn Program esa dksbZ Error gks rks Program lHkh Errors dks ,d lkFk Display djrk gS vkSj rc rd Program dks Machine Language esa Convert ugha djrk gS tc rd fd lHkh Errors dks Debug uk dj fn;k tk,A tks Program Interpreted gksrs gSa os Compiled Program dh rqyuk esa /khjs pyrs gSaA ysfdu Java ,d ,slh Language gS ftldks Interpreter o Compiler nksuksa dh t:jr gksrh gSA tc Hkh ge dksbZ Program fy[krs gSa rks mlesa fdlh uk fdlh rjg dh Errors gesa”kk vkrh gSA bu Errors dks Computer Programming dh Hkk’kk esa Bug dgk tkrk gS vkSj bu Errors dks lgh djus ds Process dks Debug djuk dgrs gSaA

Procedural Techniques and OOPS

Pascal, C, Basic, Fortran tSlh ikjEifjd Hkk’kk,a Procedural Languages ds mnkgj.k gSa] ftlesa izR;sd Statement Computer dks dqN djus dk vkns”k nsrk gSA ;kuh Procedural Languages Instructions dk ,d lewg gksrk gSA Procedural Languages esa NksVs Programs ds fy;s fdlh Hkh vU; izdkj ds Pattern dh vko”;drk ugh gksrh gSA Programmer Instructions dh List cukrk gS vkSj Computer muds vuqlkj dke djrk gSA

tc izksxzke dkQh cMs o tfVy gks tkrs gSa] rc Instructions dh ;g List dkQh ijs”kkuh iSnk djrh gSA blfy;s ,d cMs izksxzke dks NksVs&NksVs VqdMksa esa ckaV fn;k tkrk gSA bu NksVs&NksVs 27 Any Question or Suggestion, Just Discuss Here...

Java in Hindi VqdMksa dks Functions dgk tkrk gSA Functions dks nwljh vU; Hkk’kkvksa esa Subroutine, Subprogram ;k Procedure dgk tkrk gSA ,d cMs izksxzke dks NksVs&NksVs Functions esa foHkkftr djus ls iwjk Program Functions dk ,d lewg cu tkrk gSA bls Module dgk tkrk gSA ysfdu ;s Modules Hkh Procedural Programming esa gh vkrs gaS D;ksafd lHkh Functions esa Statements dh ,d List gksrh gS vkSj lHkh Functions fey dj iwjk Program cukrs gSa] ftlls iwjk Program Instructions dh ,d cgqr cMh List cu tkrh gSA Procedural Languages ds “kq:vkrh nkSj esa buesa gh Program Develop fd, tkrs FksA “C” Hkh ,d Procedural Languages gS vkSj tc “C” Hkk’kk dk vkfo’dkj gqvk Fkk rc Programmers vU; Hkk’kkvksa dks NksM dj “C” esa gh vius Program Develop djus yxs FksA

ysfdu le; o vko”;drk ds vuqlkj tc Program cMs o tfVy gksus yxs] rc Programmers dks bl Hkk’kk esa izksxzke cukus esa fnDdrsa vkus yxhaA mUgksus eglwl fd;k fd bl Hkk’kk esa dqN lq/kkj dh vko”;drk gS rkfd ;s Hkk’kk ljy o yksdfiz; cu ldsA ;s Hkk’kk ljy cu lds blds fy;s bldk okLrfod thou ds vuqlkj gksuk t:jh FkkA ;kuh ge gekjs lkekU; thou esa ftl izdkj ls O;ogkj djrs gSa] bl Hkk’kk dk Hkh oSlk gh gksuk t:jh Fkk rkfd Programmers blesa vf/kd ljyrk o lQyrk ls Program cuk ldsaA Hkk’kk okLrfod thou ds vuqlkj gks] ;gh Concept Object Oriented Programming ;kuh OOP dk vk/kkj cukA “C” Hkk’kk dh bu dfe;ksa dks igpkuk x;k vkSj blesa lq/kkj fd;k x;kA QyLo:i gesa “C” Hkk’kk dk ,d u;k laLdj.k “C++” izkIr gqvk tks fd Object Oriented Concept ij vk/kkfjr gSA vko”;drk ds vuqlkj bl Hkk’kk dh dfe;ksa dks Hkh igpkuk x;k vkSj mlesa lq/kkj djus ij tks ubZ Hkk’kk lkeus vkbZ og Java FkhA vkb;sa] ge Hkh tkuus dh dksf”k”k djrs gSa fd “C” Hkk’kk esa ,slh dkSulh dfe;ka Fkha] ftuesa lq/kkj dh vko”;drk eglwl dh xbZ \ Procedural Languages esa dke gksus dk egRo Fkk Data dk ugha] ;kuh fd Keyboard ls Data Input fd;k tk,] Data ij Processing dh tk,] Errors dks Check fd;k tk, vkfnA Functions esa Hkh blh egRo dks tkjh j[kk x;kA Functions dksbZ dke djrs gSa] mlh izdkj ls ftl izdkj ls lk/kkj.k Statement djrk gSA Functions dksbZ tfVy dke Hkh dj ldrs gSa

ysfdu buesa Hkh dke ds gksus dk gh egRo FkkA

iwjs Program esa Data ij dksbZ /;ku ugha fn;k tkrk Fkk tcfd iwjs izksxzke dk ewy vk/kkj Data gh gksrk gSA fdlh Inventory ds Program esa bl ckr dk dksbZ T;knk egRo ugha gksrk gS fd Data dks fdl izdkj ls Display fd;k tkrk gS ;k ,d Function fdl izdkj ls Corrupt Data dks Check djrk gS] cfYd bl ckr dk gksrk gS fd Data D;k gS vkSj og fdl izdkj ls Program esa dke vk jgk gSA Procedural Program esa Data dks f}rh; Lrj ij j[kk x;k Fkk tcfd fdlh Hkh Program dk ewy vk/kkj Data gh gksrk gSA mnkgj.k ds fy;s] fdlh Inventory ds Program esa fdlh Data File dks Memory esa Load fd;k tkrk gS] rc ;s File ,d Global Variable dh rjg gksrh gS] ftls dksbZ Hkh Function Use dj ldrk gSA ;s Functions Data ij fofHkUu izdkj ds Operations djrs gSaA ;kuh ;s Data dks Read djrs gS] Analyze djrs gSa] Update djrs gSa] Rearrange djrs gSa] Display djrs gSa vkSj okil Disk ij Write djrs gSaA “C” esa Local Variables Hkh gksrs gSa ysfdu Local Variables, egRoiw.kZ Data ds fy;s brus mi;ksxh ugha gksrs gSa] tks fd fofHkUu Functions }kjk Access fd, tkrs gSaA 28 Any Question or Suggestion, Just Discuss Here...

Java in Hindi eku yksa fd ,d u, Programmer dks Data dks fdlh [kkl rjhds ls Analyze djus ds fy;s ,d Function fy[kus dks dgk x;kA izksxzke dh tfVyrk ls vufHkK Programmer ,d ,slk Function cukrk gS] tks fd vpkud fdlh egRoiw.kZ Data dks u’V dj nsrk gSA ,slk gksuk dkQh vklku gS D;ksafd dksbZ Hkh Function Data dks Access dj ldrk gSA blfy;s D;ksafd Procedural Language esa Data Global gksrk gSA ;s dqN ,slk gh gS tSls fd vki vius Personal dkxtkr dks Telephone Directory ds ikl j[k nsa tgka dHkh Hkh dksbZ Hkh igqap ldrk gS] mlls NsMNkM dj ldrk gS vkSj mls u’V dj ldrk gSA blh izdkj ls Procedural Languages esa gksrk gS tgka vkidk Data Global gksrk gS vkSj dksbZ Hkh Function mls Use djds [kjkc dj ldrk gS ;k uqdlku igqapk ldrk gSA Procedural Languages dh nwljh deh ;s Fkh fd dbZ Functions ,d lkFk ,d gh Data dks Use dj jgs gksrs gSa] blfy;s Data dks Store djus dk rjhdk dkQh tfVy gks tkrk gSA leku Data dks Use dj jgs lHkh Functions dks Modify fd, fcuk Data esa fdlh izdkj dk dksbZ

ifjorZu ugha fd;k tk ldrk gSA

mnkgj.k ds fy;s ;fn vki ,d u;k Data Add djrs gSa rks mu lHkh Functions dks Modify djuk gksxk tks fd Data dks Use dj jgs gSa] rkfd ;s lHkh Functions Add fd, x, u, Data dks Use dj ldsaA ;s irk djuk fd dkSu&dkSu ls Function Data dks Use dj jgs gSa vkSj lHkh dks fcYdqy lgh rjhds ls Modify djuk dkQh dfBu gksrk gSA Procedural Programs dks Design djuk dkQh eqf”dy gksrk gSA leL;k ;s gksrh gS fd Design okLrfod thou ls Related ugha gksrk gSA tSls fd] ekuk vki ,d Graphics Interface esa Menus, Windows ds fy;s Code fy[kuk pkgrs gSa] rks vkidks ;s r; eqf”dy gksxk fd dkSuls Functions Use fd, tk,\ dkSulk Data Structure Use fd;k

vkfnA budk dksbZ Li’V mRrj ugha gSA

budk

User

djuk tk,\

Procedural Programs ds lkFk dbZ vkSj ijs”kkfu;ka gSaA muesa ls ,d leL;k u, Data Type dh gSA Computer Languages esa dbZ izdkj ds Built-in Data Types gksrs gSa] tSls fd Integer, Float, Character vkfnA ekuyks fd vki Complex Numbers ds lkFk izfØ;k djuk pkgrs gSa ;k Two-dimensional Coordinates ds lkFk dke djuk pkgrs gSa ;k Data ds lkFk izfØ;k djuk pkgrs gSaA Built-in Data Type budks vklkuh ls Handle ugha dj ldrs gSaA

blfy, gesa gekjh vko”;drkuqlkj Lo;a ds Data Type cukus dh t:jr gksrh gSA Procedural Language esa Lo;a ds Data Type cuk dj ge mUgs fcYdqy Built-in Data Type dh rjg Use ugha dj ldrs gSaA Procedural Language brus mUur ugha gSaA fcuk vizkd`frd tfVy rjhdksa ds vki Procedural Languages esa x o y nksuksa Coordinates dks ,d gh Variable esa Store djds ml ij Processing ugha dj ldrs gSaA Procedural Languages dks fy[kuk o Maintain djuk dkQh eqf”dy dke gksrk gSA

The Object-Oriented Approach

Object Oriented Language dk ewyHkwr fopkj ;s gS fd ftl leL;k dk lek/kku Computer ij izkIr djuk gS ml leL;k ds ewy Data vkSj ml Data ij dke djus okys Functions dks Combine djds ,d Unit ds :i esa ys fy;k tkrk gSA bl Unit dks Object dgk tkrk gSA

29 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ,d Object ds Data ij dke djus ds fy;s fy[ks x, Operations ;k Functions dks Java esa Methods dgk tkrk gSA ;s Methods fdlh Object ds Data dks Access djus dk ,d ek= ek/;e gksrs gSaA ;fn vki fdlh Object ds vUnj j[ks fdlh Data dks Read djuk pkgrs gSa] rks vkidks blh Object ds vUnj Define fd, x, ml Method dks Use djuk iMrk gS] ftls ml Object ds Data dks Access djus ds fy;s gh ifjHkkf’kr fd;k x;k gSA ;gh ,d Method gksrk gS ftldh enn ls vki ml Object ds Data dks Read dj ldrs gSaA vki lh/ks gh Data ds lkFk fdlh izdkj dh izfØ;k ugha dj ldrs gSa D;ksafd Data Hidden jgrk gSA blfy;s fdlh izdkj ls vpkud gq, ifjorZu ls Data lqjf{kr jgrk gSA Data o Data dks Use dj ldus okys Functions ;k Operations dk ,d lkFk ,d gh Unit ds :i esa gksuk Encapsulation dgykrk gSA Data dk Hidden jguk ;kuh Data Hiding o Encapsulation Object Oriented Programming dk ewy rF; ;k Key Terms gSA ;fn vki fdlh Data dks Modify djuk pkgrs gSa] rks vkidks irk gksuk pkfg, fd dkSulk Method ml Data ij Required Operation djus dh {kerk j[krk gSA dksbZ Hkh vU; Method ml Data dks Access ugha dj ldrk gSA ;s Processing Program dks fy[kuk] Debug djuk o Maintain djuk vklku cukrh gSA

,d Java dk izksxzke us esa tfVy gks tkrk gS] gkykafd Pointers ds iz;ksx ls gekjk Program Directly Memory Locations dks Access dj ldrk gS] blfy, Program dh Speed rqyuk esa rst gks tkrh gSA “C++” ds Programmers gesa”kk Dynamic Data Structure dks Create o Maintain djus ds fy, Pointers Arithmetic dk iz;ksx djrs gSa vkSj gesa”kk tfVy Bugs esa Qalrs gSaA “C++” Programmers dk T;knkrj le; mu Programs dks Create djus esa ugha chrrk ftuesa Pointer dk iz;ksx gksrk gS] cfYd mu Programs dks Debug djus esa chrrk gSA Java Pointers dks Support ugha djrk gSA ;kuh Java esa Pointes tSlh dksbZ O;oLFkk ugha gS tks Directly Memory dks Access dj ldsA gkykafd Pointers ds LFkku ij Java esa References dk cgqr iz;ksx fd;k tkrk gS tks fd Pointers ds leku gh dke djrs gSa ysfdu References dk Arithmetic lkekU; Arithmetic tSlk gh gksrk gS uk fd Pointer Arithmetic

tSlkA

bl Process ls mu lHkh Errors ls NqVdkjk fey tkrk gS tks Pointers ds Mismanagement ds dkj.k Generate gksrh gSaA References dk iz;ksx djus ls Java ds Program i;kZIr Readable o le>us ;ksX; gksrs gSa tcfd Pointers dk pkgs iwjh rjg ls lgh iz;ksx fd;k tk,] ysfdu Program vklkuh ls le>us ;ksX; o Readable ugha gksrk gSA “C” o “C++” ds Programmers lksap ldrs gSa fd os tks dke Pointers dk iz;ksx djds dkQh vklkuh ls dqN Data Structures dks Implement dj ldrs Fks os dke Java esa ugha fd, tk ldsaxsA tSls fd Dynamic Arrays Java esa Create ugha gks ldrsA ysfdu ,slk ugha gSA okLrfodrk ;s gS fd os lHkh dke Java esa Objects o Objects ds Array ds iz;ksx ls vf/kd vklkuh o Reliability ds lkFk fd, tk ldrs gSaA Java gesa dqN Runtime Security Hkh iznku djrk gS tks dksbZ vU; Language Provide ugha djrhA tSls fd ;fn ge “C” ;k “C++” esa fdlh Array dh Size dks 10 Define fd;k gS vkSj ge 11th Index Number ij dksbZ eku Input djuk pkgsa rks Java gesa ,slk ugha djus nsrk tcfd “C” o “C++” esa ge ,slk djds fdlh nwljs Data dks Damage dj ldrs gSaA

Structure and Union “C” esa nks rjg ds (Structure and Union) vkSj “C++” esa rhu rjg ds (Structure Union and Class ) Complex Data Types gSaA Java esa dsoy ,d gh Complex Data Type gS ftls Class dgrs gSaA “C” o “C++” esa ftrus dke bu rhuksa dks iz;ksx djds fd, tkrs gSa Java esa os lHkh dke dsoy ,d Class ls gh fd;k tk ldrk gSA tc gesa Structure ;k Union ds Functionality dh t:jr gksrh gS rks Java gesa bu Functionality dks Class }kjk izkIr djus ds fy, ck/; djrk gSA 32 Any Question or Suggestion, Just Discuss Here...

Java in Hindi gkykafd ,slk yx ldrk gS fd Java esa Programmers dks Structure o Union ds LFkku ij Class Use djus ds fy, Extra dke djuk iMsxk ysfdu ,slk ugha gSA cfYd Class ds iz;ksx ls Program dh tfVyrk de gks tkrh gSA Java cukus okyksa us blh ckr dks izkFkfedrk nh gS fd ftruk gks lds mruk Java dks Simple o vklkuh ls le>us ;ksX; Language esa j[kk tk,] blfy, Java esa ls “C” o “C++” dh mu phtksa dks gVk fn;k x;k gS tks lh[kus o le>us esa ijs”kkuh Create djrh gSa vkSj Language dks

tfVy cukrh gSaA

oSls “C” o “C++” dks mu yksxksa ds fy, fy[kk x;k Fkk tks igys ls gh is”ksoj Programmer Fks] ysfdu Java dks u, Programmers dks /;ku esa j[k dj Develop fd;k x;k gS] tks fd is”ksoj ugha gSa vkSj Computer dks cgqr xgjkbZ ls ugha tkurs cfYd ftUgsa Computer dk lkekU; Kku gh gSA pwafd Java esa Structure o Union ugha gSa blfy, Java ,d iw.kZ Object Oriented Programming Language gS] D;ksafd blesa tks Hkh dke djuk gksrk gS] mlds fy, Class Develop djuh iMrh gSA blls Program Codes dks uk dsoy Reuse fd;k tk ldrk gS cfYd Program dks Maintain djuk Hkh vU; Languages dh rqyuk esa dkQh ljy gksrk gSA

Functions “C” o “C++” esa lHkh Program Codes dks fdlh uk fdlh Function esa fy[kk tkrk gSA ;gka rd fd Main Program Hkh ,d Function main() esa gksrk gS tgka vko”;drkuqlkj vU; Functions dks Call djds viuk dke iwjk fd;k tkrk gSA ;s Functions Global j[ks tkrs gSa rkfd iwjs Program dk dksbZ Hkh vU; Function bUgsa Call dj lds vkSj Data ij Required Processing dj ldsA “C++” esa Hkh Functions gksrs gSa ftuds ek/;e ls Class ds Data dks Access fd;k tkrk gSA bu Functions dks gh Method dgk tkrk gSA “C++” Class ds Methods Java Class ds Methods ds leku gh gksrs gSaA fQj Hkh pwafd “C++” “C” tSlh Procedural Language dks Hkh Support djrk gS blfy, bls iwjh rjg ls Object Oriented Programming Language ugha dgk tk ldrk] cfYd bls Hybrid Language dgk tkrk gSA bl fLFkfr esa “C++” ds Class ds Methods o Class ds ckgj ds Functions nksuksa dk Mixture gksrk gS] blfy, dqN gn rd “C++” esa Confusion dh fLFkfr Hkh cuh jgrh gS ftlls dbZ ckj vthc rjg ds Bugs dk lkeuk djuk iMrk gSA Java esa dksbZ Function ugha gksrk gS] blfy, Java “C++” dh rqyuk Oriented Programming Language gSA Java Programmer dks bl gS fd Programmer vius lHkh Routines dks Class Methods ds :i Java dh bl ck/;rk ds dkj.k Programmer vius Codes dks Organize djds j[krk gSA

esa iwjh rjg ls Object ckr ds fy, ck/; djrh esa O;ofLFkr djds j[ksA vf/kd vPNs rjhds ls

Multiple Inheritance

Multiple Inheritance “C++” dh ,d ,slh O;oLFkk gS ftlesa ge dbZ Classes ls viuh vko”;drkuqlkj dqN&dqN Features dks ysdj ,d ubZ Class cuk ldrs gSaA ;kuh ge ,d Class dks dbZ Parent Class ls Derive dj ldrs gSaA gkykafd Multiple Inheritance okLro 33 Any Question or Suggestion, Just Discuss Here...

Java in Hindi esa dkQh Powerful gS] ysfdu dbZ Classes ls ,d Derive Class cukus o mls Maintain djus esa Programmer dks dkQh ijs”kkuh dk lkeuk djuk iMrk gSA Java Multiple Inheritance dks Support ugha djrk gSA “C++” dh bl Functionality dks ge Java esa Interfaces dk iz;ksx djds izkIr dj ldrs gSaA Java ds Interfaces Object Method Description Provide djrs gSa ysfdu buesa dksbZ Implementation ugha gksrk gSA

Strings “C” o “C++” esa Text Strings dks Handle djus ds fy, dksbZ Built – In Support ugha gSA String dks Handle djus ds fy, “C” o “C++” Programmers dks ,d Null Terminated Array dk iz;ksx djuk iMrk gSA Java esa Strings dks ,d First Class Object dh rjg Implement fd;k tkrk gS ;kuh] Strings Java Language dk eq[; fcUnq ;k Core gSA Java esa ge ,d Object ds :i esa String dks Implement djrs gSa] ftlls gesa dbZ Advantages izkIr gksrh gSA

goto Statement “C” o “C++” esa bl Statement dks vko”;drkuqlkj dkQh Use fd;k tkrk gSA ysfdu blds Use djus ij ftruh rjg dh ijs”kkfu;ka vkrh gSa] mUgsa r; djuk gh eqf”dy gSA goto Statement dk iz;ksx ;fn cMs Program esa fd;k tkrk gS] rks fdlh u, Programmer ds fy, ml Program dks le>uk ukeqefdu gks tkrk gSA ;s ,d Branching Statement gS] ysfdu Program esa ;s Statement Program Control dks dkQh Jump djokrk gS] ftlls Program dh Efficiency Hkh izHkkfor gksrh gSA Java esa bl Statement dks Support ugha fd;k x;k gSA Java us goto dks ,d Keyword ds :i esa ekU;rk nh gS ysfdu blds mi;ksx dks Support ugha fd;k gSA

Operator Overloading Operator Overloading dks Java esa Support ugha fd;k x;k gSA Operator Overloading “C++” dh ,d ,slh rduhd gS ftlls fdlh Hkh Primary Operator dks vko”;drkuqlkj nwljk vFkZ iznku dj fn;k tkrk gSA tSls + Operator dk iz;ksx nks Objects dks tksMus ds fy, fd;k tk ldrk gSA gkykafd Java esa bl dke dks Class esa fd;k tkrk gSA ysfdu Operator Overloading rduhd dks Java esa NksM fn;k x;k gSA Operator Overloading Programmer ds fy, ,d lqfo/kk gksrh gS] ysfdu blls ,d gh Operator dks ,d gh Program esa fofHkUu vFkZ iznku dj fn, tkus ls Program dks le>us esa Confusion gks tkus dh lEHkkouk jgrh gSA blfy, bl rduhd dks Java esa NksM fn;k x;k gSA Automatic Type Casting “C” o “C++” esa Automatic Type Casting gks ldrh gSA ;kuh ,d Integer izdkj ds Variable dks ;fn Float izdkj dk eku iznku djuk gks] rks “C” o “C++” dk Compiler Automatic Type Casting djds ,d Variable ds eku dks nwljs Variable ds eku esa Automatically Convert dj nsrk gSA ;g Automatic Type Casting dgykrh gSA tcfd Java esa bls Support ugha fd;k x;k gSA

34 Any Question or Suggestion, Just Discuss Here...

Java in Hindi D;ksafd tc fdlh ,d Data Type ds Variable dks nwljs izdkj ds Data Type ds Variable dk eku iznku fd;k tkrk gS] rks Data ds eku dk Loss gks tkrk gSA tSls ;fn Integer izdkj ds Variable dks fdlh Float izdkj ds Variable dk eku iznku fd;k tk,] rks Integer izdkj ds Variable esa Float izdkj ds eku esa nleyo ds ckn dh la[;k Store ugha gksrh gSA ;kuh nleyo ds ckn dh la[;k dk Loss gks tkrk gSA blfy, Java esa bl Automatic Type Casting dks Support ugha fd;k x;k gSA Java esa ;fn fdlh Data ds eku dk fdlh Hkh izdkj dh izfØ;k ls Loss gksrk gS rks Java Automatic Type Casting ugha djrk gSA bldh Type Casting Programmer dks gh djuh iMrh gSA Variable Number of Arguments “C” o “C++” esa geus ns[kk gS fd ge printf() Function ;k Scanf() Function esa viuh vko”;drkuqlkj ,d ;k ,d ls vf/kd pkgs ftrus Hkh Arguments iznku dj ldrs gSaA ;fn gesa pkj Variable ds eku Output esa Print djus gksa rks ge printf() Function esa pkj Variable Argument ds :i esa Hkst ldrs gSa vkSj ;fn dsoy ,d gh Variable dk eku Print djuk gks rks dsoy ,d Argument Hkh printf() Function esa Hkst ldrs gSA gkykafd ;s ,d vPNk rjhdk gS ysfdu Java esa bls Support ugha fd;k x;k gSA D;ksafd Compiler ;s dHkh Check ugha dj ikrk gS fd mls ftl Argument ds eku dks Print djuk gS og mfpr Data Type dk gS ;k ughaA Command Line Argument Java Program esa ftl rjg ls Command Line ij Argument Pass fd, tkrs gSa os “C” o “C++” ds Program esa Pass fd, tkus okys Arguments dh rqyuk esa FkksMs vyx gksrs gSaA “C” o “C++” esa System main() Function dks nks Arguments Pass djrk gSA igyk Argument argc vkSj nwljk Argument argv gksrk gSA igyk Argument argc ;s Specify djrk gS fd nwljs Argument argv esa fdrus Arguments gSaA nwljk Argument argv ,d Array of Characters dk Pointer gksrk gSA blh Argument esa Command Prompt ij fn, tkus okys Actual Arguments gksrs gSaA Java esa System Command Line ls dsoy ,d gh Argument args Java Program esa Pass djrk gSA ;s ,d Strings dk Array gksrk gS ftlesa Command Line Arguments gksrs

gSaA

“C” o “C++” esa Command Line Arguments ,d Program esa Pass gksrs gSaA bl Argument esa ml Program dk uke Hkh gksrk gS ftlesa Arguments dks Pass djuk gksrk gSA ;s uke Command Line ij lcls igys First Argument ds :i esa fy[kk tkrk gSA Java esa ge igys ls gh ml Program dk uke tkurs gksrs gSa ftlesa gesa Argument Hkstuk gksrk gSA ;s uke gesa”kk ml Program ds Class dk uke gh gksrk gS] blfy, Command Prompt ij gesa dsoy Argument gh Pass djuk gksrk gSA

35 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Programming – The Basic Concept

Computer Programming le>us ls igys gesa ;s le>uk gksrk gS fd Computer D;k dke djrk gS vkSj dSls dke djrk gSA dEI;qVj dk eq[; dke Data dk Management djuk gksrk gSA gekjs vkl&ikl tks Hkh phtsa gesa fn[kkbZ nsrh gSa os lHkh ,d Object Oriented Programming Language ds fy, Objects gSaA

gj Objects ds dqN Attributes gksrs gSa] ftuls fdlh Particular Object dh igpku gksrh gSA bl Attribute esa Numerical ;k Non–Numerical fdlh uk fdlh izdkj dk eku iznku fd;k tk ldrk gSA ;s eku gh Computer dk og Data gksrk gS] ftls Computer Manage djrk gSA ;fn fcYdqy gh ljy “kCnksa esa dgsa rks dksbZ eku ;k ekuksa dk lewg Computer ds fy, Data gksrk gSA ;s eku nks rjg ds gks ldrs gSa % Numerical ;k Non-Numerical, Computer esa ge bUgha Data dks Store djrs gSa] Process djrs gSa vkSj fdlh uk fdlh izdkj dh Information Generate djrs gSaA Computer dsoy Electrical Signals ;k e”khuh Hkk’kk dks le>rk gSA ;s e”khuh Hkk’kk ck;ujh :i esa gksrh gS tgka fdlh Signal ds gksus dks 1 o uk gksus dks 0 ls iznf”kZr fd;k tkrk gSA ;fn ge gekjh fdlh ckr dks Binary Format esa Computer esa Feed dj ldsa] rks Computer gekjh ckr dks le> ldrk gSA Computer Hkk’kk og Hkk’kk gksrh gS] ftls Computer le> ldrk gSA gj Computer Hkk’kk dk ,d Software gksrk gS] ftls Compiler ;k Interpreter dgrs gSaA ;s Software gekjh ckr dks Computer ds le>us ;ksX; e”khuh Hkk’kk ;k Binary Format esa Convert djrk gSA Computer dks dksbZ ckr le>kus ds fy, mls ,d fuf”pr Øe esa lwpuk,a nsuh gksrh gSa] ftUgsa Instructions dgk tkrk gSA Computer bu nh xbZ Instructions ds vuqlkj dke djrk gS vkSj gekjh bPNkuqlkj gesa ifj.kke iznku djrk gSA Instructions ds bl lewg dks gh Program dgk

tkrk gSA

Computer esa gj Electrical Signal ;k mlds lewg dks Store djds j[kus dh lqfo/kk gksrh gSA bu Electrical Signals ds lewg dks File dgrs gSaA Computer esa tks Hkh dqN gksrk gS og File ds :i esa gksrk gSA Computer esa nks rjg dh File gksrh gSA igyh og File gksrh gS ftlesa ge gekjs egRoiw.kZ Data Store djds j[krs gSaA bls Data File dgk tkrk gSA

nwljh File og File gksrh gS] ftlesa Computer ds fy;s os Instructions gksrh gSa] tks Computer dks crkrh gSa fd mls fdlh Data ij fdl izdkj ls Processing djds Result Generate djuk gSA bl nwljh izdkj dh File dks Program File dgk tkrk gSA ge fofHkUu izdkj dh Computer Languages esa Program Files gh Create djrs gSaA tc cgqr lkjh Program Files fey dj fdlh leL;k dk lek/kku izkIr djokrh gSa] rks mu Program Files ds lewg dks Software dgk tkrk gSA Computer Software eq[;r;k nks izdkj ds gksrs gSa%

36 Any Question or Suggestion, Just Discuss Here...

Java in Hindi System Software: ;s Software mu izksxzkeksa dk ,d lewg gksrk gSa tks dEI;wVj dh Performance dks Control djrk gSA ;kuh Computer ij fdl rjg ls ,d izksxzke ju gksxk vkSj fdl rjg ls izksxzke Output nsxkA fdl rjg Hard Disk ij Files Save gksaxh] fdl rjg iqu% izkIr gksaxh] vkfnA Windows, Unix, Linux, vkfn System Software ds mnkgj.k gSaA Application Software: ;s Software izksxzkejksa }kjk fy[ks tkrs gSa o ;s Software fdlh [kkl izdkj dh leL;k dk lek/kku izkIr djus ds fy;s gksrs gSaA tSls Tally, MS–Office vkfn Application Software ds mnkgj.k gSaA

Computer Architecture Computer ls viuk eupkgk dke djokus ds fy,] lcls igys gesa Computer ds Architecture dks le>uk gksxkA Computer ds Architecture dks le>s fcuk] ge Computer Programming dks Bhd ls ugha le> ldrsA Computer System ds eq[;&eq[; rhu Hkkx gksrs gSa&

I/O Devices os Devices ftuls Computer esa Data Input fd;k tkrk gS vkSj Computer ls Data Output esa izkIr fd;k tkrk gS] I/O Devices dgykrh gSaA Keyboard ,d Standard Input Device gS vkSj Monitor ,d Standard Output Device gSA

Center Processing unit (CPU) ;g ,d Microprocessor Chip gksrk gSA bls Computer dk fnekx Hkh dgk tkrk gS D;ksafd Computer esa tks Hkh dke gksrk gS] mu lHkh dkeksa dks ;k rks CPU djrk gS ;k Computer ds vU; Devices ls mu dkeksa dks djokrk gSA bldk eq[; dke fofHkUu izdkj ds Programs dks Execute djuk gksrk gSA bl CPU esa Hkh fuEu foHkkx gksrs gSa tks vyx&vyx dke djrs gSa&

37 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Control Unit bl Unit dk eq[; dke lkjs Computer dks Control djuk gksrk gSA CPU dk ;s Hkkx Computer dh vkarfjd izfØ;kvksa dk lapkyu djrk gSA ;g Input/Output fØ;kvksa dks Control djrk gS] lkFk gh ALU o Memory ds chp Data ds vknku&iznku dks funsZf”kr djrk gSA ;g Program dks Execute djus ds fy, Program ds Instructions dks Memory ls izkIr djrk gS vkSj bu Instructions dks Electrical Signals esa Convert djds mfpr Devices rd igqapkrk gS] ftlls Data ij Processing gks ldsA Control Unit ALU dks crkrk gS fd Processing ds fy, Data Memory esa dgka ij fLFkr gSa] Data ij D;k izfØ;k djuh gS vkSj Processing ds ckn Data dks okil Memory esa dgka ij Store djuk gSA Arithmetic Logic Unit (ALU) CPU ds bl Hkkx esa lHkh izdkj dh vadxf.krh; o rkfdZd izfØ;k,a gksrh gSaA bl Hkkx esa ,slk Electronic Circuit gksrk gS tks Binary Arithmetic dh x.kuk,a djrk gSA ALU Control Unit ls funsZ”k ;k ekxZn”kZu ysrk gS] Memory ls Data izkIr djrk gS vkSj ifj.kke dks ;k Processed Data dks okil Memory esa gh Store djrk gSA Registers

Microprocessor esa dqN ,slh Memory gksrh gS tks FkksMs le; ds fy, Data dks Store dj ldrh gSA bUgsa Registers dgk tkrk gSA Control Unit ds funsZ”kkuqlkj tks Hkh Program Instructions o Data Memory ls vkrs gSa os ALU esa Calculation ds fy, bUgha Registers esa Store jgrs gSaA ALU esa Processing ds ckn okil ;s Data Memory esa Store gks tkrs gSaA

Memory Memory Computer dh Working Storage ;k dk;Zdkjh eseksjh gksrh gSA ;g Computer dk lcls egRoiw.kZ Hkkx gksrk gSA bls RAM dgrs gSaA blh esa Process gksus okys Data vkSj Data ij Processing djus ds fy[ks x, Program Instructions gksrs gSa] ftUgsa Control Unit ALU esa Processing ds fy, Registers esa Hkstrk gSA Processing ds ckn tks lwpuk,a ;k Processed Data Generate gksrs gSa] os Hkh Memory esa gh vkdj Store gksrs gSaA Memory esa Data dks laxzg djus ds fy, dbZ Storage Locations gksrh gSaA gj Storage Location ,d Byte dh gksrh gS vkSj gj Storage Location dk ,d iw.kkZad Number gksrk gS] ftls ml Memory Location dk Address dgrs gSaA gj Storage Location dh igpku mlds Address ls gksrh gSA 1 Byte dh RAM esa ,d gh Character Store gks ldrk gS vkSj blesa flQZ ,d gh Storage Location gks ldrh gSA

blh rjg 1 KB dh RAM esa 1024 Storage Locations gks ldrh gSa vkSj blesa 1024 v{kj Store gks ldrs gSaA tks Memory ftrus Byte dh gksrh gS mlesa mrus gh Characters Store gks ldrs gSa vkSj mlesa mruh gh Storage Locations gks ldrh gSaA

38 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ftl rjg ls fdlh “kgj esa us dh dksf”k”k djrs gSaA tc ge Keyboard (Input Device) ij dksbZ Key Press djrs gSa] rks CPU dk Control Unit Active gks tkrk gS vkSj Input gks jgs Character dks Memory esa fdlh Storage Location ij Store dj nsrk gSA ekuk ge Keyboard ls ,d vad 6 Input djrs gSa] rks CPU dk Control Unit bl eku dks Memory dh fdlh Storage Location ij Store dj nsrk gSA vc ge + dk fpUg Keyboard ls Press djrs gSaA Control Unit mls Hkh Memory dh fdlh Storage Cell esa Store dj nsrk gSA vc ge 4 Input djrs gSaA Control Unit bls Hkh Memory esa Store djrk gSA ekuk fd ;s rhuksa eku fuEukuqlkj Memory dh fofHkUu Storage locations ij Save gks jgh gSa &

vc ;fn Input fd, x, nksuksa vadksa dks tksMuk gks rks Control Unit Input fd, x, igys eku Storage Cell 1001 ls mBkrk gS vkSj mls Binary Format esa Convert djds CPU Registers esa Hkst nsrk gSA fQj bl vad ij Processing djus ds fy, Control Unit + Memory Location 1003 ls mBkrk gS vkSj CPU dks bl vad dks tksMus dh izfØ;k djus Instruction nsrk gSA

dks ds dks dh

fQj Control Unit nwljs eku 4 dks Binary Format esa Convert djds CPU ds Register esa Hkst nsrk gS vkSj ALU dks bu nksuksa vadks dks tksMus dh lwpuk nsrk gSA ALU Registers ls bu Data dks izkIr djds mUgsa tksMrk gS vkSj tksMs x, eku dks CPU ds Registers esa Store dj nsrk gSA ;gka ls okil Control Unit Registers esa Stored eku dks Memory esa Storage Cell 1009 o 1010 ij Store dj nsrk gSA bl rjg ls nks la[;kvksa dks tksMus dh izfØ;k iwjh gksrh gSA Computer ,d Digital Machine gSA Computer rHkh dksbZ dke dj ldrk gS tc mls fdlh dke dks djus ds fy, Program fd;k x;k gksA Programming nks rjg dh gksrh gSA igyh Programming og gksrh gS tks fdlh Computer dks dke djus yk;d voLFkk esa ykus ds fy, dh tkrh gSA bl Programming dks Hkh nks Hkkxksa esa ckaVk tk ldrk gS%

Hardware Programming bl Programming ds vUrxZr Computer ds Hardware ;kuh Computer ds Motherboard ij yxk, x, fofHkUu izdkj ds Chips o Computer ls tqMs gq, vU; fofHkUu izdkj ds Peripherals tSls fd Keyboard, Mouse, Speaker, Monitor, Hard Disk, Floppy Disk, 39 Any Question or Suggestion, Just Discuss Here...

Java in Hindi CD Drive vkfn dks Check djus o Control djus ds fy, gj Mother Board ij ,d BIOS Chip yxkbZ tkrh gSA bl BIOS Chip dk eq[; dke Computer dks ON djrs gh fofHkUu izdkj ds Devices dks Check djuk gksrk gSA

;fn Computer ds lkFk tqMh gqbZ dksbZ Device rk gS vkSj gekjh bPNkuqlkj dke djds gesa ifj.kke iznku djrk gSA bUgsa Application Software dgk tkrk gSA ge fdlh Hkh Operating System ds fy, fdlh Hkh Hkk’kk esa tc dksbZ Program fy[krs gSa] rks okLro esa ge Application Software gh fy[k jgs gksrs gSaA Application Software dk eq[; dke fdlh fo”ks’k leL;k dk lek/kku iznku djuk gksrk gSA MS-Office, Corel-Draw, PageMaker, PhotoShop vkfn Application Software ds mnkgj.k gSa] tks gesa fdlh fo”ks’k leL;k dk lek/kku iznku djrs gSaA tSls ;fn gesa Photo Editing ls lEcaf/kr dksbZ dke djuk gks rks ge PhotoShop tSls fdlh Application Software

dks mi;ksx esa ysrs gSaA

Language Hkk’kk] nks O;fDr;ksa ds chp laokn] Hkkoukvksa ;k fopkjksa ds vknku&iznku dk ek/;e iznku djrh gSA ge yksxksa rd vius fopkj igqapk ldsa o vU; yksxkas ds fopkjksa dk ykHk izkIr dj ldsa] blds fy;s t:jh gS fd laokn LFkkfir djus okys nksuksa O;fDr;ksa ds chp laokn dk ek/;e leku gksA ;gh laokn dk ek/;e Hkk’kk dgykrh gSA vyx&vyx LFkku] jkT;] ns”k] ifjfLFkfr;ksa ds vuqlkj Hkk’kk Hkh cnyrh jgrh gSa] Yksfdu lHkh Hkk’kkvksa dk edln lans'kksa ;k lwpukvkas dk vknku iznku djuk gh gksrk gSA

40 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Bhd blh rjg dEI;wVj dh Hkh viuh dbZ Hkk’kk,a gS] tks t:jr o mi;ksx ds vuqlkj fodflr dh xbZ gSA ge tkurs gSa] fd dEI;wVj ,d bysDVªkWfud e”khu ek= gSA ;s ge lthoksa dh rjg lksap fopkj ugha dj ldrk gS vkSj uk gh gekjh rjg budh viuh dksbZ Hkk’kk gS] ftlls ge buls lEca/k cuk dj lwpukvksa dk ysu&nsu dj ldsaA blfy;s dEI;wVj dks mi;ksx esa ysus ds fy;s ,d ,slh Hkk’kk dh t:jr gksrh gS] ftlls ge gekjh Hkk’kk esa dEI;wVj dks lwpuk,a nsa o dEI;wVj mls mldh e”khuh Hkk’kk esa le>s vkSj gekjh pkgh xbZ lwpuk ;k ifj.kke dks gesa gekjh Hkk’kk esa ns rkfd ge mls gekjh Hkk’kk esa le> ldsaA Java ,d ,slh gh Hkk’kk gSA ;s ,d High Level Language gSA bl Language esa ge lkekU; English ds “kCnksa esa Code fy[krs gSaA bu Codes dks Java dk ,d Software Program ftls Compiler dgrs gSa] ml Hkk’kk esa Convert djrk gS] ftls Computer le> ldrk gSA bl Software dh enn ls Compute gekjs fy[ks x, Codes ds vuqlkj dke djrk gS vkSj gesa og ifj.kke iznku djrk gS] tks ge Computer ls pkgrs gSaA Java dk Program fy[kus ds fy, ,d Simple Word Processor dh t:jr gksrh gSA Windows ds lkFk vkus okys Notepad dks ge Java dk Program fy[kus ds fy, Use dj ldrs gSaA Java esa gj Program dks ,d Class ds :i esa fy[kk tkrk gSA Program fy[kus ds ckn Source File dks .Java Extension ds lkFk Save fd;k tkrk gSA Java esa nks rjg ds Programs lcls T;knk fy[ks tkrs gSaA tc ge Java Application fy[krs gSa rks ml Application esa gesa”kk ,d main() Method gksrk gSA Java ,d Case Sensitive Language gS blfy, Capital Letters esa fy[kk x;k uke o Small Letters esa fy[kk x;k uke

nksuksa uke vyx&vyx gksrs gSaA

Java Compiler (javac)

Java Compiler (Javac) Java Developer’s Kit dk ,d Component gS] ftldk iz;ksx Java dh Source Code File dks Bytecodes Executable File esa Convert djus ds fy, fd;k tkrk gS] rkfd og File Java Runtime Environment (JRE) System esa Run gks ldsA Java dh Source Code File dk Extension .java gksrk gSA Java dh Source Code File ,d Standard ASCII Text File gksrh gSA ;s Java ds Compiler dk dke gksrk gS fd og Java Source Code File dks Process djs vkSj Executable Java Bytecodes Class File Create djsA Executable Bytecodes Class File dk Extension .class gksrk gS vkSj ;s viuh Useable Form esa Java Class dks Represent

djrs gSaA

Java Compiler gekjh Source File dh gj Class ds fy, ,d .Class File Generate djrk gSA rduhdh :i ls ge ,d gh Source File esa ,d ls vf/kd Class Define dj ldrs gSa ysfdu Compiler ,d gh Source File esa Define dh xbZ ,d ls vf/kd Classes ds fy, Hkh vyx&vyx .class File Create djrk gSA Java Compilers bl ckr ds fy, ftEesnkj gksrs gSa fd ,d Java Source File ls Java Executable Bytecodes File fdl izdkj ls Generate dh tk, tks fd Java Runtime System esa Run gks ldsa vkSj Java Virtual Machine, tks fd Java Runtime System dk

41 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ,d fgLlk gS] bl ckr ds fy, ftEesnkj gksrk gS] fd Bytecodes dks fdl izdkj ls Interpret fd;k tk,A Java Compiler ,d Command Line Tool gSA bldk eryc ;s gqvk fd bUgsa DOS Prompt ij gh Execute fd;k tk ldrk gSA budks Use djus dk Syntax fuEukuqlkj gksrk gS% Command Prompt > javac Options Filename

bl Command esa Filename Argument ml Java Source Code File dk uke gksrk gS ftls Compile djuk gSA bl File esa ftruh Hkh Classes Define dh xbZ gksrh gSa] mu lHkh dh Bytecodes okyh .class File curh gSA ;s Compiler mu lHkh Classes dks Bytecodes Class File esa Convert dj nsrk gS tks ,d nwljs ij Depend gksrh gSaA ;kuh ekuyks fd ,d File X.Java gS vkSj bl File esa ,d nwljh File ftldk uke B.Java gS] dh Class dks Derive fd;k x;k gSA rks bl fLFkfr esa ge ;fn B.Java dks Compile djrs gSa rks Compiler X.Java dh Hkh Compiling djsxk vkSj nksuksa Qkbyksa ds lHkh Classes dh Bytecodes (.Class) File Generate djsxkA

Java Interpreter (java)

Java Runtime Interpreter (Java) Hkh Java Developer’s Kit dk ,d Component gS ftldk iz;ksx Executable Java Bytecodes Classes dks Run djus ds fy, fd;k tkrk gSA Java Interpreter ,d rjhdk iznku djrk gS ftlls Java ds Programs dks fdlh Web Browser ds fcuk Execute fd;k tk ldrk gSA Java Compiler ftl Class Format dh Executable Bytecodes File dks Generate djrk gS] ml Bytecodes File dks Java Interpreter }kjk Execute fd;k tkrk gSA

fdlh Java Applet o Java Application Program esa bruk gh vUrj gS fd Applet fdlh uk fdlh Java Enabled Web Browser esa Run gksrs gSa] tcfd Application dk Lo;a dk Window gksrk gSA fdlh Compile fd, x, Java Source File dh Bytecodes (.Class) File dks ge fuEukuqlkj Syntax }kjk Command Prompt ij Run dj ldrs gSa& Command Prompt>Java ClassName Arguments

;gka ClassName ml Class File dks Specify djrk gS] ftls Execute djuk gSA ;fn ;s Class File fdlh Package esa gks rks gesa Class File dk iwjk uke nsuk gksrk gSA tSls ekuyks fd dksbZ Hello.class uke dh Class File India uke ds Package esa gS] rks gesa bl File dks Run djus ds fy, fuEukuqlkj Command fy[kuk gksxk% Command Prompt>Java India.Hello

tc Java Interpreter fdlh Class dks Execute djrk gS rks og okLro esa ml Class ds main() Method dks Execute dj jgk gksrk gSA main() Method esa ge dqN Arguments Hkh ns ldrs gSa ftudk iz;ksx main() Method ds Execution dks Control djus ds fy, fd;k tkrk gSA

42 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Structure of Java Programs

fdlh tkok ds Program esa ge vko”;drkuqlkj ,d ls vf/kd Classes dks Define dj ldrs gSaA ysfdu fQj Hkh ge ,d Program esa fdlh ,d Class esa gh main() Method dks Define dj ldrs gSaA fofHkUu Classes esa fofHkUu izdkj ds Data vkSj mu Data ij Perform gksus okys Operations dks Define fd;k tkrk gSA tkok dk Program cukus ds fy, ge lcls igys fofHkUu izdkj dh Classes cukrs gSa vkSj fQj mu lHkh Classes dks Combine dj ysrs gSaA ,d tkok Program ds fofHkUu foHkkxksa dks ge fuEukuqlkj n”kkZ ldrs gSa % Documentation Section Package Statements Import Statements Interface Statements Class Definitions { Data Members Methods Main Method Class { Main Method Definitions }

Documentation Section fdlh Hkh Program ds bl Section esa gesa Program ls lEcaf/kr Descriptions nsus gksrs gSaA tSls fd Author dk uke, Program Creation dh Date] Program Create djus dk dkj.k] Program dh mi;ksfxrk vkfn ls lEcaf/kr ckrsa gesa Comment ds :i esa Documentation Section esa fy[kuh gksrh gSaA gkykafd ;s ,d Optional Section gS] fQj Hkh Program dks Readable cukus ds fy, gesa gj Program dks Well Documented djuk pkfg,A ;gka gesa ;s crkuk pkfg, fd geus Program esa fdu Classes dks Use fd;k gS vkSj fdl dkj.k ls Use fd;k gSA lkFk gh Program ds Algorithm ;kuh Flow dks Hkh lkjka”k :i esa Describe djus dh dksf”k”k djuh pkfg,A lkekU;r;k Documentation dks /** . . . */ Format esa fy[kuk pkfg,A bl rjg ls Comment djus ij ge Documentation dh ,d File JDK Tools ds mi;ksx }kjk Generate dj ldrs gSaA

Package Statements Package Statement fdlh Hkh tkok Program dk igyk Statement gksrk gSA ;s Statement ,d Package dk uke Declare djrk gS vkSj tkok Program dks crkrk gS fd Program esa Use gksus okyh Classes bu Packages esa Defined dh xbZ gSaA fdlh Package dks ge fuEukuqlkj tkok ds Source Program esa Use dj ldrs gSa %

43 Any Question or Suggestion, Just Discuss Here...

Java in Hindi package StudentInformation;

;s Statement StudentInformation uke ds Package dks ml Program ;k Source File esa Include dj ysxk] ftlesa ;s Statement fy[kk x;k gksxkA Import Statements fdlh Package Statement ds ckn tks vxyk Statement gks ldrk gS og import Statements gksrk gSA igys ls cuh gqbZ fdlh Class dks tkok ds Source Program esa Include djus ds fy, gesa tkok ds import Keyword ds lkFk ml Class dk uke fy[kuk gksrk gS] ftls vius Program esa Use djuk gksrk gSA ;s dke ge fuEukuqlkj Statement }kjk dj ldrs gSa % import StudentInformation.testMarks;

;s Statement tkok Interpreter dks testMarks uke dh Class dks Source File esa Include djus dk Message nsrk gS] tks fd StudentInformation uke ds Package esa miyC/k gS vkSj bl package dk ,d fgLlk gSA

Interface Statements Interface ,d Class ds leku gh gksrk gS ysfdu blesa Methods ds Declarations dk ,d Group gksrk gSA ;s Hkh ,d Optional Statement gS vkSj bldk iz;ksx ge rHkh djrs gSa tc gesa vius Program esa Multiple Inheritance dh lqfo/kk izkIr djuh gksrh gSA bl fo’k; esa ge vkxs foLrkj ls isaxsA

gS] ds gSa] gS]

First Application in Java fdlh Hkh Language esa Programming lh[kus ds fy, ge lcls igys Hello World Program ls “kq:vkr djrs gSaA ;s Program dqN ugha djrk gS] dsoy Screen ij “Hello World” Message Print djrk gS] ysfdu bl Program ds }kjk ge Language ds Program dh Basic phtksa dks Clear djrs gSaA “Hello World” Application

lcls igys uhps fy[ks x, Program dks Notepad esa Type djsa% "Hello World" Application Program class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }

//Display this String

45 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Notepad esa bl Coding dks Type djus ds ckn File Menu ls Save Option dks Select djsaA fuEukuqlkj ,d Save As Dialog Box Display gksxk%

bl Dialog Box esa Save as type Drop Down List esa All Files dks Select djsa] D;ksafd ;gka gesa”kk Default :i ls Text Documents (*.txt) Option Selected jgrk gSA vc Save in Drop Down List ls ml Folder dks Select djsa] tgka ij Java dh File dks Save djuk gS vkSj File name Text Box esa File dk ogh uke fy[ksa tks uke Source File esa ml Class dk gS ftlesa main() Method fy[kk x;k gSA pwafd gekjs bl Example dh Source File esa main() Method dks HelloWorld Class esa fy[kk x;k gS blfy, gekjh Source File dk uke gesa HelloWorld gh nsuk gksxk lkFk gh gekjh Source File, Java dh ,d Program File gS] blfy, bls .java Extension ds lkFk Save djuk gksxkA bl izdkj ls gekjh bl File dk uke HelloWorld.java gksxkA ,slk ugha gS fd ge bl Source File dk ogh uke nsa tks geus Source File esa Class dk uke fn;k gSA ge File dk uke dqN Hkh ns ldrs gSa] ysfdu tc File dks Compile fd;k tkrk gS] rks ,d Class File curh gSA bl Class File dk uke fcYdqy ogh gksrk gS] tks ml Source File dh ml Class dk uke gksrk gS] ftlesa main() Method fy[kk x;k gksrk gSA blfy, fdlh Hkh rjg ds Confusion ;k ijs”kkuh ls cpus ds fy, Bhd ;gh jgrk gS] fd ge gesa”kk gekjh Source File dks Hkh mlh uke ls Save djsa] ftl uke ls ge og Class cukrs gSa] ftlesa main() Function gksrk gSA

Compiling Java Source File Source File Create djus ds ckn vc gesa bl Source File dks Compile djuk gksrk gS] rkfd ;s File Byte Codes esa Convert gks ldsA Compile djus ds fy, gesa Command Prompt ;k DOS Prompt ij tkuk gksrk gS vkSj fuEukuqlkj Command fy[kus gksrs gSa& Command Prompt \>cd\ C:\>path=C:\jdk\bin\

( Press Enter ) ( Press Enter )

46 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ge ;s eku jgs gSa fd tc Java dks Install fd;k tkrk gS rc Java dk 7th Version C: Drive ij jdk uke ds Folder esa Install gksrk gSA ;gka igys Command ls ge Root Directory ;kuh C: Drive ij vk tkrs gSa vkSj nwljk Statement Path Statement gSA ge fdlh QkbZy dks ogha ls Run dj ldrs gSa] tgka og File j[kh gqbZ gSA ysfdu DOS ds Path Command dh ;s fo”ks’krk gS fd ge fdlh File dks ogka ls Directly Run dj ldrs gSa] tgka dk Path ge Command Prompt ij Path Statement }kjk fy[k nsrs gSaA ge tkurs gSa fd Java ds Bin uke ds Folder esa gh Java ds lHkh t:jh Tools gksrs gSaA blfy, ge pkgrs gSa fd ge dgha ls Hkh Java ds Commands dks Execute dj ldsa vkSj ge ,slk rHkh dj ldrs gSa tc Computer dks igys gh ;s crk;k tk, fd mls Command Prompt ij fn, tkus okys fofHkUu Command dks dgka ij [kkstuk gSA pwafd ge pkgrs gSa fd ge fdlh Hkh LFkku ij Java dk tks Hkh Command fy[ksa] og Execute gks] rks gesa path=C:\jdk\bin\ fy[kuk gksrk gSA ;s Path Set fd, fcuk vkxs fy[ks x, dksbZ Command ugha pysaxsA blfy, lcls igys blh Command dks fy[k dj Path Set fd;k x;k gSA ge ftruh ckj Hkh Command Prompt ij vkrs gSa] gesa ;s Path Set djuk iMrk gSA ysfdu ;fn gesa gesa”kk ds fy, bl Path dks Permanently Set djuk gks] rks Command Prompt Open djds ge fuEu Command Fire dj ldrs gSa% CommandPrompt>setx PATH "c:\jdk\bin"

;s Commend Fire djrs gh gekjk Path, Windows Operating System dh Registry esa Add gks tkrk gSA ifj.kkeLo:i vc ge tc Hkh dHkh Command Prompt Open djrs gSa] gesa gekjs Path dks fQj ls Set djus dh t:jr ugha gksrhA Path Set djus ds ckn gesa ml Folder esa tkuk gksrk gS] tgka geus gekjh Source File dks Save dh gSA ekuyks fd geus gekjh Source File dks C: Drive esa Java uke dk ,d Folder cuk dj mlesa Save dh gS] rks ge fuEu Command }kjk vius Java Folder rd tkrs gSa& C:\>cd java C:\Java>

(Press Enter )

vc gesa HelloWorld.Java dks fuEukuqlkj Command fy[k dj Compile djuk gksxk& C:\Java>javac HelloWorld.Java

( Press Enter )

;fn Source File esa fdlh izdkj dh Error uk gks] rks Java dh File Compile gks tk,xhA tc Java dh File Compile gks tkrh gS] rc Java dh File dh ,d Class File curh gS] ftldk uke ogh gksrk gS tks gekjh Source File dk gksrk gS] ysfdu ml File dk Extension .class gksrk gSA ;s Class File Java dh Bytecodes File gksrh gS] tks fd Platform Independent gksrh gS vkSj fdlh Hkh Java Runtime Environment esa Interpret gksrh gSA

47 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Running Java Application tc Source File Bhd ls fcuk fdlh Error ds Compile gks tkrh gS] rc mldh ,d Class File curh gSA ;s Class File gh Java Runtime Environment esa Run gksrh gSA vc HelloWorld Application dks Run djus ds fy, gesa Command Prompt ij fuEu Command fy[kuk gksrk gS& C:\Java>java HelloWorld

( Press Enter )

vc gesa File dk Extension Use djus dh t:jr ugha gksrh gSA tkok dk ;s Interpreter lgh File dks Lo;a gh Run djrk gS vkSj gekjs Screen ij “Hello World” Display gksrk gSA ;gka ;s ckr /;ku j[kus okyh gksrh gS fd Source File dk uke ge pkgs tSlk Hkh nsa ysfdu File dks Run djrs le; gesa ogh uke nsuk iMrk gS] tks uke Class dk gksrk gS vkSj Bhd mlh rjg ls Class dk uke fy[kuk iMrk gS] ftl rjg ls Source File esa geus Class dk uke fy[kk gSA ;fn ge uke fy[kus esa tjk lh Hkh Mistake djrs gSa] rks gesa fuEukuqlkj Error Message izkIr gksrk gS& C:\JAVA>java helloworld Exception in thread "main" java.lang.NoClassDefFoundError: helloworld (wrong name: HelloWorld)

Anatomy of Java Application geus Java esa ,d NksVk lk Program Develop fd;k vkSj mls Compile djds Run Hkh dj fy;kA vc ge bldh cukoV o blds dke djus ds rjhds dks le>rs gSaA lcls igyh ckr rks ;gh gS fd Java Application Standalone Java Programs gksrs gSaA bUgsa Java Applets dh rjg fdlh Java Enabled Web Browser dh t:jr ugha gksrh gSA Comments in Java Java esa Comments nsus ds fy, rhu rjhdksa dk iz;ksx fd;k tk ldrk gSA rhuksa rjhdksa ls fuEukuqlkj Comment fn;k tk ldrk gS & /* This is a Comment in Java which Java Compiler Ignores. */

bl /* */ ds chp fy[ks x, Comments dks Java dk Compiler iwjh rjg ls Ignore dj nsrk gSA ;kuh buds chp fy[ks x, fdlh Hkh Word dks Compiler Check ugha djrk gS uk gh Compile djrk gSA ;s Comments ,d Programmer vius Program ds chp&chp esa nsrk jgrk gS] rkfd mls mlds Program dk Flow irk jgsA /** Documentation */ bl Comment dks Documentation Comment ;k Doc Comment dgk tkrk gSA tc ge gekjh fdlh Class File dk Documentation djuk pkgrs gSa rks Documentation dks /** . . . */ ds chp esa fy[krs gSaA bl izdkj ds Documentation dks Java Developer’s Kit ds Javadoc Tool dk iz;ksx djds ,d vyx Documentation HTML File esa Store fd;k tk ldrk gSA bl Documentation dks vyx File esa Store djus ds fy, ge Command Prompt ij Javadoc Tool dk fuEukuqlkj mi;ksx djds viuh Class ds fy, Documentation File rS;kj dj ldrs gSaA

48 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Command Prompt> Javadoc // This is Third Comment Style

tc gesa dsoy ,d gh Line dk Comment nsuk gksrk gS] rc ge bl rjhds ls Comment fy[krs gSaA Compiler bl izdkj ds Comments dks Ignore dj nsrk gS ;kuh Compile ugha djrk gSA ,d ckr gesa”kk /;ku j[ksa fd ,d Comment ds vUnj nwljk Comments ugha fy[kk tk ldrkA ;kuh Comments dh Nesting ugha dh tk ldrh gSA tSls /** Madhav is a Union Leader /* and I am his Friend*/ He is a Programmer too.*/ Java esa fdlh Hkh Application Program esa de ls de ,d Class t:j gksrh gS vkSj ml Class esa ,d main() Method gksrk gSA Java dk Compiler blh main() Method ls Java ds Application dh Compiling “kq: djrk gSA Class Statement

bl Program dh igyh Code Line dks nsf[k,% class HelloWorld {

tc bl Program dks Compile fd;k tkrk gS rc ;s Code Line Compiler dks ;s Instruction nsrk gS fd | | “Computer, Java ds bl Program dk uke HelloWorld Assign dj nsA”

||

tSlkfd geus igys Hkh crk;k Fkk fd ,d Program ds :i esa ge Computer dks ftrus Hkh Instructions nsrs gSa] os lHkh Statements dgykrs gSaA ;gka class Statement og rjhdk gS] ftlls ge gekjs Program dks ,d uke nsrs gSaA ;s Statement dbZ vU; ckrksa dks Hkh Determine djrk gS ftlds ckjs esa ge vkxs i ldrs gSa fd ,d Applet Develop djus ds fy, gesa applet Package vkSj awt Package dks vius Program esa Include djuk t:jh gksrk gS vkSj bUgsa viuh Source File esa Include djus ds fy, gesa fuEu Statement fy[kus gksrs gSaA import java.applet.*; import java.awt.*;

// Statement 01 // Statement 02

Applet Package – The Applet Class applet Package Java API dk lcls NksVk Package gS vkSj Applet Class bl Package dh bdykSrh Class gSA applet Package esa Applet Class ds vykok nwljh dksbZ Class gh ugha gSA tc Hkh ge fdlh ,sls Web Page dks Open djrs gSa] ftlesa Applet Embed gksrk gS] rks og Applet Automatically Browser esa Load gks tkrk gSA pwafd Applet gesa”kk fdlh uk fdlh HTML File ;k Web Page esa Run gksrs gSa] tks fd fdlh uk fdlh Browser esa Load gksrs gSa] blfy, Applet ds bl Environment dks “Context of the Applet” dgk tkrk gSA Applets o Applications nksuksa dks gh Compile djus ds fy, gesa javac Compiler dk iz;ksx djuk iMrk gS] tcfd ,d Console Mode Application dks Execute djus ds fy, gesa java Interpreter dk iz;ksx djuk iMrk gS vkSj ,d GUI Applet dks Execute djus ds fy, gesa Appletviewer dk iz;ksx djuk iMrk gSA fdlh Applet dks ge ,sls Browser }kjk Hkh ns[k ldrs gSa] tks Java Enabled gksA Netscape Navigator ,d Java Enabled Browser gS] ftlesa Applets dks fcuk Appletviewer dk iz;ksx fd, ns[kk tk ldrk gSA

57 Any Question or Suggestion, Just Discuss Here...

Java in Hindi OOPS and OOPL – The Definition

ge Computer ij tks Hkh Program cukrs gSa oks Program fdlh uk fdlh Real Life Problem dks Solve djus ds fy, cukrs gSa vkSj gj Real World Problem esa Real World Objects gksrs gSaA bl fLFkfr esa OOPS ,d ,slk Concept gS ftlds vk/kkj ij ge fofHkUu izdkj dh Real Life ls Related Problems dks Solve djus ds fy, gekjh leL;k ls lEcaf/kr fofHkUu Real World ds Physical Objects dks Computer esa Logically Represent dj ldrs gSa vkSj ml Real Life ls lEcaf/kr leL;k dks Computer esa Logically Hkh mlh rjg ls Solve dj ldrs gSa] ftl rjg ls ml leL;k dks Real World esa Physically Solve djrs gSaA fdlh Problem dks Solve djus dk og System ;k rjhdk ftlds vk/kkj ij fdlh Real World Problem dks Solve djus ds fy, ml Real World Problem ls lEcaf/kr Physical Objects dks Computer esa Logically Represent djds Problem dks Computer }kjk Solve fd;k tk lds] Object Oriented Programming System (OOPS) dgykrk gS vkSj ftl Computer Programming Language esa OOPS ds Concepts dks Bhd rjg ls Implement fd;k tk ldrk gS] ml Programming Language dks Object Oriented Programming Language (OOPL) dgk tkrk gSA tkok ,d ,slh gh Object Oriented Programming Language gS] ftlesa fdlh Real World leL;k ls lEcaf/kr fofHkUu Real World Physical Objects dks Computer esa Logically Represent djds leL;k dks mlh izdkj ls Logically Solve fd;k tk ldrk gS] ftl rjg ls ml leL;k dks Real World esa Physically Solve fd;k tkrk gSA

Problem – The Definition nqfu;ka ds gj dke dks lEiUu djus ds fy, gesa ,d fo”ks’k Øe dk ikyu djuk iMrk gS vkSj tc ge fdlh dke dks Bhd rjhds ls dj ysrs gSa] rks ifj.kke Lo:i gesa dqN uk dqN mfpr Output izkIr gksrk gSA Bhd blh rjhds ls Computer ls Hkh fdlh dke dks djokus ds fy, gesa mlls ,d fo”ks’k Øe dk ikyu djokuk iMrk gS vkSj tc Computer gekjs crk, x, fdlh Øe ds vuqlkj dke dj ysrk gS] rks gesa dqN uk dqN mfpr ifj.kke Hkh izkIr gksrk gSA ftl fdlh Hkh dke dks djus ds fy, gesa fdlh fo”ks’k Øe dk ikyu djuk iMrk gS] ml dke dks ge ,d Problem dg ldrs gSaA bl fLFkfr esa gj dke ,d izdkj dh leL;k gksrh gS D;ksafd nqfu;ka ds fdlh Hkh NksVs ls NksVs dke dks lEiUu djus ds fy, Hkh gesa fdlh uk fdlh Øe dk ikyu rks djuk gh iMrk gSA ,d mnkgj.k ls le>sa rks ;fn gesa ikuh ihuk gks rks Hkh gesa ,d fuf”pr Øe dk ikyu djuk iMrk gSA ikuh ihus ds fy, Hkh gesa% 1 2 3 4

lcls igys fxykl ysuk iMsxkA fxykl esa ikuh ysuk iMsxkA fQj ml ikuh dks eqag rd ykuk iMsxk ikuh eqag esa tk,xk vkSj r`fIr dk vglkl gksxkA

[ Variable Declaration ] [ Input ] [ Process ] [ Output ]

;kuh ikuh ihus ds fy, Hkh gesa ,d fuf”pr Øe dk ikyu djuk iM jgk gS] blfy, ikuh ihus dks Hkh ge ,d izdkj dh leL;k ds :i esa ns[k ldrs gSaA

58 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Data – Value OR a Set of Values

ewy :i ls ns[kk tk, rks Computer ds fy, fdlh Hkh izdkj dk eku ;k ekuksa dk lewg Data dgykrk gSA Computer esa ge fdlh Hkh eku dks eq[;r% rhu izdkj ls Specify dj ldrs gSaA Integer tc gesa Computer esa fdlh ,sls eku dks Store djuk gksrk gS] ftlesa dsoy iw.kZ la[;k,a gh gksrh gSa] rc ml Value dks Integer izdkj dh Value dgk tkrk gSA Float tc gesa Computer esa fdlh ,sls eku dks Store djuk gksrk gS ftlesa nleyo okyh la[;k gksrh gS] rc ml Value dks Float izdkj dh Value dgk tkrk gSA Character tc gesa Computer esa dsoy Characters Store djus gksrs gSa] rc bl izdkj ds eku dks Character izdkj dk eku dgrs gSaA

Object – The Definition

nqfu;ka dh gj ml pht dks Object dg ldrs gSa] ftls Physically ns[kk tk lds ;k Logically fdlh fn[kkbZ nsus okyh pht ds Reference esa eglwl fd;k tk ldsA tSlkfd geus dgk fd Object dks ns[kk tk ldrk gS] bldk eryc ;s gqvk fd gj og pht ftldk dksbZ jax] :i o vkdkj gks og Object gSA tSls fd Keyboard, Employee, Client vkfnA blh izdkj ls gj og pht ftls fdlh fn[kkbZ nsus okyh pht ds Reference esa eglwl fd;k tk lds] Object gSA tSls Bank Account.

gj Object dh dqN fo”ks’krk,a gksrh gSa] ftldh otg ls dksbZ ,d Object fdlh nwljs Object ls vyx igpkuk tkrk gSA fdlh Hkh Object dh bu fo”ks’krkvksa dks ge ml Object ds Attributes ;k ml Object dh Properties dgrs gSaA fdlh Object ds Attribute ds eku esa ifjorZu djus ij og Object cny tkrk gSA mnkgj.k ds fy, fdlh Account Object dh ,d Property, mldk Account Number gks ldrk gSA vc ;fn fdlh Account ds Account Number Property dk eku Change fd;k tk,] rks og Account fdlh nwljs Account Object dks Refer djus yxrk gSA ;kuh Object ds Attribute ds eku esa ;fn ifjorZu dj fn;k tk, rks Object cny tkrk gSA ftl rjg ls gj Object Uniquely Identify gksus ds fy, vius dqN Unique Attributes dk iz;ksx djrk gS] mlh rjg ls gj Object fdlh uk fdlh rjhds ls dksbZ uk dksbZ dke djrk gSA Object ds bl dke djus dh izo`fr dks Object dk Behavior dgrs gSaA

59 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Objects – Based on Problem

okLrfod thou (Real World) esa ge fdlh Hkh leL;k dks ftl izdkj ls ns[krs gSa] mlh izdkj ls ge ml leL;k dks Computer esa Hkh Represent dj ldrs gSaA leL;k dks Computer esa Logically rHkh Represent fd;k tk ldrk gS] tc leL;k dks Bhd izdkj ls le>k tk, vkSj ;s irk fd;k tk, fd leL;k ds eq[; Objects dkSu&dkSu ls gSaA mnkgj.k ds fy, eku yhft, fd ,d Company esa mlds lHkh Employees ds Bio – Data dks Manual Register ls Upgrade djds Computerized djuk gSA vc gesa lcls igys bl Real World leL;k ls lEcaf/kr lcls egRoiw.kZ Object dks Identify djuk gSA pwafd] fofHkUu Employees ds Bio – Data dks Computer ij Store djuk gS] blfy, bl leL;k ls lEcaf/kr tks lcls egRoiw.kZ Object gS] og Employee gh gSA Employee ,d Physical Object gS vkSj bls tc Computer esa Represent fd;k tk,xk rks] Computer esa og Employee Logical Object dgyk,xkA

Abstraction – The Problem Simplifying Process

fdlh Hkh Real Life Problem dks tc gesa Computer ij Logically Represent djuk gksrk gS] rks lcls igys gesa ;s r; djuk gksrk gS fd leL;k ls lEcaf/kr os t:jh phtsa dkSu&dkSu lh gSa] tks leL;k ds ifj.kke dks izHkkfor djrh gSaA leL;k ds lek/kku dks izHkkfor djus okyh t:jh ckrksa dks leL;k ds lek/kku dks izHkkfor uk djus okyh fcuk t:jh ckrksa ls vyx djus dh izfØ;k dks Abstraction dgrs gSaA OOPS ds bl Concept dks ge fiNys mnkgj.k }kjk gh le>us dh dksf”k”k djrs gSaA ekuyks fd fdlh Company ds fofHkUu Employees ds Bio – Data dks Computer ij Store djuk gSA pwafd bl dke dks lEiUu djus ds fy, ,d fuf”pr Øe dk ikyu djuk iMrk gS] blfy, Computer ds fy, ;s dke ,d izdkj dh leL;k gS] ftls Solve djuk gSA vc pwafd gekjh leL;k dk eq[; Object Employee gS] blfy, mlds dbZ Attributes gks ldrs gSa tks ,d Employee dks nwljs Employee ls Uniquely Identify djus esa enn djrs gSaA Employee dh fofHkUu Properties esa ls dqN fuEukuqlkj gks ldrs gSa% • • • • • • • • • • • • • •

Employee’s First Name Employee’s Last Name Address City District State Date Of Birth Qualification Extra Ability Degrees Designation Date Of Company Joining Hobbies Contact Number

60 Any Question or Suggestion, Just Discuss Here...

Java in Hindi • • •



No. of His Brothers and Sisters His Father’s Date of Birth His Father’s Name His Friends Contact Number

ge ns[k ldrs gSa fd blh rjg ls ,d Employee dh blls Hkh T;knk Properties gks ldrh gSa] ftuds vk/kkj ij mls Uniquely fdlh nwljs Employee ls vyx Identify fd;k tk ldsA ysfdu bl List esa ge ns[k ldrs gSa] fd Employee ds dqN Attributes ,sls gSa] ftudk Employee ds Bio–Data ;kuh eq[; leL;k ds ifj.kke ls dksbZ lEca/k ugha gSA tSls fd Employee ds fdrus HkkbZ&cgu gSa] bl ckr dk Employee ds Bio–Data ls dksbZ lEca/k ugha gSA blh rjg ls Employee ds firk ds Date of Birth dk Employee ds Bio–Data ls dksbZ lEcU/k ugha gS vkSj Employee ds nksLr ds Contact Number dk dksbZ lEca/k Employee ds Bio–Data ls ugha gSaA ;kuh ;s rhu Attributes ,sls Attributes gSa] ftudk Employee ds Bio–Data ls dksbZ lEca/k ugha gSA blfy, bu fcuk t:jh Data dks ckdh ds t:jh Data ls vyx dj nsus ij gekjs lkeus fuEukuqlkj Attributes vkrs gSa% • • • • • • • • • • • • • • •

Employee’s First Name Employee’s Last Name Address City District State Date Of Birth Qualification Extra Ability Degrees Designation Date Of Company Joining Hobbies Contact Number His Father’s Name

bl izdkj ls geus leL;k (Bio–Data of Employee) ds ifj.kke dks izHkkfor djus okys t:jh Attributes dks leL;k ls vlEcaf/kr fcuk t:jh Attributes ls vyx fd;kA bl izfØ;k dks Abstraction dgrs gSa vkSj gesa leL;k ds ifj.kke dks izHkkfor djus okys tks t:jh Attributes izkIr gq, gSa] bu Attributes dks Abstract Attributes dgrs gSaA

Abstract Data Type - Logical Representation of a Real World Object

ge ns[k ldrs gSa fd Bio – Data Problem ls lEcaf/kr Attributes dks izkIr djus ds fy, geus lcls igys fdlh Employee ds lHkh Attributes ij fopkj fd;k vkSj fQj t:jh Attributes dks fcuk t:jh Attributes ls vyx djds t:jh Attributes dks izkIr dj fy;kA 61 Any Question or Suggestion, Just Discuss Here...

Java in Hindi vc blh leL;k ds Employee Object dks ;fn Computer esa Logically Represent djuk gks] rks gesa bu Abstract Attributes ds vk/kkj ij ,d Abstract Data Type cukuk gksrk gSA bl Abstract Data Type dks Object Oriented Programming Languages esa Class Hkh dgrs gSaA Class ,d u, izdkj dk User Defined Data Type gksrk gS] tks leL;k ls lEcaf/kr fdlh Real World Object dks Computer esa Logically Represent djus ds fy, cuk;k tkrk gSA Class ,d Specification gksrk gS] tks fdlh leL;k ls lEcaf/kr fdlh Real World Object ds fofHkUu Abstract Attributes ds ekuksa dh Computer Memory esa Representation dks Specify

djrk gSA

Attributes – The Data Members of The Class fdlh leL;k ds ifj.kke ls lEcaf/kr fdlh Object ds fofHkUu Attributes dks tc Computer esa Represent djuk gksrk gS] rc Computer esa ml Object ds Attributes esa Store gksus okys Data ds vk/kkj ij ge ;s r; djrs gSa fd Object dk dkSulk Attribute fdl izdkj ds eku (Integer, Character ;k Float) }kjk Represent gks ldrk gSA tks Attribute ftl izdkj ds eku }kjk Represent gks ldrk gS] ml Attribute dks mlh izdkj ds Data Type ds lkFk Declare dj fn;k tkrk gSA Data Type ds lkFk Object ds Attributes dks Declare djus ij Object ds fofHkUu Abstract Attributes Class ds Data Members dgykrs gSaA

blh ckr dks ;fn ge nwljs “kCnksa esa dgsa rks Abstraction ls izkIr Abstract Attributes fdl izdkj ds Data Store djsaxs] bl rF; ij fuHkZj djrs gq, ;k bl ckr dks /;ku esa j[krs gq,] bu fofHkUu Abstract Attributes ds Basic Data Type dks r; fd;k tkrk gSA tc bu Abstract Attributes dks muds Data Type ds lkFk Class esa Specify fd;k tkrk gS] rc bu Abstract Attributes ds Declaration dks Class ds Data Members dgrs gSaA

Behaviors – The Methods of The Class dksbZ Object tks dke djrk gS] mu dkeksa dks ml Object dk Behavior dgrs gSaA ysfdu tc ge fdlh Object dks Computer esa Represent djuk pkgrs gSa] rc ge ;s ugha ns[krs gSa fd Object okLro esa D;k&D;k dj ldrk gS] cfYd ge ;s ns[krs gSa] fd Object ds os dkSu ls dke gSa] ftuds }kjk ,d Object vius fdlh ml Attribute dks Change djrk gS] ftUgsa Abstraction dh izfØ;k }kjk Identify fd;k x;k gSA fdlh leL;k ls lEcaf/kr Abstract Attributes dks ml Object ds tks Behaviors izHkkfor djrs gSa] Object ds os Behaviors gh ml leL;k ls lEcaf/kr Behaviors gSaA tkok esa Object dh Class }kjk bu Behaviors dks Represent djus ds fy, gesa Methods dk iz;ksx djuk gksrk gSA Methods tkok ds os Code Segments gksrs gSa] tks fdlh Object ds fdlh uk fdlh Abstract Attribute ds eku dks fdlh uk fdlh izdkj ls Change djrs gSaA ;kuh os Operations ftUgsa lEiUu djus ij Object ds fdlh uk fdlh Abstract Attribute ds eku esa ifjorZu gks] Methods dgykrs gSaA

62 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Problem Design (OOPS) v/s Problem Implementation (OOPL)

OOPS o OOPL nksuksa ds vk/kkj ij gesa”kk fdlh Hkh OOPS Concept dh nks ifjHkk’kk,a curh gSaA ,d ifjHkk’kk dsoy OOPS ds Concept dks Represent djus dk dke djrh gS tcfd nwljh ifjHkk’kk ml igyh ifjHkk’kk ds vk/kkj ij fdlh Programming Language esa OOPS ds ml Concept dks Implement djus ls lEcaf/kr gksrh gSA tc ge OOPS ds lEca/k esa dksbZ ifjHkk’kk nsrs gSa] rks og ifjHkk’kk fdlh Real World leL;k o mlls lEcaf/kr fdlh Real World Physical Object ds lEca/k esa vkSj fdlh Software dks Design djus ds lEca/k esa gksrh gSA

ysfdu tc ge OOPS dh fofHkUu ifjHkk’kkvksa dks fdlh Programming Language esa Implement djrs gSa] rc OOPS dk eq[; Purpose ;s gksrk gS fd fdlh Real World Object dks Best rjhds ls fdlh Programming Language esa Logically Represent fd;k tk,] rkfd leL;k ls lEcaf/kr fdlh Real World Object dks Computer esa ,d u, Data Type ftls Abstract Data Type dgrs gSa] ds :i esa Represent fd;k tk ldsA fdlh leL;k dks Solve djus ds fy, ge nks Approach Use dj ldrs gSaA igyk Approach iwjh rjg ls OOPS ds Concepts ij vk/kkfjr gksrk gS vkSj Problem ds Solution dks Design djus ls lEcf/kr gksrk gSA ;kuh ge ,d Hkh Line dh Coding fy[ks fcuk Hkh fdlh Software dks OOPS ds Concept ds vk/kkj ij Design dj ldrs gSaA vUrj dsoy bruk gksxk fd bl Design dk dksbZ izR;{k ifj.kke gesa izkIr ugha gksxkA tcfd OOPS ds vk/kkj ij ge ftl Modal dks cuk,axs ml Modal dks ;fn fdlh OOPL Language esa Implement dj fn;k tk, rks gesa leL;k dk izR;{k ifj.kke izkIr gks tk,xkA bl ckr dks ljy rjhds ls dgsa rks nks la[;kvksa dks tksMus dk Algorithm fy[k nsus ls gesa nks la[;kvksa dk ;ksx izkIr ugha gksxk cfYd nks la[;kvksa dk ;ksx djus ds fy, fdl izdkj ls dke djuk gksxk] ml dke djus dh Process dk irk pysxkA tcfd bl Algorithm ds vk/kkj ij fdlh Programming Language esa Computer Codes fy[k fn, tk,a rks gesa nks la[;kvksa dh Actual tksM izkIr gks tk,xhA ;kuh Algorithm cukuk Problem Design djus ls lEcaf/kr dke gS tcfd Program cukuk ml Algorithm dks Implement djus ls lEcaf/kr dke gSA blh rjg ls OOPS ds Concept dks Apply djuk Problem Design djus ls lEcaf/kr gS tcfd OOPS ds Concept ds vk/kkj ij cuus okys Design dks Computer Language esa Implement djuk Problem Solve djus ls lEcaf/kr dke gSA ge ,slk Hkh dg ldrs gSa fd tc fdlh Problem dks Real World esa Define djuk gksrk gS] rc Problem ds fofHkUu Objects dks Physical :i esa Identify dj ldrs gSa] ysfdu tc mlh Problem dks Computer esa Logical :i esa Define djuk gksrk gS] rc Problem dks ,d u, Data Type ds :i esa Represent djuk gksrk gS] ftls ge fdlh Computer Programming Language esa Abstract Data Type ;k Object dh Class ds :i esa Identify djrs gSaA

63 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Encapsulation – The Unitizing Process of Attributes and Behaviors

tSlkfd geus igys dgk fd OOPS o OOPL ds vk/kkj ij gj OOPS Concept dh nks ifjHkk’kk,a gksrh gSaA ;gh fu;e OOPS ds Encapsulation Concept ds lEca/k esa Hkh ykxw gksrh gSA tc ge OOPS ds lEca/k esa ns[krs gSa] rks fdlh Object dh Internal Workings dks ;k mlds dke djus ds tfVy rjhdksa dks le>s fcuk mls mi;ksx esa ysus ds fy, dqN O;oLFkk,a dj nsuk] bl izfØ;k dks Encapsulation dgrs gSaA bl Concept dks le>us ds fy, ,d mnkgj.k ns[krs gSaA eku yks fd gekjs ikl ,d Computer gSA vc tc ge Computer dks Switch ON djrs gSa] rks ;s tkus fcuk fd Computer fdl izdkj ls ON gksrk gS] ge Computer dks mi;ksx esa ysrs jgrs gSaA blh rjg ls fdlh Car ds Accelerator dks Press djus ij Car dh Speed fdl izdkj ls csa] rks ifjHkk’kk cny tkrh gSA Programming Language tkok ds lEca/k esa tc ge Encapsulation dks ifjHkkf’kr djuk gksrk gS] rks ge bl Concept dks vxzkuqlkj ifjHkkf’kr djrs gSaA leL;k ls lEcaf/kr Abstracted Attributes dks muds Data Type ds lkFk Specify djus dh Process ls ml Object ds Data Members izkIr gksrs gSa vkSj leL;k ls lEcaf/kr ftu Operations dks Perform djds dksbZ Object vius fdlh Abstract Attribute dh fLFkfr ;k eku esa ifjorZu djrk gS] ml Operation dks Object dk Behavior dgrs gSa] ftls tkok esa Implement djus ds fy, ftu Codes dks fy[krs gSa] mu Code Block dks Methods dgrs gSaA ;kuh fdlh leL;k ls lEcaf/kr Object ds Physical Attributes o Behaviors dks Java esa Implement djus ij Object ds leL;k ls lEcaf/kr fofHkUu Abstracted Attributes dks Data Members o fofHkUu Attributes dks Change djus okys Operations dks Methods ds :i esa Specify djrs gSaA fdlh Hkh Object ds xq.k ;kuh mlds Attributes o mlds Behaviors nksuksa fdlh ,d gh Physical Object ds fgLls gksrs gSaA blfy, Object ds Attributes dks Represent djus okys Data Members o Behaviors dks Represent djus okys Methods nksuksa dks ,d bdkbZ ds :i esa Specify djus dh izfØ;k dks OOPL esa Encapsulation dgrs gSaA Encapsulation ds ckn ;kuh Computer esa fdlh leL;k ls lEcaf/kr Object ds fofHkUu Data Members (Attributes) o Methods (Behaviors) dks Combine djds ,d Unit ds :i esa Encapsulate djus ds ckn tks Specification gesa izkIr gksrk gS] ml Specification dks ;fn ,d uke ns fn;k tk,] rks og Specification leL;k ls lEcaf/kr fdlh Object dh Class dk Representation gksrk gSA

tkok ds fy, ;s ,d u, izdkj dk Data Type gksrk gS] tks fdlh Real World leL;k ls lEcaf/kr fdlh Real World Object dks Computer esa Logically Represent djus esa l{ke gksrk gSA bls Abstract Data Type Hkh dg ldrs gSa] D;ksafd ;s fdlh leL;k ds Abstraction ls izkIr Abstracted Attributes ds vk/kkj ij curk gSA

64 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Class – A Logical Specification of Problem Related Object

vHkh rd geus OOPS ds ftu Concepts o Elements dks ifjHkkf’kr fd;k gS] muesa ls T;knkrj ifjHkk’kk,a Hkzfer djus okyh o le> esa uk vkus okyh gSaA pfy,] ge bu ifjHkk’kkvksa dks dsoy tkok ds lEca/k esa gh Apply djus dh dksf”k”k djrs gSaA fdlh Hkh Real World Problem dks tc gesa Computer ij Solve djuk gksrk gS] rks lcls igys gesa ;s tkuuk gksrk gS] fd Problem ls lEcaf/kr og lcls egRoiw.kZ Object dkSulk gS] ftl ij leL;k vk/kkfjr gSA Object dks igpkuus dk dksbZ fuf”pr rjhdk ;k Trick ugha gSA gj leL;k esa vyx izdkj dk Object izHkkfor gksrk gS vkSj gj leL;k esa ml vyx izdkj ds Object ds vyx izdkj ds Attributes dks Manage djuk gksrk gSA blfy, fdlh leL;k ds lcls egRoiw.kZ Object dk irk yxkus ds fy, gesa ckj&ckj fofHkUu izdkj dh leL;kvksa dks gy djus dh dksf”k”k djuh gksrh gSA dbZ ckj fdlh leL;k dks Solve djrs le; ge xyr Object ys ysrs gSaA ,sls esa tc ge vkxs c ysuk pkfg, fd Object dk og Operation leL;k ls lEcaf/kr t:jh Operation ugha gS vkSj Object ds ml Operation dks Neglect dj nsuk pkfg,A ;fn ge ljy “kCnksa esa dgsa rks dg ldrs gSa fd fdlh leL;k ls lEcaf/kr t:jh Data dk irk yxkus ds fy, gesa ml leL;k ls lEcaf/kr lcls egRoiw.kZ Object ds lEca/k esa ;s iwaNuk pkfg, fd Object ds D;k djus ij D;k gksxkA fdlh Object ds dqN djus ij Object dh ftu fo”ks’krkvksa ds eku cny ldrs gSa] os fo”ks’krk,a gh gekjh leL;k ls lEcaf/kr lcls egRoi.kZ Data gSaA pfy,] blh fu;e dks ge Bank Account Object ij Apply djrs gSaA Bank Account Object dk lcls egRoiw.kZ dke ;s gS fd ge fdlh Bank Account esa viuk /ku Deposit djokrs gSaA ;kuh Bank Account Object /ku dks Deposit djus dk dke djrk gSA blh rjg ls ge fdlh Bank Account esa vius Deposited /ku dks Withdraw djrs gSaA ;kuh Bank Account Object Bank esa tek /ku dks fudkyus dk dke Hkh djrk gSA

bl rjg ls ,d Bank Account Object leL;k ls lEcaf/kr nks gh lcls egRoiw.kZ dke dj jgk gSA gkykafd dqN vU; dke Hkh gksrs gSa] ftUgsa Bank Account Object Perform djrk gS] ysfdu ge ;gka ij ;gh eku jgs gSa fd Bank Object ;gh nks dke djrk gSA tc Bank Account esa /ku Deposit djrs gSa] rc Deposit Form Fill djds :i;ksa ds lkFk ml Form dks Hkh Bank esa tek djokuk iMrk gSA Deposit Form esa gesa fuEu lqpuk,a nsuh gksrh gSa% • • • • • •

Branch Name Branch Number Account Number Account Head Name Money Date

blh rjg ls ;fn Bank ls :i, Withdraw djus gksa] rks ,d Withdrawal Form Fill djds tek djokuk iMrk gSA ml Withdrawal Form esa fuEu lqpuk,a nsuh gksrh gSa% • • • • • •

Branch Name Branch Number Account Number Account Head Name Money Date

;s lHkh fdlh Bank Account ds os Attributes gSa] ftUgsa Deposit ;k Withdraw Operation }kjk Change fd;k tkrk gSA blfy, ;s lHkh Attributes Bank Account Object ds Abstract Attributes gSa vkSj Deposit o Withdraw os Operations gSa tks t:jr ds vk/kkj ij bu Abstract Attributes dks Change djus ds fy, Use Perform ;k Execute gksrs gSaA

66 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl rjg ls gesa Account Object ds fy, nks Operations o 6 Abstract Attributes izkIr gksrs gSaA bUgh Operations o Attributes dks ge ,d Abstract Data Type ;k ,d tkok Class ds :i esa Specify djsa] rks cuus okyk Description leL;k ls lEcaf/kr Real World Object (Account) dks Computer esa Logically Represent djrk gSA leL;k ls lEcaf/kr Account Object ds fofHkUu Abstract Attributes esa ge fuEu izdkj ds Data Feed dj ldrs gSa% • • • • •



Branch Name Branch Number Account Number Account Head Name Money Date

= = = = = =

Jaipur JPR01 AC1201235 Achyut 2000.00 12-July-2007

ftu Attributes ds ekuksa ds lkFk fdlh izdkj dh Calculation gks ldrh gS] mu Attributes dks Integer ;k Float izdkj dk Declare fd;k tkuk gksrk gSA pwafd Bank Account dk Money Attribute ,d ,slk Attribute ftlds eku ds lkFk fdlh izdkj dh Calculation gks ldrh gS] lkFk gh ;s eku nleyo okyk gS blfy, bl eku dks Hold djus ds fy, Float izdkj ds Data Type ds Variable dh t:jr iMsxhA ftu Attributes esa Character izdkj ds eku gksrs gSa] mUgsa String izdkj ds Variable esa Store fd;k tk ldrk gSA os Attributes tks fdlh izdkj dh Calculation esa Hkkx ugha ysrs gS]a mUgsa Hkh gesa String ;k Character izdkj ds Variable esa Store djuk pkfg,A bl fu;e ds vk/kkj ij ns[ksa rks String dks Store djus okys Attribute dks String Keyword ds lkFk] Character dks Store djus ds fy, char Keyword ds lkFk] Integer izdkj ds eku dks Hold djus okys Attribute ds lkFk int Keyword o Float izdkj ds eku dks Store djus ds fy, float Keyword ds lkFk Attributes dks fy[kus ij gesa fuEukuqlkj Format izkIr gksrk gS% • • • • • •

String String String String float String

Branch Name Branch Number Account Number Account Head Name Money Date

tc gess fdlh leL;k ds eq[; Object ds Abstraction ls Abstract Attributes izkIr gksrs gSa] vkSj muesa Store fd, tkus okys ekuksa ds vk/kkj ij ge ;s r; dj ysrs gSa fd fdl Attribute esa fdl izdkj dk eku Store gksxk] vkSj tkok ds vk/kkj ij mu Data Types dks Represent djus okys Keywords dks Abstract Attributes ds lkFk Specify dj nsrs gSa] rks gesa Abstract Attributes dh vc tks Description izkIr gksrh gS] mls tkok Class ds Data Members dgrs gSaA tkok dh fdlh Hkh Class dks gesa”kk fdlh uk fdlh Real World Object dks ,d u, User Defined Data Type dh rjg Represent djus ds fy, Develop fd;k tkrk gS vkSj fdlh Hkh Real World Object ds dqN Attributes ds lkFk mlds dqN Behaviors Hkh gksrs gSa] blfy, tkok dh ml Account Class esa fofHkUu Abstract Attributes dks Represent djus okys Data Members ds lkFk mu Behaviors dks Hkh Specify djuk gksrk gS] tks leL;k ls lEcaf/kr Operations Perform djds bu Data Members ds ekuksa esa ifjorZu djrs gSaA 67 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ;kuh Account Object dks tkok esa rHkh iwjh rjg ls Represent fd;k tk ldrk gS] tc bu Data Account ds Abstract Attributes dks Represent djus okys Data Members ds lkFk Account Object ds Behaviors ;kuh Deposit o Withdraw Operations dks Hkh Specify fd;k tk,A lkekU;r;k Abstract Attributes esa ifjorZu djus okys Operations dks tkok esa Methods dgrs gSaA vr% tc rd ge leL;k ls lEcaf/kr Data Members o Methods dks ,d lkFk ,d Group ds :i esa Specify ugha djsaxs] rc rd tkok fdlh Real World Object dks iwjh rjg ls Logically Represent ugha dj ldsxkA blfy, gesa Account Object ds Abstract Data Members (Attributes) o Methods (Behaviors) nksuksa dks fuEukuqlkj ,d Unit ds :i esa Specify djuk gksxk% Abstract Data Type or Class

//Data Members or Abstract Attributes String Branch Name String Branch Number String Account Number String Account Head Name float Money String Date // Methods or Behaviors Deposit Withdraw

tc gesa tkok esa fdlh Object ds Behavior dks Represent djuk gksrk gS] rc gesa Behavior ;kuh Method ds uke ds lkFk Parenthesis dk iz;ksx djuk gksrk gSA lkFk gh ;s Hkh crkuk gksrk gS fd Method fdlh izdkj dk dksbZ eku Return djsxk ;k ughaA pwafd ge ;gka ij Method dks fcYdqy Simple j[kuk pkgrs gSa] blfy, ge ;s eku jgs gSa fd Method fdlh Hkh rjg dk dksbZ eku Return ugha djsxkA tc ge Method ls fdlh rjg dk dksbZ eku Return djokuk ugha pkgrs gSa] rc tkok Compiler dks bl ckr dh Information nsus ds fy, Method ds uke ds vkxs void fy[krs gSaA tc gesa tkok dh Coding ds :i esa fdlh Object ls lEcaf/kr Abstracted Attributes ;kuh Data Members o Behaviors ;kuh Methods dks ,d Group ;k ,d Single Unit ds :i esa Specify djuk gksrk gS] rc Object ds fofHkUu Data Members o Methods dks Opening o Closing Curly Braces { } ds chp esa Specify djuk gksrk gSA mijksDr nksuksa fu;eksa dks Account Class ds Code Segment ij Apply djus ij gesa Account Object dh Class dk fuEukuqlkj Specification izkIr gksrk gS% // Account Abstract Data Type or Class class Account { // Data Members or Abstract Attributes String Branch Name ;

68 Any Question or Suggestion, Just Discuss Here...

Java in Hindi String String String float String

}

Branch Number ; Account Number ; Account Head Name ; Money ; Date ;

// Methods or Behaviors void Deposit() void Withdraw()

fdlh Object dks Represent djus okys Data Members o Methods dks ,d Unit ds :i esa Specify djus dh izfØ;k dks OOPS Concept ds vUrxZr Encapsulation uke fn;k x;k gSA ;kuh tc ge Account Object ds Data Members o Methods dks Opening o Closing Curly Braces ds chp esa Specify djrs gSa] rks okLro esa ge Account Object dks Encapsulate dj jgs gksrs gSaA ;kuh geus Account Object dks mijksDr Code Statement }kjk Encapsulated dj fn;k gSA vc bl Code Segment dh “kq:vkr esa class Keyword ds lkFk esa ge Account “kCn Specify dj nsa] rks bldk eryc ;s gS fd geus Account Class cuk nh gS] ftlds Objects dks tkok dk Compiler igpkurk gSA tkok ds lHkh Code Statements ds vUr dks fu/kkZfjr djus ds fy, ;kuh tkok ds Compiler dks ;s crkus ds fy, fd CPU dks fn;k tkus okyk ,d Instruction iwjk gks x;k gS] gesa gj Statement ds ckn esa Semicolon dk iz;ksx djuk gksrk gSA gkykafd vHkh ;s Class v/kwjh gS] D;ksafd geus tkok Compiler dks vHkh ;s ugha crk;k gS fd Deposit() o Withdraw() Methods Account Class ds fofHkUu Data Members dks fdl izdkj ls Change djsaxsA tc gesa Methods dks ;s crkuk gksrk gS fd os fdlh Class ds fofHkUu Data Members ds ekuksa dks fdl izdkj ls Change djsaxs] rc gesa fofHkUu izdkj ds Java Codes fy[kus iMrs gSaA bu fofHkUu izdkj ds Java Codes dks Method ds Parenthesis ds ckn Opening o Closing Curly Braces { } ds chp esa fy[kuk gksrk gSA bu rhuksa fu;eksa dks Apply djus ij gesa Account Object dh Class dk fuEukuqlkj Specification izkIr gksrk gS] tks ,d Real World Account Object dks Computer esa Logically Represent djrk gS% // Account Abstract Data Type or Class class Account { //Data Members or Abstract Attributes String Branch Name ; String Branch Number ; String Account Number ; String Account Head Name ; float Money ; String Date ;

69 Any Question or Suggestion, Just Discuss Here...

Java in Hindi //Methods or Behaviors void Deposit() { // Java Codes for changing the states of // Data Members based on requirement. }

}

void Withdraw() { // Java Codes for changing the states of // Data Members based on requirement. }

vHkh Hkh bl Class ds Objects Create ugha fd, tk ldrs gSaA D;ksafd tkok esa fofHkUu izdkj ds ekuksa dks Store djus ds fy, ftu Variables dks Declare djrs gSa] mu Variables ds uke nsus ds dqN fu;e gSaA ;fn ge mu esa fdlh Hkh fu;e dks Neglect djrs gSa] rks Java Compiler Program esa Compile Time Error Generate djrk gSA

Identifier Naming System

Computer esa fofHkUu izdkj ds ekuksa dks Store djus ds fy, Data ds vuqlkj Memory esa dqN txg Reserve dh tkrh gS vkSj ml Reserved txg dks igpkuus ds fy, Programmer ml txg dks dksbZ uke nsrk gSA tSls ;fn Programmer fdlh O;fDr dh Age Computer esa Store djuk pkgrs gSa] rks Age Store djus ds fy, mls Integer izdkj dk ,d Identifier Create djuk gksxk ;kuh eku dks Store djus ds fy, Memory esa dqN txg Reserve djuh gksxh vkSj ml Reserved Memory dks ,d uke nsuk gksxkA bl uke ls gh ml Memory Location dks igpkuk tk ldrk gS ftl ij Programmer us Age ds eku dks Store fd;k gSA tkok esa fdlh Identifier dks uke nsus ds dqN fu;e gSa] tks fuEukuqlkj gSa% •

• • • •

Identifier ds uke esa A to Z Capital o Small Letters dk iz;ksx fdlh Hkh izdkj ls fd;k tk ldrk gSA Underscore dk iz;ksx fd;k tk ldrk gSA ;fn uke esa fdlh Digit dk iz;ksx djuk gks] rks uke ds vUr esa Digit dk iz;ksx fd;k tk ldrk gSA uke esa fdlh Operator, Special Symbol ;k Keyword dk iz;ksx ugha fd;k tk ldrk gSA uke esa Blank Space dk iz;ksx ugha fd;k tk ldrk gS] D;ksafd Blank Space ,d rjg dk Special Symbol gSA

geus gekjh Specification esa Abstract Attributes dks Represent djus okys T;knkrj Data Members ds uke ds chp esa Whitespace dk iz;ksx fd;k gSA blfy, tkok bu Identifiers dks Accept ugha djrk gS vkSj gesa Errors nsrk gSA tkok dk ,d Naming Convention gS] ftlesa tc gesa fdlh Class dk uke nsuk gksrk gS vkSj uke esa nks ;k vf/kd “kCn gksrs gSa rc gesa fuEukuqlkj uke nsuk pkfg,%

70 Any Question or Suggestion, Just Discuss Here...

Java in Hindi PopulationOfIndia, AgeOfMoon, BasicSalary

blh rjg ls tc gesa fofHkUu Data Members dk uke nsuk gksrk gS vkSj uke esa ,d ls T;knk “kCn gksa rks mUgsa fuEukuqlkj uke nsuk pkfg,% populationOfIndia, ageOfMoon, basicSalary

vc pwafd geus gekjs Description esa fofHkUu Data Members ds chp Space dk iz;ksx fd;k gS] blfy, ;fn bl Class dks Bhd izdkj ls Specify djuk gS rks gesa bl Class dks fuEukuqlkj Modify djuk iMsxkA // Account Abstract Data Type or Class class Account { //Data Members or Abstract Attributes String branchName ; String branchNumber ; String accountNumber ; String accountHeadName ; float money ; String date ; //Methods or Behaviors void Deposit() { // Java Codes for changing the states of // Data Members based on requirement. }

}

void Withdraw() { // Java Codes for changing the states of // Data Members based on requirement. }

gkykafd geus Deposit() o Withdraw() Method esa fdlh rjg ds Code ugha fy[ks gSa] blfy, bl Class ds Object fdlh Hkh rjg dk dksbZ Hkh dke ugha djsaxsA fQj Hkh ;s Class iwjh rjg ls Executable gS vkSj ge bl Class ds Objects Create dj ldrs gSaA bl rjg ls ge fdlh leL;k ls lEcaf/kr fdlh t:jh Object dks ,d Abstract Data Type (Class) ds :i esa Specify djds Object dks Computer esa Logically Represent dj ldrs gSaA ,d ckj fdlh leL;k ds vk/kkj ij fdlh Object dh Class cuk nsus ds ckn ge ml Class ds ftrus pkgsa mrus Objects Create dj ldrs gSaA ;kuh mijksDr Account Class ds vk/kkj ij ge ftrus pkgsa mrus Customers ds Account dks Computer esa mlh rjg ls Logically Create o Manage dj ldrs gSa] ftl rjg ls Real World esa yksxksa ds Account dks Physically Create o Manage fd;k tkrk gSA

71 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Java – Graphical User Interface and Graphics Management

Computer esa GUI o Graphics Management dks Hkh ge ,d leL;k ds :i esa ns[k ldrs gSaA fofHkUu izdkj ds User Interface Components (Button, Scrollbars, Menu Bars, Status Bars, Dialog Boxes, Radio Buttons, Check Boxes, Text Fields) dks Create djus o mUgsa Computer esa Bhd rjg ls Manage djus ds fy, Hkh fofHkUu izdkj dh Graphics Classes dks igys ls gh Develop djds tkok ds Compiler ds lkFk gesa iznku fd;k tkrk gSA

bu fofHkUu izdkj dh Graphics Classes dks tkok esa Abstract Windowing Toolkit (AWT) uke ds ,d Package esa Store djds j[kk x;k gSA pwafd tkok OOPS dks iwjh rjg ls Support djrk gS] blfy, ge blesa Inheritance dh lqfo/kk dks iwjh rjg ls izkIr dj ikrs gSaA Inheritance OOPS dk ,d ,slk Concept gS] ftlds vk/kkj ij ge fofHkUu izdkj dh Classes cuk dj mUgsa muds Group ds vk/kkj ij fofHkUu izdkj ds Packages esa Store dj ldrs gSa vkSj t:jr gksus ij mu Classes ds Codes dks T;ksa dk R;ksa izkIr Hkh dj ldrs gSa vkSj muesa Modification djds viuh t:jr ds vuqlkj ubZ Classes Hkh cuk ldrs gSa] ftuesa mudh iqjkuh Classes ds lHkh Features ekStwn gksrs gSaA

bldk eryc ;s gqvk fd vius Program dks Graphics Mode esa Develop djus ds fy, ;s t:jh ugha gS fd ge fofHkUu izdkj ds Graphical Components dks fQj ls Develop djsa vkSj muds fy, fQj ls fofHkUu izdkj dh Classes Create djsa] cfYd ge AWT Package esa miyC/k fofHkUu izdkj dh Classes dks Inherit djds fQj ls Reuse dj ldrs gSa vkSj vius Program dks Graphical Mode esa Develop dj ldrs gSaA

Web Page – The Part of Website

tSlkfd geus igys Hkh dgk gS fd Applet os NksVs Programs gksrs gSa tks fdlh Web Page dks vf/kd Interactive cukus ds fy, Develop fd, tkrs gSaA Applet dks le>us ls igys ge ;s le>rs gSa fd vkf[kj Web Pages D;k gSa vkSj budh t:jr D;k gSA Web Pages ,sls Electronic Pages gSa] ftu ij Stored Information nqfu;ka esa dgha Hkh ns[kh tk ldrh gSaA Web Pages lwpukvksa dks rsth ls lkjh nqfu;ka esa QSykus dk lcls vPNk ek/;e gS] fQj pkgs ;s lwpuk fdlh University dk Declare fd;k x;k Result gks ;k fdlh Company ds

fdlh u, mRikn ds ckjs esa fn;k x;k foKkiu A

lkekU;r;k Web Pages dk T;knkrj mi;ksx fofHkUu izdkj dh Companies vius mRikn dh Advertisement djus ds fy, djrh gSa] rkfd muds mRikn dks lkjh nqfu;ka tku lds vkSj mudk O;olk; National ls c ikrs gSaA blh

72 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Concept ds vk/kkj ij ;s ekuk x;k fd ;fn Web Pages Hkh Multimedia ls ;qDr gksa] rks T;knk ls T;knk yksx Web Pages dks ns[ksaxs vkSj fdlh Company ds mRikn dk T;knk ls T;knk yksxksa esa foKkiu gks ldsxkA

blfy, ,sls Web Pages cukus dh t:jr eglwl dh xbZ] ftlesa Multimedia ;kuh Sound, Video, Animation, Graphics vkfn dk T;knk ls T;knk iz;ksx fd;k x;k gks vkSj fdlh Web Page esa Multimedia dks ykus ds fy, tkok Applets lcls vPNk lk/ku gSaA blds lkFk gh vkt tks O;olk; fd, tkrs gSa os fdlh ,d “kgj ;k ,d ns”k rd lhfer ugha gksrs gSaA fofHkUu izdkj dh Multinational Companies vkil esa fey dj O;olk; djrh gSaA ,sls esa fdlh Multinational Company ds fofHkUu Hkkxhnkjksa dks dHkh Hkh viuh Company dh Financial fLFkfr tkuus dh t:jr iM ldrh gSA ,sls esa gj Hkkxhnkj viuh Company dh fLFkfr tkuus ds fy, Center Office ls tkudkjh izkIr dj lds] ;s O;oLFkk Bhd ugha dgh tk ldrhA D;ksafd gks ldrk gS fd Company dk dksbZ Partner India esa jgrk gks vkSj Company dk Center Office America esa gksA ,sls esa India dk og O;fDr ;s dSls tku ldsxk fd mldh Company dh fLFkfr D;k gS] ftlesa mlus viuk /ku Invest fd;k gSA bl izdkj dh fLFkfr esa Company ls lEcaf/kr lHkh lwpukvksa dks America ds Center Office esa ;fn gj jkst Web Pages ds :i esa Internet ij Mky fn;k tk,] rks India dk og Partner Hkh Company dh fLFkfr dks gj jkst fdlh Hkh le; tku ldrk gSA pwafd Company dh orZeku fLFkfr dh fofHkUu izdkj dh lwpukvksa dks Analyze djds fofHkUu izdkj ds Decisions ysus gksrs gSa] blfy, fofHkUu izdkj dh Information dks fofHkUu izdkj ds Graphs, Charts vkfn ds :i esa O;ofLFkr fd;k tkrk gS] rkfd fofHkUu izdkj ds t:jh Decisions rqjUr fy, tk ldsaA bu fofHkUu izdkj ds Graphics o Charts vkfn dks fofHkUu izdkj ds User }kjk fn, tkus okys Data ds vk/kkj ij Online Develop gks ldsa] blds fy, ,sls Interactive Web Pages dh t:jr gksrh gSa] tks User ds lkFk FkksMk cgqr Interaction dj ldsa vkSj ;s lqfo/kk dsoy Applets }kjk gh izkIr dh tk ldrh gSa] D;ksafd tkok Applets os Programs gksrs gSa] tks Web Pages esa Run gksrs gSa vkSj Web Pages iwjh nqfu;ka esa dgha ls Hkh Access fd, tk ldrs gSaA bu Web Pages ij User }kjk Parameter ds :i esa Specify fd, x, Inputs dks Applets Accept dj ldrs gSa vkSj fofHkUu izdkj ls Modify gksdj User dh lkekU; t:jrksa dks Online ;kuh Run Time esa iwjh dj ldrs gSaA lkjka”k ;s gqvk fd Applets dk iz;ksx Web Pages esa djuk gksrk gS] blfy, Applet Programming djus ls igys gesa Web Page cukuk lh[kuk gksxkA Web Site ,d ,slh Book dh rjg gksrh gS] ftlesa cgqr lkjs ,sls Electronic Pages gksrs gSa] ftuesa lwpukvksa dks Present djus ds fy, fofHkUu izdkj ds Multimedia dk iz;ksx fd;k tkrk gSA Web Pages Develop djus ds fy, gesa fdlh fo”ks’k Compiler ;k Software dh t:jr ugha gksrh gS uk gh Web Pages ds Output dks ns[kus ds fy, ;s t:jh gksrk gS fd ge Internet ls Connected gksaA

73 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ge fdlh Web Site ds fofHkUu Pages dks Notepad esa Develop dj ldrs gSa] vkSj mls Internet Explorer ;k ,sls gh fdlh Browser esa Embed djds ;kuh Run djds ns[k ldrs gSa fd ;s Web Pages Internet ij Run gksus ij fdl izdkj ds fn[kkbZ nsaxsA Web Pages Develop djus ds fy, dqN Basic rS;kfj;ka djuh gksrh gSaA ;kuh gesa ;s r; djuk gksrk gS fd ge Web Pages dks fdu yksxksa ds fy, Develop dj jgs gSa vkSj mu yksxksa dks Web Pages }kjk D;k tkudkjh nsuk pkgrs gSaA ge tks tkudkjh nsuk pkgrs gSa] mlds Contents dks iwjh rjg ls Develop djus ds ckn gesa mu Contents dks Web Pages ds :i esa Represent djuk gksrk gSA

vius Contents dks Web Pages esa Represent djus ds fy, gesa HTML (Hyper Text Markup Language) Tags dk iz;ksx djuk gksrk gSA HTML Tags ,sls Tags gksrs gSa] ftUgsa lHkh Computers Platforms leku :i ls Support djrs gSa] blfy, ge ftl Web Site dks Develop djds Internet ds Web Server ij Store dj nsrs gSa] og Web Site fofHkUu izdkj ds Hardware o Platform dks Use djus okys lHkh yksxksa dks leku :i ls fn[kkbZ nsrh gSA HTML Pages cukus ds fy, gesa HTML ds fofHkUu Tags dks ,d Notepad esa fy[kuk gksrk gS vkSj ml Notepad dh File dks .HTML uke ls Save djuk gksrk gSA tc ge fdlh Notepad esa Create dh xbZ File dks .HTML Extension ls Save djrs gSa] rc og File Internet Explorer ;kuh fdlh Web Browser esa Open gksus okyh File cu tkrh gSA ge Windows Platform ij dke dj jgs gSa] blfy, ge gekjh lHkh Files, Internet Explorer esa Open gksxhA

HTML Tags for Web Pages

HTML File cukus ds fy, gesa tks Tabs fy[kus gksrs gSa] os Tabs Hkh dqN fo”ks’k rjhds ls fy[kus gksrs gSaA ,d Web Page esa Contents o Tags ;kuh dqy nks phtsa gksrh gSaA Tags os Commands gksrs gSa ftUgsa Web Browser le>rk gS vkSj muds vk/kkj ij fn, x, Contents dks fofHkUu izdkj ds Web Pages ij Display djrk gSA fofHkUu izdkj ds HTML Tabs dks Opening o Closing Bracket ( < > ) ds chp fy[kk tkrk gSA

lkFk gh fofHkUu izdkj ds Contents dks < > o ds chp fy[kk tkrk gSA “ / ” dk fpUg ,d Tag ds vUr dks n”kkZrk gSA ,d Web Page ds fofHkUu Tags o Contents dks o Tags ds chp fy[kk tkrk gSA fdlh Hkh Web Page ds eq[;r% rhu Hkkx gksrs gSa% Comment Section ;s ,d Optional Section gSA ge pkgsa rks bls fcuk Specify fd, gq, Hkh Web Page Develop dj ldrs gSaA Comments fdlh Web Page ds ckjs esa General tkudkjh nsrs gSaA Comment nsus ds fy, ds chp Statement fy[kk tkrk gSA bl rjg ds Bracket esa tks Text fy[ks tkrs gSa] os Browser esa fn[kkbZ ugha nsrs gSaA ;s Comment gesa fuEukuqlkj fy[kuk gksrk gS%

gkykafd Comment Text Web Pages esa Front esa fn[kkbZ ugha nsrs gSa] ysfdu fQj Hkh ;s Web Pages ds lkFk Client ds Computer esa Download rks gksrs gh gSa] blfy, gesa gekjs Web 74 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Page esa de ls de Comment fy[kus pkfg,aA gkykafd ge Web Page esa dgha Hkh vkSj fdruh Hkh ckj Comment fy[k ldrs gSaA

Head Section ;s Hkh ,d Optional Section gSA ge pkgsa rks bls Hkh fcuk Specify fd, Web Page Develop dj ldrs gSaA Head Section dks o Tag }kjk Define fd;k tkrk gSA bl Tag dk iz;ksx Web Page dk uke ;kuh Title nsus ds fy, fd;k tkrk gSA bl Section esa o ds chp esa ge tks Text fy[k nsrs gSa] og Text Web Page ds Title Bar esa fn[kkbZ nsus yxrk gSA Web Page esa fn[kkbZ nsus okys Title dks fuEukuqlkj Tags }kjk Define fd;k tk ldrk gS% Betalab Computer Center

Body Section ;s Hkh ,d Optional Section gSA Head Section ds ckn esa Body Section vkrk gS] tgka ge Web Page ds Contents fy[krs gSa vkSj fofHkUu izdkj ds Multimedia dk iz;ksx Hkh ;gha ij djuk gksrk gSA mUgsa fofHkUu rjhdksa ls Web Page ij n”kkZ ldrs gSaA

Adding Applet in HTML File

ftl rjg ls ge fofHkUu izdkj ds Tags dk iz;ksx djds fofHkUu izdkj ls fdlh Web Page dks Design djrs gSa] mlh rjg ls fdlh Applet dks HTML Page esa Embed djus ds fy, gesa Tag dk iz;ksx djuk iMrk gSA bl Tag esa gesa ;s Specify djuk gksrk gS fd Web Page esa Embed fd, tkus okys Applet dk uke D;k gS vkSj ml APPLET dh Web Page esa Size D;k gksxhA ;fn gesa fdlh HellJava uke ds Applet dks Web Page esa Embed djuk gks] rks gesa fuEukuqlkj APPLET Tag Code fy[kuk gksrk gS% Betalab Computer Center Welcome to the world of Java.

75 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Applet Architecture – The Event Based GUI Application Program

fdlh Applet dks ,d Web Page esa fdl Code }kjk Embed fd;k tk ldrk gS vkSj Web Page dks Java Applet dk iz;ksx djds fdl izdkj ls vf/kd Interactive cuk;k tk ldrk gS] bl lEca/k esa FkksMh Basic tkudkjh ysus ds ckn vc ge ;s le>saxs fd Applets dks dSls Develop fd;k tkrk gSA lkFk gh ge ;s Hkh tkusaxs fd Applets fdl izdkj ls dke djrs gSa vkSj fdl izdkj ls Define fd, tkrs gSaA ;kuh ge Applets ds Architecture dks le>saxsA Applet ds lEca/k esa lcls igyh ckr ;s gS fd Applet ,d Window-Based Event Driven Program gksrk gSA Event Driven Programming ds ckjs esa ge blh v/;k; esa vkxs le>saxsA pwafd Applet ,d Event Driven Window-Based Program gksrk gS] blfy, bldk Architecture fdlh vU; Normal Console-Based Program ls vyx gksrk gSA

blfy, Applets Develop djus ls igys gesa ;s tkuuk t:jh gS fd Applets fdl izdkj ls dke djrs gSa vkSj fdl izdkj ls bUgsa Design fd;k tkrk gSA Applets fofHkUu izdkj ds Interrupts Service Routines dks Handle djus okys Code Segments ;k Methods ds Implementation ij vk/kkfjr gksrs gSaA GUI Applications esa Mouse ;k Keyboard ls dqN Hkh djuk Event dgykrk gSA ;kuh Mouse ls Click djuk ;k Keyboard ls Key Press djuk] bu nksuksa fLFkfr;ksa esa dqN Events Generate gksrs gS]a ftuds ckjs esa ge vkxs foLrkj ls le>saxsA

gekjk Applet bUgha Events dk bUrtkj djrk jgrk gSA tSls gh dksbZ Event Generate gksrk gS] AWT Package Applet }kjk iznku fd, x, fdlh ,d Event Handler Method dks Call djrk gS vkSj Generate gksus okys Event ds lEca/k esa tkudkjh ns nsrk gS ;k Notify dj nsrk gSA ,d ckj ,slk gks tkus ds ckn Appropriate Action ysus vkSj Control dks okil AWT esa Pass djus dh ftEesnkjh Applet dh gksrh gSA ge fdlh Applet ij tSls gh fdlh Mouse Button ls Click djrs gSa] ,d Mouse Event Generate gksrk gS] ftls Applet esa Define fd;k x;k Handler Respond djrk gSA blh rjg ls ;fn Keyboard ls dksbZ Key Press dh tkrh gS] rks Hkh ,d Event Generate gksrk gS] ftls Applet dk dksbZ Handler Respond djrk gSA fdlh Applet ls lEcaf/kr ftrus Hkh Basic ;k Primary Initializations o Functionality gSa] mUgsa Applet uke dh Class esa Define fd;k x;k gSA Applet uke dh ;s Class applet uke ds Package esa miyC/k gSA pwafd tkok OOPS ds Concepts dks Implement djrk gS vkSj ,d iw.kZ Object Oriented Programming Language gS] blfy, ge blesa Inheritance Concept dks iwjh rjg ls Apply dj ldrs gSa vkSj Packages esa Classes ds :i esa Stored fofHkUu izdkj ds igys ls Define fd, x, Codes dks T;ksa dk R;ksa Reuse dj ldrs gSaA 76 Any Question or Suggestion, Just Discuss Here...

Java in Hindi blfy, Applet Class dks Inherit djds ge ,d Applet ls lEcaf/kr fofHkUu Basic Initializations o Functionality dks izkIr dj ldrs gSaA pfy,] vc ge ,d Applet dks Applet Class ls Inherit djds Applet Class dh fofHkUu Properties o Functionality dks izkIr djrs gSa] ;kuh ,d Applet cukrs gSaA Program: MyFirstApplet.java // Inheriting An Applet from Built–In Applet Class import java.awt.*; import java.applet.*; public class MyFirstApplet extends Applet { }

bl Code dks ,d Notepad esa fy[ksa “C:\” Derive esa ,d JAVASOURCE uke dk Folder cuk dj mlesa MyFirstApplet.java uke ls Save djsaA vc Command Prompt ij tkdj fuEu Statement }kjk ml Folder esa igqaps] tgka ij MyFirstApplet.java dks Save fd;k gS] ;kuh JavaSource Folder esa igqapsaA C:\>CD JAVASOURCE

// Press Enter

vc fn[kkbZ nsus okyk Command Prompt fuEukuqlkj gksxk% C:\JAVASOURCE>

vc Source File dks Compile djus ds fy, fuEu Command Type djsa% C:\JAVASOURCE>javac MyFirstApplet.java

// Press Enter

tc fcuk fdlh Error ds File Compile gks tk,xh] rc JAVASOURCE Folder esa ,d ubZ File cusxh ftldk Extension .class gksxkA ;kuh gekjh Source File Compile gksus ds ckn MyFirstApplet.class uke dh ,d Class File cusxh ;s File ,d Executable File gksrh gS] ftls fdlh Hkh Platform esa fdlh Hkh Browser }kjk ,d Web Page esa Embed djds Run fd;k tk ldrk gSA bl Applet dks Test djus ds fy, gesa ,d Web Page cukuk gksxkA Web Page cukus ds fy, ,d Notepad esa fuEu HTML APPLET Tag fy[k dj mlesa MyFirstApplet.class Filed dks Embed dj ldrs gSaA My First Applet

77 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Welcome to the world of Java. Notepad esa ;s HTML Tabs fy[kus ds ckn File dks mlh Folder esa Save djuk gksrk gS] tgka ij Java Applet dh Class File Stored gSA ge ;s eku jgs gSa fd gekjh Source File o mldh Class File nksuksa gh “C:\JAVASOURCE” esa Stored gSaA blfy, bl HTML File dks Hkh gesa ;gha ij Store djuk gksxkA

;fn gekjk Browser Java dks Support djrk gS ;k Java Enabled gS] rks ge Create gksus okys MyFirstApplet.HTML Web Page dks Open djds Applet dks Web Page esa ns[k ldrs gSaA Netscape Navigator ,d Java Enabled Web Browser gS] ftlesa ge fdlh Hkh Web Page esa Contained Applet dks Directly ns[k ldrs gSaA ;kuh ;fn ge MyFirstApplet.HTML File dks Open djsa] rks gesa ;s File fuEukuqlkj fn[kkbZ nsxh%

;fn gekjk Browser Java Enabled ugha gSa] rks gesa tkok ds lkFk vkus okys Appletviewer dk iz;ksx djds gesa vius Applet dks Test djuk gksrk gSA Appletviewer dk iz;ksx djds Applet dks Test djus ds fy, MyFirstApplet.HTML File Create djus ds ckn Command Prompt ij fuEukuqlkj Command fy[kuk gksrk gS% C:\JAVASOURCE>Appletviewer MyFirstApplet

// Press Enter

tc ;s Command fy[kdj Enter Key Press djrs gSa] rks gesa Output esa fuEukuqlkj Applet Viewer fn[kkbZ nsrk gSA

78 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

pfy,] vc ge bl Applet dh Coding dks le>us dh dksf”k”k djrs gSaA dksbZ Hkh Applet Create djus ds fy, gesa tkok esa igys ls Define dh xbZ Applet Class ds xq.kksa dks Inherit djus ds fy, ,d Sub Class cukuh iMrh gS vkSj igys ls cuh gqbZ Applet Class ds lHkh xq.kksa o Functionality dks Derive djuk iMrk gSA tkok fdlh esa Class dks Inherit djus ds fy, extends Keyword dk iz;ksx djuk gksrk gSA ;kuh tc ge viuh dksbZ Applet Class cukuk pkgrs gSa] rc gesa gekjh Applet Class dks tkok dh Applet Class ls Inherit djuk iMrk gS] rkfd ge gekjh Class esa fdlh Applet ls lEcaf/kr fofHkUu izdkj dh Properties o Functionality dks T;ksa dk R;ksa izkIr dj ldsa vkSj fcuk fdlh izdkj ds fo”ks’k Overhead ds ,d Applet Create dj ldsaA extends Keyword dk iz;ksx blfy, fd;k x;k gS] D;ksafd tkok esa Applet ls lEcaf/kr tks Built–In lqfo/kk,a iznku djrk gS] ge mu lqfo/kkvksa dks rks T;ksa dk R;ksa Use dj ysrs gSa] lkFk gh Create gksus okyh Sub Class esa viuh vko”;drkuqlkj u, Features Hkh Add dj ldrs gSaA geus gekjh Coding esa fuEu Statement }kjk tkok dh Applet Class dks Inherit fd;k gS% public class MyFirstApplet extends Applet { }

bl Statement esa geus tkok Compiler dks crk;k gS fd ,d ubZ Class cuk jgs gSa] ftldk uke MyFirstApplet gS ,d Access Specifier gS] tks ;s crkrk gS fd bl Class esa Create fd;k tk ldrk gSA Access Specifies ds ckjs

ge Applet Class dks Extend djds vkSj ;s ,d Public Class gSA Public ds Objects dks fdlh Hkh vU; Class esa ge vkxs foLrkj ls ppkZ djsaxsA

ge tc Hkh dksbZ Applet Extend djrs gSa] rks Create gksus okys fdlh Hkh Applet dh Lifetime ds eq[;&eq[; pkj Events gksrs gSa vkSj gj Event ls Applet Class dk ,d Method Associated jgrk gSA fdlh Applet dh Life Cycle ds pkjksa Steps dks ge pkj Methods }kjk Represent dj ldrs gSa% public void init() Method tc User fdlh ,sls Web Page dks Open djrk gS] ftlesa Applet Embed gksrk gS] rks Web Page ds Memory esa Load gksrs gh Applet dqN izkjfEHkd ekuksa ls Initialize gksrk gSA Applet ds ;s izkjfEHkd eku Applet Class ds init() Method }kjk Initialize gksrs gSaA ;fn ge Applet ds Initialization ds le; fdUgha Variables dks dksbZ eku iznku djuk pkgsa] ;k dqN ,sls dke djuk pkgsa] tks Applet ds Initialize gksrs gh Execute djus gksa] tSls fd fofHkUu izdkj ds GUI Objects dks Applet ij Add djuk gks] rks bu dkeksa dks djus ds Codes gesa

79 Any Question or Suggestion, Just Discuss Here...

Java in Hindi init() Method esa fy[kus gksrs gSaA ;s Method fdlh Applet dh Life esa dsoy ,d gh ckj Execute gksrk gSA

;fn nqckjk init() Method dks Execute djuk gks] rks gesa Web Page dks Close djds fQj ls Open djuk iMrk gSA public void start() Method init() Method }kjk Applet Initialize gksus ds ckn start() Method Call gksrk gSA lkFk gh ge ftruh Hkh ckj Applet dks Restart djrs gSa] ;s Method Execute gksrk gSA Applets dks ml le; Stop fd;k tk ldrk gS] ftl le; User ,d Web Site ls nwljh Web Site ij Move gksrk gSA ;fn User dqN le; ckn esa fQj ls ml Web Site ij vkrk gS] rks Applet fQj ls Restart gksrk gSA blfy, start() Method dks Applet dh Life Time esa vko”;drkuqlkj dbZ ckj Call fd;k tk ldrk gSA Applet tc Hkh fdlh Event ds dkj.k Focus Receive djrk gS] ;s Method Execute gksrk gSA ge bl Method esa mu Codes dks fy[k ldrs gSa] ftUgsa Applet ds Restart esa Execute djokuk pkgrs gSaA tSls fd Applet esa fdlh Thread dks Initialize djus ds le; ;k Screen ds Data dks Update djrs le; Applet gj ckj ,d Focus izkIr djrk gS ftlls gj ckj Applet Restart gksrk gSA

public void stop() Method ;s Event rc Generate gksrk gS] tc ,d Web Browser fdlh HTML Page dks NksM dj fdlh nwljs Web Page ij tkrk gS] ;k Web Page ij ls Focus Lost gksrk gSA ge bl Method dks rc Use dj ldrs gSa tc ge Program ds fofHkUu Variables dks Reset djuk pkgrs gSa ;k fdlh Running Thread dks Stop djuk pkgrs gSaA public void destroy() Method tc Applet iwjh rjg ls Execute gksuk cUn gks tkrk gS ;k tc User ,d Page ls nwljs Page ij Move gks tkrk gS] rc ;s Method Execute gksrk gSA ge bl Method dk iz;ksx fdlh Applet }kjk Use gks jgs fdlh Resource dks Free Up djus ds fy, dj ldrs gSaA stop() Method gesa”kk destroy() Method ls igys Call gksrk gSA ;s pkjksa gh Methods Automatically Call gksrs gSa vkSj ge bUgsa fdlh Hkh izdkj ls vyx ls Call ugha djrs gSaA Applet esa tks dqN Hkh Display gksrk gS] mls Display djus ds fy, gesa paint() Method dks Use djuk gksrk gSA bl Method ds fcuk ge Applet esa dqN Hkh Display ugha dj ldrs gSaA bl Method ds vykok nks vU; Methods update() o repaint() Hkh gSa] ftudk iz;ksx vyx&vyx ifjfLFkfr;ksa esa Applet dks Paint djus ds fy, djuk iMrk gSA public void paint() Method tc Hkh gesa Applet Window dks Paint djuk gksrk gS] rc gesa bl Method dks Call djuk iMrk gSA Applet Window dks Paint djus dk eryc ;s gS fd tc Hkh gesa fdlh Information OR Graphics dks Applet esa Display djuk gksrk gS] rks ml Information ;k Graphics dks Applet

80 Any Question or Suggestion, Just Discuss Here...

Java in Hindi dh Window esa Draw dj nsrs gSaA Information ;k Graphics dks Window esa Display djus dh izfØ;k dks Window Paint djuk dgrs gSaA dqN fLFkfr;ksa esa Paint Method Lo;a gh Automatically Call gks tkrk gSA tSls tc ,d Window Display gks jgk gks vkSj ml Window ij dksbZ nwljk Window Overwrite gks tk, vkSj fQj igys Window dks Activate fd;k tk,] rks gesa nwljk Window fn[kkbZ nsus ls igys Repaint gksrk gSA bls ge fuEu fp= }kjk le> ldrs gSa% bl fp= esa MS Paint ls Media Player Hide gks jgk gSA vc ;fn ge Media Player dks Activate djsa] rks Media Player fQj ls Paint gksrk gS vkSj MS Paint Hide gks tkrk gS] ftls ge fuEu fp= esa ns[k ldrs gSa%

blh rjg ls tc ge fdlh Window dks Minimize ;k Restore djrs gSa] rc Hkh og Window Paint gksrk gSA tc igyh ckj Applet dk Execution “kq: gksrk gS] rc Hkh ;s Method Call gksrk gSA

81 Any Question or Suggestion, Just Discuss Here...

Java in Hindi dkj.k dksbZ Hkh gks] tc Hkh Window ds Output dks Redraw djuk gksrk gS] ;s Method Call gksrk gSA paint() Method dks repaint() Method dks Call djds Trigger fd;k tk ldrk gSA Applet Class ds paint() Method esa Parameter ds :i esa Graphics Class dk ,d Object Specify djuk gksrk gSA bl Parameter esa ml Graphics Object dh Information gksrh gS] ftls Applet ij Draw djuk gksrk gSA

public void update() Method ;s Method paint() Method dh rjg gh dke djrk gSA bl Method dks Call djus ij ;s Method Screen dks Clear djrk gS vkSj fQj ls paint() Method dks Call djds Screen dks Repaint dj nsrk gSA public void repaint() Method tc ge Applet dks Repaint djuk pkgrs gSa] rc ge repaint() Method dks Call dj ldrs gSaA repaint() Method Automatically update() Method dks Call djds Screen dks Redraw djrk gSA

First Applet in Java

fdlh Applet esa Text dks Display djuk lcls ljy dke gSA ysfdu Applet Window Based GUI dks Support djrk gS vkSj Window esa tks dqN Hkh fn[kkbZ nsrk gS] og lcdqN Graphical Form esa gksrk gS] blfy, tkok ds Graphical Text Function dks Use djds Applet esa String dks Draw djuk iMrk gSA tkok esa String dks Draw djus ds fy, drawString() Method dks Generally Use fd;k tkrk gSA ;s Method awt Package esa fLFkr Graphics Class dk ,d fgLlk gSA Package dqN lEcaf/kr izdkj dh Classes ds Collection ds vykok vkSj dqN ugha gksrk gSA fuEu Code Segment ,d Applet dk gS] ftlesa ,d String dks Display djok;k x;k gSA import java.awt.*; import java.applet.*; public class DrawStringApplet extends Applet { public void paint(Graphics firstString) { firstString.drawString("First String in Java Applet ", 10, 25); } } Output:

82 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

bl Program esa lcls igys awt o applet Package dks Use djus ds fy, Import fd;k x;k gSA Import Statement ds dkj.k ge Applet Class ds lHkh Features dks DrawStringApplet uke dh ubZ Class esa Derive ;k Inherit djus dh lqfo/kk izkIr djrs gSaA tc ge Applet Class dks Derive djds mlds Features dks DrawStringApplet Class esa izkIr djrs gSa] rks ge blh Class esa Applet Class ds fofHkUu Methods dks Hkh izkIr djrs gSaA paint() Method Hkh Applet Class dk gh ,d Method gSA ;s Method gesa Applet Class dks Derive djus ls izkIr gksrk gSA bl Method dks Override djds ge Applet ij String dks Draw dj ldrs gSaA String dks Draw djus ds fy, Graphics Class dk drawString() Method Execute fd;k x;k gSA

public abstract void drawString(String text, int x, int y)

bl Program esa geus Applet Class ds drawString() Method }kjk ,d String dks Applet ij x o y dh Location ij Display fd;k gSA gesa ftl String dks Screen ij Display djuk gksrk gS] mls bl Method esa igys Argument ds :i esa fy[kuk gksrk gSA nwljk o rhljk Argument ,d Number gksrk gS] tks Applet ij String dh Display gksus dh Location dks Specify djrs gSaA Flow of This Applet

ge tkurs gSa fd tc Hkh Applet dh Screen dks Draw djuk gksrk gS] rc Applet Class dk paint() Method Execute gksrk gSA tc igyh ckj Applet Screen ij Appear gksrk gS] rc paint() Method igyh ckj Execute gksrk gSA bl Program esa tc ge Web Page Run djrs gSa vkSj Applet Appear gksrk gS] rc Applet ds Appear gksrs gh tkok paint() Method dks Call djrk gS vkSj paint() Method drawString() Method dks Call djrk gS] tks fd String dks Applet ij Display dj nsrk gSA paint() Method Graphics Class dk Method gSA ;s Method fdlh Graphics Object dks Applet esa Display djus dk dke djrk gSA bl Program esa ge ns[k ldrs gSa blds Parenthesis esa firstString uke dk ,d Object Pass fd;k x;k gSA

bldk eryc ;s gS fd tkok paint() Method esa Graphics Class dk ,d Object Argument ds :i esa Hkst jgk gS] ftldk uke firstString gSA pwafd firstString Graphics Class dk ,d Object gSA blfy, ;fn ge bl Object dks Display djuk pkgrs gSa] rks gesa Graphics Class ds gh fdlh ,sls Method dks Call djuk gksxk] tks gekjh t:jr dks iwjk dj nsA

83 Any Question or Suggestion, Just Discuss Here...

Java in Hindi pwafd ge ,d String dks Display djuk pkgrs gSa] blfy, gesa firstString Object ds fy, drawString() Method dks Call djuk gksxkA tc gesa fdlh Object ds fy, fdlh Method dks Call djuk gksrk gS] rc gesa ml Object dks Dot dk iz;ksx djds Method ls tksMrs gq, Call djuk iMrk gS] rkfd Call gksus okyk Method mlh Object ij izfØ;k djs] ftlds lkFk mls Call fd;k x;k gSA blhfy, geus gekjs Program esa fuEu Code Line fy[kh gS% firstString.drawString("First String in Java Applet ", 10, 25);

;s Statement tkok Compiler dks firstString Object ds drawString() Method dks Call djus ds fy, Message nsrk gSA drawString() Method ds Parenthesis esa iznku fd;k tkus okyk eku Argument dgykrk gSA ;s os eku gksrs gSa] ftUgsa Method esa Information ds :i esa Pass djuk gksrk gSA drawString() Method ds Arguments tkok Compiler dks “First String in Java Applet” String dks Column Number 10 o Row Number 25 ij Display djus ds fy, Instruction nsrk gSA Row o Columns dks Pixels esa Measure fd;k tkrk gS uk fd Characters esaA Pixel fdlh Screen ij fn[kkbZ nsus okyk lcls NksVk Dot gksrk gSA Display gksus okys Text dks vyx Location ij Display djuk gks] rks gesa Row o Column dh la[;k Change djuh gksrh gSA

GUI – The Event Driven Programming System ekuyks fd ge lqcg&lqcg tSls gh Office tkus ds fy, ?kj ls ckgj fudyus okys gksrs gh gSa fd rqjUr Phone dh ?k.Vh ctus yxrh gSA Phone dh ?k.Vh dk ctuk ,d izdkj dk Event gSA Real Life esa dbZ ckjs ,sls Events gksrs gSa] ftUgsa ckdh lHkh dkeksa dks Suspend djds rqjUr Respond djuk iMrk gSA mnkgj.k ns[ksa rks ge pkgs ftruh Hkh tYnh esa gksa] ysfdu vxj Phone dh ?k.Vh ctrh gS] rks gesa ml Phone dks Attend djuk gh iMrk gSA blh Concept dks tc ge Programming ds lUnHkZ esa ns[krs gSa] rc fdlh Program o mlds User ds chp ftruh Hkh Activities gksrh gSa] mu lHkh Activities dks tkok esa Events dgk tkrk gSA User Keyboard ls dksbZ Key Press djrk gS ;k Mouse ls Application ds fdlh Command Button ij Click djrk gS ;k Application Program ds Window dks Resize djrk gS] Software ;k Hardware dk Fail gksuk] fdlh List esa ls fdlh Item dks Select djuk] Timer ds Counter dk Increment gksuk vkfn fofHkUu izdkj ds Events gSaA

tc User fdlh Program ds lkFk Interaction djrk gS] rc Computer ,d Event Object Create djrk gSA ;s Event Object ml Action dks Represent djrk gS] ftls User us Perform fd;k gSA ;kuh ekuyks fd User us fdlh Application ds fdlh Button ij Click fd;k] rks Computer ,d Object Create djsxk vkSj ml Object }kjk Click Event Represent gksxkA fQj ge bl Click Event dks ,d Event Handler Coding }kjk Handle dj ldrs gSa vkSj og dke djokrs gSa] tks Click Event ds Generate gksus ij djokuk gksrk gSA 84 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ;s Event Handler Code gh ;s r; djrk gS fd fdlh Event dks fdl izdkj ls Handle djuk gSA fdlh Event dks fofHkUu izdkj ls Drive djds Program Develop djus o mls Handle djus dh rduhd dks Event Driven Programming dgrs gSa] ftlesa fofHkUu izdkj dh Events dks Response djus okys Code Handlers fy[k dj Programming ;k Development fd;k tkrk gSA tkok ,d Pure Object Oriented Programming Language gS] blfy, ge bl Language esa fdlh Hkh pht dks ,d Object ds :i esa Represent djrs gSaA blhfy, User }kjk fdlh Hardware dks Access djus ls dksbZ Event Generate gks ;k fdlh Software }kjk dksbZ Event Generate gks] nksuksa gh fLFkfr;ksa esa fdlh Event dks Represent djus ds fy, ,d Event Object Create gksrk gSA GUI Programming esa Event Handle djuk lcls t:jh dke gksrk gSA GUI Program ;k Event Driven Programming Modal esa gekjk GUI Program User ds fdlh Hkh Action dk

bUrtkj djrk jgrk gSA

tc User ml Application ds lkFk fdlh izdkj dk Interaction djrk gS] rks ml Interaction ls lEcaf/kr dksbZ uk dksbZ Event Generate gksrk gS vkSj ml Event dks Handle djus ds fy, dksbZ uk dksbZ Handler fy[kk x;k gksrk gS] tks fd Event ds Response esa Execute gks tkrk gSA GUI dh lcls cMh fo”ks’krk ;s gS fd fdlh GUI Application ds Operations ds Perform gksus ds Øe dks User fu/kkZfjr djrk gS] ;kuh og fdlh Application ij fn[kkbZ ns jgs fdlh Hkh Button dks ;k fdlh Hkh vU; Control dks fdlh Hkh le; Use dj ldrk gS] tcfd CUI Applications esa Program ds Execution dk Sequence Programmer r; djrk gS vkSj User dks mlh izdkj ls pyuk iMrk gS ftl rjg ls Programmer us Program dks fy[k dj r; fd;k gSA Event Driven Program fuEukuqlkj Execute gksrs gSa% Algorithm of GUI Application 1 START [Starting the Window Based GUI Application ] 2 CREATE GUI OBJECT [Create a GUI Application Object like A Window] 3 LISTEN EVENT [Listen for an Event Occurred by the Interaction] 4 IF EVENT = CLOSE APPLICATION [If Event is for closing the Application] EXIT ELSE PROCESS EVENT 5 GOTO STEP 3 [Go to the Step 4 again and get next Event ]

85 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Flow of GUI Application START

Create a GUI Interface Object

Listen for an Event

Is Event = Close Window

Yes

END

No Process the Event

Components of an Event

tkok esa fdlh Hkh Event dks rhu fgLlksa esa caVk gqvk ekuk tk ldrk gS% Event Object tc User Keyboard ds fdlh Button dks Press djds ;k Mouse ds fdlh Button dks Click djds fdlh Application ls Interact djrk gS] rc ,d Event Generate gksrk gSA Event Driven Architecture ij vk/kkfjr Operating System bl Event o Event ls Related t:jh Data dks Trap dj ysrk gSA mnkgj.k ds fy, User fdlh Application ds Window ij Click djrk gS] rc User us fdl Button ls Click fd;k gS vkSj fdl x, y Location ij Click fd;k gS] bl ckr dh tkudkjh Data ds :i esa mlh Application ds mlh Object dks okil Hkst nsrk gS] ftl Object ij Click djus ij Event Generate gqvk gksrk gSA tkok esa gj Event dks ,d Object }kjk Represent fd;k tkrk gS vkSj og Object Generate gksus okys Event ls lEcaf/kr fofHkUu tkudkfj;ksa dks Hold djds j[krk gSA Event Object ds fdlh Data Member ds eku esa ifjorZu gksus dk eryc gS fd dksbZ Event Generate gqvk gSA ;k fQj ge ,slk Hkh dg ldrs gSa fd fdlh Event Object ds fdlh Data Member ds eku esa ifjorZu gksus dks gh ge Indirectly Event Generate gksuk dg ldrs gSaA tkok esa fofHkUu

86 Any Question or Suggestion, Just Discuss Here...

Java in Hindi izdkj ds Events dks Describe o Handle djus ds fy, dbZ Classes igys ls gh Develop djds Library ds :i esa iznku dj nh xbZ gSAa Event Source

Event Source ,d ,slk Object gS tks Event Generate djus esa l{ke gksrk gS ;k Event Generate djrk gSA Event rc Generate gksrk gS] tc fdlh rjhds ls fdlh Event Object dh Internal State ;kuh Object ds fdlh Data Member dh fLFkfr esa ifjorZu gksrk gSA dksbZ Event Source ,d ls vf/kd izdkj dh Events dks Hkh Generate dj

ldrk gSA

mnkgj.k ds fy, ;fn ge fdlh Button ij Click djrs gSa] rks ,d ActionEvent Object Generate gksrk gSA ActionEvent Class ds Object esa bl Event ds ckjs esa fofHkUu izdkj dh Information Stored jgrh gSaA Event Handler

Event – Handler ,d Method gksrk gS tks Generate gksus okyh Event dks le>rk gS vkSj mls Process djus esa l{ke gksrk gSA Event Handler Method ,d Event izdkj ds Object dks Parameter ds :i esa ysrk gSA

ActionEvent Class esa getSource() uke dk ,d Method gksrk gSA ;s Method ml Component dk Reference Return djrk gS] ftlus Event Generate fd;k gSA ;kuh fdlh Application Window ij fLFkr ,d Command Button dks Click djus ij tks Click Event Generate gksrk gS] ml Click Event dks Generate djus okys Command Button dks getSource() Method Refer djrk gSA import java.awt.*; import java.applet.*; public class DrawStringAppletWithEvent extends Applet { TextField textBox = new TextField(50); public void init() { add(textBox); } public void paint(Graphics firstString) { firstString.drawString("Enter String in Text Box ", 6, 50); String strOfTextBox = textBox.getText();

}

firstString.drawString("String in Text Box is ", 6, 100); firstString.drawString(strOfTextBox, 30, 120);

87 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

public boolean action(Event evnt, Object obj) { repaint(); return true; }

Output:

bl Program esa geus Applet Class dks Derive djds DrawStringAppletWithEvent uke dh ,d Class cukbZ gS vkSj blesa Applet Class ds lHkh Attributes o Functionality dks Inherit fd;k gSA fQj geus TextField Class dk ,d Object textBox Create fd;k gS vkSj mldh Size 50 Define dh gSA ;kuh ge Text Box esa ,d le; esa 50 v{kj ns[k ldrs gSaA Create gksus okyk ;s Object vHkh Memory esa gh Create gqvk gSA ge bls rc rd Applet ij ugha ns[k ldrs gSa] tc rd fd ge bls Applet ij Add uk djsaA Applet ij bl textBox Object dks Add djus ds fy, Applet Class ds init() Method dks Override djds Create fd, x, textBox Object dks Add() Method }kjk Applet ij Add fd;k x;k gSA blds ckn Applet Class ds paint() Method dks Override djds ,d Message “Enter String in Text Box” dks Applet ij Display fd;k gSA fQj String Class dk ,d Object strOfTextBox Create fd;k gS vkSj TextField Class ds ,d getText() Method dks Call djds textBox Object esa Type fd, x, Texts dks bl strOfTextBox Object esa Hold fd;k x;k gSA fQj drawString() Method dk iz;ksx djds textBox esa Type dh xbZ String dks T;ksa dk R;ksa Applet ij Display djok fn;k x;k gSA bl Program esa geus action uke ds Event Method dks Override fd;k gS vkSj bl Method esa repaint() Method dks Call fd;k gSA bl Applet Program dks Compile djds Run djus ij gesa Applet Window esa ,d Text Box fn[kkbZ nsrk gSA bl Text Box esa tks dqN Hkh Type djds ge Enter Key Press djrs gSa] gesa og lc dqN Applet ij fn[kkbZ nsus yxrk gSA bldk dkj.k ;s gS fd tc Hkh ge Text Box esa dqN fy[krs gSa vkSj Enter Key Press djrs gSa] rks ,d action Event Generate gksrk gSA bl action Event ds Generate gksrs gh] bl Event dks Handle djus ds fy, Applet esa action uke dk ,d Method fy[kk x;k gSA bl Method esa repaint() Method dks Call fd;k x;k gSA

88 Any Question or Suggestion, Just Discuss Here...

Java in Hindi tSls gh ge Text Box esa dqN Type djds Enter Key Press djrs gSa] action Event Trigger gksrk gSA ;s Event Trigger gksrs gh] action() Method Execute gksrk gS vkSj Applet ds paint() Method dks fQj ls Call djrk gS] ysfdu bl ckj Text Box esa tks Texts fy[kk tkrk gS] og Text Applet ij fn[kkbZ nsus yxrk gSA

89 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Java Fundamentals The Core Concepts

90 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Java Fundamentals – Core Concepts

lHkh Programming Languages esa ;fn dksbZ pht Common gksrh gS rks og ;gh gS fd lHkh Programming Languages esa Develop fd, tkus okys Programs esa Data dks Input fd;k tkrk gS vkSj mu ij Required Processing Perform djds Output Generate fd;k tkrk gSA pwafd fdlh Hkh Computer Program esa lcls Important pht Data gh gksrh gS] blfy, gj Computer Program esa blh ckr dk /;ku j[kk tkrk gS fd Data dks fofHkUu rjhdksa ls Store fd;k tk,] rkfd mu ij fofHkUu izdkj dh Processing dks Apply djds fofHkUu izdkj ds Results Generate fd, tk ldsaA Data Memory esa fdl izdkj ls Store gksaxs vkSj fdl izdkj ls mu ij Processing dks Apply fd;k tk,xk] bl ckr dk Track j[kus ds fy, Programs esa Constants o Variables dk iz;ksx fd;k tkrk gSA

Constants

fdlh Hkh Computer Program esa ge fofHkUu izdkj ds ekuksa dks Computer esa Store djrs gSa] mUgsa Manage djrs gSa] mu ij Required Processing Apply djrs gSa vkSj muds ifj.kke dks Output esa izkIr djrs gSaA ;fn ge Real World esa ns[ksa rks nks rjg ds eku gksrs gSaA ,d eku os gksrs gSa ftUgsa dHkh Change ugha fd;k tkrk gSA tSls fd lky esa dqy 12 eghus gksrs gSaA eghuksa dh la[;k fuf”pr gSA dHkh Hkh fdlh Hkh lky esa 11 ;k 13 eghus ugha gks ldrsA blh rjg ls gj eghus dk ,d fuf”pr uke gksrk gSA gj Week esa lkr fnu gksrs gSaA gj fnu dk ,d fuf”pr uke gksrk gSA blh rjg ls PI dk eku 22/7 gksrk gSA ge le> ldrs gSa fd ,slh gh gtkjksa phtsa gSa] ftuds eku gesa”kk fuf”pr gksrs gSaA tks eku gesa”kk fuf”pr gksrs gSa] mu ekuksa dks Constants dgk tkrk gSA blh rjg ls fdlh Computer Program esa Use fd;k x;k og eku tks iwjs Program esa Change ugha gksrk gS] Constant dgykrk gSA ge fdlh Hkh Data dks eku ;k ekuksa ds ,d lewg ds :i esa eku ldrs gSaA ;kuh fdlh Hkh rF; dks Computer Program esa Represent djus ds fy, gesa ml rF; dks fdlh uk fdlh eku ds :i esa ifjHkkf’kr djuk gksrk gSA Computer esa ekuksa dks ;k rks Texts ds :i esa Represent fd;k tkrk gS ;k fQj fdlh vad ds :i esaA mnkgj.k ds fy, ;fn gesa lky ds dqy fnuksa dks Computer esa Store djuk gks rks ge vad 12 dks mi;ksx esa ysrs gSa] tks fd ,d la[;k gSA tcfd ;fn gesa fdlh eghus ds uke ekuk “January” dks Computer esa Store djuk gks rks ge Characters ds lewg dk iz;kssx djrs gSaA bl mnkgj.k ds vk/kkj ij ge dg ldrs gSa fd fdlh Hkh Real World eku dks Computer esa ;k rks fdlh vad ;k vadksa ds lewg ds :i esa Define fd;k tkrk gS ;k fdlh Character ;k Character ds lewg ds :i esaA fofHkUu vad ;k vadksa ds lewg dks ge Numeral Constants dg ldrs gSa vkSj fofHkUu Characters o Characters ds lewg dks Character ;k String Constants dg ldrs gSaA

91 Any Question or Suggestion, Just Discuss Here...

Java in Hindi mnkgj.k ds fy, eku yks fd gesa 100 :i;s dk 6.0 izfr”kr C;kt Kkr djuk gSA ;s Calculation ge fuEukuqlkj dj ldrs gSa% Interest = 100 * 6.0 / 100

bl Line esa Numerical eku 100 o 6.0 fLFkr eku gSa] blfy, bUgsa Constant dgk tkrk gSA ekuyks fd gesa fdlh Program esa bl Calculation dks dbZ ckj Perform djuk iMrk gSA bl fLFkfr esa ge bl Statement dks iwjs Program esa dbZ ckj fy[k ldrs gSaA ysfdu FkksMs le; ckn ;fn gesa 6.0 ds ctk; 7.0 izfr”kr C;kt Calculate djus ds fy, blh Program dks Modify djuk iMs] rks geus Program esa ftruh ckj bl Calculation dks Perform fd;k gS] mruh gh ckj vad 6.0 ds LFkku ij 7.0 dks Replace djuk iMsxkA ;fn gekjs Program esa 200 ckj bl Statement dks Use fd; x;k gks rks gesa gekjs Program esa 200 LFkkuksa ij 6.0 ds LFkku ij 7.0 djuk iMsxkA bl izdkj ls fdlh Program dks Modify djus esa dkQh le; yxrk gS vkSj xyfr;ka gksus dh Hkh dkQh lEHkkouk jgrh gSA bl izdkj dh fLFkfr;ksa dks Avoid djus ds fy, Programmers gesa”kk dqN Symbolic Constants dk iz;ksx djrs gSa] tks lkekU;r;k os “kCn gksrs gSa] tks Program esa fdlh eku dks Represent djrs gSaA gekjs bl Statement ds lEca/k esa ns[ksa rks 6.0 dks Represent djus ds fy, ge Percent uke dk ,d Symbolic Content Use dj ldrs gSa] tks Current Percent dks Represent djrk gS vkSj Program dh “kq:vkr esa Percent dks og nj iznku dj nsrs gSa] ftls iwjs Program esa Calculate djuk gSA tkok esa fdlh Constant dks Represent djus ds fy, tks Statement fy[kk tkrk gS] mls Constant Declare djuk dgrs gSa vkSj bls fuEukuqlkj Declare djrs gSa% final float PERCENT = 6.0;

tkok esa final “kCn dk iz;ksx rc fd;k tkrk gS] tc gesa tkok Compiler dks ;s crkuk gksrk gS] fd ge fdlh eku dks iwjs Program esa fLFkj ;k Constant j[kuk pkgrs gSaA float “kCn tkok Compiler dks ;s crkrk gS fd ge ftl Constant eku dks Store djuk pkgrs gSa] og eku ,d Floating Point eku ;k nleyo okyk eku gSA PERCENT “kCn ,d Symbolic Content gSA bl Statement esa = dk fpUg crkrk gS fd = ds Left Side esa tks Word gS og Word ml eku ds cjkcj gS tks = fpUg ds Right Side esa gS tks fd gekjs bl Statement esa 6.0 gSA

;kuh ge fdlh Calculation esa 6.0 fy[ksa ;k PERCENT fy[ksa] nksuksa ls fudyus okyk ifj.kke leku gh izkIr gksxk] D;ksafd nksuksa gh leku eku dks Represent dj jgs gSaA ;kuh ;fn ge pkgsa rks fuEukuqlkj Hkh Interest Kkr djus dk Statement fy[k ldrs gSa% Interest = 100 * PERCENT / 100;

lkekU;r;k Symbolic Constants dks Program ds vU; Codes ls vyx fn[kkus ds fy, Symbolic Constants dks UPPERCASE esa fy[kk tkrk gSA

92 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Variables

Program ds os eku tks iwjs Program esa le;≤ ij vko”;drkuqlkj cnyrs jgrs gSa] Variables dgykrs gSaA Variables dHkh Hkh fdlh fLFkj eku dks Represent djus ds fy, Use ugha fd, tkrs gSaA tc Hkh gesa fdlh Constant dks Program esa Use djuk gksrk gS] rks ml Constant dks Represent djus ds fy, gesa Symbolic Constants dh t:jr gksrh gSA

bu Symbolic Constants dks gh Literal Hkh dgk tkrk gSA loky ;s iSnk gksrk gS fd Program esa Variables dh D;k t:jr gS\ bls le>us ds fy, fiNys Statement dks gh ysrs gSa] tks fd fuEukuqlkj gS% Interest = 100 * PERCENT / 100;

bl Statement esa Interest ,d Variable gSA ;kuh fdlh Calculation ds Result dks Store djus ds fy, gesa gekjs Program esa gesa”kk ,d ,slh Memory dh t:jr gksrh gS] ftlesa fofHkUu izdkj ds cnyrs gq, eku Store gks ldsaA bl Statement }kjk ge dsoy 100 dk gh PERCENT Kkr dj ldrs gSaA ysfdu lkekU;r;k gesa vyx&vyx LFkkuksa ij vyx&vyx izdkj ds ekuksa dk Percent Kkr djuk gksrk gSA ,sls esa gj la[;k dk Percent Kkr djus ds fy, ;fn gesa vyx ls Program cukuk iMs rks ;s ,d cgqr gh vlqfo/kktud ckr gksxhA Program ,slk gksuk pkfg, fd fdlh ,d gh Program ls ,d izdkj ls Perform gksus okyh fofHkUu izdkj dh Calculations dks Perform fd;k tk ldsA ;kuh ge ;fn 100 dh txg 200 dj nsa] rks gesa 200 dk Interest izkIr gks tk,A ;fn ge Program dks Multipurpose cukuk pkgrs gSa] rks gesa 100 dks Hkh fdlh Symbolic rjhds ls Represent djuk gksxkA ;s dke ge fuEukuqlkj Statement }kjk dj ldrs gSa% Principal = 100; Interest = Principal * PERCENT / 100;

ge ns[k ldrs gSa fd ;fn Principal dk eku 100 ls 200 dj fn;k tk, rks Interest uke ds Variable esa gesa Principal 200 dk Interest izkIr gksxkA pwafd ewy/ku 100 ds Symbolic Representative Principal dk eku cny dj 200, 300, 400 vkfn fd;k tk ldrk gS] blfy, Principal Hkh ,d Variable gS vkSj Principal ds Change gksus ls Calculate gksus okys Interest esa Hkh ifjorZu gksrk gS] blfy, Interest Hkh ,d Variable gSA

Naming Constants and Variables – The Identifiers

tks lcls igyh Computer Language Develop dh xbZ Fkh og xf.krKksa ds fy, xf.krh; leL;kvksa dks gy djus ds fy, Develop dh xbZ FkhA bl otg ls fofHkUu Calculations esa Use fd, tkus okys Variables o Calculations dks bl izdkj ls Model fd;k x;k Fkk ftl izdkj ls xf.krK le>rs FksA mnkgj.k ds fy, iqjkus le; esa C;kt Kkr djus ds fy, xf.krK fuEukuqlkj Syntax dk iz;ksx djrs Fks% 93 Any Question or Suggestion, Just Discuss Here...

Java in Hindi a = b * c / 100;

ge bl Statement }kjk ;s irk ugha yxk ldrs gSa] fd ;s Expression fdl dke dks iwjk djus ds fy, fy[kk x;k gSA bl izdkj dh Coding fy[kus ij Programmers dks cgqr lkjk Comment Hkh fy[kuk iMrk Fkk] rkfd ;s Clear gks lds fd Program D;k dke djsxkA ;kuh ge mijksDr Statement dks fcuk mfpr Comment ds ugha le> ldrs gSaA ;fn mijksDr Statement dks fuEukuqlkj fy[kk tk, rks ge cgqr gh vklkuh ls tku ldrs gSa fd ;s Statement D;k dke djus ds fy, fy[kk x;k gS% Interest = Principal * PERCENT / 100;

;fn ge bl rjg ls Variables ds uke pqurs gSa rks ge fcuk fdlh fo”ks’k Commenting ds Hkh vklkuh ls le> ldrs gSa fd Program D;k dke djus ds fy, cuk;k tk jgk gS vkSj Program dk dksbZ Statement D;k dke dj jgk gSA ;kuh Program Lo;a gh Self Commenting cu tkrk gS vkSj Program dk gj Statement Lo;a gh crkrk gS fd dkSulk Statement D;k dke dj jgk gSA bu ukeksa dks Identifiers Hkh dgrs gSa] D;ksafd bu ukeksa dks Use djds gh ge fdlh Program Object dks Identify djrs gSaA cnyrs gq, (Variable) o fLFkj (Constant) ekuksa dks Represent djus ds fy, mfpr ukeksa dks pquus ds lEca/k esa tkok esa dqN fu;e Hkh gSaA ;kuh ge vadksa ;k v{kjksa ds fdlh lewg dks Identifier ds :i esa Use ugha dj ldrs gSaA tkok esa fdlh Identifier dk uke nsus dk igyk fu;e ;s gS fd fdlh Hkh Identifier (Variable ;k Constant) dk uke fdlh Character, $ ;k _ (Underscore) ds fpUg ls gh “kq: gks ldrk gSA Characters Uppercase ;k Lowercase fdlh Hkh rjg ds gks ldrs gSa vkSj ge bu Valid Characters dh vkil esa Mixing Hkh dj ldrs gSaA ;fn gesa fdlh uke esa vad dk iz;ksx djuk gks] rks vadksa dk iz;kssx ge dsoy uke ds ckn esa gh dj ldrs gSaA mnkgj.k ds fy, fdlh fuEu uke Valid gSa% number number2 amount_of_sale $amount salary daysOfWeek monthsOfYear

blh rjg ls vkxs fn, tk jgs uke xyr gSa] D;ksafd ;s uke tkok ds Naming Rules dk iwjh rjg ls ikyu ugha djrs gSa% number# number2* 1amount_of_sale &$amount days Of Week months OfYear10

94 Any Question or Suggestion, Just Discuss Here...

Java in Hindi “Java” Characterset izR;sd Hkk’kk esa fpUgks] vadksa] v{kjksa dk ,d lewg gksrk gSA bu fpUgks] vadksa o v{kjksa dks ,d fo”ks’k Øe esa j[kus ij ,d “kCn curk gS] ftldk fd viuk ,d [kkl vFkZ gksrk gSA tSls j~ $ v $ e~ feydj jke “kCn cukrs gSa ftldk viuk ,d mfpr vFkZ gSA blh rjg ^^tkok** esa Hkh dqN [kkl fpUgks] vadks o v{kjksa dks ekU;rk nh xbZ gS] ftuds feyus ls dqN [kkl vFkZ fudyrs gSaA bu vFkksZa dks okLrfod rkSj ij flQZ dEI;wVj gh le>rk gSA ;s “kCn lewg fuEu fyf[kr gSa] ftudk iz;ksx tkok dk Program fy[kus esa fd;k tkrk gS& 1 2 3 4

Uppercase (A-Z) and Lowercase (a-z) Alphabet 0 to 9 Digits Whitespace Characters (Blank Space, H-Tab, V-Tab, Form Feed, New Line Character, Carriage Return ) Special Characters , Comma ; Semi Colon : Colon ? Question Mark . Dot ' Single Quote " Double Quote | V-Bar $ Dollar Sign # Pound Sign & Ampersand * Asterisk ( Left Parentheses ) Right parentheses [ Left Bracket ] Right Bracket { Left Curly Brace } Right Curly Brace < Less Then Sign > Greater Then Sign Blank = Equal to \ Back Slash / Slash _ Under Score % Percent ~ Tilde ^ Upper Carat + Plus Minus ! Exclamation mark

“Java” Tokens ftl izdkj ls “kCn] fdlh Hkh iSjkxzkQ dh og y?kqRre bdkbZ gksrh gS] ftlesa ,d fo”ks’k vFkZ fo/keku jgrk gS] Bhd blh rjg bl Hkk’kk esa Hkh ,sls gh dqN “kCn] fpUg vkfn gSa] tks Lora= :i ls viuk dqN vFkZ j[krs gSaA ^^tkok** Hkk’kk dh og y?kqRre bdkbZ tks Lora= :i ls viuk dksbZ vFkZ j[krh gS] Vksdu~ dgykrh gSA tc ge fdlh Java Source Program dks Compile djrs gSa] rc Compiler ml Source Program esa Tokens dks Extract djrk gSA Token og Smallest Element gksrk gS ftldk Compiler ds fy, ,d Meaningful vFkZ gksrk gSA ;s Tokens gh Java Program ds Structure dks ifjHkkf’kr djrs gSaA ;kuh ;s r; djrs gSa] fd Java Program ds fofHkUu Statements Java ds fu;eksa ds vuqlkj fy[ks x, gSa vFkok ughaA lHkh Languages esa ;s Tokens gksrs gSa vkSj budh la[;k lHkh Hkk’kkvksa esa lkekU;r;k ikap gh

95 Any Question or Suggestion, Just Discuss Here...

Java in Hindi gksrh gSA ;s ikap Tokens Keywords, Literals, Identifiers, Operators o Separators gksrs gSaA Java Compiler bu Tokens ds vykok Blank Space o Comments dks Hkh igpkurk gSA tc Java Program dks Compile fd;k tkrk gS] rc Java Compiler Java Program esa ls lHkh Comments o Blank Spaces dks Remove djds “ks’k Program esa ls Tokens dks izkIr dj ysrk gSA tks Tokens mls izkIr gksrs gSa] og Compiler mu Tokens dks Computer ds le>us ;ksX; Machine Independent Java Bytecodes esa Convert dj nsrk gSA Keywords ;k Reserve Words ^^tkok** Hkk’kk ds dqN Reserve Words gSaA budk iz;ksx lkekU; :i esa ugha gksrk gS] cfYd ;s dqN [kkl dkeksa esa mi;ksx esa vkrs gSa vkSj budk Compiler ds fy, fo”ks’k vFkZ gksrk gS] ftUgsa le> dj Compiler ml fo”ks’k vFkZ ds vuqlkj dke djrk gSA abstract catch do finally import new short this volatile

assert char double float instanceof package static throw while

Boolean class else for int private strictfp throws

break const enum goto interface protected super transit

byte continue extends if long public switch try

case default final implements native return synchronized void

;s Keywords Java ds fy, Reserve fd, x, gSaA ysfdu bu esa ls dqN Keywords ,sls gSa] ftUgsa Future Use ds fy, Reserve fd;k x;k Fkk ysfdu vHkh rd mi;ksx esa ugha fy;k x;k gSA lEHkor;k Future esa dHkh fdlh t:jr dks iwjk djus ds fy, budk mi;ksx fd;k tk,A blds vykok tkok esa true, false o null dks Hkh Reserve fd;k x;k gSA gkykafd ;s Keywords ugha gSa] ysfdu bu ukeksa dk iz;ksx fdlh Variable, Constant ;k Class ds uke ds :i esa ugha fd;k tk ldrk gSA

Identifiers Identifiers os Token gksrs gSa] tks uke dks Represent djrs gSaA ;s os uke gksrs gSa tks ,d Programmer vius Program ds fofHkUu vo;oksa dh Compiler ls igpku djokus ds fy, mUgsa iznku djrk gSA ;s uke Variables, Methods o Classes dks iznku fd, tkrs gSaA geus Java dk tks igyk Program Create fd;k gS] mldh Class dk uke geus HelloWorld fn;k gS vkSj ml File dk uke HelloWorld.Java fn;k gSA ;s nksuksa os uke gSa] ftUgsa Compiler igpkurk gSA ;s uke Compiler ds fy, Identifiers gSaA lHkh izdkj dh Hkk’kkvksa esa pkgs og Real World Language gks ;k dksbZ Computer Language, uke nsus ;k uke j[kus dk ,d fuf”pr fu;e gksrk gSA mnkgj.k ds fy, Real World esa Hkh ge fdlh dk dksbZ ,slk uke ugha j[krs gSa] ftlds mPpkj.k ls xyr vFkZ fudyrk gksA

96 Any Question or Suggestion, Just Discuss Here...

Java in Hindi blh rjg ls Java Language esa Hkh uke nsus ds dqN fu;e gSa vkSj ge bu fu;eksa dh vogsyuk ugha dj ldrs gSaA tkok esa fdlh Identifier (Variable ;k Constant) dks uke nsus ds fu;eksa dks ge fuEukuqlkj Point Wise fy[k ldrs gSa% 1 Java esa fdlh uke dh “kq:vkr Alphabet ds fdlh Hkh Character ls pkgs og Character Lowercase gks ;k Uppercase vkSj Under Score ;k Dollar ds fpUg ls gks ldrh gSA 2 fdlh Identifier ds uke esa 0 ls 9 rd ds vadksa dk Hkh iz;ksx fd;k tk ldrk gS] ysfdu ;s vad uke ds chp esa ;k vUr esa vk ldrs gSaA uke dh “kq:vkr fdlh vad ls ugha gks ldrhA 3 uke esa fdlh Special Symbols tSls fd Blank Space, % dk fpUg ;k fdlh Reserve Word dk iz;ksx ugha fd;k tk ldrk gSA Java esa dqN vU; fu;eksa dk Hkh ikyu fd; tkrk gSA gkykafd ;fn bu fu;eksa dk ikyu uk fd;k tk,] rks Hkh Program iwjh rjg ls dke djrk gS] ysfdu fQj Hkh budk ikyu djuk Bhd jgrk gSA budk ikyu djus ls Program vf/kd ljy o le>us ;ksX; gks tkrk gSA

;fn uke esa nks ls vf/kd “kCnksa dk iz;ksx djuk gks] rks uke dh “kq:vkr Lowercase Letter ls djuh pkfg,A ckdh ds vU; ftrus Hkh Words gSa] muds ukeksa dh “kq:vkr Capital Letter ls djuh pkfg,A tSls totalSellingAmount ,d lgh uke gSA bl uke dks iuk dkQh ljy jgrk gS] tcfd totalsellingamount ;k TOTALSELLINGAMOUNT ,d xyr uke gSA

Literal tSlkfd geus igys Hkh dgk fd dqN phtksa ds eku Real World esa Hkh fLFkj gksrs gSaA tSls lIrkg ds lkr fnuksa ds gj fnu dk ,d fuf”pr uke] lky ds ckjg eghuksa ds gj ekg dk ,d fLFkj ukeA PI dk eku tks fd 3.14 ds yxHkx gksrk gSA ,sls gh gtkjksa mnkgj.k fn, tk ldrs gSaA ftl rjg ls Real World esa dqN eku fLFkj gks ldrs gSa mlh rjg ls fdlh Hkh Computer Hkk’kk esa Hkh dqN ,sls ekuksa dh t:jr iM ldrh gS] ftudk eku iwjs Program esa fLFkj jgsA bl izdkj ds Data dks Computer Language esa Literals dgk tkrk gSA ;s eku Numerical gks ldrs gSa vkSj Non-Numerical Hkh gks ldrs gSa vkSj ekuksa dk ,d lewg Hkh gks ldrk gSA Literals dks Constants Hkh dgrs gSa vkSj bUgsa lkekU;r;k Symbolic Form esa Represent fd;k tkrk gS vkSj bUgsa budh izd`fr ds vk/kkj ij fuEukuqlkj Hkkxksa esa foHkkftr djds le>k tk ldrk gSA

Integer Constant iw.kkZd a la[;k,a Integer dgykrh gSaA ftu la[;kvksa ds eku esa nleyo ugha gksrk gS] os la[;k,a iw.kkZad la[;k,a dgykrh gSaA blesa $ o – fpUg gks ldrs gSaA ftl vad ij dksbZ fpUg u gks og +ve gksrh gSaA tSls 124, 3223, 545, 23 vkfnA bles la[;kvksa ds chp dksek dk iz;ksx ugh fd;k tkrk gSA tSls 1233,33,000 ,d xyr fLFkjkad gSA ;s eq[;r% rhu rjg ds gksrs gS& Decimal Octal Constant

& blesa 0 ls 9 rd dh la[;k, gksrh gSaA & blesa 0 ls 7 rd dh la[;k,a gksrh gSa] o gj la[;k dh “kq:vkr O ls gksrh gSA 97 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Hexadecimal

& blesa 0 ls 9 rd ds vad o A ls F ;k a ls f rd ds v{kj lfEefyr gksrs gSaA bu la[;kvksa dh “kq:vkr geas”kk ox ;k OX ls gksrh gSA

Floating Point Constant ;s os eku gksrs gSa ftuesa n”keyo gksrk gSA ;g okLrfod fLFkjkad (Real Constant) dgykrk gSA bls nkss Hkkxksa esa ckaVk tk ldrk gS& ⇒ Fractional Form:- bl izdkj ds fLFkjkad esa de ls de ,d vad n”keyo ds iwoZ o ,d vad n”keyo ds ckn gksuk pkfg;sA ckdh ds lkjs fu;e Integer Constant dh rjg gh gSaA tSls %& 12122-122] 11-22 vkfn ⇒ Exponent Form :-blds nks Hkkx gksrs gSa& (1) Mantissa o (2) Exponent blesa cMh & cMh la[;kvksa dks ?kkrkad ds :i esa n”kkZ;k tkrk gSA tSls 1200000000 dks ?kkrkad :i esa ge fuEukuqlkj Hkh fy[k ldrs gSaA 1200000000=1.200000000 X 1010 vc 1.2 Mantissa okyk Hkkx gksxk o 1010 Exponent okyk Hkkx gks tk,xkA bl rjg ge fdlh Hkh eku dks ?kkrkad esa Convert djus ds fy;s fuEu lw= dk iz;ksx dj ldrs gSa & Value 1200000000

= =

Mantissa 1.2

e/E +E

Exponent 10

=

1.2+E10

bl rjg ls fdlh Hkh la[;k dk ?kkrkad :i izkIr fd;k tk ldrk gSA ;fn ?kkrkad /kukRed gks rks +e ;k +E vkrk gS vU;Fkk -e ;k -E vkrk gSA

Boolean Constants bu Constants dk iz;ksx true ;k false dks Represent djus ds fy, gksrk gSA Programming esa dbZ LFkkuksa ij ,sls ekuksa dh t:jr iMrh gS] tks fdlh Statement ds lR; ;k vlR; gksus dks Represent djrs gSaA

Character Constant tc fLFkjkad ds :i esa Alphanumeric Characters dk iz;ksx fd;k tkrk gS] rks bls Character Constant dgrs gSaA ;s rhu rjg ds gksrs gSa&  Single Character Constant bls ges”kk Single Quote esa can djrs gSA tSls ‘n’, ‘e’, ‘e’, ‘l’, ‘u’ vkfnA  String Constant bls ges”kk Double Quote esa can djrs gSaA tSls “Madhav“, “Raghav”, “Gopal” vkfn

98 Any Question or Suggestion, Just Discuss Here...

Java in Hindi  Back slash Character Constant ^^tkok** Hkk’kk esa dqN Characters Back Slash ds lkFk iz;ksx dj ldrs gSa] ftudk mi;ksx eupkgk Output izkIr djus esa gksrk gSA ;s Control Characters gksrs gSa tks fuEukuqlkj gSa& ‘\\’ ‘\b’ ‘\f’ ‘\r’ ‘\’’ ‘\\’

‘\’ ‘\udddd ‘\n’ ‘\t’ ‘\”’ ‘\ddd’

Back Slash Backspace Form Feed Carriage Return Single Quote Back Slash

Continuation Unicode Character New Line Horizontal Tab Double Quote Octal Character

igys Computer tc T;knk fodflr ugha Fks rc dsoy English Language esa gh Information dks Store fd;k tkrk FkkA blds fy, dsoy ASCII Character Code dk iz;ksx fd;k tkrk FkkA ;s 8-Bit ij vk/kkfjr Fks blfy, dsoy 128 Characters dks gh Represent dj ldrs FksA mlds ckn tc dbZ Languages esa Data dks Store o Manage djus dh t:jr iMh] rc Unicode dk fodkl fd;k x;kA blesa 16-Bit Code ls Characters dk Representation gksrk gS] blfy, nqfu;k dh yxHkx lHkh Hkk’kkvksa ds fy, blesa Code miyC/k gksrs gSaA mnkgj.k ds fy, Unicode ‘\u0048’ Character ‘H’ dk Hexadecimal Representation gS tks fd Octal esa ‘\110’ ds leku gSA

Variables chtxf.kr esa fdlh leL;k dk lek/kku izkIr djus ds fy, geus Equations esa dbZ ckj x o y dk iz;ksx fd;k gSA fdlh Equation esa ;s x o y fdlh eku dks Represent djrs gSaA bUgsa pj (Variable) dgk tkrk gS] D;ksafd budk eku Equation esa le;≤ ij cnyrk jgrk gSA mnkgj.k ds fy, fuEu Equation nsf[k,& X = Y + 10

bl Equation esa X dk eku Y ds eku ds cnyus ds lkFk cnyrk jgrk gSA ;fn Y = 1 gks rks X = 11 gks tk,xkA ;fn Y = 20 gks rks X dk eku 30 gks tk,xkA ;kuh X ,d pj (Variable) gS ftldk eku fdlh vU; pj Y ds eku ij fuHkZj gSA ftl izdkj ls Y dk eku cnyrk gS mlh rjg ls X dk eku Hkh cnyrk jgrk gSA dbZ ckj dbZ Equations esa dqN ekuksa dks fLFkj dj fn;k tkrk gSA bu fLFkj ekuksa dks vpj eku (Constants) dgrs gSa] D;ksafd budk eku iwjs Equation esa dgha ij Hkh ugha cnyrk gSA tSls ekuyks fd% pi = 3.14 X = 2 * pi * R

bl Equation esa Hkh ge ns[k ldrs gSa fd bl pj (Variable) X dk eku R ij fuHkZj gSA ;fn R dk eku cnyk tk, rks X dk eku Hkh cny tkrk gS] tcfd R dk eku cnyus ij Hkh pi ds eku esa fdlh izdkj dk dksbZ ifjorZu ugha gksrk gSA blfy, ge dg ldrs gSa fd R o X pj (Variable) eku (Data) dks Represent dj jgs gSa tcfd pi ,d vpj (Constant) eku (Data) dks Represent dj jgk gSA

99 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Computer esa fdlh Hkh eku (Data) ds lkFk fdlh Hkh izdkj dh izfØ;k rHkh dh tk ldrh gS] tc og Data Memory esa Stored gksA Computer esa ekuksa dks Store djus ds fy, Computer Memory Location dk iz;ksx djrk gSA

pwafd Java esa ge Directly fdlh Hkh Memory Location dks Access ugha dj ldrs gSa] blfy, gesa fdlh Memory Location dks dksbZ uke nsuk gksrk gSA bl uke }kjk gh Compiler fdlh Specific Memory Location dks Identify dj ikrk gSA ;s uke ,d Identifier gksrk gS tks Programmer Lo;a viuh bPNkuqlkj r; djrk gSA lkFk gh ge fdl izdkj ds eku dks Computer dh Memory esa Store djuk pkgrs gSa] ml eku ds izdkj ;kuh Data Type dks Hkh Compiler dks crkuk iMrk gSA Compiler ml Data Type ds vuqlkj Memory esa dqN Space Reserve dj ysrk gS vkSj ml Space dks Identify djus ds fy, ml Reserve fd, x, Memory Block dk ,d uke j[k nsrk gSA ;s uke ogh uke gksrk gS] tks Programmer r; djrk gSA

Operators fdlh Hkh izksxzkfeax Hkk’kk esa Mathematical o Logical Calculations djus ds fy;s dEI;wVj dks funsZf”kr djus okys fpUgksa dks Operators dgrs gSaA ;s ftu Elements ds lkFk fØ;k djrs gSa] mUgs bu Operators dk Operand dgrs gSaA Operators nks rjg ds gksrs gSa& Unary Operator ftl Operator dks dke djus ds fy;s flQZ ,d Operand dh vko”;drk gks mls Unary Operator dgrs gSaA tSls - ,d Unary Operator gSA ftl fdlh Hkh la[;k ds lkFk - fpUg yxk fn;k tkrk gS] ml la[;k dk eku cny tkrk gSA tSls 6 ds lkFk - fpUg yxk nsus ls la[;k -6 gks tkrh gSA Unary Operators fuEu gksrs gSaA & * + ~ + !

Address Operator Indirection Operator Unary Plus Unary Minus Bit wise Operator Unary Increment Operator Decrement Operator Logical Operator

Binary Operators ftu Operators dks dke djus ds fy;s nks Operands dh t:jr gksrh gS] mUgsa Binary Operators dgrs gSaA tSls 2 $ 3 dks tksMus ds fy;s nks Operands dh t:jr gksrh gS] vr% Plus ,d Binary Operator Hkh gSA ^^lh** ds Binary Operators dks Category ds vuqlkj fuEu Hkkxksa esa ckaVk x;k gS& A Arithmetic Operators

100 Any Question or Suggestion, Just Discuss Here...

Java in Hindi budk mi;ksx xf.kr ds la[;kRed ekuksa dh x.kuk djus ds fy;s gksrk gSA ;s dqy ikap gksrs gSa& $ & * / %

nks Operands dks tksMus esa mi;ksx gksrk gSA igys Operand esa ls nwljs dks ?kVkus ds fy;s mi;ksx gksrk gSA nks Operands dks vkil esa xq.kk djus ds fy;s mi;ksx gksrk gSA HkkxQy izkIr djus ds fy;s mi;ksx gksrk gSA Hkkx ds ckn cpus okys “ks’kQy dks izkIr djus ds fy;s mi;ksx gksrk gSA

tSls% 4+2=6

4–2=2

4*2=8

4/2=2

2%4=0

ftl rjg ls ge Integer o Float izdkj ds ekuksa dks bu Operators dk iz;ksx djds tksM ldrs gSa] mlh rjg ls ge Strings ( Characters ds ,d lewg ) dks Hkh vkil esa tksM ldrs gSaA tSls & “Bal” “5” “30”

+ + +

“Gopal” “20” “Madhav”

= = =

“BalGopal” “520” “30Madhav”

Java esa Modules Operator dk iz;ksx Floating Point Values ij Hkh mlh izdkj ls fd;k tk ldrk gS] ftl izdkj ls Integer izdkj ds ekuksa ij fd;k tkrk gSA ;kuh X = 49 Y = 50.20 A = X % 10 = 9 (Resultant Reminder Value of A) B = Y % 10 = 0.20 (Resultant Reminder Value of B)

Relational Operators tc izksxzke esa nks ekuksa dh vkil esa rqyuk djuh gksrh gS] rc Relational Operators dk iz;ksx fd;k tkrk gSA budk iz;ksx fdlh izksxzke esa djus ij ;fn dFku lR; gksrk gS] rks izksxzke true Return djrk gS vU;Fkk false Return djrk gSA Relational Operators fuEu gSa& Operator Equal to Not Equal to Less then Greater then Less then or Equal to Greater then or Equal to

Mathematical Symbol = < > < >

“Java” Symbol == != < > =

101 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Logical Operators tc nks ;k nks ls vf/kd Conditions ds lkFk izfØ;k djds ifj.kke izkIr djuk gksrk gS] rc Logical Operators dk mi;ksx fd;k tkrk gSA ;s Java esa eq[;r% nks gksrs gSa& 1

2

AND (&&) - tc nksuksa Conditions lR; gksa rks izksxzke true Return djrk gS] vU;Fkk false Return gksrk gSA OR ( || ) - tc nks esa ls dksbZ Hkh ,d Condition lR; gks rks true Return djrk gS] vU;Fkk false Return gksrk gSA

true Return gksus dk eryc gS fd Condition lR; gSA Condition lR; gksus dh fLFkfr esa dqN [kkl Statements dk Execution gksuk gksrk gSA

Assignment Operators tc gesa izksxzke esa fdlh osfj;scy dks fdlh izdkj dh x.kuk ls izkIr gksus okyk eku iznku djuk gks] ;k dksbZ fLFkj eku iznku djuk gks] rks bls ge Assignment Operators }kjk iznku djrs gSaA Assignment Operator eq[;r% ,d gh gS ysfdu bls fofHkUu :iksa esa iz;ksx dj ldrs gSaSA tks fuEukuqlkj gS& Operator = += -= *= /= %=

Declaration Assignment Assigning Sum Assigning Difference Assigning Product Assigning Dividend Assigning Reminder

Example A = 10 A += 10 A -= 10 A *= 10 A /= 10 A %= 10

Explanation A = 10 A = A + 10 A = A – 10 A = A *10 A = A / 10 A = A % 10

Increment and Decrement Operators tc ges fdlh osfj;scy esa Øe ls ,d tksMuk ;k ?kVkuk gks] rks ge Increment ( ++ ) ;k Decrement ( - - ) Operators dk iz;ksx djrs gSaA osfj;scy ds lkFk budh fn”kk cny nsus ls buds LoHkko esa ifjorZu vk tkrk gSA budk iz;ksx Looping Statements esa fd;k tkrk gS] tgka Øe ls fdlh Calculation dks rc rd djrs jguk gksrk gS] tc rd fd Condition vlR; uk gks tk,A fuEu mnkgj.k ns[ksa if sum = 10 ++sum = 11 sum++ =11 --sum = 9 sum-- = 9

1 + 10 = 11 10 + 1 = 11 -1 + 10 = 9 10 – 1 = 9

Conditional Operators ;g if . . . else Conditional Statement dk laf{kIr :i gSA bldk Syntax ? : :i dk gksrk gSA ;kuh blesa nks Operand gksrs gSaA ;fn Condition True gksrh gS rks igyk Statement

102 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Execute gksrk gS ;k igys osfj;scy dk eku Output esa izkIr gksrk gSA ;fn igyh Condition lR; ugha gksrh gS rks nwljs osfj;scy dk eku Return gksrk gSA bls ,d mnkgj.k ls le>s rks &

ekuk a = 2, b = 3, x = 4 vc ;fn ge pkgrs gSa fd Data Input ds le; y = x gks] rks a dk eku z esa Store gks tk, vU;Fkk b dk eku z esa Store gks tk, rks ;s dke ge fuEukuqlkj Statements fy[kdj dj ldrs gSa& if ( x = = y ) z = a; else z = b;

bls Conditional Operator }kjk fy[kus ij fuEukuqlkj fy[k ldrs gSa%

;kuh ;fn “krZ lR; gksxh rks z = a gks tk,xk vU;Fkk z = b gks tk,xkA Bitwise Operators bu Operator dk mi;ksx fcV dks tkapus vkSj Bit dks nk;sa ls ck;sa ;k ck;sa ls nk;sa f[kldkus ds fy;s gksrk gSA bl Operator dk mi;ksx lh/ks gh dEI;wVj dh Bits ij dke djus ds fy;s gksrk gSA bl Operator dk iz;ksx gesa”kk Integer izdkj ds Data Type ds lkFk gh gksrk gSA bls vPNh rjg rHkh le>k tk ldrk gS tc izksxzfeax dk Bhd&Bhd Kku gks tk,A blfy;s bls vkxs le>k;k tk,xkA bldk iz;ksx rc fd;k tkrk gS tc fdlh osfj;scy esa LVksj eku dks cnyuk gksrk gSA ;s Operators fuEukuqlkj gSa& & | ^ ~

AND OR Exclusive OR Ones Compliment

Shift Operators Computer dh Memory esa lHkh Data Binary Format esa Store gksrs gSa] ftlesa gj Bit dk eku ;k rks 1 ;k fQj 0 gksrk gSA ekuyks fd ge 0 ls 4 rd dh la[;k dks Memory esa Store djsa] rks os la[;k,a fuEukuqlkj Store gksaxh& Decimal Number 0 1

Binary Equivalent

0000000000000000 0000000000000001

103 Any Question or Suggestion, Just Discuss Here...

Java in Hindi 2 3 4

0000000000000010 0000000000000011 0000000000000100

Shift Operators os Operators gksrs gSa tks lh/ks gh Data ds Bits ij dke djrs gSa vkSj Data ds Bits dks Left ;k Right esa Shift djrs gSa ftlls Data ds eku esa ifjorZu gks tkrk gSA ge Shift Operators dk iz;ksx dsoy Integer izdkj ds ekuksa ij gh dj ldrs gSaA ;s Operators fuEukuqlkj gSa& > >>>

SHIFT LEFT SHIFT RIGHT UNSIGNED SHIFT

;fn ge ekuysa fd Memory esa eku 1 Stored gS vkSj ge bl ij Left Shift Operator dk iz;ksx djsa rks ge ;s dke fuEukuqlkj dj ldrs gSa& ( 1 3 ) = ( 0000000000010000 >> 0000000000000010 )

=

2

;fn gesa la[;k 16 dk fpUg cnyuk gks rks ge bl ij Negation dk iz;ksx djds blds lkjs Bits dks mYVk djrs gSaA ;kuh ~ (16) = ~( 0000000000010000 ) = (1111111111111101 ) =

-16

Punctuation dqN Special Symbols dk iz;ksx izksxzke esa “kCnksa o okD;ksa dks vyx djus ds fy;s fd;k tkrk gSA bUgs Punctuation ;k Separator Hkh dgrs gSaSA [] {} ( ) , ; : .

Array dh Size Define djus esa mi;ksx gksrk gSA lHkh Functions ds Executables Code bUgh dks’Bdks ds chp fy[ks tkrs gSaA ;s fpUg crkrk gS fd Use gks jgk Statement ,d Function gSA bls Separator dh rjg Use djrs gSaA gj Executable Statement dk vUr Semi Colon ls gh gksrk gSA Label Statement esa Use gksrk gSA Class ls Package o Sub-Packages dks Separate djus ds fy, bldk iz;ksx

fd;k tkrk gSA

104 Any Question or Suggestion, Just Discuss Here...

Java in Hindi new Operator bl Operator dk iz;ksx fdlh Class dk u;k Instance ;k Object Create djds mls Memory iznku djus dk dke djrk gSA bls le>us ls igys gesa Class dks le>uk t:jh gksrk gS] rHkh bldk iz;ksx Bhd ls le> esa vkrk gSA

Precedence Of Operators ^^lh** Hkk’kk esa gj Operator dk ,d izkFkfedrk dk Øe gksrk gSA ftlls x.kukvksa esa gksus okyh ijs”kkfu;ka lekIr gks tkrh gSaA tSls fuEu Expression ns[ksa %& 11 + 23+20/6 – 4 = 5 11 + 23+20/6 – 4 = 27 11 + 23+20/6 – 4 = 33.333

bl rjg ls ftl ifj.kke dh gesa t:jr gS] og dkSulk gS] ;s irk yxkuk cgqr gh eqf”dy gks tk,xk D;ksafd rhuksa gh eku lgh gSaA ,sls esa ,d ,sls Øe dh vko”;drk gqbZ] ftlls ;g irk py lds fd igys dkSulh x.kuk gksxh o ckn esa dkSulh] rkfd gesa izkIr gksus okyk eku ogh gks tks ge pkgrs gSaA ^^tkok** esa bl izdkj dh ijs”kkuh ls cpus ds fy;s Operators dks ,d izkFkfedrk Øe esa O;ofLFkr fd;k x;kA blesa x.kuk, blh Øe esa gksrh gSaA tks Operator izkFkfedrk Øe esa igys vkrk gS] mlds Operands dh x.kuk igys gksrh gS vkSj tks Operator izkFkfedrk Øe esa ckn esa vkrk gS] mlds Operands dh x.kuk ckn esa gksrh gSA ;s izkFkfedrk Øe Lkkj.kh fuEukuqlkj gS& Category Highest Precedence Unary

Multiplication Additive Shift Relational

Equality Bit wise AND

Operator ( ) [ ] . + ~ ! ++ -* / % + > >>> < = > == != &

Operations Function Call Array Subscript Dot Operator Unary Plus Unary Minus Bit wise 1st complement Logical Negation Increment Decrement Multiply Divide Reminder Binary Plus Binary Minus Shift Left Shift Right Unsigned Shift Less Than Less Than of equal to Greater Than or Equal to Greater Than Equal To Not Equal To Bit wise AND

Precedence 1 2

Associatively Left To Right Right To

3 4 5

Left Left To Right Left To Right Left To Right

6

Left To Right

7

Left To Right L to R

8

105 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Bit wise XOR Bit wise OR Logical AND Logical OR Conditional Assignment

^ | && || ?: = *= /= %= += -= &= ^= |= > ,

Comma

Bit wise XOR Bit wise OR Logical AND Logical OR Ternary Operator Simple Assignment Assign Product Assign Quotient Assign Reminder Assign Sum Assign Difference Assign Bit wise AND Assign Bit wise XOR Assign Bit wise OR Assign Left Shift Assign Right Shift Evaluate

9 10 11 12 13 14

L to R L to R L to R L to R L to R R TO L

15

L to R

Data Types

Real World esa Hkh Data (eku ;k ekuksa dk lewg [Value or a Set of Values]) dbZ izdkj ds gksrs gSaA tSls fdlh O;fDr dh mez dks ge la[;k ds :i esa fn[kkrs gSa tcfd ml O;fDr ds uke dks Characters ds lewg ds :i esa ifjHkkf’kr djrs gSaA

tkok esa fofHkUu izdkj ds Data dks Represent djus ds fy, eq[; :i ls nks rjg ds Data Type cuk, x, gS]a ftUgsa Øe”k% Primary (Standard) Data Type o Secondary (Abstract or Derived) Data Type dgk tkrk gSA Primitive Data Type Standard Data Type gksrs gSa] tcfd Derived ;k Abstract Data Type Primitive Data Type ij vk/kkfjr gksrs gSaA ^^tkok** ds fofHkUu Data Types dks ge

fuEukuqlkj foHkkftr dj ldrs gSa%

Data Type fdlh Hkh Programming Language dk ,d Fundamental Concept gksrk gSA Data Type dk iz;ksx djds ,d Programmer Compiler dks ;s crkrk gS fd mls fdl izdkj ds eku dks Store djuk gSA Compiler Programmer }kjk r; fd, x, Data Type ds vk/kkj

ij nks dke djrk gSA

106 Any Question or Suggestion, Just Discuss Here...

Java in Hindi 1 Compiler Data Type ds vuqlkj Memory Reserve djrk gSA 2 ml Reserved Memory dks ,d uke nsrk gSA ftl rjg ls Real World esa NksVh pht dks j[kus ds fy, de txg dh t:jr gksrh gS vkSj cMh pht dks Store djus ds fy, vf/kd txg dh] mlh rjg ls Computer esa Hkh gksrk gSA ;fn Computer esa NksVs eku dks Store djuk gks] rks de Memory dh t:jr gksrh gS vkSj ;fn cMs eku dks Store djuk gks rks vf/kd Memory dh t:jr gksrh gSA bl rF; dks ,d mnkgj.k ls le>us dh dksf”k”k djrs gSaA ge tkurs gSa fd Computer esa ,d

Character Store djus ds fy, ,d Byte dh Memory dh t:jr gksrh gSA

;kuh ;fn fdlh Student dk uke 10 v{kjksa dk gks rks ml Student ds uke dks Memory esa Store djus ds fy, 10 Bytes dh t:jr gksxh tcfd ;fn fdlh Student dk uke 15 v{kjksa dk gks] rks 15 Bytes dh Memory dh t:jr gksxhA blh izdkj ls ;fn fdlh Student dh Age Computer esa Store djuh gks rks gesa de Memory dh t:jr gksxhA tcfd ;fn gesa fdlh ns”k dh dqy tula[;k dks Computer esa Store djuk gks rks gesa Age dks Store gksus ds fy, Age }kjk yh tkus okyh Memory dh rqyuk esa dkQh vf/kd Memory dh t:jr gksxh] D;ksafd Practically fdlh Hkh ns”k dh tula[;k de ls de gksxh rks Hkh djksMksa esa gksxhA ;kuh ;fn ge lkjka”k esa dgsa rks vyx&vyx izdkj (Data Type) ds ekuksa dks Memory esa Store djus ds fy, vyx&vyx Memory Size dh t:jr gksrh gSA

Identifier (Variable / Constant) Declaration tc gesa Computer esa fdlh eku ;k Data ij fdlh izdkj dh izfØ;k ;k Processing djuh gksrh gS] rc lcls igys gesa ml Data dks Computer dh Memory esa Store djuk iMrk gSA Computer dh Memory esa fdlh Data dks Store djus ds fy, Java esa fofHkUu izdkj ds Keywords r; fd, x, gSaA bu Keywords }kjk Compiler ;s r; djrk gS fd User dks fdl izdkj ds eku dks Store djus ds fy, Memory pkfg,A User ftl Data Type ds Keyword dk iz;ksx djrk gS] Compiler ml Keyword dh Size ds vuqlkj Memory Reserve dj ysrk gSA ysfdu vHkh Hkh ,d leL;k jgrh gS vkSj oks leL;k ;s gS fd Compiler tks Memory Reserve djrk gS] ml Memory ij ekuksa (Data) dks Hkstus ds fy, vkSj fdlh Processing esa mu Memory Locations ls Data dks okil izkIr djus ds fy, Programmer dks ,d uke dh t:jr gksrh gS] rkfd og Compiler dks ;s crk lds fd og fdl Memory Location ds eku dks Access djuk pkgrk gSA

blfy, Data Type dks Represent djus okys Keyword ds lkFk Programmer dks ,d uke Hkh nsuk gksrk gSA bl uke dks gh Variable ;k Constant dgrs gSaA Computer esa fdlh eku dks Store djus ds fy, Compiler dks nks ckrsa crkuh iMrh gSA igyh ;s fd Programmer fdl izdkj dk eku Memory esa Store djuk pkgrk gSA bl igyh ckr dks crkus ds fy, Programmer vko”;drkuqlkj fdlh Keyword dk iz;ksx djrk gSA

107 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl Keyword ds vk/kkj ij Compiler Memory Reserve djrk gSA Compiler dks nwljh ckr ;s crkuh gksrh gS fd Programmer ml Reserve dh xbZ Memory dks fdl uke ls Access djsxkA blds fy, Programmer Data Type ds Keyword ds lkFk ,d uke Hkh r; djrk gS vkSj Compiler ml Reserve dh xbZ Memory dks og uke iznku dj nsrk gS tks Programmer r; djrk gSA ,d Programmer tc Compiler dks ;s tkudkjh nsrk gS fd og fdl izdkj ds eku dks Memory esa Store djuk pkgrk gS vkSj Compiler }kjk Reserve dh tkus okyh ml Memory dks fdl uke ls Access djuk pkgrk gS] rks bl iwjh izfØ;k dks Identifier Declaration dgrs gSaA dksbZ Identifier Declare djus ds fy, Programmer dks fuEu Syntax ds vuqlkj Java dh Source File esa viuk Code fy[krk gS& Identifier Declaration Syntax :

Data_Type Identifier_Name

;fn gesa ,d gh le; esa ,d gh Syntax }kjk ,d gh Data Type ds ,d ls vf/kd Identifiers Create djus gksa ;k Declare djus gksa rks gesa fuEu Syntax Use djuk iMrk gS& Identifier Declaration Syntax : Data_Type Identifier_Name_1, Identifier_Name_2, , . . . , Identifier_Name_n, Variable o Constants nksuksa gh izdkj ds Identifiers dks Declare djus dk rjhdk ,d tSlk gh gksrk gSA vUrj dsoy buesa Store fd, tkus okys Data dks Store djus ds rjhds dk gksrk gSA tc fdlh Identifier dks Declare djrs gh mls ,d fuf”pr eku iznku dj fn;k tkrk gS vkSj Programmer ml eku dks iwjs Program esa Change djuk ugha pkgrk gS] rks Declare fd, x, ml Identifier dks Constant dgk tkrk gSA tcfd ;fn Identifier dks Declare djus ds ckn Programmer mlesa ,d Permanent eku Initialize ugha djrk gS] rks ml Identifier dks Variable dgk tkrk gSA

Value Initialization tc Programmer fdlh Identifier dks Declare djrk gS vkSj Declaration ds lkFk gh mlesa dksbZ izkjfEHkd eku iznku dj nsrk gS] rks bl izfØ;k dks Identifier Initialization dgrs gSaA lkekU;r;k yxHkx lHkh Languages Identifiers dks Initialize fd;k tkrk gSA dqN High Level Languages ,slh Hkh gksrh gSa] ftuesa ;fn Identifier dks Declare djrs gh mls Initialize uk fd;k tk,] rks Hkh mu Languages dk Compiler mu Identifiers esa Default eku Initialize dj nsrk gSA Java Hkh ,d ,slh gh Language gSA ;fn ge blds fdlh Identifier dks Create djds mls dksbZ eku Initialize uk djsa] rks Hkh Java Lo;a mlds Identifiers dks muds Data Type ds vuqlkj Initialize dj nsrk gSA dbZ Hkk’kkvksa esa ;s lqfo/kk ugha gksrh gSA ftu Hkk’kkvksa esa ;s lqfo/kk ugha gksrh gS] mu Hkk’kkvksa esa ;fn fdlh Identifier dks Create djus ds ckn mls Initialize uk fd;k tk,] rks muesa Garbage Values Stored jgrh gSaA ;s Garbage Values dHkh&dHkh Program esa dkQh tfVy Errors Generate dj nsrh gSa] ftuls Program dks Debug djuk dkQh dfBu gks tkrk gSA

108 Any Question or Suggestion, Just Discuss Here...

Java in Hindi tc ge fdlh Class ds fdlh Method esa Identifier Create djrs gSa] rc mu Identifiers esa ;s Default eku Initialize ugha gksrs gSaA bl fLFkfr esa gesa fdlh Class ds Methods esa ekuksa dks Initialize djuk t:jh gksrk gSA

Garbage Values Computer dh Memory ds gj Memory Location ij gj le; dksbZ uk dksbZ eku Store gksrk jgrk gSA fofHkUu Program ds fofHkUu izdkj ds Data Memory esa gj Location ij Store gksrs jgrs gSaA fdlh Program dks Terminate djus ds ckn Hkh mu LFkkuksa ij ,sls eku Store jgrs gSa] ftudk dksbZ eryc ugha gksrk gSA bu ekuksa dks Garbage Values dgk tkrk gSA Java ds fofHkUu Data Types dks ge eq[;r% nks Hkkxksa esa ckaV ldrs gSa % igys Hkkx dks Simple Data Type dg ldrs gSaA ;s Java ds eq[; Data Types gksrs gSaA bUgsa fdlh Hkh vU; Data Type ls Derive ugha fd;k x;k gksrk gSA bl Data Type dks eq[; :i ls pkj vU; Data Types Integer, Floating-Point, Boolean and Characters esa foHkkftr fd;k tk ldrk

gSA

nwljs Hkkx dks Composite Data Type dgrs gSa vkSj ;s iwjh rjg ls Simple Data Types ij vk/kkfjr gSaA ;kuh ;s Primary Data Type ds gh Modified :i gSaA Array, String, Class vkSj Interface (Methods) blds eq[; Hkkx gSaA Integer Data Types tc gesa fdlh leL;k ds ,sls Data dks Computer esa Store djuk gksrk gS] tks iwjh rjg ls iw.kkZad ysfdu fpUg okys (Signed) eku gksrs gSa] rc ge bl Class ds Data Type dk iz;ksx djds Identifiers Declare djrs gSaA bl Class ds Data Type dks Hkh ge pkj vU; SubClasses byte, short, int o long esa foHkkftr dj ldrs gSaA ;s pkjksa Data Types vyx&vyx Size dh Memory Reserve djrs gSaA budh Size fuEukuqlkj gksrh gS% Data Type Byte Short Int Long

Size 8 bits 16 bits 32 bits 64 bits

Integer Data Types of JAVA

Range -128 to +128 (-27 to +27-1) -32768 to +32767 (-215 to +215-1) (-231 to +231-1) (-263 to +263-1)

byte, short, int o long ;s pkjksa Java Keywords gSaA pwafd ;fn Computer esa Store fd;k tkus okyk eku cgqr gh NksVk gks] rks ge byte Data Type dk iz;ksx djrs gSaA tSls fd gesa Student dh Age dks Computer esa Store djuk gSA

pwafd ge lHkh tkurs gSa fd T;knkrj bUlkuksa dh mez dh vf/kdre lhek 100–125 lky rd gh gks ikrh gSA blfy, mez dks Computer esa Store djus ds fy, ge byte Data Type dk iz;ksx dj ldrs gSaA fdlh Student dh mez dks Computer esa Store djus ds fy, ge fuEukuqlkj Identifier Create dj ldrs gSa% byte age;

109 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ;fn gesa Computer esa fdlh Employee dh Salary Store djuh gks] rks ge Salary Store djus ds fy, fuEukuqlkj short izdkj dk Variable Create dj ldrs gSa% short salary;

pwafd ;fn fdlh Company esa Employees dh Salary ;fn 32767 rd gks] rks ge short Data Type dk iz;ksx dj ldrs gSaA ysfdu ;fn fdlh Company esa Employees dh Salary blls vf/kd gks rks ge Salary Store djus ds fy, fuEukuqlkj int izdkj dk Variable Declare dj ldrs gSa%

int salary;

dbZ ckj gesa dkQh cMh la[;kvksa dh x.kuk djus dh t:jr iMrh gSA mnkgj.k ds fy, ;fn gesa fdlh ns”k dh dqy tula[;k dks Computer esa Store djuk gks] rks gesa cgqr cMh la[;k dks Store djus dh t:jr iMrh gSA bl t:jr dks byte, short ;k int izdkj ds Data Type }kjk iwjk ugha fd;k tk ldrkA blfy, bl fLFkfr esa gesa long izdkj dk Variable Declare djuk gksrk gSA ;s Data Type rc Use fd;k tkrk gS tc cgqr cMs eku dks Computer esa Store djuk gksrk gSA bl Data Type dk Variable ge fuEukuqlkj Declare dj ldrs gSa% long population;

Floating – Point Data Types tc gesa Computer esa ,sls ekuksa dks Store djuk gksrk gS] ftuesa nleyo gks] rks ,slh la[;kvksa dks Computer esa Store djus ds fy, gesa Floating Point Data Type ds Variables Create djus iMrs gSaA bl izdkj ds Data dks Hkh nks Hkkxksa float o double esa foHkkftr fd;k tk ldrk gSA float izdkj dk Data Memory esa 32 Bits ;k 4 Bytes dh Space ysrk gS tcfd double izdkj dk Data Memory esa 64 Bits ;k 8 Bytes dh Space ysrk gSA tc gesa ,sls eku Computer esa Store djus gksrs gSa tks NksVs rks gksrs gSa ysfdu nleyo okys gksrs gSa rc ge float izdkj dk Variable Declare djrs gSa ysfdu tc cMs ekuksa dks Computer esa Store djuk gks] rc double izdkj ds Variables Declare djus iMrs gSaA float temperature; double speedOfLight;

tkok esa tc Initialize Hkh dk Hkh iz;ksx dk Declare

fdlh Floating Point Variable dks Create fd;k tkrk gS vkSj lkFk gh mls fd;k tkrk gS] rks Initialize fd, tkus okys eku ds lkFk gesa f ;k F Character djuk t:jh gksrk gSA D;ksafd tkok esa nleyo okys lHkh ekuksa dks double izdkj djuk gksrk gSA

ysfdu pwafd double izdkj dk Variable Memory esa 8 Bytes dh Space ysrk gS] blfy, ;fn gesa fdlh NksVs nleyo okys eku dks Computer esa Store djuk gks] rks ge float izdkj dk

110 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Variable Create dj ldrs gSaA ysfdu lkFk gh ;fn mls Initialize Hkh djuk gks rks ;s dke gesa fuEukuqlkj djuk gksrk gS% float temperature = 95.45F; float pi =3.1428f ;

;fn ge bl rjg ls eku ds lkFk f ;k F dk iz;ksx ugha djrs gSa] rks Compiler gesa fuEu Error nsrk gS] tks fd ;s crkrk gS fd Variable dks double izdkj dk Declare fd;k tkuk pkfg,] rkfd Variable esa Stored Data dk fdlh izdkj ls Loss uk gksA [Name of the main Class ].java:5: possible loss of precision found : double required: float float firstNumber = 5787.54; ^

Boolean Data Type Real World esa Hkh ge ns[krs gSa fd dbZ lokyksa ds tokc dsoy gka ;k uk esa fn, tkrs gSaA tSls fd dejsa dk cYc pkyw gS ;k ugha] Computer ij Internet pyrk gS ;k ugha] rqe cktkj x, Fks ;k ugha] vkfnA blh izdkj ls Computer esa Hkh gesa dbZ ckj bl izdkj ds ekuksa dks Store djuk iMrk gS tks dsoy gka ;k uk vFkok lR; ;k vlR; dks gh Represent djrs gSaA bl izdkj ds ekuksa dks Computer esa Store djus ds fy, ge Boolean Data Type dk Identifier Create djrs gSaA ;s Data Type Memory esa dsoy ,d Bit dh Space ysrk gSA ;fn Bit dk eku 1 gksrk gS rks mlesa true Store gksrk gS vkSj ;fn Bit dk eku 0 gks rks mlesa false Stored jgrk gSA Java esa 0 ;k 1 Store djus ds ctk; ge lh/ks gh true ;k false Store dj ldrs gSaA ,d Boolean Variable Declare djus ds fy, ge boolean Keyword dk iz;ksx djrs gSaA bl Data Type dk Variable Hkh mlh vU; lkekU; Variables dh rjg gh Declare fd;k tkrk

gSA tSls

boolean isGameOver;

Character Data Type dbZ ckj gesa Computer esa dsoy ,d gh Unicode Character Store djuk gksrk gSA dsoy ,d Character dks Computer esa Store djus ds fy, ge Java ds char Keyword dk iz;ksx djds Identifier Create djrs gSaA pwafd Unicode Characters 16 Bit ds gksrs gSa] blfy, char Data Type ,d 16 Bit Unsigned Value ds :i esa Character dks Store djrk gSA ge Character izdkj dk Variable fuEukuqlkj Create dj ldrs gSa& char firstInitial, middleInitial, lastInitial;

vHkh rd geus bl v/;k; esa tks dqN Hkh ikus dh dksf”k”k djrs gSaA fiNys v/;k; esa geus ,d String dks Output esa Print djus dk Program ns[kk gSA pfy,] blh rjg dk ,d vkSj mnkgj.k Program ns[krs gSaA

111 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Example

,d Program cukvks ftlesa vius ?kj dk Address Output esa Print gksuk pkfg,A Name of File = HomeAddress.java public class HomeAddress { public static void main(String args []) { System.out.println(“Bedal Road ”); System.out.println(“Behind of Vidhya Jyoti School ”); System.out.println(“Dist. Pali Falna Station “); } } Output Bedal Road Behind of Vidhya Jyoti School Dist. Pali Falna Station

bl Program esa ge ns[k ldrs gSa fd gesa tks Hkh Statement Output esa Print djuk gksrk gS] og Statement System.out.println() ds dks’Bd esa fy[krs gSaA pwafd ge ;gka ij Characters dk ,d lewg] ftls String dgrs gSa] Output esa Print djuk pkgrs gSaA blfy, geus ml String dks Double Quote ds vUnj fy[kk gSA println() Method out Object dk ,d Method gSA out Object Computer ds Console dks Represent djrk gSA ge tks dqN Hkh bl Object esa Hkst nsrs gSa] og lcdqN Screen ij Print gks tkrk gSA tSlkfd geus igys dgk fd println() out Object dk ,d Method gS] ftls out Object ds fy, Call fd;k tkrk gSA Java Programming esa ftl fdlh Statement ds ckn ( ) dk iz;ksx fd;k tkrk gS] og dksbZ uk dksbZ Method gksrk gS vkSj fdlh dke dks iwjk djrk gSA println() Method ds dks’Bd esa geus ,d String dks fy[kk gS tks fd Output esa Screen ij Print gks tkrk gSA ;s String println() Method dk Argument dgykrk gSA tc bl Program dks Compile fd;k tkrk gS] rc Java dk Compiler lcls igys ml uke dh Class dks [kkstrk gS] tks uke File dk uke gksrk gSA D;ksafd mlh Class esa main() Method gksrk gS vkSj Compiler gesa”kk main() Method dks gh lcls igys Compile djuk “kq: djrk gSA main() Method dks geus public Declare fd;k gSA ,slk blfy, fd;k gS rkfd ;s Method Command Prompt ls Access fd;k tk ldsA ;fn ;s Method public uk fd;k tk,] rks Program dks Run ugha fd;k tk ldrk gSA void Keyword dk iz;ksx blfy, fd;k gS] D;ksafd main() Method dHkh ,slk dksbZ eku Return ugha djrk gS] ftls dksbZ vU; Method Use dj ldsA static Keyword dk iz;ksx blfy, fd;k gS] rkfd main() Method ds eku esa fdlh izdkj dk dksbZ ifjorZu Command Prompt ls uk fd;k tk ldsA

112 Any Question or Suggestion, Just Discuss Here...

Java in Hindi main() Method esa Argument ds :i esa String args[] fy[kk x;k gSA args ,d String dk Array gSA Array ds ckjs esa ge vkxs i ldrs gSa fd Table ds izFke Row izFke Column dk eku Index Number [0][0] ij Store gksrk gSA Table ds nwljs Row ds nwljs Column dk eku Index Number [1][1] ij Store gksrk gSA ;kuh ;fn ge pkgsa rks mijksDr Table ds fofHkUu ekuksa dks fuEukuqlkj Statement }kjk Memory esa Store dj ldrs gSa& Table[0][0] = 10 ; Table[0][1] = 20 ; Table[0][2] = 30 ; Table[1][0] = 50 ; Table[1][1] = 46 ; Table[1][2] = 20 ; Table[2][0] = 2 ; Table[2][1] = 12 ;

126 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Table[2][2] = 30 ; Table[3][0] = 93 ; Table[3][1] = 39 ; Table[3][2] = 3 ;

;fn ge bls Program ds :i esa n”kkZuk pkgsa rks fuEukuqlkj n”kkZ ldrs gSa& Program public class Table { public static void main(String args[]) { int table[][] = new int[4][3]; table[0][0] = 10 ; table[0][1] = 20 ; table[0][2] = 30 ; table[1][0] = 50 ; table[1][1] = 46 ; table[1][2] = 20 ; table[2][0] = 2 ; table[2][1] = 12 ; table[2][2] = 30 ; table[3][0] = 93 ; table[3][1] = 39 ; table[3][2] = 3 ;

}

}

System.out.println("Value in Array at Index Number [0][0] = " +table[0][0]); System.out.println("Value in Array at Index Number [0][1] = " +table[0][1]); System.out.println("Value in Array at Index Number [0][2] = " +table[0][2]); System.out.println("Value in Array at Index Number [1][0] = " +table[1][0]); System.out.println("Value in Array at Index Number [1][1] = " +table[1][1]); System.out.println("Value in Array at Index Number [1][2] = " +table[1][2]); System.out.println("Value in Array at Index Number [2][0] = " +table[2][0]); System.out.println("Value in Array at Index Number [2][1] = " +table[2][1]); System.out.println("Value in Array at Index Number [2][2] = " +table[2][2]); System.out.println("Value in Array at Index Number [3][0] = " +table[3][0]); System.out.println("Value in Array at Index Number [3][1] = " +table[3][1]); System.out.println("Value in Array at Index Number [3][2] = " +table[3][2]);

Output Value in Array at Index Number [0][0] = 10 Value in Array at Index Number [0][1] = 20 Value in Array at Index Number [0][2] = 30 Value in Array at Index Number [1][0] = 50 Value in Array at Index Number [1][1] = 46 Value in Array at Index Number [1][2] = 20

127 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Value in Array at Index Number [2][0] = 2 Value in Array at Index Number [2][1] = 12 Value in Array at Index Number [2][2] = 30 Value in Array at Index Number [3][0] = 93 Value in Array at Index Number [3][1] = 39 Value in Array at Index Number [3][2] = 3

blh rjg ls ;fn ge pkgsa rks Multi-D Array Hkh Create dj ldrs gSa vkSj mlds fofHkUu Index Numbers ij fofHkUu Data Items dks Store dj ldrs gSaA ;fn ge fdlh 2-D Array dks Create djrs le; gh mls Initialize djuk pkgsa] rks ;s dke ge fuEukuqlkj dj ldrs gSa& int table[][] = {{1,2,3},{4,5,6},{7,8,9},{12,21,12}};

;fn ge pkgsa] rks mijksDr Program dks fuEukuqlkj Modify dj ldrs gSa& Program public class Table1{ public static void main(String args[]){ int table[][] = {{1,2,3},{4,5,6},{7,8,9},{12,21,12}}; System.out.println("Value in Array at Index Number [0][0] = " +table[0][0]); System.out.println("Value in Array at Index Number [0][1] = " +table[0][1]); System.out.println("Value in Array at Index Number [0][2] = " +table[0][2]); System.out.println("Value in Array at Index Number [1][0] = " +table[1][0]); System.out.println("Value in Array at Index Number [1][1] = " +table[1][1]); System.out.println("Value in Array at Index Number [1][2] = " +table[1][2]); System.out.println("Value in Array at Index Number [2][0] = " +table[2][0]); System.out.println("Value in Array at Index Number [2][1] = " +table[2][1]); System.out.println("Value in Array at Index Number [2][2] = " +table[2][2]); System.out.println("Value in Array at Index Number [3][0] = " +table[3][0]); System.out.println("Value in Array at Index Number [3][1] = " +table[3][1]); System.out.println("Value in Array at Index Number [3][2] = " +table[3][2]); } } Output Value in Array at Index Number [0][0] = 1 Value in Array at Index Number [0][1] = 2 Value in Array at Index Number [0][2] = 3 Value in Array at Index Number [1][0] = 4 Value in Array at Index Number [1][1] = 5 Value in Array at Index Number [1][2] = 6 Value in Array at Index Number [2][0] = 7 Value in Array at Index Number [2][1] = 8 Value in Array at Index Number [2][2] = 9 Value in Array at Index Number [3][0] = 12 Value in Array at Index Number [3][1] = 21 Value in Array at Index Number [3][2] = 12

128 Any Question or Suggestion, Just Discuss Here...

Java in Hindi T;knkrj gesa 2-D Array dh gh t:jr iMrh gSA Multi-D Array dh t:jr gh ugha gksrh gSA fQj Hkh ;fn Multi-D Array dh t:jr iMs rks mls Hkh blh izdkj ls Create o Initialize fd;k tkrk gSA fdlh Hkh Array dh Size gesa”kk length uke ds ,d Object esa Store gksrh gSA ;fn gesa fdlh Array X[ ] dh Size irk uk gks] rks ge bl Array X[ ] dh Size dks fuEukuqlkj Kkr dj ldrs gSa& int sizeOfArray = X.length

;s Statement sizeOfArray uke ds Integer izdkj ds Variable esa X uke ds Array dh dqy Size dks Store dj nsrk gSA tkok ,d Multi Dimensional Array dks “Array of Arrays” dh rjg Treat djrk gSA ;kuh fdlh 2-D Array dks ge fuEukuqlkj Hkh Declare dj ldrs gSa& int info[][] = new int [3][]; info[0] = new int[2]; info[1] = new int[5]; info[2] = new int[3];

bl izdkj dk Declaration fuEukuqlkj Variable Size dk 2-D Array Create djrk gS&

Strings

Character izdkj ds Data Type dk Variable Memory esa dsoy ,d Character dks gh Store dj ldrk gSA “C” o “C++” esa Hkh char Data Type dsoy ,d gh Character dks Store djrk gSA ;fn gesa fdlh Student dk uke Computer esa Store djuk gks] rks “C” o “C++” esa Characters dk ,d Array cukuk iMrk gS] tcfd Java esa ,slk djus dh t:jr

ugha gSA

ge String izdkj ds Data Type dk iz;ksx djds ,d Variable Create dj ldrs gSa vkSj bl Variable }kjk fdlh Student ds uke dks Computer esa Store dj ldrs gSaA gkykafd Java esa Strings (Characters ds ,d iwjs lewg) dks Store djus ds fy, dksbZ Hkh Primary Data Type ugha gS] ysfdu Java esa Strings dks Computer esa Store djus ds fy, Java ds ,d String Class ds Object ds :i esa gesa Variable Declare djuk iMrk gS vkSj bl String Class (Data Type) ds Object (Variable) ds vUnj ge fdlh String dks Store dj ldrs gSaA tSls% String nameOfStudent;

129 Any Question or Suggestion, Just Discuss Here...

Java in Hindi String Manipulation dbZ tkok Programs dk lcls Common dke gSA String Characters dh ,d Sequence dks Represent djrk gS] ftls ge ,d 1-D Array ds :i esa fuEukuqlkj Represent dj ldrs gSa& char name[] = new char[4]; name[0] = ‘K’; name[1] = ‘a’; name[2] = ‘w’; name[3] = ‘a’;

gkykafd Character Array gesa ;s lqfo/kk iznku djrk gS fd ge Array ds fofHkUu Characters dks Query djds Array dh Length dk irk yxk ldrs gSaA ysfdu dbZ String Operations ds fy, ;s Characters dk Array gesa i;kZIr lqfo/kk iznku ugha djrk gSA tSls ;fn ,d String dks nwljh String esa Copy djuk gks rks ,d Array ls gj Character dks Read djds nwljs Array esa Øe”k% Write djuk] ,d lqfo/kktud dke ugha gks ldrk gSA blds fy, gesa dkQh Extra dke djuk ;k Coding djuh iMrh gSA bl izdkj dh fLFkfr;ksa ls cpus ds fy, tkok esa String Object dks Use fd;k tkrk gSA tkok esa Strings ,d Class gS ftls nks Classes “String” o “StringBuffer” dks Use djds Implement fd;k tkrk gSA Java String tkok dh String Class dk ,d Instance ;k Object gksrk gS vkSj “C” ds String (1-D Character Array) dh rqyuk esa dkQh Reliable gksrk gSA tkok dh String ,d Null Terminated String ugha gksrh gS uk gh og ,d 1-D Character Array gksrk gSA bl Strings dks fuEukuqlkj Declare o Create fd;k tk ldrk gS% String stringName; stringName = new String(“String”); Array dh rjg gh String dh Hkh Length dks String Class ds length Method }kjk izkIr

fd;k tk ldrk gSA tSls

int m = name.length();

tkok String dks ge + Operator dk iz;ksx djds vkil esa fuEukuqlkj tksM ldrs gSa& String firstName, lastName; String fullName = firstName + lastName String City = “New” + “Maharastra”;

ge Strings dk Hkh mlh izdkj ls Array Create djds Use dj ldrs gSa ftl izdkj ls fdlh Integer izdkj ds Array dks Use djrs gSAa tSls String name = new String[3];

;s Statement name uke ds rhu String Variable Memory esa Create djsxk] ftuds Index Numbers vyx&vyx gksaxs vkSj gj Variable Memory esa ,d String dks Store dj ldsxkA ukeksa dks Memory esa Store djus ds fy, ge for Loop dk iz;ksx dj ldrs gSaA

130 Any Question or Suggestion, Just Discuss Here...

Java in Hindi String Methods String Class esa dbZ Methods dks Define fd;k x;k gS] tks fofHkUu izdkj ds String Manipulation dkeksa dks lEHko cukrs gSaA String Objects o Methods dk iz;ksx GUI Programs esa cgqr gh General :i esa fd;k tkrk gSA lkekU;r;k fdlh GUI Program tSls fd Applet Window esa fLFkr fdlh Text Box esa User tks dqN Hkh Input djrk gS] og lcdqN String ds :i esa gh gksrk gSA ;kuh fdlh Text Box esa User pkgs Texts Input djs ;k Number] Text Box esa User tks Hkh dqN Input djrk gS] og lcdqN String gh gksrk gSA ;gka ij ge dqN String Manipulation Methods dks Describe dj jgs gSa] ftudk iz;ksx fofHkUu izdkj ds String Manipulation Operations dks Perform djus ds fy, fd;k tk ldrk gSA String string1 = new String(“ Rahul ”); String string2 = new String(); string2 = string1.toLowerCase; ;s Statement string1 ds lHkh Characters dks Lowercase Letters esa Convert dj nsrk gSA bldk Output fuEukuqlkj izkIr gksrk gS& “ rahula



string2 = string1.toUpperCase; ;s Statement string1 ds lHkh Characters dks Uppercase Letters esa Convert dj nsrk gSA bldk Output fuEukuqlkj izkIr gksrk gS& “ RAHUL “ string2 = string1.replace(‘a’, ‘i'); ;s Statement string1 esa fLFkr lHkh ‘a’ Characters ds LFkku ij Character ‘i’ dks Replace dj nsrk gSA bldk Output fuEukuqlkj izkIr gksrk gS& “ Rihul “ string2 = string1.trim(); ;s Statement string1 ds igys vkSj ckn esa vk, gq, lHkh White Space Characters dks Remove dj nsrk gSA bldk Output fuEukuqlkj izkIr gksrk gS& “Rihul“

131 Any Question or Suggestion, Just Discuss Here...

Java in Hindi String1.equals(strin2); ;fn nksuksa Strings Objects esa leku String gks rks ;s Statement true Return djrk gSA mnkgj.k ds fy, ;fn string1 = “Rahul” gks vkSj string2 = “Rahul” gks] rks ;s Statement true Return djsxkA String1.equalsIgnoreCase(strin2); ;fn nksuksa Strings Objects esa leku String gks rks ;s Statement true Return djrk gS] tcfd nksuksa String dk Case pkgs vyx gh D;ksa uk gksA mnkgj.k ds fy, ;fn string1 = “Rahul” gks vkSj string2 = “rahul” gks rks Hkh ;s Statement true gh Return djsxkA string1.length(); ;s Statement string1 dh length Return djrk gSA ;fn string = “Rahul” gks rks ;s Statement 5 Return djrk gS] D;ksafd bl String esa ikap Characters gSaA string1.chartAt(n); ;s Statement string1 dh nth Location ds Character dks Return djrk gSA ;kuh ;fn string1 = “Madhav” gks vkSj n = 3 gks rks ;s Statement ‘d’ Return djrk gSA string1.compareTo(string2); ;s Statement ;fn string1 < string2 gks rks Negative Value, ;fn string1 > string2 gks Positive Value vkSj ;fn nksuksa Strings ,d leku gks rks Zero Return djrk gSA string1.concat(string2); ;s Statement string1 dks string2 ls tksM nsrk gSA string1.substring(n); ;s Statement string1 dh n Location ds Character ds lkFk n Location ds Character ls vkxs dh Sub String Return djrk gSA string1.substring(n, m); ;s Statement string1 dh n Location ds Character ds lkFk n Location ds Character ls vkxs vkSj m Location ds Character ls igys rd dh Sub-String Return djrk gSA String.ValueOf(m); ;s Statement Parameter m ds fy, ,d String Object Create djrk gSA m.toString(); ;s Statement Object m dks String Representation esa Convert djds Return djrk

gSA

132 Any Question or Suggestion, Just Discuss Here...

Java in Hindi string1.indexOf(‘b’); ;s Statement String1 ds igys ‘b’ Character ds Index Number dks Return djrk gSA string1.indexOf(‘b’, n); ;s Statement String1 ds n Characters ds ckn igys ‘b’ Character ds Index Number dks Return djrk gSA String.ValueOf(ValueM); ;s Statement Parameter ValueM dks String Representation esa Convert djds Return djrk gSA

buesa ls dqN String Methods dks ge ,d Applet Program esa Use djds mldk Output ns[k ldrs gSaA Applet Program dks fuEukuqlkj Develop fd;k tk ldrk gS% Program // Source File : StringMethodApplet.java // Compiled File: StringMethodApplet.Class // Imports import java.applet.*; import java.awt.*; public class StringMethodApplet extends Applet { TextField textBox = new TextField(40); String str; public void init() { add(textBox); } public void paint(Graphics g) { boolean yes; char characterAtPosition; int strLength; str = textBox.getText(); str = str.toLowerCase(); g.drawString("toLowerCase Method : " + str, 20, 80); str = str.toUpperCase(); 133 Any Question or Suggestion, Just Discuss Here...

Java in Hindi g.drawString("toUpperCase Method : " + str, 20, 60); str = str.trim(); g.drawString("trim Method : " + str, 20, 100); yes = str.equals("Man Mohan"); g.drawString("equals Method : " + yes, 20, 140); yes = str.equalsIgnoreCase("Man Mohan"); g.drawString("equals Method : " + yes, 20, 160); str = str.replace('a', 'i'); g.drawString("replace Method : " + str, 20, 120); strLength = str.length(); g.drawString("length Method : " + strLength, 20, 180); characterAtPosition = str.charAt(4); g.drawString("charAt Method : " + characterAtPosition, 20, 200); strLength = str.compareTo("Man Mohan"); g.drawString("compareTo Method : " + strLength, 20, 220); str = str.concat(" Lal"); g.drawString("concat Method : " + str, 20, 240);

}

}

str = String.valueOf(1000); g.drawString("String.valueOf Method : " + str, 20, 260);

public boolean action(Event evnt, Object obj) { repaint(); return true; }

Output

134 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

GUI esa fdlh Number dks Display djuk gks ;k fdlh Character dks] nksuksa dks gh String Format esa gh Display djuk iMrk gSA fdlh Numerical eku dks Text Format ;k String Format esa Convert fd, fcuk ge mls GUI Application Window ;k fdlh Applet ij Display ugha dj ldrs gSaA

blfy, tc gesa fdlh Applet esa fdlh Numerical eku dks Display djuk gksrk gS] rc ml eku dks Display djus ls igys gesa ml eku dks String Object esa Convert djuk t:jh gksrk gSA fdlh Numerical eku dks String Object esa Convert djus ds fy, gesa String Class ds valueOf() Method dk iz;ksx djuk iMrk gS vkSj ftl eku dks String esa Convert djuk gksrk gS] ml eku dks Argument ds :i esa valueOf() Method ds Parenthesis esa nsuk gksrk gSA fiNys Program esa eku 1000 dks geus blh rjhds ls Applet ij Display fd;k gSA blh rjg ls compareTo() String Method dk iz;ksx djds ge Strings ds Array dh Sorting dj ldrs gSaA Program class StringSorting { static String name[] = { "Madhav", "Krishna", "Kanhaiya", "Balgopal", "Nandlal" }; public static void main(String args[])

135 Any Question or Suggestion, Just Discuss Here...

Java in Hindi {

}

int size = name.length; String temp = null; for(int i = 0; i < size; i++) { for(int j = i+1; j < size; j++) { if(name[j].compareTo(name[i]) < 0) { //swap the strings temp = name[i]; name[i] = name[j]; name[j] = temp; } } } for( int i = 0; i java HelloWorld Madhav Raghav Nandlal Madan Gopal

rks args Array ds fofHkUu Elements ds :i esa ;s Objects fuEukuqlkj Store gks tkrs gSa& Madhav Raghav Nandlal Madan Gopal

    

args[0] args[1] args[2] args[3] args[4]

vc ;fn ge args[3] dks Program esa fdlh izdkj ls Use djuk pkgsa] rks args[3] esa vkus okyk eku Command Prompt ls vk,xk] ftls Handle djus ds fy, ge igys ls gh Codlings fy[k ldrs gSaA bl Concept ds vk/kkj ij ge fuEukuqlkj ,d Program Develop dj ldrs gSa% Program class CmdLineParameters { public static void main(String args[]) { int count, i=0; String string; count = args.length; System.out.println("\nNumber of arguments = " +count+ "\n"); while( ijava CmdLineParameters Madhav Mohan Manmohan Madan Nandlal Balgopal Gopal

139 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Output Number of arguments = 7 args[0] : Madhav args[1] : Mohan args[2] : Manmohan args[3] : Madan args[4] : Nandlala args[5] : Balgopal args[6] : Gopal

bl Program esa Command Line Arguments dh dqy la[;k dks Kkr djus ds fy, geusa length Method dks Use fd;k gSA bl Method dk iz;ksx fdlh Hkh Array dh Size Kkr djus ds fy, fd;k tk ldrk gSA tkok ,d Freeform Language gSA ;kuh tkok dk Program fy[krs le; ;s t:jh ugha gksrk gS fd tkok ds gj Line ds Codes dks Indent djds ,d gh Form esa j[kk tk,A tkok dks bl ckr ls dksbZ QdZ ugha iMrk gS fd ge tkok ds Source Codes dks Source File dh fdlh Line esa dgka ls fy[kuk “kq: djrs gSaA gkykafd ,slk djus ls gesa gh Program dks Debug djus esa ijs”kkuh gksrh gSA fuEu Statement dks nsf[k, % System.out.println(“Balgopal Nandlal”);

bl Statement dks ge Source File esa fuEukuqlkj Hkh fy[k ldrs gSa % System.out.println (“Balgopal Nandlal”);

blh rjg ls ;fn ge pkgsa] rks blh Statement dks fuEukuqlkj Hkh fy[k ldrs gSa& System. out. println ( “Balgopal Nandlal” );

Wrapper Classes

geus igys Hkh dgk gS fd tkok ,d Pure Object Oriented Programming Language gSA ;kuh blesa Primary Data Types dks Hkh Objects dh rjg Represent djds fofHkUu izdkj ds dke djus gksrs gSaA gkykafd ge Primary Data Type ds Variables Hkh Create dj ldrs gSa] ysfdu bUgsa fofHkUu izdkj dh Built–In Classes ds lkFk Use djus ds fy, gesa bUgsa Class Type esa Convert djuk iMrk gSA

140 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Conversion ds ckn ;s Class dks Represent djrs gSa] ysfdu buds eku esa dksbZ ifjorZu ugha vkrk gS cfYd budks Basic Data Type ls Class Type esa Convert dj fy;k tkrk gS] rkfd fofHkUu izdkj dh Built–In Classes bUgsa vklkuh ls mi;ksx esa ys ldsa vkSj ge bu ij fofHkUu izdkj dh mu Calculations dks Perform dj ldsa] tks dsoy Class ds Objects ds lkFk gh Perform dh tk ldrh gSaA

lkjka”k esa ge rks ;s dg ldrs gSa fd fofHkUu izdkj ds Basic Data Types dks mudh lEcaf/kr Wrapper Class }kjk Object esa Convert fd;k tkrk gSA rkfd ge Basic Data Types ds ekuksa dks Hkh mudh Class ds Objects ds :i esa mi;ksx esa ys ldsaA fofHkUu izdkj ds Basic Data Types ds ekuksa dks Object esa Convert djus ds fy, Number uke dh ,d Class java.lang uke ds Package esa miyC/k gSA ;s ,d Abstract Class gS ;kuh ge bl Class dk dksbZ Hkh Object Create ugha dj ldrs gSa] cfYd bldh Derived ;k Subclasses ds Objects Create djrs gSaA bl Class ls Derive dh xbZ dqy 6 Classes Byte, Short, Integer, Float, Long, Double gSa] tks Øe”k% byte, short, int, float, long, double Basic Data Types dks Represent djrh gSaA bls ge fuEukuqlkj ,d lkj.kh ds :i esa Represent dj ldrs gSa% Wrapper Class for Converting Simple Types Simple Data Type Boolean Char Double Float Int Long

Corresponding Wrapper Class Boolean Character Double Float Integer Long

tkok dh bu Wrapper Classes esa fofHkUu izdkj ds Basic Data Type o Objects dks Handle djus ds fy, dbZ Unique Methods dks Define fd;k x;k gSA buesa ls dqN t:jh o T;knk mi;ksx esa vkus okys Methods o mUgsa mi;ksx esa ysus dk Description vkxs crk;k tk jgk gSA fdlh Basic Data type ds Variable ;k Constant dks ;fn lEcaf/kr Wrapper Class ds Object esa Convert djuk gks] rc gesa mu lEcaf/kr Wrapper Classes ds Constructors dks Use djuk gksrk gSA ;s dke ge fuEukuqlkj Code Statement }kjk dj ldrs gSa% A. Converting Primary Numbers to Object Numbers Using Constructor Methods Constructor Calling Integer IntVal = new Integer( i ); Float FloatVal = new Float( f ); Double DoubleVal = new Double( d ); Long LongVal = new Long( l );

Performed Conversion Action Conversion from int Data Type to Integer Object Conversion from float Data Type to Float Object Conversion from double Data Type to Double Object Conversion from long Data Type to Long Object

141 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl Table esa i, f, d o l Øe”k% int, float, double o long izdkj ds Basic Data Type ds Variables gSa] ftUgsa muds Corresponding Class ds Object esa Convert fd;k tk jgk gSA ,d ckj fdlh Basic Data Type ds eku dks lEcaf/kr Object esa Convert djus ds fy, fofHkUu izdkj ds Operations Perform djus ds ckn ;fn gesa ml Object dks fQj ls lEcaf/kr Basic Data Type esa Convert djuk gks] rks gesa Wrapper Classes ds fuEu typeValue() Methods dks Call djuk gksrk gS] tgka type ml Type dks Represent djrk gS] ftl Basic Data Type esa Object ds eku dks Convert djuk gSA B. Converting Object Numbers to Basic Numbers Using typeValue() Methods Method Calling int i = IntObj.intValue(); float f = FloatObj.floatValue(); double d = DoubleObj.doubleValue(); long l = LongObj.longValue();

Performed Conversion Action Conversion from Integer Object to int Data Type Conversion from Float Object to float Data Type Conversion from Double Object to double Data Type Conversion from Long Object to long Data Type

dbZ ckj ,slh t:jr gksrh gS fd gekjs ikl Primary Data Type ds Numerical eku gksrs gSa] ysfdu mUgsa ,d String dh rjg Use djuk gksrk gSA fdlh Numerical eku dks String dh rjg Use djus ds fy, gesa ml Numerical eku dks igys String izdkj ds Representation esa Convert djuk gksrk gSA fdlh Basic Data Type ds eku dks String Representation ds :i esa Convert djus ds fy, gesa Wrapper Class ds fuEu Methods dks Use djuk gksrk gS% C. Converting Basic Numbers to Strings Using String() Methods Method Calling str = Integer.toString( i ); str = Float.toString( f ); str = Double.toString( d ); str = Long.toString( l );

Performed Conversion Action Conversion from int Data Type to String Object Conversion from float Data Type to String Object Conversion from double Data Type to String Object Conversion from long Data Type to String Object

blh izdkj ls dbZ ckj gesa ,slh t:jr gksrh gS fd gesa fdlh eku dks nwljs eku ls Calculate djds u;k eku Generate djuk gksrk gS] ysfdu gekjs ikl tks Numerical eku gksrk gS] og String Format esa gksrk gS] ftl ij fdlh Hkh izdkj ds Numerical Operation dks Directly Perform ugha fd;k tk ldrk gSA bl fLFkfr esa igys gesa eku ds String Representation dks Wrapper Class Object Representation esa Convert djuk gksrk gS vkSj mlds ckn ml Object Representation dks Basic Data Type esa Convert djds eku ds lkFk Calculation Perform djuk gksrk gSA String Representation dks Wrapper Object esa Convert djus ds fy, gesa fuEu lkj.kh ds vuqlkj dke djuk gksrk gSA D. Converting String to Numerical Objects Using Static Method ValueOf() Method Calling DoubleObj = Double.valueOf( str ); FloatObj = Float.valueOf( str ); IntObj = Integer.valueOf( str ); LongObj = Long.valueOf( str );

Performed Conversion Action Conversion from String Object to double Data Type Conversion from String Object to float Data Type Conversion from String Object to int Data Type Conversion from String Object to long Data Type 142

Any Question or Suggestion, Just Discuss Here...

Java in Hindi fdlh String Representation dks Numerical Object esa Convert djus ds ckn ml Numerical Representation dks fQj ls Basic Data Type esa Convert fd;k tk ldrk gSA Numerical Strings ekuksa dks Parsing Methods dk iz;ksx djds Directly Primary ;k Basic Data Type ds ekuksa esa Convert fd;k tk ldrk gSA Parsing Methods dsoy nks gh gSa] tks fd fdlh Integer ;k Long izdkj ds String Representation dks Directly Integer ;k Long izdkj ds Basic Data Type dk eku Return dj nsrk gSA E. Converting Numerical Strings to Primary Numbers Using Parsing Method Method Calling int i = Integer.parseInt( str ); long i = Long.parseLong( str );

Performed Conversion Action Conversion from String Object to int Data Type Conversion from String Object to float Data Type

;fn parseInt() o parseLong() Methods esa Pass fd, tkus okys str String Object esa Integer eku ds vykok dksbZ eku gks] rks ;s Methods ,d NumberFormatException Throw djrs gSaA blfy, bUgsa try Block esa Use djuk pkfg, vkSj bl Exception dks Handle djus ds fy, ,d catch Block Hkh fy[kuk pkfg,] vU;Fkk str esa Integer ds vykok dksbZ nwljk eku gksus ij Program Crash ;k Terminate gks tkrk gSA Program // File Name: AdditionApplet.java import java.awt.*; import java.applet.*; public class AdditionApplet extends Applet { TextField textField1; TextField textField2; public void init() { textField1 = new TextField(5); textField2 = new TextField(5); add(textField1); add(textField2); textField1.setText("0"); textField2.setText("0"); } public void paint(Graphics g) { int value1 = 0, value2 = 0, sum = 0; String s ; g.drawString("Type a number in each box.", 10, 20);

143 Any Question or Suggestion, Just Discuss Here...

Java in Hindi try {

s = textField1.getText(); value1 = Integer.parseInt(s); s = textField2.getText(); value2 = Integer.parseInt(s);

} catch(Exception excp) { g.drawString("Enter a Valid Number", 300, 20); } sum = value1 + value2; s = String.valueOf(sum);

}

}

g.drawString("The sum of the values is:", 10, 40); g.drawString(s, 160, 40);

public boolean action(Event event, Object arg) { repaint(); return true; }

144 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Description:

bl Applet Program esa lcls igys geus Applet Window esa nks TextField Objects textField1 o textField2 Create fd, gSaA fQj Applet ds init() Method esa bu nksuksa Text Boxes dks Applet Window esa add Method }kjk Add fd;k gS vkSj muesa Default eku 0 Display fd;k gS] rkfd Applet Window ij Text Boxes Empty fn[kkbZ uk nsaA fQj paint() Method esa Graphics Class dk ,d Object g Create fd;k gS] rkfd Applet ij fofHkUu izdkj ds Text Messages dks Display fd;k tk ldsA paint() Method esa rhu Integer izdkj ds Basic Data Type ds Variables Create fd, gSaA value1 uke ds Variable esa igys Text Box dk eku Store fd;k tkrk gSA value2 uke ds Variable esa nwljs Text Box dk eku Store fd;k tkrk gS vkSj sum uke ds Variable esa bu nksuksa ekuksa ds ;ksx dks Store fd;k tkrk gSA tkok esa ge tc Hkh dksbZ Basic Data Type dk Variable Create djrs gSa] gesa mu Variables dks Initialize djuk t:jh gksrk gSA ;fn ge ,slk ugha djrs gSa] rks tkok dk Compiler Error Generate djrk gS vkSj Program dks Compile ugha gksus nsrk gSA blhfy, value1, value2 o sum uke ds rhuksa Integer Variables dks eku 0 Initialize fd;k x;k gSA pwafd Text Box esa User tks Hkh eku Input djrk gS] og eku String Format esa gksrk gS vkSj gesa bl String izdkj ds eku dks nwljs Text Box esa fn, x, String izdkj ds eku ls tksMuk gS] blfy, lcls igys gesa bu String izdkj ds ekuksa dks Integer izdkj ds ekuksa esa Convert djuk t:jh gksrk gS] rkfd mu ij Arithmetical Operations dks Perform fd;k tk ldsA bl dke dks iwjk djus ds fy, geus String Class dk ,d Object s Create fd;k gS] rkfd Text Boxes ls Return gksus okys String Format ds eku dks Integer Format esa Convert djds value1 o value2 uke ds Variables esa Store fd;k tk ldsA User nksuksa Text Boxes esa ekuksa dks Fill djs] blds fy, Applet Window ij ,d Message “Type a number in each box.” dks Location Number (10, 20) ij Display fd;k x;k gSA blds ckn User tks Hkh eku Applet ij fn[kkbZ nsus okys nksuksa Text Boxes esa Fill djrk gS] mu ekuksa dks izkIr djus ds Statement dks try {} Block esa fy[kk x;k gSA

rkfd ;fn User bu Text Boxes esa Integer ds vykok dqN Hkh Fill djrk gS] rks Throw gksus okys Exception dks blds uhps fn, x, catch() Exception Block esa Catch djds Exception dks Process fd;k tk lds] rkfd Program Crash uk gksA User us igys Text Box esa tks Hkh eku Input fd;k gksrk gS] og eku s uke ds String izdkj ds Object esa Store gks tkrk gSA fQj bl eku dks Integer Wrapper Class ds parseInt() Method esa Pass djds Basic Integer Data Type ds eku esa Convert dj fy;k tkrk gS vkSj ml Integer izdkj ds Basic Data Type esa Converted eku dks value1 uke ds Basic Integer Data Type ds Variable esa Store dj fy;k tkrk gSA blh rjg ls nwljs Text Box okys eku dks Hkh value2 uke ds Basic Integer Data Type ds eku esa Convert djds Store

dj fy;k tkrk gSA

Text Box esa Fill fd, x, eku dks Integer izdkj ds eku esa Convert djus ds fy, fy[ks tkus okys Codes dks geus try{} Block esa blfy, fy[kk gS] D;ksafd User Text Boxes esa tks dqN Hkh

145 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Enter djrk gS] og s uke ds String izdkj ds Object esa Store gksrk gSA fQj tc bl String izdkj ds Object s esa Stored eku dks parseInt() Method }kjk Integer izdkj ds eku esa Convert fd;k tkrk gS] rc ;fn s esa iw.kkZad la[;kvksa ;kuh Integers ds vykok dqN Hkh gksrk gS] rks ;s Method ,d Exception Throw djrk gSA

;fn bl Exception dks Handle uk fd;k tk,] rks Program Crash gks ldrk gSA blfy, bl Exception dks Handle djus ds fy, try {} Block ds Just ckn esa catch() Block Define fd;k x;k gSA bl catch Block esa ,d Message Display djus ds fy, Statement fy[kk x;k gSA tks mlh fLFkfr esa Execute gksrk gS] tc try Block esa dksbZ Error ;k Exception Generate gksrk gSA tSls gh User Text Boxes esa Integer ds vykok dqN Hkh Fill djds Enter Key Press djrk gS] ,d action Event Generate gksrk gS vkSj repaint() Method paint() Method dks Call dj ysrk gSA paint() Method esa gh try...catch Block dks Define fd;k x;k gSA blfy, ;fn User us Text Boxes esa lgh eku ;kuh Integer Input fd;k gS] rc rks Applet ij nksuksa Text Boxes ds ekuksa dk ;ksx fn[kkbZ nsrk gS] vkSj ;fn User us fdlh Hkh Text Box esa Integer ds vykok dqN Hkh Input djds Enter Key dks Press fd;k gS] rks ,d Exception ds dkj.k Applet Window ij ,d Error Message “Enter a Valid Integer Number” fn[kkbZ nsus yxrk gSA bu nksuksa gh fLFkfr;ksa ds Applet dks fp= esa n”kkZ;k x;k gSA tc User lgh eku Input djrk gS] rc nksuksa Text Boxes ds eku value1 o value2 uke ds Variables esa Basic Integer Data Type ds :i esa Store gks tkrs gSaA bu ekuksa dks tksM dj buds ;ksx dks sum uke ds Variable esa Store dj fy;k tkrk gSA pwafd vc gesa sum esa Stored nksuksa Text Boxes ds ekuksa ds ;ksx dks Applet ij Display djuk gS] ysfdu sum ,d Integer izdkj dk Variable gS] ftlds eku dks Directly drawString() Method }kjk Display ugha djok;k tk ldrk gSA ;kuh ge fuEukuqlkj Statement }kjk sum dks Applet ij Draw ugha dj ldrs gSa% g.drawString("The sum of the values is:", 10, 40); g.drawString(sum, 160, 40);

ge ,slk blfy, ugha dj ldrs gSa] D;ksafd drawString() Method dsoy Strings dks gh Applet ij Draw dj ldrk gSA blfy, sum esa fLFkr Basic Integer Data Type ds eku dks igys String izdkj ds Object esa Convert djuk t:jh gSA bl Conversion dks Perform djus ds fy, geus fuEukuqlkj Statement dks Use fd;k gS% sum = value1 + value2; s = String.valueOf(sum);

bl Statement }kjk geus Basic Integer Data Type ds sum esa Stored eku dks String izdkj ds eku esa Convert djds s uke ds String izdkj ds Variable esa Store fd;k gS vkSj fQj fuEu Statement }kj sum ds eku dks Applet ij Display dj fn;k gS% g.drawString("The sum of the values is:", 10, 40); g.drawString(s, 160, 40);

146 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Integer ds ctk; ;fn gesa Float ;k double izdkj ds ekuksa dk ;ksx djuk gks] rks gesa gekjs Program esa dqN Basic ifjorZu djus gksaxsA D;ksafd ge fdlh Hkh Float izdkj ds eku dks tkok esa Directly ugha tksM ldrs gSa vkSj uk gh bUgsa tksMus ds fy, dksbZ Parsing Method gh tkok

esa miyC/k gSaA

bl fLFkfr esa lcls igys gesa Text Boxes ds String izdkj ds eku dks Float izdkj ds Wrapper Object esa Convert djuk gksxkA fQj ml Wrapper Object ds eku dks Basic Float izdkj ds eku esa Convert djuk gksxk vkSj nksuksa Text Boxes ds ekuksa dks bl izdkj ls Basic Float Data Type esa Convert djus ds ckn mUgsa tksMuk gksxkA bl izfØ;k dks ge vxys Applet Program }kjk le> ldrs gSa% Program import java.awt.*; import java.applet.*; public class FloatAdditionApplet extends Applet { TextField textField1; TextField textField2; public void init() { textField1 = new TextField(5); textField2 = new TextField(5); add(textField1); add(textField2); textField1.setText("0"); textField2.setText("0"); } public void paint(Graphics g) { float value1 = 0, value2 = 0, sum = 0; String s ; Float toBasicFloat; g.drawString("Type a number in each box.", 10, 20); try {

}

s = textField1.getText(); toBasicFloat = Float.valueOf(s); value1 = toBasicFloat.floatValue(); s = textField2.getText(); toBasicFloat = Float.valueOf(s); value2 = toBasicFloat.floatValue();

147 Any Question or Suggestion, Just Discuss Here...

Java in Hindi catch(Exception excp) { g.drawString("Enter a Valid Integer Number", 300, 20); } sum = value1 + value2; s = String.valueOf(sum);

}

}

g.drawString("The sum of the values is:", 10, 40); g.drawString(s, 160, 40);

public boolean action(Event event, Object arg) { repaint(); return true; }

Description:

bl Program esa ge ns[k ldrs gSa fd geus Integer ds ctk; bl ckj Float izdkj ds rhu Variables Create fd, gSa vkSj Text Box ds eku dks Hold djus ds fy, String izdkj dk ,d Object s Create fd;k gSA pwafd gesa Wrapper Class Float ds ek/;e ls Text Box ds eku dks Basic Float izdkj ds eku esa Convert djuk gS] blfy, geus toBasicFloat uke dk ,d Wrapper Float Class dk Object Create fd;k gSA ;s Program fiNys Program dh rjg gh gSA geus dsoy blds try {} Block esa gh ifjorZu fd;k gSA

148 Any Question or Suggestion, Just Discuss Here...

Java in Hindi User tks Hkh eku Text Box esa Fill djrk gS] og eku s uke ds String izdkj ds Object esa Store gks tkrk gSA fQj bl Object ds eku dks Float izdkj ds Wrapper Object esa Convert djus ds fy, Float.valueOf(s) Statement }kjk String Object s esa Stored eku dks Float izdkj ds Object esa Convert fd;k tkrk gSA

;s Converted eku Float izdkj ds Object toBasicFloat esa Store gksrk gSA blds ckn bl Float Object esa Stored eku dks Basic Float Data Type esa Convert djus ds fy, Float Object toBasicFloat ds Reference esa floatValue() Method dks Call fd;k tkrk gSA ;s Method ftl Object ds Reference esa Call gksrk gS] ml Object ds eku dks Basic Float Data Type ds eku esa Convert djds Return dj nsrk gS] ftls value1 uke ds Basic Float izdkj ds Variable esa Store dj fy;k tkrk gSA blh rjg ls nwljs Text Box ds eku dks Hkh Basic Float Object esa Convert djds value2 uke ds Basic Float izdkj ds Variable esa Store djds j[k fy;k tkrk gSA blds ckn ;s Program Hkh mlh rjg ls Flow gksrk gS] ftl rjg ls fiNyk Program Flow gksrk gSA ftl rjg ls geus fiNys nks Applet Programs }kjk tksM djus dh Process dk o.kZu fd;k gSA mlh rjg ls fofHkUu izdkj ds Arithmetical Operations dks Perform djus ds fy, Hkh gesa fofHkUu izdkj dh Wrapper Classes dk iz;ksx djds fofHkUu izdkj ds vko”;drkuqlkj Conversions djus gksrs gSaA mijksDr nksuksa Applet Programs dks ge cgqr gh vklkuh ls Application Programs esa Convert dj ldrs gSaA ;fn ge bl Applet dks T;ksa dk R;ksa GUI Application esa Convert djuk pkgsa] rks bls T;ksa dk R;ksa GUI Application esa Convert dj ldrs gSaA ysfdu bl Conversion dks ge vkxs le>saxsA GUI Mode esa User ls Input izkIr djus ds fy, gesa Applet Window ;k Application Window esa GUI Objects tSls fd Text Boxes, Radio Buttons, Command Buttons vkfn dks Create djuk iMrk gSA

ysfdu tc ge Consol Mode Application esa User ls Input izkIr djuk pkgrs gSa] rc gesa dqN vyx Classes dk iz;ksx djuk t:jh gksrk gSA ysfdu Console Mode Applications esa Hkh gesa fofHkUu izdkj dh Arithmetical Calculations dks Perform djus ds fy, Wrapper Classes dk iz;ksx djuk t:jh gksrk gSA Console Mode Application esa fiNys Applet dks Convert djus ds fy, gesa fuEukuqlkj Console Mode Program Develop djuk gksrk gS % Program // File Name: FloatAdditionApplication.java import java.io.*; public class FloatAdditionApplication { public static void main(String arg [])

149 Any Question or Suggestion, Just Discuss Here...

Java in Hindi {

Float value1 = new Float(0); Float value2 = new Float(0); float sum = 0; String s; try {

DataInputStream in = new DataInputStream(System.in); System.out.println("Enter First Value : "); System.out.flush(); s = in.readLine(); value1 = Float.valueOf(s); System.out.println("\nEnter Second Value : "); System.out.flush(); s = in.readLine(); value2 = Float.valueOf(s);

}

}

} catch(Exception excp) { System.out.println("\nYou have not entered a Valid Number"); System.exit(1); } sum = value1.floatValue() + value2.floatValue(); System.out.println("\nThe sum of the values is: " + sum);

Output : When entered valid Value Enter First Value : 20.65 Enter Second Value : 689.5 The sum of the values is: 710.15

Output : When not entered valid Value Enter First Value : 12.55 Enter Second Value : f12.2

150 Any Question or Suggestion, Just Discuss Here...

Java in Hindi You have not entered a Valid Number Description: Console Mode Application esa gesa fofHkUu izdkj ds dke djus ds fy, ftu Basic Classes dh t:jr gksrh gS] os Classes gesa java.io Package }kjk izkIr gksrh gSa] blfy, bl Package dks gesa gekjs Program esa Import djuk t:jh gksrk gSA

pwafd Application Program esa Compiler gesa”kk main() Method dks [kkstrk gS] blfy, bl Program esa geus gekjh Coding dks main() Method esa gh fy[kk gSA main() Method esa geus lcls igys Float Wrapper Class ds nks Objects value1 o value2 dks new Operator dk iz;ksx djds Create fd;k gS] lkFk gh Create gksus okys Object dks eku 0 ls Initialize Hkh fd;k gSA

eku 0 dks geus Float(0) Code }kjk Initialize fd;k gSA ;s Code tkok dk ,d Default Constructor gS] ftls ge Define ugha djrs gSaA tkok esa ;s Default Constructor igys ls gh Defined gSA Constructor ,d ,slk Method gksrk gS] tks ml Class ds Create gksus okys Object dks Initialize djus dk dke djrk gS vkSj fcuk Call fd, gq, Automatically Call gksrk gS] D;ksafd fdlh Hkh Class ds Constructor dk gesa”kk ogh uke gksrk gS] tks mldh Class dk uke gksrk

gSA

pwafd ge Float Wrapper Class dk Object Create dj jgs gSa] blfy, Float() uke dk Constructor Execute gks tkrk gS vkSj Create gksus okys Object dks Initialize dj nsrk gSA blh rjg ls geus sum uke dk ,d Basic Float izdkj dk Variable Hkh Create fd;k gS vkSj String dks Hold djus ds fy, String Class dk ,d Object s Hkh Create fd;k gSA tkok esa System Class fofHkUu izdkj ds Input o Output Devices dks Represent djrk gSA ;kuh tc gesa Monitor ij dqN Display djuk gksrk gS] rc Display fd, tkus okys Matter ;k eku dks System Class ds out Object esa Hkstuk gksrk gS vkSj tc gesa Keyboard ls dksbZ Matter ;k eku Input ds :i esa izkIr djuk gksrk gS] rc gesa System Class ds in Object dks Use djuk gksrk gSA Keyboard dks Represent djus okyh tkok dh Class dk uke DataInputStream gSA ;kuh ;fn gesa Keyboard ls dksbZ eku izkIr djuk gS] rks gesa DataInputStream Class dk ,d Object Create djuk iMrk gS vkSj ml Object esa Keyboard ls vkus okys ekuksa dks Store djuk gksrk gSA

blhfy, geus DataInputStream Class dk in uke dk ,d Object Create fd;k gS vkSj bl Object ds System.in uke dk eku Argument ds :i esa mlds Constructor dks iznku fd;k gS] ftldk eryc ;s gS fd ge bl Object esa Keyboard ls vkus okys ekuksa dks Store djsaxsA fQj vxys Statement esa geus Screen ij izFke eku Input djus ds fy, ,d Message “Enter First Value” iznku fd;k gS vkSj Input Buffer dks Clear djus ds fy, ;kuh ;fn Screen ;k Monitor ds Buffer esa dksbZ Character Stored gks] rks mls lkQ djus ds fy,

151 Any Question or Suggestion, Just Discuss Here...

Java in Hindi System Class ds out Object ds Reference esa System Class ds flush() Method dks Call fd;k gS] rkfd Calculation esa Garbage Value Display uk gksA User Keyboard ls dksbZ Numerical eku Input djs ;k Character Input djs] og tks dqN Hkh Enter djrk gS] og lcdqN String gh gksrk gSA blfy, Keyboard ls vkus okyh String dks Read djus ds fy, in Object ds fy, readLine() Method Keyboard ls Input dh xbZ String dks Return djrk gSA

pwafd Keyboard ls String Read gks jgh gS] blfy, bl String dks Hold djus ds fy, Hkh ,d String Variable dh gh t:jr gksrh gSA vr% geus Keyboard ls Read gksus okyh String dks s uke ds String izdkj ds Object esa Store fd;k gSA fQj bl String dks Float Wrapper Class ds Object esa Convert djus ds fy, Float.valueOf(s); Code dks Use fd;k gSA ;s Conversion Method String esa Stored Numerical eku dks Float Object izdkj ds eku esa Convert djds value1 Object esa Store dj nsrk gSA blh rjg ls nwljs eku dks Hkh Keyboard ls Read djds mls Hkh Float izdkj ds Object value2 esa Store dj nsrk gSA pwafd User ls Input izkIr djus okys Statements dks geus try { } Block esa fy[kk gS] blfy, ;fn User Numerical eku ds ctk; dksbZ Character Input dj nsrk gS] rks try {} Block ,d Exception Throw djrk gSA bl Exception dks catch Block Catch dj ysrk gS vkSj Monitor ij ,d Error Message Display djds Program dks Terminate dj nsrk gSA pwafd value1 o value2 nksuksa gh Float izdkj ds Objects gSa] ftUgsa Basic Float izdkj ds eku esa Convert fd, fcuk tksMk ugha tk ldrk gS] blfy, floatValue() Conversion Methods dks Program ds vfUre Statement }kjk value1 o value2 Float izdkj ds Object ds Reference esa Call djds igys bUgsa Basic Float izdkj ds eku esa Convert fd;k gSA ,slk djus ij ;s Objects Basic Float izdkj ds eku Return djrs gSa] ftUgsa Addition Operator (+) }kjk tksM dj sum uke ds Basic Float izdkj ds Variable esa Store fd;k x;k gS vkSj vUr esa bl Resultant eku dks Output esa Display dj fn;k x;k gSA fiNys lHkh Programs dks ns[k dj ge le> ldrs gSa fd tkok Data Type ds lEca/k esa fdrus Strict rjhds ls dke djrk gSA ;fn ge fdlh Hkh Statement esa mfpr Type Conversion uk djsa] rks tkok gekjs Program dks Compile ugha gksus nsrk gSA blh dkj.k ls tkok dk Program T;knk lqjf{kr o Error Free gksrk gS] D;ksafd ftruh Hkh Errors Generate gksuh gksrh gSa] os lHkh Program ds Compile Time esa gh Generate gks tkrh gSaA blfy, Run Time esa Program iwjh rjg ls lqjf{kr jgrk gSA

Control Statements

vHkh rd geus ftrus Hkh Examples ns[ks gSa] mu lHkh esa ftl Øe esa fofHkUu Statements fy[ks x, gksrs gSa] mlh Øe esa Program dk Execution gksrk gSA ysfdu dbZ ckj fdlh Program esa ,slh fLFkfr;ka iSnk gks tkrh gS] fd Program ds fofHkUu Statements ,d fuf”pr Øe esa Execute gks dj gekjs Required dke dks iwjk ugha dj ikrs gSaA ml fLFkfr esa Program ds Control dks viuk Normal Flow NksM dj fdlh vU; LFkku ls Statements dk Execution djuk iMrk gS] rks dbZ ckj ,slh fLFkfr iSnk gks tkrh gS fd gesa 152 Any Question or Suggestion, Just Discuss Here...

Java in Hindi fdlh ,d gh Statement dks ckj&ckj Execute djuk iMrk gSA bl rjg dh t:jrksa dks iwjk djus ds fy, tkok esa ftu Statements dks Use fd;k tkrk gS] mUgsa Control Statements dgrs gSaA

Program Control ge tkurs gSa fd dksbZ Hkh izksxzke Statements dk ,d leqg gksrk gS] ftUgsa lkekU;r;k ftl Øe esa Source File esa fy[krs gSa] os mlh Øe esa Execute gksrs gSaA fdlh izksxzke esa fy[ks x, Statements dk Execution, ftl Øe esa gksrk gS] ml Øe dks Flow Of Control dgk tkrk gSA dHkh&dHkh gekjs lkeus bl rjg dh fLFkfr;ka gksrh gSa] ftuds dkj.k gesa Statements ds Øe dks Conditions ds vk/kkj ij cnyuk iMrk gS vkSj Condition ds lR; ugha gksus rd fdUgha Statement ds lewg dks ckj&ckj Execute djuk iMrk gSA tkok esa bl izdkj ds dqN Statement miyC/k gSa] ftuesa Condition ds lR; gksus ij ge ml Condition ls lEcaf/kr Statement dk Execution dj ldrs gSa rFkk ;fn Condition lR; ugha gksrh gS rks ge vU; Statement dk Execution djrs gSaA ;s fo”ks’k izdkj ds Statements Control Statements dgykrs gSaA

Types Of Control Statement tkok esa fofHkUu izdkj ds Conditional Statements dks ge eq[;r;k rhu Hkkxksa esa ckaV ldrs gSa% Sequential Statements ftu Statements dk Execution gksus ds ckn Øe ls vxyh iafDr esa fy[ks Statements dk Execution gksrk gS] os Statements Sequential Statement dgykrs gSaA vHkh rd geus tks Hkh Statements Use fd;s gSa] os lHkh Sequential Statements gSaA tSls Assignment Statements, Output Statements vkfnA Program ds bl izdkj ds Flow dks Control dk Normal Flow dgk tkrk gS] D;ksafd bl izdkj ds Execution esa Program Control dk Flow ,d Øe esa pyrk jgrk gS vkSj Program Control dks fdlh vU; Point ij tkus dh t:jr ugha iMrh gSA bl izdkj ds Statements gj main() Method esa gksrs gSa vkSj fdlh Hkh izksxzke esa ;s vo”; gh gksrs gSaA

Conditional Statements izksxzke esa dbZ txg ij fdlh Condition ds vk/kkj ij Control dks vius lkekU; izokg dks NksM dj fdlh fHkUu fcanq ij ls Statement dk Execution djuk iMrk gSA bl izdkj ds p;ukRed Execution ds fy;s iz;qDr Statements dks Conditional Statements ;k Branching Statements dgk tkrk gSA

153 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ;kuh tc fdlh leL;k ds fdlh “krZ ds vuqlkj nks ;k nks ls vf/kd ifj.kke laHkkfor gksrs gSa] rc fdlh fuf”pr ifj.kke ij igqapus ds fy;s izksxzke dks viuk Normal Flow NksM dj fdlh fHkUu fcanq ls Program dks Execute djuk iMrk gSA bl izfØ;k dks izksxzke dh Branching gksuk dgrs gSA goto Statement fcuk Condition dk ,d ,slk Control Statement gS] ftls ge looping o Branching nksuksa :iksa esa iz;ksx dj ldrs gaSA bl izdkj ds Control Statements eq[;r% pkj izdkj ds gksrs gSa&

Iterative Statements tc izksxzke esa dqN Statements dks fdlh Condition ij fuHkZj djrs gq, tc ckj&ckj nksgjkus dh vko”;drk gksrh gS] rks iqujkorhZ ;k Iterative Statements dk iz;ksx fd;k tkrk gSA tkok esa Iterative Statements eq[;r% rhu gksrs gSa&

Compound Statement or Block tc Statement ds ,d lewg dks bdkbZ ds :i esa ysrs gSa] rks mls Block ;k Compound Statement dgrs gSaA ,d Block esa ys dks’Bd esa fy[ks tkrs gSaA ,d Block esa dks’Bd ds vUnj dbZ Definitions, Declarations o Statements dk lewg gks ldrk gSA tSls% {

//Starting of the Block int a; float b; double c;

154 Any Question or Suggestion, Just Discuss Here...

Java in Hindi c = a+b; ………… ………… }

//End of the Block

if statement lHkh Control Statements esa ls if Statement lcls “kfDr”kkyh Statement gS] ftlds }kjk ge Statements ds Execution ds Flow dks Control dj ldrs gSaA ;g ,d f} ekxhZ ( Two Way ) Statement gS] ftlesa Condition ds lR; ;k vlR; gksus ds vk/kkj ij fuHkZj djrs gq, izksxzke dk Control nks vyx&vyx fcanqvksa ij igqap ldrk gSA bl rjg If Statement ds vuqlkj izksxzke ds ikl nks jkLrs gksrs gSa] ,d Condition ds lR; gksus dh fLFkfr esa o nwljk Condition ds vlR; gksus dh fLFkfr esaA tc gesa Condition ds lR; gksus ij dsoy ,d Statement dk Execution djuk gksrk gS] rc ge fuEu izdkj ds Syntax esa if Condition dks Use dj ldrs gSa& if ( Expression and Condition ) Statement 1;

blesa tc if Condition lR; gksxh rc Statement 1 Execute gks tk,xkA tc gesa fdlh Condition ds lR; gksus ij ,d ls vf/kd Statements dk Execution djuk gks] rks gesa lHkh Statements ea>ys dks’Bd esa fy[kus iMrs gSaA ;fn ge ,slk ugha djrs o Åij crk, Syntax ds vuqlkj gh izksxzke fy[k nsrs gSa] rks Condition ds lR; gksus ij Java Compiler igys Statement dk rks Execution dj nsrk gS] ysfdu “ks’k Statements dks Program dh Condition ds vuqlkj Execute ugha djrk cfYd mUgsa Program ds Normal Flow ds vuqlkj Execute djrk gSA bl fLFkfr esa igys Statement dks NksMdj ckdh ds lHkh Statements gesa”kk Execute gksrs gSas pkgs if Condition lR; gks pkgs vlR;A blfy;s ;fn if Condition ds izksxzke esa ,d ls vf/kd Statements dk Execution djuk gks rks gesa fuEu if Syntax Use djuk iMrk gS& if ( Expression and Condition ) { Statement 1; Statement 2; “ “ “ “ “ “ Statement n; } Other Statements

blesa tc Condition lR; gksrh gS] rks Block ds vUnj fy[ks lkjs Statements dk Execution gks tkrk gS] mlds ckn Other Statements dk ;kuh Block ls ckgj ds Statements dk Execution gksrk gSA ysfdu ;fn Condition vlR; gksrh gS] rks izksxzke Control, if Condition ds Block dks NksM dj lh/ks gh Other Statements ;kuh Block ds ckgj ds Statements dk Execution dj nsrk gSA 155 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Condition lR; gks ;k vlR; fQj Hkh Other Statements ;kuh Block ls ckgj ds Statement dk Execution gksrk gS] D;ksafd ;s Statement Sequential Flow esa gSA bl Control Statement ds vk/kkj ij ge fuEukuqlkj ,d Example Program Develop dj

ldrs gSaA

Example

,d ,slk Program cukvks ftlesa nks la[;kvksa esa ls cMh la[;k dks Output esa Print fd;k tk,A Program public class IfControlStatement { public static void main(String args[]) { float firstNumber = 5787.54f; float secondNumber = 8454.12F; float result; if(firstNumber > secondNumber){ System.out.println("firstNumber is Greater than secondNumber "); System.out.println("and secondNumber is Less than firstNumber"); }

}

}

if(secondNumber > firstNumber) { System.out.println("secondNumber is Greater than firstNumber "); System.out.println("and firstNumber is Less than secondNumber "); }

Output secondNumber is Greater than firstNumber and firstNumber is Less than secondNumber

bl Program esa geus float izdkj ds nks ekuksa dh rqyuk dh gSA Program Control tc igys if Statement ij igqaprk gS] rc og firstNumber esa Stored eku dh rqyuk secondNumber esa Stored eku ls djrk gSA pwafd firstNumber esa Stored eku Variable secondNumber esa Stored eku ls NksVk gS] blfy, izFke if Statement false Return djrk gSA tc dksbZ Control Statement false Return djrk gS] rc Program Control ml Control Statement ds Statement Block esa izos”k ugha djrk gSA blfy, gekjs Program esa Program Control izFke if Statement ds Statement Block dks Skip dj nsrk gSA fQj Program Control dks nwljk if Statement feyrk gSA blesa secondNumber Variable dk eku firstNumber Variable ds eku ls NksVk gksus dh otg ls Boolean eku true Return gksrk gSA true Return gksus ij Program Control nwljs if Control Statement ds Statement Block esa izos”k djrk gS vkSj ml Block ds lHkh

156 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Statements dk Execution djrk gSA ifj.kkeLo:i gesa Output esa nwljs if Statement Block esa fy[ks x, Message izkIr gks tkrs gSaA

if – else statement tc gesa nks ;k nks ls vf/kd “krksaZ ds vk/kkj ij dksbZ fu.kZ; ysuk gksrk gS] ;k izksxzke ls dksbZ [kkl dke djokuk gksrk gS] rc ge if - else Statement dk iz;ksx djrs gSaA ;g lk/kkj.kr% if Statement dk foLr`r :i gSA bldk Syntax uhps fn[kk;k x;k gS& if ( Expression and Condition ) { Statement 1; Statement 2; “ “ “ Statement n; } else { Statement 3; Statement 4; “ “ “ Statement m; } Sequential Statement a;

bl Syntax ds vuqlkj tc if Condition lR; gksxh] rks Statement 1, Statement 2, ls Statement n rd dk Execution gksxk vkSj ;fn if Condition vlR; gksxh] rks izksxzke Control, if Statement Block dks NksM nsxk vkSj Default :i ls else Condition dh Statements dk Execution gks tk,xkA bl rjg ls Statement 3, Statement 4 ls Statement m rd dk Execution gksxkA ;fn if Condition lR; gksrh gS] rks else Block ds Statements dk Execution ugha gksrk gSA Input fd;s x, eku ds vk/kkj ij if ;k else Condition dk Execution gksus ds ckn izksxzke Control Sequential Statements dk Execution djrk gSA Sequential Statements dk rks Execution gksrk gh gS] D;ksafd ;s main() Method Block esa fy[ks x, gSa] vkSj Sequential Øe esa gSaA ;fn ge bl Statement dk iz;ksx fiNys Program esa djuk pkgsa] rks fuEukuqlkj dj ldrs gSa& Program public class IfElseControlStatement { public static void main(String args[]) { float firstNumber = 5787.54f; float secondNumber = 8454.12F; float result;

157 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

}

if(firstNumber > secondNumber) { System.out.println("firstNumber is Greater than secondNumber "); System.out.println("and secondNumber is Less than firstNumber"); } else { System.out.println("secondNumber is Greater than firstNumber "); System.out.println("and firstNumber is Less than secondNumber "); }

Output secondNumber is Greater than firstNumber and firstNumber is Less than secondNumber

ge ns[k ldrs gSa fd nksuksa gh Programs dk Output leku gh izkIr gksrk gSA ,slk blfy, gks jgk gS D;ksafd ;s Statement if Statement dk gh foLr`r :i gSA

Nested if else statement tc ,d if Condition ds Statement Block esa ,d vkSj if Condition ;k if else Condition ds Statement Block dk iz;ksx fd;k tkrk gS] rks bls if Condition dh Nesting djuk dgrs gSaA ge fofHkUu if Conditions dh vko”;drk ds vuqlkj Nesting dj ldrs gSa] ;kuh ge ,d if Condition ds Statement Block esa nwljk if ;k if else Condition dk Statement Block, nwljs esa rhljk if ;k if else Condition dk Statement Block, rhljs esa pkSFkk vkfn fdruh Hkh la[;k esa if Condition Statements Blocks dh Nesting dj ldrs gSaA bldk Syntax fuEukuqlkj gksrk gS& if ( Expression and Condition 1 ) { if ( Expression and Condition 2 ) { Statement 1; Statement 2; “ “ “ Statement l; } else { Statement 3; Statement 4; “ “ “ Statement m; }

158 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Inner Sequential Statement n; } else { Statement 5; Statement 6; “ “ “ Statement o; } Outer Sequential Statement a;

bl Syntax esa ;g crk;k x;k gS] fd ;fn izFke if Condition lR; gksrh gS] rks izksxzke Control izFke if Condition ds Statement Block esa tk,xkA ogka izksxzke Control dks nwljh if Condition feysxhA ;fn ;s nwljh if Condition Hkh lR; gS] rks izksxzke Control, Inner if Condition Statement Block esa tk,xk vkSj Statement 1, Statement2 ls Statement n rd ds Statements dk Execution djsxkA fQj Inner if Statement Block ds ckgj vkdj Outer if Condition Block ds Inner Sequential Statement n dk Execution djsxk vkSj var esa izksxzke Control nksuksa if Condition Statement Block ls ckgj vk dj Outer Sequential Statement a dk Execution djsxkA ysfdu ;fn Inner if Condition lR; uk gks] rks izksxzke Control, Inner else Statement Block ds Statement 3 ls ysdj Statement m rd ds Statements dk Execution djsxk vkSj Inner else ls ckgj vkdj Outer if Condition ds Inner Statement, Statement n dk Execution djsxkA vxj nksuksa gh if Conditions vlR; gks tkrh gS] rks izksxzke Control lh/ks gh Outer else Condition ds Statement Block dk Execution dj nsrk gS vkSj else Statement Block ls ckgj vkdj Outer Sequential Statement a dk Execution djrk gSA lkjka”k ds :i esa ge ;g dg ldrs gSa fd tc If Condition ds Statement Block dk Execution gksrk gS] rc else ds Statement Block dk Execution ugha gksrk] vkSj else Statement Block dk Execution rHkh gksrk gS] tc if Condition vlR; gks tkrh gSA bls vPNh rjg ls le>us ds fy;s ge fuEu mnkgj.k ns[krs gSa] ftlesa rhu la[;kvksa esa ls cMh la[;k dks Output esa Print fd;k tk jgk gS& Program public class NestedIfElseControlStatement { public static void main(String args[]){ float firstNumber = 5784547.54f; float secondNumber = 855454.12F; float thirdNumber = 45478.6545f; float result; if(firstNumber > secondNumber){ if(firstNumber > thirdNumber)

159 Any Question or Suggestion, Just Discuss Here...

Java in Hindi else

}

}

result = firstNumber;

result = thirdNumber; } else { if(secondNumber > thirdNumber) result = secondNumber; else result = thirdNumber; } System.out.println("Largest Number is " + result);

Output Largest Number is 5784547.5

if – elseif – else Ladder statement tc gekjs ikl ,slh leL;k gksrh gS fd us ds fy, ge fuEukuqlkj Program cuk ldrs gSa ftlesa fdlh Student ds dqy Marks dh Total ds Percent ds vk/kkj ij Output esa Student dh Grade dk irk pyrk gSA Program public class IfElseIFLadderControlStatement { public static void main(String args[]) {

160 Any Question or Suggestion, Just Discuss Here...

Java in Hindi float percent = 80;

}

}

if(percent > 79) System.out.println("Pass with Honors"); else if(percent > 59) System.out.println("First Division Pass "); else if(percent > 44) System.out.println("Second Division Pass "); else if(percent > 33) System.out.println("Third Division Pass"); else System.out.println("Fail");

Output Pass with Honors

bl Program esa ge ns[k ldrs gSa fd Student ds percent dk eku 80 gS] blfy, bl Control Statement dh igyh Condition gh true gks tkrh gS vkSj Output esa “Pass with Honors” Print gks tkrk gSA ysfdu ;fn percent dk eku 40 gksrk] rks pkSFkh else if Condition true gksrh vkSj Output esa “Second Division Pass Print” gksrkA switch statement tc ge fdlh izskxzke esa uk o iys dks’Bd dh t:jr ugha gksrh gSA fQj Hkh ;fn ;s dks’Bd yxk fn;s tk,a] rks Hkh Java Compiler dksbZ ijs”kkuh ugha djrk gSA switch Statement ds Execution ds fy;s loZizFke variable ;k expression ds eku dh rqyuk Øe ls ,d&,d djds value1, value2 ...... value n ls dh tkrh gS vkSj tgka Hkh ;s eku fey tkrk gS] ml case label ds vuqlkj fy[ks x;s Statements dk Execution gks tkrk gSA

bl lajpuk esa lHkh Statements Block ds ckn break fy[kk tkrk gSA ;g Statements ds lewg dk var n”kkZrk gS o Statements Block ds Execution ds ckn izksxzke Control dks switch Statement ds ckgj sequential Statement a ij ys tkrk gSA ;fn ;g break uk fy[kk tk,] rks Statement Block ds Execution ds ckn Hkh Program Control switch Statement Block ds vanj gh jgrk gS vkSj vkxs ds Statement dk Execution djrk jgrk gS vkSj rc rd djrk jgrk gS tc rd fd bls dksbZ break Statement

ugha fey tkrkA

162 Any Question or Suggestion, Just Discuss Here...

Java in Hindi switch Statement ds fy;s nh xbZ lajpuk esa default case label ,d Optional Label gSA ;fn ;g switch Statement esa gksrk gS o expression ;k variable dk eku switch Statement esa fn;s x, fdlh Hkh Statement ls esy ugh djrk] rks Program Control default case label ij pyk tkrk gS vkSj blds varxZr fn;s x, Statement dk Execution dj nsrk gSA switch case labels dks ge fdlh Hkh Øe esa j[k ldrs gSa] ;kuh pkSFks LFkku dk case izFke LFkku ij] izFke LFkku dk case rhljs LFkku ijA default Statement dks Hkh fdlh Hkh LFkku ij j[k ldrs gSaA bl Control Statement dks ge if else if Ladder Statement ds LFkku ij Use dj ldrs gSaA

;kuh ge fiNys Program dks fuEukuqlkj bl Statement ds iz;ksx }kjk Hkh fy[k ldrs gSa& Program public class SwitchControlStatement { public static void main(String args[]) { int percent = 75; percent = percent/10; switch(percent) { case 10: case 9: case 8: System.out.println("Pass with Honors"); break; case 7: case 6: System.out.println("First Division Pass "); break; case 5: System.out.println("Second Division Pass "); break;

}

}

}

case 4: System.out.println("Third Division Pass"); break; default: System.out.println("Fail");

Output First Division Pass 163 Any Question or Suggestion, Just Discuss Here...

Java in Hindi dHkh&dHkh gesa switch Statement esa fdlh Calculation ds fy, Variable Declare djus iMrs gSaA tc gesa fdlh switch Statement esa Variable Declare djuk iMrk gS] rc gesa Curly Braces ds Block dks Use djuk t:jh gksrk gSA ftl rjg ls ge if Control Statement dh Nesting dj ldrs gSa] mlh rjg ls ge switch Control Statement dh Hkh Nesting dj ldrs gSaA Increment and Decrement Increment tc fdlh Variable ds eku esa Øe ls dksbZ la[;k tksM dj okil mlh Variable esa Store dj nsrs gSa] rks ml Variable dk eku ml tksMh xbZ la[;k ds vuqlkj mlh Øe esa ck;k x;k gS%

251 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Program class Box { //Attributes double width; double height; double length; //Methods public double volume(Box temp) { double volume; volume = temp.length * temp.height * temp.width; return volume; }

}

public void setDimension(double len, double wid, double hei) { width = wid; length = len; height = hei; }

public class BoxVolumeWithBoxObjectArgument { public static void main(String args[]) { Box cpuCabinet = new Box(); Box hardDisk = new Box(); double volumeCPUCabinet; double volumeHardDisk; cpuCabinet.setDimension(20, 30, 40); hardDisk.setDimension(21,12,3); volumeCPUCabinet = cpuCabinet.volume(cpuCabinet); System.out.println("Volume of CPU Cabinet is " + volumeCPUCabinet);

}

}

volumeHardDisk = hardDisk.volume(hardDisk); System.out.println("Volume of Hard Disk is " + volumeHardDisk);

Output Volume of CPU Cabinet is 24000.0 Volume of Hard Disk is 756.0

252 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl Program esa ftl Object ds fy, volume() Method dks Call fd;k tkrk gS mlh Object dks ,d Argument ds :i esa volume() Method esa Hkst fn;k tkrk gSA volume() Method esa ml Object ds lHkh eku ,d temp uke ds Temporary Object esa Store gks tkrs gSaA fQj Dot Operator ds iz;ksx }kjk ge ml Object ds fofHkUu Data Members dks Access djds Object dk Volume Kkr dj ysrs gSa vkSj Volume() dks Calling Method main() esa Return dj nsrs gSaA

Methods Overloading

tkok esa ge ,sls Methods Create dj ldrs gSa ftuds uke rks leku gksa ysfdu muds Parameter List o Definitions vyx gksaA bl izfØ;k dks Method Overloading o ,sls Methods dks Overloaded Methods dgrs gSaA Method Overloading dk iz;ksx rc fd;k tkrk gS tc Objects dks ,d gh rjg ds dke djus gksrs gSa ysfdu Input Parameters vyx&vyx izdkj ds gksrs gSaA tc ge ,d Object ds fy, Method Call djrs gSa] rc tkok Method ds uke vkSj mlds ckn Parameter dh la[;k o Parameters ds Type dks Check djds ;s r; djrk gS fd mls Object ds fy, fdl Method dks Call djuk gSA bl izfØ;k dks tkok esa Polymorphism Hkh dgk tkrk gS] D;ksafd Java Interpreeter }kjk ,d gh uke o vyx&vyx Parameter List }kjk vyx&vyx Method dks Call fd;k tkrk gSA Overloaded Method Create djus ds fy, gesa dsoy bruk djuk gksrk gS fd leku izdkj ds dke djus okys fofHkUu Methods ds uke leku Define fd, tk,a o lHkh Methods ds Parameter dh la[;k ;k Parameters ds Data Type ;k nksuksa dks lHkh Methods esa vyx izdkj dk j[kk tk,A ;kuh gj Method ds fy, Arguments ds Data Type ;k la[;k Unique gksuh pkfg,A /;ku nsa fd Method Overloading esa Method ds Return Type dk dksbZ Role

ugha gksrk gSA bls le>us ds fy, ,d mnkgj.k nsf[k,% class Room { float length; float breadth; Room(float x, float y) { length = x; breadth = y; }

//Constructor1

Room(float x){ length = breadth = x; }

}

int area(){ return (length * breadth); }

253 Any Question or Suggestion, Just Discuss Here...

Java in Hindi this Keyword

fiNys Program esa geus ns[kk fd Class dk volume() Method mlh Object ds Data Members dks Use djrk gS] ftlds fy, volume() Method dks Call fd;k tkrk gSA ;kuh volumeCPUCabinet = cpuCabinet.volume(cpuCabinet); volumeHardDisk = hardDisk.volume(hardDisk);

tc gesa gekjs Program esa bl rjg ls fdlh Object dks mlh Method esa Argument ds :i esa Pass djuk iMrk gS] ftl Object ds fy, Method dks Call fd;k tkuk gksrk gS] rc ge this Keyword dk iz;ksx djds Object ds Data Members dks Access dj ldrs gSaA mnkgj.k ds fy, fuEu Method dks nsf[k,% public double volume(Box temp) { double volume; volume = temp.length * temp.height * temp.width; return volume; }

bls fuEukuqlkj Hkh fy[k ldrs gSa% public double volume() { double volume; volume = this.length * this.height * this.width; return volume; }

;s Method Hkh ogh dke djrk gS tks dke fiNyk Method djrk gSA fdlh Member Method ds vUnj this Keyword gesa”kk mlh Object dks Refer djrk gS ftlds fy, Method dks Call fd;k tkrk gSA gekjs fiNys Program esa ;fn ge volume() Method ds bl Version dks fiNys Version ds LFkku ij Replace dj nsa] rks ge bl Program dks fuEukuqlkj Hkh fy[k ldrs gSa% Program class Box { //Attributes double width; double height; double length; //Methods public double volume() { double volume; volume = this.length * this.height * this.width; return volume;

254 Any Question or Suggestion, Just Discuss Here...

Java in Hindi }

}

public void setDimension(double len, double wid, double hei) { width = wid; length = len; height = hei; }

public class BoxVolumeWithBoxObjectArgument { public static void main(String args[]) { Box cpuCabinet = new Box(); Box hardDisk = new Box(); double volumeCPUCabinet; double volumeHardDisk; cpuCabinet.setDimension(20, 30, 40); hardDisk.setDimension(21,12,3); volumeCPUCabinet = cpuCabinet.volume(); System.out.println("Volume of CPU Cabinet is " + volumeCPUCabinet);

}

}

volumeHardDisk = hardDisk.volume(); System.out.println("Volume of Hard Disk is " + volumeHardDisk);

Output Volume of CPU Cabinet is 24000.0 Volume of Hard Disk is 756.0

bl Program esa fuEukuqlkj nksuksa Statements esa bl Modified volume() Method dks Use fd;k x;k gS% volumeCPUCabinet = cpuCabinet.volume(); volumeHardDisk = hardDisk.volume();

tc igyk Statement Execute gksrk gS rc volume() Method esa this Keyword ds dkj.k cpuCabinet Object ds Data Members Access gksrs gSa vkSj cpuCabinet dk Volume Calculate djrs gSa tcfd nwljs Statement ds Execution ij volume() Method dk this Keyword hardDisk Object ds Data Members dks Access djds HardDisk dk Volume Calculate djrk gSA

255 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Automatic Garbage Collection

pwafd ge ns[k pqds gSa fd fofHkUu Classes ds Objects Program ds Run Time esa new Operator ds iz;ksx }kjk Dynamically Create gksrs gSa] blfy, bu Objects dh t:jr uk gksus ij bUgsa Destroy gksuk Hkh t:jh gksrk gS] rkfd tks Memory ;s Objects Reserve djrs gSa] og Memory dksbZ vU; Variable ;k Object Use dj ldsA tkok esa Memory Releasing dk ;s dke Automatically gksrk gSA ftl rduhd }kjk tkok esa ;s dke gksrk gS] mls Garbage Collection dgrs gSaA tc fdlh Actual Memory Block ds fy, Reference ds :i esa dksbZ Object miyC/k ugha gksrk gS] rc tkok dk Compiler ;s ekurk gS fd ml Object dh t:jr ugha gS vkSj Compiler ml Object dh Memory dks Release dj nsrk gSA tkok esa fofHkUu izdkj ls Use gksus okys fofHkUu izdkj ds Objects dks Release djus ds fy, fofHkUu izdkj ds Operations Implement gksrs gSaA gesa fdlh Object dh Memory dks Release djus dh fpUrk djus dh t:jr ugha gksrh gS] D;ksafd tkok dk Compiler ;s dke t:jr ds vuqlkj fofHkUu Internal rjhdksa ls Lo;a gh djrk jgrk gSA

Finalize() Method

dbZ ckj gesa ,slh t:jr gksrh gS fd Object Destroy gksus ls igys dqN fo”ks’k dke djs] mlds ckn Destroy gksA mnkgj.k ds fy, tc dksbZ Object Non-Java Resources tSls fd File Handle ;k Windows Character Font dks Hold djrk gS] rc Object ds Destroy gksus ls igys bu fo”ks’k Resources dks Release djus dk dke Automatically ugha gksrk gSA bl fLFkfr esa gesa gh bu Resources dks Release djuk gksrk gSA bu Resources dks Release djus ds fy, Java gesa ,d fo”ks’k Mechanism Provide djrk gS ftls Finalization dgrs gSaA bl Finalization Process dk iz;ksx djds ge ,sls dke Define dj ldrs gSa] tks Object ds Destroy gksus ls igys Perform gksrs gSaA fdlh Class esa Finalize Method dks Add djus ds fy, gesa Class esa dsoy ,d finalize() Method dks Define djuk gksrk gSA Java Compiler bl Method dks Automatically ml le; Call dj ysrk gS] tc dksbZ Object Destroy gks jgk gksrk gSA bl Method esa ge os Actions Specify djrs gSa] tks Object ds Destroy gksus ls igys Perform djus gksrs gSaA Garbage Collector le;≤ ij Run gksrk jgrk gS vkSj ftu Objects ds References fdlh Memory Block dks Refer ugha dj jgs gksrs gSa] mu Objects dks Release djrk jgrk gSA blls igys fd ,slk dksbZ Object iwjh rjg ls Memory Release djs] Java finalize() Method dks Execute dj nsrk gSA

lkekU;r;k bl Method dks fdlh Object ds fy, Use ugha fd;k tkrk gSA tkok Compiler Lo;a gh bls vko”;drkuqlkj Use djrk jgrk gSA gesa gekjs Program esa fdlh lkekU; dke ds fy, bl Method dk iz;ksx ugha djuk pkfg,A bl Method dks ge fuEukuqlkj Define dj ldrs gSa% protected void finalize() { //Finalization Codes goes here. }

256 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ge ns[k ldrs gSa fd bl Definition esa geus public ds LFkku ij protected Access Specifier dk iz;ksx fd;k gSA tc fdlh Method dks protected Declare fd;k tkrk gS] rc bldk eryc ;s gksrk gS fd ;s Method Class ls ckgj fdlh Hkh rjg ls Access ugha fd;k tk ldrk gSA ,sls Method ds lkFk tks Hkh izfØ;k gksrh gS] og Class ds vUnj gh gksrh gSA Access Specifier ds ckjs esa vkxs ge foLrkj ls ius ds fy, ge CalculateSquare Class Develop djrs gSa] tks fd fuEukuqlkj gS% class CalculateSquare { public void square() { System.out.println("No Parameter Method Called"); } public int square( int number ) { int square = number * number; System.out.println("Method with Integer Argument Called"); return square;

258 Any Question or Suggestion, Just Discuss Here...

Java in Hindi } public double square( double number ) { double square = number * number; System.out.println("Method with Double Argument Called"); return square; }

}

public float square( float number ) { float square = number * number; System.out.println("Method with float Argument Called"); return square; }

bl Class dk iz;ksx ge fdlh Program esa dj ldrs gSaA Methods dh Overloading dks Practically le>us ds fy, fuEu Program nsf[k,% Program public class OverLoadedMethodDemonstraton { public static void main(String [] args) { CalculateSquare firstNumber = new CalculateSquare(); CalculateSquare secondNumber = new CalculateSquare(); CalculateSquare thirdNumber = new CalculateSquare(); CalculateSquare forthNumber = new CalculateSquare(); int intResult; double doubleResult; float floatResult; forthNumber.square(); intResult = firstNumber.square(11); System.out.println("Value of integer = " + intResult); doubleResult = secondNumber.square(10.25); System.out.println("Value of double = " + doubleResult);

}

}

floatResult = thirdNumber.square(2.4f); System.out.println("Value of float = " + floatResult);

Output No Parameter Method Called

259 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Method with Integer Argument Called Value of integer = 121 Method with Double Argument Called Value of double = 105.0625 Method with float Argument Called Value of float = 5.76

vki lksp ldrs gSa fd tkok Compiler ;s fdl rjg ls r; djrk gS fd mls fdl eku ds fy, fdl Method dks Call djuk gS] tcfd Class esa Define fd, x, lHkh Methods ds uke leku gS\a bl loky dk tokc ;s gS fd tkok Compiler Method dks Call djrs le; tks eku Argument ds :i esa Method ds Parenthesis esa iznku fd;k tkrk gS] ml eku ds Data Type ds vk/kkj ij ;s r; djrk gS] fd mls Overloaded Method ds fdl Version dks Call

djuk gSA

geus gekjs Program esa lcls igys square() Method ds Parenthesis esa dksbZ Argument iznku ugha fd;k gSA bl fLFkfr esa Compiler Class ds ml Method dks Call djrk gS] ftlesa Argument dks izkIr djus ds fy, fdlh Parameter dks Define ugha fd;k x;k gSA ;kuh Compiler Class ds fuEu Method dks forthNumber Object ds fy, Call djrk gS% public void square() { System.out.println("No Parameter Method Called"); }

blh rjg ls tc firstNumber Object ds fy, square() Method dks Call fd;k tkrk gS vkSj Argument ds :i esa ,d Integer izdkj dk eku Method ds Parenthesis esa iznku fd;k tkrk gS] rc Compiler square() Method ds ml Version dks Call djrk gS] ftlesa Parameter ds :i esa ,d Integer izdkj dk Argument izkIr djus ds fy, ,d Variable Declare fd;k x;k gSA ;kuh% intResult = firstNumber.square(11); Statement ds Reference esa fuEu Method Call gksrk gS% public int square( int number ) { int square = number * number; System.out.println("Method with Integer Argument Called"); return square; }

blh rjg ls tc fuEu Statement Execute gksrk gS% floatResult = thirdNumber.square(2.4f); 260 Any Question or Suggestion, Just Discuss Here...

Java in Hindi rc bl Statement ds Reference esa square() Method dk fuEu Version Execute gksrk gS% public float square( float number ) { float square = number * number; System.out.println("Method with float Argument Called"); return square; }

bl rjg ls ge ,d gh uke ds ,d ls vf/kd Methods dks fdlh Class esa Define dj ldrs gSa] ftls Method Overloading djuk dgrs gSa vkSj bl rjg ls Define fd, x, Methods ds Arguments ds Data Type ds vk/kkj ij tkok dk Compiler Lo;a gh fdlh Object ds fy, mfpr Method Call dj ysrk gSA

Constructors

nqfu;k dk dksbZ Hkh Real World Object ,slk ugha gksrk gS] ftlds fofHkUu Attributes dk Object ds Create gksrs le; dksbZ eku uk gks vkSj lHkh eku ckn esa Set fd, tkrs gksaA ;kuh ekuyks fd dksbZ Company ,d cpuCabinet cukrh gSA rks Company dksbZ Hkh cpuCabinet ,slk ugha cuk ldrh ftlds fuekZ.k ds le; ml cpuCabinet Object dk dksbZ Length, width o Height uk gksA tks Hkh cpuCabinet Company cuk,xh ml gj cpuCabinet dk dksbZ uk dksbZ izkjfEHkd Dimension t:j gksxkA blh Concept ds vk/kkj ij tkok esa Hkh ;s lqfo/kk iznku dh xbZ gS fd fdlh Hkh Class dk dksbZ Hkh Object Create gksrs le; mlesa izkjfEHkd eku Initialized gks ldsA Create gksus okys Object esa Object ds Create gksrs le; gh dqN izkjfEHkd eku Initialize djus ds fy, ,d Method Create fd;k tkrk gSA bl Method dks Constructors dgrs gSaA Constructor fdlh Class dk ,d ,slk Member Method gksrk gS] ftldk uke ogh gksrk gS tks ml Class dk uke gksrk gS] ftlesa ;s Member Method gksrk gSA mnkgj.k ds fy, ;fn ge Box Class dk Constructor Define djuk pkgsa rks ;s Constructor Box Class dk ,d Member Method gksxk vkSj bl Method dk uke Hkh Box() gh gksxkA

pwafd Constructor dk ogh uke gksrk gS tks Class dk uke gksrk gS] blfy, tc Hkh ge ml Class dk dksbZ Object Create djrs gSa] rks Object ds Create gksrs gh ;s Constructor Method Execute gks tkrk gSA blfy, ge bl Method esa fdlh Object dks iznku fd, tkus okys izkjfEHkd eku iznku dj nsrs gSa vkSj tSls gh ge fdlh Class dk dksbZ Object Create djrs gSa] ml Class dk ;s Constructor Execute gks dj Create gksus okys Object ds fofHkUu Instance Variables dks Initialize dj nsrk gSA Constructors dh t:jr gesa blfy, Hkh iMrh gS D;ksafd tc Hkh dksbZ Object Create gksrk gS rks mldk dksbZ uk dksbZ izkjafHkd eku Hkh t:j gksrk gSA blfy, ;fn ge Constructors dk iz;ksx ugha djrs gSa] rks Object Create gksus ds ckn gesa ml Object ds fofHkUu Instance Variables dks fofHkUu eku Initialize djus iMrs gSaA bl dke dks djus ds fy, ge ,d Initialize() uke dk Member Method Hkh Create dj ldrs gSa] ysfdu ,slk djus ij gj Object ds fy, bl Method dks Call djuk iMrk gSA

261 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Program class Box { //Attributes double width; double height; double length; //Methods public double volume() { double volume; volume = this.length * this.height * this.width; return volume; } public void initializeObject(double len, double wid, double hei) { width = wid; length = len; height = hei; } } public class BoxVolumeWithBoxObjectArgument { public static void main(String args[]) { Box cpuCabinet = new Box(); Box hardDisk = new Box(); double volumeCPUCabinet; double volumeHardDisk; cpuCabinet.initializeObject(1, 2, 3); hardDisk.initializeObject(1, 2, 3); volumeCPUCabinet = cpuCabinet.volume(); System.out.println("Volume of CPU Cabinet is " + volumeCPUCabinet);

}

}

volumeHardDisk = hardDisk.volume(); System.out.println("Volume of Hard Disk is " + volumeHardDisk);

Output Volume of CPU Cabinet is 6.0 Volume of Hard Disk is 6.0

262 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl mnkgj.k esa geus ,d initializeObject uke dk Member Method Create fd;k gSA Object dks Create djus ds ckn gj Object ds fy, gesa bl Method dks Call djds ml Object dks Initialize djuk t:jh gksrk gSA vc blh Program dks ge Constructor ds iz;ksx }kjk fuEukuqlkj Modify dj ldrs gSa& Program class Box { //Attributes double width; double height; double length; //Methods public double volume() { double volume; volume = length * height * width; return volume; }

}

Box() //No-Argument Constructor { System.out.println("No-Argument Constructor Executed"); width =1; length =2; height =3; }

public class ConstructorDemo { public static void main(String args[]) { Box cpuCabinet = new Box(); Box hardDisk = new Box(); double volumeCPUCabinet; double volumeHardDisk; volumeCPUCabinet = cpuCabinet.volume(); System.out.println("Volume of CPU Cabinet is " + volumeCPUCabinet);

}

}

volumeHardDisk = hardDisk.volume(); System.out.println("Volume of Hard Disk is " + volumeHardDisk);

Output

263 Any Question or Suggestion, Just Discuss Here...

Java in Hindi No-Argument Constructor Executed No-Argument Constructor Executed Volume of CPU Cabinet is 6.0 Volume of Hard Disk is 6.0

bu nksuksa mnkgj.kksa ds Output leku gh gSa tks fd ge ns[k ldrs gSa] ysfdu main() Method esa vUrj gSA igys Program esa ,d initializeObject() Method dks Object ds fy, Call djds Object ds fofHkUu Instance Variables dks Initialize fd;k x;k gS] tcfd nwljs Program esa ;s dke Java Compiler Constructor dk iz;ksx djds Lo;a gh dj ysrk gSA tc ge Box Class dk ,d Object cpuCabinet Create djrs gSa] rks tSls gh Compiler u, Object ds fy, Memory Allocate dj nsrk gS] ml Memory Locations ij fofHkUu Instance Variables ds fy, eku Hkh Initialize gks tkrs gSaA ,slk blfy, gksrk gS] D;ksafd Object ds fy, Memory Allocate gksus ds rqjUr ckn Box Class dk Box uke dk Constructor Method Execute gks tkrk gS vkSj og Method Object ds fofHkUu Instance Variables dks Initialize dj nsrk gSA blh rjg ls tc nwljk Object Create gksrk gS rks nwljs Object dk Hkh igys Constructor Execute gksrk gS vkSj Object ds fofHkUu Dimensions dks Initialize dj nsrk gSA Output esa ge izkIr gksus okyh igyh nks Lines ds vk/kkj ij ge le> ldrs gSa] fd Box Constructor Execute gks jgk gSA tc ge Constructors Define dj jgs gksrs gSa] rc gesa ,d ckr dk /;ku j[kuk pkfg, fd Constructor Method dHkh Hkh dksbZ eku Return ugha djrk gS] blfy, blesa return Statement dk iz;ksx ugha fd;k tkuk pkfg, lkFk gh Return Type dks Hkh Declare ugha fd;k tkuk pkfg,A ;gka rd fd Return Type ds LFkku ij void dk Hkh iz;ksx djus ij Compiler Error iznku djrk gSA lkFk gh ,d Class dk Constructor dsoy mlh Class ds Object ds fy, Execute gksrk gS] blfy, blds lkFk fdlh Access Specifier dk Hkh iz;ksx ugha fd;k tkuk gksrk gSA ;kuh fdlh Class dk Constructor Method Create djrs le; gesa ml Class ds uke dks gh Constructor ds uke ds :i esa Define djuk gksrk gSA blhfy, geus gekjs Program esa dsoy fuEukuqlkj Statement }kjk gh Constructor dks Define fd;k gS] ftlesa fdlh Access Specifier ;k Return Type dk iz;ksx ugha fd;k x;k gS% Box()

//No-Argument Constructor

pwafd] ;s Constructor fdlh izdkj dk dksbZ eku main() Method ls izkIr ugha djrk gS] blfy, blds Parenthesis dks Empty j[kk x;k gSA tc fdlh Constructor dk Parenthesis Empty gksrk gS rks bl izdkj ds Constructor dks No-Argument Constructor dgk tkrk gSA gkykafd ge bl rjg ls Initialization dj ldrs gSa] ysfdu fdlh Object dks Create djrs le; gh ;fn mlds fofHkUu Dimensions dks Set fd;k tk lds] rks T;knk csgrj gksrk gS] D;ksafd ,slk t:jh ugha gksrk gS fd Create gksus okys lHkh Objects ds Attributes ds eku gesa”kk leku gh gksaA ;kuh ge Box Class ls ftrus Hkh CPU Box Object Create djrs gSa] gesa”kk ,slk 264 Any Question or Suggestion, Just Discuss Here...

Java in Hindi gksuk t:jh ugha gksrk gS] fd Create gksus okys gj CPU dh Height, Width o Length leku gksA blfy, ,d gh Class ds dbZ vyx&vyx Size ds Box Objects Create djus ds fy, ge ,slk Constructor Method Define dj ldrs gSa] ftldk iz;ksx djds Create gksus okys gj Object dh Size dks Object Creation ds le; gh Define fd;k tk ldsA bl izdkj ds Constructor dks Parameterized Constructor dgk tkrk gSA pwafd tkok esa ge Methods dh Overloading dj ldrs gSa] blfy, ge Constructors dh Hkh Overloading dj ldrs gSaA ;kuh ge ,d gh uke ds ,d ls vf/kd Constructors dks ,d gh Class esa Define dj ldrs gSaA Program class Box { //Attributes double width; double height; double length; //Methods public double volume() { double volume; volume = length * height * width; return volume; } Box() //No-Argument Constructor { System.out.println("No-Argument Constructor Executed"); width =1; length =2; height =3; }

}

Box(double len, double wid, double hei) { System.out.println("3-Argument Constructor Executed"); width = wid; length = len; height = hei; }

public class ConstructorDemo { public static void main(String args[])

265 Any Question or Suggestion, Just Discuss Here...

Java in Hindi {

Box cpuCabinet = new Box(); Box hardDisk = new Box(1,2,3); double volumeCPUCabinet; double volumeHardDisk; volumeCPUCabinet = cpuCabinet.volume(); System.out.println("Volume of CPU Cabinet is " + volumeCPUCabinet);

}

}

volumeHardDisk = hardDisk.volume(); System.out.println("Volume of Hard Disk is " + volumeHardDisk);

Output No-Argument Constructor Executed 3-Argument Constructor Executed Volume of CPU Cabinet is 6.0 Volume of Hard Disk is 6.0

bl Program ds Output ls ge le> ldrs gSa fd tc ge cpuCabinet uke dk Box Object Create djrs gSa] rc Box Class dk No-Argument Constructor Execute gksrk gS vkSj tc ge Box Class dk hardDisk Object Create djrs gSa vkSj mlds Constructor esa Dimension ds rhuksa eku Define dj nsrs gSa] rks Compiler hardDisk Object ds fy, 3-Argument Constructor dks Execute djrk gS] tSlkfd ge Output esa ns[k ldrs gSa vkSj hardDisk Object dks Initialized dj nsrk gSA

Arguments Passing

tkok esa fdlh Subroutine (Method) esa Arguments dks Pass djus ds nks rjhds gksrs gSaA igys rjhds dks Pass By Value o nwljs rjhds dks Pass By Reference rjhdk dgk tkrk gSA Pass By Value tc fdlh eku dks Argument ds :i esa Calling Method ls Called Method esa Pass By Value rjhds ls Pass fd;k tkrk gS] rc Calling Method ls vkus okys eku dks izkIr djus ds fy, Called Method esa ,d vkSj Local Variable Create gksrk gSA ;kuh Create gksus okys ml Local Variable esa Calling Method ls vkus okyk eku Copy gks tkrk gSA fQj Called Method esa ml Copied eku ij tks Hkh izfØ;k gksrh gS] mldk izHkko Calling Method ds Variables ds eku ij ugha iMrk gSA bl iwjh izfØ;k dks le>us ds fy, ge ,d mnkgj.k ns[krs gSa] tks fd fuEukuqlkj gSA Program class PassByValue

266 Any Question or Suggestion, Just Discuss Here...

Java in Hindi {

}

//Attributes //Methods public void calculation( int i, int j) { i = i + 3; j = j + 3; }

public class PBVDemonstration { public static void main(String args[]) { PassByValue object = new PassByValue(); int x=10, y=20; System.out.println("Value of x and y is " + x + " " + y); object.calculation(x, y);

}

}

System.out.println("Value of x and y is " + x + " " + y);

Output Value of x and y is 10 20 Value of x and y is 10 20

bl mnkgj.k Program ds Output ls ge le> ldrs gSa fd x o y ds eku dks calculation() Method esa Pass djus ds ckotwn Hkh x o y dk eku Change ugha gks jgk gSA ,slk blfy, gksrk gS D;ksafd tc x o y dk eku calculation() Method esa Pass fd;k tkrk gS] rc bu Variables ds ekuksa dks Hold djus ds fy, calculation() Method esa i o j uke ds nks Variables Create gksrs gSa vkSj bu Variables esa x o y ds eku Øe”k% Copy gks tkrs gSaA fQj calculation() Method esa tks Hkh Processing gksrh gS og Actual esa i o j ds eku ij gksrh gS] uk fd x o y ds eku ijA blhfy, x o y ds eku esa dksbZ ifjorZu ugha gksrk gSA tc fdlh Method dks bl rjhds ls Call fd;k tkrk gS] ftlesa Actual Argument ds eku dh Copy gh Call gksus okys Method ds Local Variables dks Pass fd;k tkrk gS] rc bl izdkj ds Calling rjhds dks Call By Value ;k Pass By Value rjhdk dgk tkrk gSA Pass By Reference tc Calling Method ls fdlh Method esa bl izdkj ls eku dks Pass fd;k tkrk gS fd ;fn Called Method esa ml eku esa ifjorZu fd;k tk, rks Calling Method esa Hkh ml eku esa ifjorZu gks tkrk gS] rks bl izdkj ls fdlh Method esa eku Pass djus dh izfØ;k dks Pass

267 Any Question or Suggestion, Just Discuss Here...

Java in Hindi By Reference ;k Call By Reference rjhdk dgk tkrk gSA bls Hkh ge fuEUk mnkgj.k }kjk

le> ldrs gSaA

Program class PassByReference { //Attributes int x, y; //2-Argument Constructor PassByReference(int i, int j) { x = i; y = j; }

}

//Methods public void calculation( PassByReference temp ) { temp.x = temp.x + 3; temp.y = temp.y + 3; }

public class PBRDemonstration { public static void main(String args[]) { PassByReference object = new PassByReference(10, 20); System.out.println("Value of object.x and object.y before call is : " + object.x + " " + object.y); object.calculation(object);

}

}

System.out.println("Value of object.x and object.y after call is : " + object.x + " " + object.y);

Output Value of object.x and object.y before call is : 10 20 Value of object.x and object.y after call is : 13 23

bl mnkgj.k esa ge ns[k ldrs gSa fd tc Object dks calculation() Method esa Hkstk tkrk gS] rc Object ds eku esa Method ds ifjorZuksa dk izHkko iMrk gS vkSj Object ds Attributes ds ekuksa esa Hkh ifjorZu gks tkrk gSA bl rjg ls tc fdlh Object dks fdlh Method esa Pass fd;k tkrk gS] rks bls Pass By Reference ;k Call By Reference rjhdk dgk tkrk gSA

268 Any Question or Suggestion, Just Discuss Here...

Java in Hindi lkekU;r;k ,d ckr /;ku j[kuh pkfg, fd tkok esa tc fdlh Method esa fdlh Basic Data Type ds eku dks Argument ds :i esa Pass fd;k tkrk gS] rc bl rjg Call gksus okyk Method “By Value” Call gksrk gS vkSj tc fdlh Object dks fdlh Method esa Argument ds :i esa Pass fd;k tkrk gS] rc Call gksus okyk Method “By Reference” Call gksrk gSA ,slk blfy, gksrk gS D;ksafd tc ge fdlh Class dk dksbZ Variable Create dj jgs gksrs gSa rc tkok esa Actual Object Create ugha gksrk gS] cfYd Object dk ,d Reference ek= gh Create gksrk gS] tks fd mlh Actual Physical Memory Block dks Refer dj jgk gksrk gS] ftls Calling Method dk Object Refer dj jgk gksrk gSA

Access Controls

Access Control dk iz;ksx djds ge ;s r; dj ldrs gSa fd Program dk dkSulk Hkkx fdlh Class ds Members dks Access dj ldrk gSA Access Controls dk iz;ksx djds ge Class ds Members dks xyr rjhds ls Use djus ls jksd ldrs gSaA

mnkgj.k ds fy, ;fn ge Class ds Data dks fdlh Well Defined Method }kjk gh Access djus ds fy, Control djuk pkgsa] rks blds fy, ge Access Controls dk iz;ksx dj ldrs gSaA ftlls fdlh Hkh vU; rjhds ls Class ds Data dks Access ugha fd;k tk ldsA ,sls esa ge Class ds Data dks ;fn Access djuk pkgsa rks ge Class es ml Data dks Access djus okyk Method Define dj nsrs gSaA ,slk djus ij ge dsoy ml Method }kjk gh Class ds Data dks Access dj ldrs gSaA Class ds Data dks Access djus dk dksbZ vkSj nwljk rjhdk ugha gksrk gSA ;fn gesa Class ds fdlh Data dks Access djuk gS] rks gesa ml Class ds mlh Method dks Use djuk gksxk] tks ml Data dks Access dj ldrk gSA Encapsulation dk eq[; mn~ns”; ;gh gS fd ge Class ds Data dks mlh Class ds fdlh Member }kjk gh Access djus esa l{ke gksaA ,slk gksus ij Class ds Data lqjf{kr jgrs gSa vkSj fdlh Hkh vU; rjhds ls Class ds Data dks modify ugha fd;k tk ldrk gSA vHkh rd geus ftruh Hkh Classes cukbZ gSa] mu lHkh Classes ds Data dks fdlh Hkh Method esa Directly Access fd;k tk ldrk gSA blfy, bu Classes dks ge ,slh Class ugha dg ldrs gSa tks Encapsulation ds fu;e dks Follow djrs gksaA

fdlh Class ds Members dks fdl izdkj ls Access fd;k tk ldrk gS ;s r; djus ds fy, ge Access Specifier dk iz;ksx djrs gSaA tkok esa Access Specifier dk ,d lewg gS] tks ;s r; djrs gSa fd fdl fLFkfr esa fdlh Member dks fdl gn rd Access fd;k tk ldrk gSA buesa ls dqN Access Specifier eq[;r;k Inheritance o Packages ds fy, gh Use gksrs gSaA fdlh ,d fo’k; ls lEcaf/kr lHkh Classes ds ,d lewg dks Package dgk tkrk gSA Package ls lEcaf/kr Access Specifier ds ckjs esa ge vkxs foLrkj ls ppkZ djsaxsA ;gka ge dsoy ,d Single Class ls lEcaf/kr Access Specifier ds ckjs esa lh[ksaxsA tkok ds eq[; Access Specifier public, protected o private gSaA lkFk gh tkok dk ,d Default Access Specifier Hkh gSA protected Specifier dsoy rc Apply gksrk gS] tc Inheritance dk iz;ksx fd;k tkrk gSA

269 Any Question or Suggestion, Just Discuss Here...

Java in Hindi public and private Access Specifier tc fdlh Class ds Members public gksrs gSa] rc Class ds mu Members dks fdlh Hkh vU; Method }kjk Directly Access djds Modify fd;k tk ldrk gSA ysfdu tc fdlh Class ds Members private gksrs gSa] rc Class ds mu Members dks dsoy mlh Class esa Define fd, x, public Methods }kjk gh Access fd;k tk ldrk gSA main() Method dks ge blhfy, gesa”kk public j[krs gSa] rkfd main() Method dh Class ds fofHkUu Data dks vklkuh ls main() Method o fdlh Hkh vU; Method }kjk Access fd;k tk ldsA tc fdlh Class fdUgha Member ds lkFk fdlh Access Specifier dk iz;ksx ugha fd;k tkrk gS] rc Class ds os Members Default :i ls public gksrs gSaA tSlkfd geus Box Class esa fdlh Hkh Data Member ds lkFk fdlh Access Specifier dk iz;ksx ugha fd;k gS] blfy, ;s lHkh Data Members Default :i ls public gSaA ,d ckr /;ku j[kus okyh ;s gS fd tc ge fdlh Class ds Members ds lkFk fdlh Access Specifier dk iz;ksx ugha djrs gSa] rc ml Class ds Members dks ge dsoy mlh Package esa Directly Access dj ldrs gSaA Default Access Control dh Range dsoy mlh Package rd gksrh gSA ;fn gesa fdlh ,d Package ds Class ds Members dks fdlh nwljs Package ds Members esa Use djuk gS] rks ges igys Package ds Members dks public Access Specifier ds lkFk gh Declare

djuk t:jh gksrk gSA

vHkh rd geus tks Hkh Class Develop dh gS] mlesa lHkh Data Members Default :i ls public gSaA mnkgj.k ds fy, Box Class ds lHkh Members public gSa] blhfy, ge main() Method ls Hkh Box Class ds Data dks eku iznku dj ldrs gSa vkSj Box Class ds Data ds ekuksa dks Screen ij Print dj ldrs gSaA tcfd okLro esa ,slk ugha gksuk pkfg,A ;fn ge Default Access Specifier dk iz;ksx djrs gSa] rks Program ds fdlh Hkh Method }kjk Box Class ds Object ds Data dks Modify fd;k tk ldrk gS] tks fd ugha gksuk pkfg,A D;ksafd fdlh Hkh Practical Application esa lcls t:jh pht Data dh Security gh gksrh gSA blfy, gesa gesa”kk viuh Class ds Data dks fdlh Hkh vU; Method }kjk Modify gksus ls jksduk gksrk gSA ;s dke ge rc dj ldrs gSa tc Class ds Data Members private gksaA fdlh Class ds Object Program ds vU; fgLlksa ls rHkh Communicate dj ldrs gSa] tc ml Class dk dksbZ Member public gksrk gSA Data dh lqj{kk ds dkj.k ge Data dks rks public ugha dj ldrs gSa] ysfdu Class ds Methods dks ge public j[krs gSaA Class ds Methods gh Program ds vU; fgLlksa esa Class ds Data dks Access djus dk ,d ek= ek/;e gks ldrs gSa] D;ksafd os public gksrs gSaA pfy,] bl izfØ;k dks ,d Program }kjk le>rs gSa ftlesa geus fQj ls Box Class dk gh mnkgj.k fy;k gSA pwafd ge pkgrs gSa fd Box Class ds Data dks fdlh Hkh vU; Method }kjk Directly Access uk fd;k tk lds] blfy, gesa Box Class ds Data dks private djuk gksxkA ;s dke ge fuEukuqlkj dj ldrs gSa% class Box { private double width; private double height; private double length;

270 Any Question or Suggestion, Just Discuss Here...

Java in Hindi }

vc bl Class dks Access djus ds fy, ge fuEukuqlkj ,d Program cuk ldrs gSa& Program class Box { //Attributes private double width; private double height; private double length;

}

//Methods public void volume() { double volume; volume = length * height * width; System.out.println("Volume is " + volume); }

public class BoxVolume { public static void main(String args[]) { Box cpuCabinet = new Box(); Box hardDisk = new Box(); cpuCabinet.length = 100; cpuCabinet.height = 70; cpuCabinet.width = 20; hardDisk.length = 10; hardDisk.height = 1.5; hardDisk.width = 6;

}

}

cpuCabinet.volume(); hardDisk.volume();

;fn bl Program dks ge Compile djrs gSa] rks gesa fuEukuqlkj Errors izkIr gksrs gSa% Output PrivateDataMember.java:25: length has private access in Box cpuCabinet.length = 100; ^ PrivateDataMember.java:26: height has private access in Box

271 Any Question or Suggestion, Just Discuss Here...

Java in Hindi cpuCabinet.height = 70; ^ PrivateDataMember.java:27: width has private access in Box cpuCabinet.width = 20; ^ PrivateDataMember.java:29: length has private access in Box hardDisk.length = 10; ^ PrivateDataMember.java:30: height has private access in Box hardDisk.height = 1.5; ^ PrivateDataMember.java:31: width has private access in Box hardDisk.width = 6; ^ 6 errors

;s Errors blfy, Generate gksrs gSa] D;ksafd Box Class ds Data Members dks private Declare fd;k x;k gS vkSj fdlh Class ds Private Data Members dks mlh Class dk dksbZ public Method gh Access dj ldrk gSA pwafd gesa Box Class ds Objects dks Initialize djuk gS rks ;k rks ge bl dke ds fy, Constructors dk iz;ksx dj ldrs gSa] D;ksafd Constructors mlh Class ds os Methods gksrs gSa] tks Object Creation ds lkFk gh Automatically Execute gks tkrs gSa] ;k fQj ge Box Class esa fuEukuqlkj ,d public Method Define djds Box Object dks Initialize dj ldrs gSa%

public void initializeObject(double len, double wid, double hei) { length = len; width = wid; height = hei; }

bl Method dks viuh Box Class esa fuEukuqlkj Include djds ge main() Method esa Box Class ds Object ds Data dks Box Class ds Outside ds main() Method esa Access dj ldrs gSa% Program class Box { //Attributes private double width; private double height; private double length; //Methods public void volume() { double volume; volume = length * height * width;

272 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

System.out.println("Volume is " + volume); } public void initializeObject(double len, double wid, double hei) { length = len; width = wid; height = hei; }

public class PrivateDataPublicMethod { public static void main(String args[]) { Box cpuCabinet = new Box(); Box hardDisk = new Box(); cpuCabinet.initializeObject(100, 70, 20); hardDisk.initializeObject(10, 1.5, 6);

}

}

cpuCabinet.volume(); hardDisk.volume();

Output Volume is 140000.0 Volume is 90.0

;s Program Compile Hkh gksrk gS vkSj Execute gks dj Result Hkh iznku djrk gSA fdlh Class ds Private Members dks ml Class ls ckgj fdlh nwljh Class esa Use djus ds fy, gesa gesa”kk blh rjhds dks Use djuk iMrk gSA ftl rjg ls ge public o private Data Members Create dj ldrs gSa] mlh rjg ls ge fdlh Class esa private Methods Hkh Create dj ldrs gSaA ysfdu ,slk djus ij ;fn ge ml private Method dks Class ls Outside esa Use djuk pkgsa] rks Hkh gesa mlh Class ds ,d public Method dh t:jr gksrh gSA lkjka”k ;s gS fd fdlh Class ds private Members dks ml Class ls ckgj fdlh vU; Class esa rHkh Use fd;k tk ldrk gS] tc mlh Class esa fdlh public Method esa private Members dks Access djus ds Code fy[ks x, gksaA fdlh Class ds private Members dks Class ls ckgj Access djus dk dksbZ vkSj nwljk rjhdk ugha gSA

static Data Members and Methods

dbZ ckj fdlh Class esa gesa ,sls Data Members Define djus dh t:jr gksrh gS] ftudk ml Class ds Object ds Conjunction ds lkFk iz;ksx ugha gksrk cfYd bu Data Members dks Lora= :i ls Access fd;k tk ldrk gSA mnkgj.k ds fy, ekuyks fd gesa ;s tkuuk gks fd

273 Any Question or Suggestion, Just Discuss Here...

Java in Hindi fdlh Program esa Class ds fdlh le; ij dqy fdrus Objects Create gq, gSa] rks ;s dke iwjk djus ds fy, gesa Class esa ,d static Data Member dks Define djus dh t:jr iMrh gSA lkekU;r;k fdlh Class ds ftrus Hkh Data Members gksrs gSa] mUgsa mlh Class ds fdlh Object ds Conjunction ds lkFk gh Access fd;k tkrk gSA ysfdu Class esa ,sls Data Member Hkh Create fd, tk ldrs gSa] ftudks fcuk fdlh Object ds Reference ds Hkh Directly Access o Use fd;k tk ldrk gSA bl izdkj ds Members Create djus ds fy, gesa Data Member ds lkFk static Keyword dk iz;ksx djuk iMrk gSA fdlh Class ds ,d static izdkj ds Data Member dks fcuk ml Class ds fdlh Object dks Create fd, gq, Hkh Directly Access dj ldrs gSA blh fy, main() Method dks static j[kk tkrk gS] D;ksafd ,d static Method dks ftl Class esa Declare fd;k tkrk gS] ml Class ds fdlh Object dks Create djus ls igys Hkh ml Class ds bl static Method dks Call fd;k tk ldrk gSA fdlh Class ds ftu Instance Variables dks static Declare fd;k tkrk gS] os lkekU;r;k Global Variables gksrs gSa] blfy, tc ml Class ds Object Create fd, tkrs gSa] rc gj Object ds fy, lHkh Non-Static Data Members dh Copy rks Create gksrh gS] ysfdu static Data Members dh Copy Create ugha gksrh gSA ;kuh ml iwjh Class ds lHkh Objects ds fy, static Data Member Common :i ls Use gksrk gS vkSj ml Class ds lHkh Objects static Data Member dks leku :i ls Share djrs gSaA static Methods dqN fuf”pr fu;eksa dk ikyu djrs gSaA 1

fdlh Class ds Static Methods dks dksbZ static izdkj dk Method gh Call dj ldrk gSA 2 static Methods fdlh static Data Members dks gh Access dj ldrs gSaA 3 ;s Methods this o super dk iz;ksx fdlh izdkj ls ugha dj ldrs gSaA super Keyword ds ckjs ge Inheritance Chapter ds vUrxZr vPNh rjg ls le>saxsA ;fn fdlh static Variable dks Initialize djuk gks] rks gesa ,d static Block Declare djuk iMrk gSA tc Class Memory esa igyh ckj Load gksrh gS] rc ;s Block ,d vkSj flQZ ,d gh ckj Execute gksrk gSA bls le>us ds fy, ge ,d mnkgj.k ns[krs gSaA Program //static variable, methods and blocks Demonstration. class StaticDemonstration { static int x = 3; static int y; static void calculation(int i) { System.out.println(“i = “ + i); System.out.println(“x = “ + x); System.out.println(“y = “ + y); }

274 Any Question or Suggestion, Just Discuss Here...

Java in Hindi static { System.out.println(“Static block being Initialized.“); y = x * 3; }

}

public static void main(String args[]) { calculation(10); }

Output Static block being Initialized. i = 10 x=3 y=9

bl Program dks tSls gh Compile djds Run fd;k tkrk gS] rks StaticDemonstration Memory esa Load gks tkrk gS] blds lHkh static Statements Execute gks tkrs gSaA lcls igys x dk eku 3 Initialize gksrk gSA fQj static Block Execute gksrk gS vkSj vUr esa y dk eku Initialize gksrk gSA fQj main() Method Call gksrk gS vkSj calculation() Method esa iznku fd;k tkus okyk eku 10 Variable i dks izkIr gks tkrk gSA bl Method esa rhu println() Statements gSa tks nks static Variables x o y rFkk ,d Local Variable i ds eku dks Screen ij Print djus dk dke djrs gSaA Class esa Define fd, x, static Variables o Methods dks ml Class ls Outside esa Hkh Lora= :i ls Use fd;k tk ldrk gSA fdlh static Variable ;k Method dks Class ls ckgj Lora= :i ls Use djus ds fy, gesa bl izdkj ds Variables o Methods dks Dot Operator ds lkFk Use djuk gksrk gSA tSls ;fn ge fdlh static Method dks Program ds fdlh fgLls esa mldh Class ls Outside esa Call djuk pkgrs gSa] rks ;s dke ge fuEukuqlkj Form esa dj

ldrs gSa%

Classname.method();

;gka Classname og Class gS ftlesa static Method dks Declare fd;k x;k gSA ge ns[k ldrs gSa fd ;s Format mlh rjg dk gS ftl rjg ds Format dk iz;ksx djds ge fdlh Object ds fy, fdlh Non-Static Method dks Call djrs gSaA fdlh static Variable dks Hkh blh rjg ls Use fd;k tk ldrk gS ysfdu Object ds uke ds LFkku ij Class dk uke Use djuk gksrk gSA fuEu mnkgj.k esa bl iwjs Process dks Use fd;k x;k gSA Program //static variable, methods and blocks Demonstration. class StaticClass { static int x = 3; static int y = 21;

275 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

static void calculation() { System.out.println("x = " + x); }

class StaticDemo { public static void main(String args[]) { StaticClass.calculation(); System.out.println("y = " + StaticClass.y); } } Output x=3 y = 21

final Keyword

dbZ ckj gesa ,sls ekuksa dh t:jr gksrh gS] tks iwjs Program esa dsoy ,d gh ckj Initialized fd;k tkrs gSa vkSj iwjs Program esa ;s eku Constant jgrs gSaA tc gesa bl izdkj ds Instance Variable Declare djus gksrs gSa] rc ge bl izdkj ds Variables dks final Keyword ds lkFk Declare djrs gSaA bl rjg ds Variables dks Declare djrs gh bUgsa Initialize djuk gksrk gSA tSls final String NAME = “Gopal”; final int ROLLNUMBER = 12121212; final double DIMENSION = 1.0;

ftu Variables dk eku final Keyword ds lkFk Declare fd;k x;k gksrk gS] mu Variables ds ekuksa dks ge iwjs Program esa dgha Hkh Change ugha dj ldrs gSaA ;fn ge bUgsa Change djus dh dksf”k”k djrs gSa] rks tkok dk Compiler gesa Error nsrk gS vkSj Program Compile ugha gksrk gSA lkekU;r;k ftu Variables dks gesa final Declare djuk gksrk gS] mUgsa Capital Letters ds iz;ksx }kjk Declare fd;k tkrk gSA gkykafd ge bls Small Letters dk iz;ksx djds Hkh Declare dj ldrs gSaA ge Variables dh rjg Methods dks Hkh final Declare dj ldrs gSa] ysfdu blds ckjs esa ge vkxs le>saxsA

Nested and Inner Classes

ftl rjg ls ge fofHkUu izdkj ds Control Statements dh Nesting dj ldrs gSa mlh rjg ls ge fdlh ,d Class esa nwljh Class dks Hkh Nest dj ldrs gSaA Nested Class dsoy ml Class rd gh miyC/k gksrk gS] ftlesa bls Create fd;k tkrk gSA

276 Any Question or Suggestion, Just Discuss Here...

Java in Hindi fdlh Nested Class ds Objects dks ge ml Class ls ckgj Create ugha dj ldrs gSa] ftlesa ;s Class Nested gSaA ;kuh ;fn ,d Class B dks Class A esa Define fd;k x;k gS] rks Class B ds ckjs esa Class A dks irk gksrk gS] ysfdu Class B ds ckjs esa Class A ds vykok Program ds fdlh fgLls dks irk ugha gksrk gSA ,d Nested Class dks fdlh Hkh rjhds ls mldh Outer Class ds vykok dgha Hkh Access ugha fd;k tk ldrk gSA ,d Nested Class mldh Outer Class ds fdlh Hkh Member dks Access dj ldrk gS ysfdu Outer Class Inner Class ds fdlh Hkh Member dks Access ugha dj ldrk gSA Nested Class Hkh nks rjg dh gks ldrh gSA igys izdkj dh Class static Class gksrh gSA bl izdkj dh Class esa static Modifier dk iz;ksx fd;k x;k gksrk gSA pwafd ;s ,d static Class gksrh gSA blfy, ;g vius Outer Class ds Members dks ,d Object ds Reference }kjk Access dj ldrk gSA ;kuh ,d static Inner Class viuh Outer Class ds Members dks fcuk vius Object ds Access ugha dj ldrk gSA lkekU;r;k bl izdkj dh Class dks Use

ugha fd;k tkrk gSA

nwljh izdkj dh Class ,d Inner Class gksrh gSA ;s ,d Non-Static Nested Class gksrk gS vkSj vius Outer Class ds lHkh Members dks Directly Access dj ldrk gSA fuEu Program }kjk ge bl Class ds Concept dks le> ldrs gSa tgka Outer ,d Outer Class gS vkSj Inner ,d Inner Class gSA Program class Outer { int outerVariable = 100; void Test() { Inner inner = new Inner(); inner.display(); } class Inner { void display() { System.out.println(“Display : outerVariable = “ + outerVariable); } } } class InnerClassDemonstractoin { public static void main(String args[]) { Outer outer = new Outer(); outer.Test(); } }

277 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Output Display : outerVariable = 100

bl Program esa Inner Class dks Outer Class ds vUnj Nested fd;k x;k gSA blfy, Inner Class Directly outerVariable dks Access dj ldrk gSA Inner Class esa ,d Instance Method display() Define fd;k x;k gSA ;s Method outerVariable ds eku dks Display djus dk dke djrk gSA main() Method Outer Class dk ,d Object Create djrk gS vkSj blds Test() Method dks Call djrk gSA ;s Method Inner Class dk ,d Object Create djrk gS vkSj display() Method dks Call djrk gSA ;s ckr /;ku nsus okyh gS fd Inner Class dks dsoy Outer Class esa gh Use fd;k tk ldrk gSA Outer Class ds Scope ls ckgj ;fn bl Class dk Instance Create djuk pkgsa] rks ge ,slk ugha dj ldrs gSaA Compiler gesa ,slk ugha djus nsrk gSA ,d Inner Class viuh Outer Class ds lHkh Members dks Directly Access dj ldrk gSA ysfdu ,d Outer Class viuh Inner Class ds fdlh Hkh Member dks Directly Access ugha dj ldrkA Inner Class ds Members dks dsoy Inner Class esa gh Access fd;k tk ldrk gSA ;fn ge ,d Outer Class esa Inner Class dks Use djus dh dksf”k”k djrs gSa] rks tkok Compiler gesa ,slk ugha djus nsrk gSA

GUI Application Of Java

fiNys v/;k; rd geus fofHkUu izdkj ds GUI Applets cuk, gSa] tks fofHkUu izdkj ds dke djus esa l{ke gSaA ysfdu Applets gesa”kk HTML Web Page ds vUnj Run gksrs gSa] blfy, ;s iwjh rjg ls gekjs local Computer ds lHkh Resources dks Use djus esa l{ke ugha gksrs gSaA lkFk gh Window ds Frame ds :i esa ;s HTML Window dks Use djrs gSaA ftl rjg ls geus vHkh rd GUI Applets Create fd, gSa] mlh rjg ls ge GUI Applications Hkh Create dj ldrs gSaA tc ge Applet Create djrs gSa] rc gesa By Default ,d Window izkIr gks tkrk gSA D;ksafd ;s Window HTML Web Page gksrk gSA ysfdu tc gesa Standalone Application cukuk gksrk gS] rc ,d Basic Window Create djus dk dke Hkh gekjk gh gksrk gSA tSlkfd ge tkurs gSa fd Applet Class Panel Class dh Sub Class gS vkSj Panel Class rFkk Window Class nksuksa gh Component Class dh Sub Classes gSaA ;kuh Panel Class o Window Class nksuksa gh Sibling Classes gSa] ftldh otg ls tks xq.k ,d Panel esa gksrs gSa] yxHkx os lHkh xq.k Window esa Hkh gksrs gSaA ftl rjg ls Panel Class dk Object Screen ij fn[kkbZ ugha nsrk gS] mlh rjg ls Window Class dk Object Hkh Screen ij fn[kkbZ ugha nsrk gSA Screen ij fn[kkbZ nsus dk xq.k Panel Class dh Sub Class Applet esa gksrk gSA Bhd blh rjg ls Window Class dh Sub Class Frame o Dialog esa Hkh Screen ij fn[kkbZ nsus dk xq.k gksrk gSA gkykafd Applet Class o Frame Class nksuksa gh Classes ds Objects Screen ij fn[kkbZ nsrs gSa] ysfdu nksuksa esa ,d Basic vUrj ;s gSa fd Applet Class

278 Any Question or Suggestion, Just Discuss Here...

Java in Hindi dk Object fdlh uk fdlh Web Page esa gh fn[kkbZ nsrk gS] tcfd Frame Class ;k Dialog Class dk Object Standalone Hkh Display gks ldrk gSA blfy, tc gesa tkok Programming Language dk iz;ksx djrs gq, Standalone GUI Application Develop djuk gksrk gS] rc Container ds :i esa Frame Class dk Object Create djuk iMrk gSA Frame Class gesa ,d Standalone GUI Window iznku djrk gS] ftlesa ,d Title Bar, Control Toolbox o Border gksrk gSA pwafd fdlh Hkh Applet Program esa dksbZ main() Method ugha gksrk gS] blfy, ;fn ge pkgsa rks fdlh Hkh Applet Program dks Application Program esa Convert dj ldrs gSaA

Java Application – The Frame Class Frame Class dk Object ,d Resizable Window iznku djrk gS] tks Menu Bar Cursor, Icon o Title dks Support djrk gSA Frame dk iz;ksx dsoy tkok ds Applet Window o Application esa gh fd;k tk ldrk gSA pwafd ;s Container Class ls Derived gksrk gS] blfy, ge blesa vU; Controls dks Place dj ldrs gSaA tc gesa tkok Application Create djuk gksrk gS] rc GUI Window Create djus ds fy, ge bl Class dk Object Create djrs gSaA Frame dk iz;ksx ge fdlh HTML Page ds fofHkUu Contents dks Frames esa Setup djus ds fy, Hkh dj ldrs gSaA ,d izdkj ls ;s gekjk Basic Application Type Window gksrk gS] tks ,d ,slk Window gksrk gS] ftls ge T;knkrj Programs esa ns[krs gSaA ge Frames dk iz;ksx Applets esa Hkh dj ldrs gSaA lkekU;r;k tc gesa fdlh Applet esa Menu Bar ;k Dialog Box dks Use djuk gksrk gS] rc gesa Frames dk iz;ksx djuk t:jh gks tkrk gSA D;ksafd fcuk Frames dk iz;ksx fd, gq, ge fdlh Applet esa Menu Bar ;k Dialog Box dk iz;ksx ugha dj ldrs gSaA ,d Frame Hkh ogh Events Generate djrk gS] tks ,d Window Object Generate djrk gSA ;kuh WINDOW_DESTROY, WINDOW_ICONIFY, WINDOW_DEICONIFY, and WINDOW_MOVED Frame Constructor dks ge dsoy ,d gh String Parameter Pass djrs gSa vkSj ;s String Parameter Frame Window dk Title gksrk gSA ge lkekU;r;k gekjh Lo;a dh Class Create djrs gSa vkSj ml Class dks Frame Class ls Extend djrs gSa ;k gekjh Loa; dh Class esa Frame dh Class ds xq.kksa dks Inherit djrs gSaA

lkFk gh fofHkUu izdkj ds Components ds Events dks Hkh Handle djrs gSaA fofHkUu izdkj ds Events dks Handle djus ds fy, ge fofHkUu Components dh Event Handling Methods dks Override djrs gSaA Frame Window Create djus ds fy, lcls igys gesa ,d Class Create djuh gksrh gS vkSj ml Class esa main() Method Create djuk gksrk gSA fQj main() Method esa Frame Class dk ,d Object Create djuk gksrk gS vkSj ml Object ds Constructor esa Argument ds :i esa Frame Window dk uke nsuk gksrk gSA ge fuEukuqlkj Statement }kjk ,d Frame Object Create dj ldrs gSa%

279 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Frame firstApplicationWindow = new Frame(“Frame Window”);

bl Statement }kjk ,d Frame Object Create gksrk gSA ysfdu vHkh rd ;s Object dsoy Memory esa gh Create gqvk gSA dsoy blh Statement }kjk ge Created Window dks ugha ns[k ldrs gSaA Frame Window fn[kkbZ ns] blds fy, gesa Frame Object dks Visible djuk gksrk gSA Frame Window dks Visible djus ds fy, gesa setVisible() Method dk iz;ksx djuk iMrk gSA bl Method esa gesa Argument ds :i esa ,d Boolean eku nsuk gksrk gS] tks ;s r; djrk gS fd Window dks Show djuk gS ;k Hide djuk gSA bl Method dks Component Class ls Derive fd;k x;k gS] blfy, bl method dks ge fdlh Hkh Control Component ds lkFk Use dj ldrs gSaA pwafd gesa gekjs Frame Window dks Screen ij Display djuk gS] blfy, gesa Frame Window Object ds lkFk bl method dks fuEukuqlkj Call djuk iMrk gS% firstApplicationWindow.setVisible(true) Frame Window dks Visible dj nsus ij Window Screen ij Visible rks gks tkrk gS] ysfdu gesa fuEukuqlkj Window dk dsoy Title Bar gh fn[kkbZ nsrk gSA

Frame Window fdruk yEck&pkSMk fn[kkbZ nsuk pkfg,] ;s Hkh gesa gh r; djuk gksrk gSA Frame Window dh Height o Width r; djus ds fy, gesa Component Class ds setSize() Method dk iz;ksx djuk gksrk gSA

bl Method dks Component Class ds fdlh Hkh Method dh Height o Width Set djus ds fy, Use fd;k tkrk gSA bl Method esa gesa nks Arguments iznku djus gksrs gSaA bl Method dk igyk Argument Width dks Specify djrk gS] tcfd nwljk Argument Frame Window dh Height dks Represent djrk gSA bl Method dks Frame Object ds lkFk esa fuEukuqlkj Use djds Frame Window dh Size dks r; fd;k tkrk gS% firstApplicationWindow.setSize(300, 200);

vc fn[kkbZ nsus okyk Frame Window gesa fuEukuqlkj fn[kkbZ nsrk gS%

pwafd fn[kkbZ nsus okys Window dk Background White Color dk gS] blfy, ;fn ge pkgsa rks Window ds Background dks setBackground() Method dk iz;ksx djds Change dj ldrs gSaA ekuyks fd gesa Window ds Color dk Background pkfg,] rks blds fy, ge

280 Any Question or Suggestion, Just Discuss Here...

Java in Hindi fuEukuqlkj Statement dk iz;ksx djds Frame Window ds Background dks Change dj ldrs gSa% firstApplicationWindow.setBackground(new Color(233, 233, 209));

bl Statement dks vius Program esa Use djus ij gesa fuEukuqlkj Frame Window izkIr gksrk gS%

bl izdkj dk Window Create djus ds fy, gesa fuEukuqlkj Application Program fy[kuk gksrk gS% Program // File: MyFirstApplicationWindow.java import java.awt.*; class MyFirstApplicationWindow { public static void main(String args[]) { Frame firstApplicationWindow = new Frame("Frame Window"); firstApplicationWindow.setVisible(true); firstApplicationWindow.setSize(300, 150); firstApplicationWindow.setBackground(new Color(233, 233, 209)); } }

;s ,d Application Program gS vkSj bls Run djus ds fy, gesa dksbZ Hkh HTML File ugha cukuh iMrh gSA ysfdu ;s Program Standalone Run gksrk gSA bls fdlh Web Page esa Run ugha fd;k tk ldrk gSA ;fn ge fdlh Applet dks Application esa Convert djuk pkgsa] rks cgqr gh vklkuh ls ;s dke fd;k tk ldrk gSA ekuyks fd fiNys v/;k; ds ModifiedThreeControlApplet Program dks gesa bl Frame Application esa Convert djuk gSA bl dke dks djus ds fy, gesa dsoy ModifiedThreeControlApplet Class dk ,d Object Create djuk gksxk] vkSj mlds init() Method dks Call djds Applet dks Initialize djuk gksxkA fQj add() Method dk iz;ksx djds Frame Window esa ModifiedThreeControlApplet Object dks Add djuk gksxkA ,slk

281 Any Question or Suggestion, Just Discuss Here...

Java in Hindi djus ij ,d ModifiedThreeControlApplet Program ,d Application dh rjg dke djus yxrk gSA bl iwjh izfØ;k dks ge fuEukuqlkj Program }kjk le> ldrs gSa% Program // File: MyFirstApplicationWindow.java import java.awt.*; public class MyFirstApplicationWindow { public static void main(String args[]) { Frame firstApplicationWindow = new Frame("Frame Window"); ModifiedThreeControlApplet appletToApplication; appletToApplication = new ModifiedThreeControlApplet(); appletToApplication.init(); firstApplicationWindow.add("Center", appletToApplication);

}

}

firstApplicationWindow.setSize(400, 200); firstApplicationWindow.setVisible(true); firstApplicationWindow.setBackground(new Color(233, 233, 209));

Output

blh rjhds ls ge fofHkUu izdkj ds vU; Applets dks Hkh Application esa Convert dj ldrs gSaA bl Program esa geus ModifiedThreeControlApplet Class dk ,d Object appletToApplication Create fd;k gSA gkykafd ;s Class geus bl Program esa Create ugha dh gSA ysfdu fQj Hkh ge bl Class dk Object nwljs Program esa dj jgs gSaA ,slk blfy, lEHko gS] D;ksafd ModifiedThreeControlApplet Program dh Class File o MyFirstApplicationWindow Program dh Class File nksuksa gh Class Files leku Folder esa Saved gSaA blfy, ge ,d Program ds Class dks nwljs Program esa Use dj ldrs gSaA

282 Any Question or Suggestion, Just Discuss Here...

Java in Hindi pwafd Applet Class ls Derive fd, x, ModifiedThreeControlApplet Class esa dksbZ main() Method ugha gSa] blfy, ;s Derived Class Hkh] fdlh vU; lkekU; Class dh rjg gh ,d lkekU; Class gSA vr% ge bl Class dk Object Hkh Create dj ldrs gSaA gekjs bl Program esa geus ;gh fd;k gSA bl Derived Applet Class dk ,d Object appletToApplication Create fd;k gS vkSj bls Initialize djus ds fy, mlh Applet Class ds init() Method dks Call fd;k gSA tc Applet Initialize gks tkrk gS] rc bl ModifiedThreeControlApplet Class ds appletToApplication Object dks Frame Object esa add() Method dk iz;ksx djds Add dj fy;k gSA ,slk djus ls Applet Class dk Object Frame Object esa Place gks tkrk gS vkSj gekjk Applet ,d Application dh rjg dke djus yxrk gSA blh Application Program }kjk ge fdlh Hkh Applet dks Application esa Convert dj ldrs gSaA

283 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Java Inheritance For

Code Reusability

284 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Java Inheritance – Code Reusability

OOP esa Inheritance Class ds ckn nwljk lcls cMk Center Concept gSA Inheritance Reusability dks lEHko cukrk gSA bldh otg ls ge ,d gh Class dks ckj&ckj vyx&vyx fLFkfr;ksa esa mi;ksx esa ys ldrs gSa vkSj gesa ckj&ckj ,d gh izdkj ds Code ugha fy[kus iMrs gSaA

Reusability

gesa”kk gj Program esa dqN dke ,sls gksrs gSa ftUgsa FkksMk cgqr ifjorZu ds lkFk djuk gh iMrk gSA mnkgj.k ds fy, vkt ge GUI okrkoj.k ds Program fy[krs gSaA bu lHkh Programs esa fdlh uk fdlh gn rd dqN Menus, dqN Standard Tool Buttons, dqN Window ;k Forms vkfn yxHkx lHkh Programs esa leku gksrs gSaA OOPS ls igys gj Program ds fy, gj Source File esa budh Coding dks fy[kuk iMrk Fkk tks yxHkx lHkh Source File esa leku gksrs FksA blds fy, T;knkrj ckj fdlh fiNys Program dh Coding dks Copy djds u, Program dh Source File esa Paste fd;k tkrk FkkA viuh vko”;drkuqlkj Source Coding esa ifjorZu fd;k tkrk Fkk vkSj Program dks fQj ls Compile djds mi;ksx esa ys fy;k tkrk FkkA

ysfdu vDlj gksrk ;s Fkk fd tc iqjkus Program dh Coding dks u, Program esa Copy fd;k tkrk Fkk rks vko”;drkuqlkj fofHkUu ifjorZu djus ij Program esa okil Bugs vk tkrs Fks ftUgsa fQj ls Debug djuk iMrk FkkA dbZ ckj rks Bugs fudkyus esa bruk le; yx tkrk Fkk fd Programmer dks yxrk Fkk fd ;fn mlus iwjh Coding gh fQj ls dj yh gksrh] rks Hkh mruk le; ugha yxrk ftruk iqjkuh Coding dks Debug djus esa yx jgk gSA ;kuh iqjkuh Coding dks Use djuk ,d cMh leL;k ds leku Fkk vkSj Programmers gesa”kk ;s pkgrs Fks fd mUgsa ,d gh izdkj dh Coding ckj&ckj uk djuh iMsA Program ds Bugs dks Reduce djus o iqjkuh Coding dks Use djus ds fy, Programmers Functions Create djus yxsA Functions dh ;s fo”ks’krk gksrh gS fd bUgsa ,d gh ckj Debug

djds dbZ ckj mi;ksx esa fy;k tk ldrk gSA fofHkUu izdkj ds dkeksa ds fy, fofHkUu izdkj ds Functions fy[ks tkrs Fks vkSj mUgsa ,d Bundle ds :i esa Reuse djus ds fy, Functions dh Library cuk yh tkrh FkhA bUgha Functions dh Library dks “C” Hkk’kk esa Header Files dgk x;kA

gkykafd Function Libraries dkQh gn rd Reusable Codes iznku djrs Fks ysfdu budh leL;k ;s Fkh fd buds }kjk Real World Objects dks Computer esa Logically Represent ugha fd;k tk ldrk Fkk] D;ksafd Functions Libraries egRoiw.kZ Data dks Include ugha djrs FksA lkFk gh ,d Function dks u, Program esa vPNh rjg ls Use djus ds fy, muesa Modifications Hkh djus iMrs FksA pwafd Functions ds :i esa Companies Source Code iznku djrs Fks ftUgsa ,d Programmer viuh vko”;drkuqlkj Modify dj ldrk Fkk ysfdu tc Programmer mUgsa Modify djrk Fkk rks mls okil mu Functions ds Bugs dks Debug djuk iMrk FkkA OOPS ds Concept }kjk ,d u;k rjhdk lkeus vk;k ftlls Reusability dkQh ljy gks xbZ vkSj ;s rjhdk Fkk Class Libraries dkA D;ksafd ,d Class Real World Object dks vPNh rjg Modal djrk gS blfy, bls u, okrkoj.k esa mi;ksx esa ysus ds fy, blesa T;knk Modification djus dh vko”;drk ugha gksrh gSA OOPS gesa ,d ,slk rjhdk iznku djrk gS ftlls fcuk Class ds Coding dks ifjofrZr fd, gq, Class dks Modify fd;k tk ldrk gS vkSj fQj ls mi;ksx esa yk;k tk ldrk gSA ;s fo”ks’krk OOPS esa Inheritance Concept ds dkj.k gesa izkIr gksrh gSA bl

285 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Concept esa fdlh iqjkuh Class (Super Class) dgrs gSa] mls Modify ugha djuk gksrk gS cfYd ,d ubZ Class (Sub Class) cuk;h tkrh gS vkSj mlesa iqjkuh Class ds lHkh Features dks Derive dj fy;k tkrk gS lkFk gh viuh vko”;drkuqlkj u, Features dks Hkh bl ubZ Class esa Add dj fy;k tkrk gSA bl izfØ;k dks OOPS esa Inheritance dgrs gSaA

Inheritance and Program Design

iqjkus Codes dks Modify djds Use djus esa ljyrk iznku djuk Inheritance dh ,d vkSj fo”ks’krk gSA Inheritance gesa ,d Program ds Components dks nwljs Program ls Relate djus ;k u, Program esa tksMus dk ,d u;k rjhdk iznku djrk gSA ;s u, izdkj dh Relationship Program dks Design djus ds fy, Extra Flexibility iznku djrk gS vkSj Programmer dks ;s lqfo/kk iznku djrk gS fd og Program Architecture dks bl izdkj ls Design dj lds fd Program T;knk ls T;knk Accurate rjhds ls Real World Relationship dks Reflect djsA Inheritance ds Concept ds vk/kkj ij ge ,d Class ls dbZ vU; Classes dk Relation cuk dj dbZ vU; ubZ Classes cuk ldrs gSa] ftUgs Sub Class dgk tkrk gSA Inheritance dks dbZ ckj “Kind of” Relationship }kjk Represent fd;k tkrk gSA bl Relationship dk eryc le>us ls igys ge ,d vU; Relationship dks le>saxs ftls “Has a” Relationship ;k Composition dgk tkrk gSA

Composition: A “Has a” Relationship geus igys Hkh Composition dks vius Program esa dbZ ckj Use fd;k gSA ge ftruh Hkh ckj fdlh Class esa ,d Instance Data Member Place djrs gSa] ge ,d “Has a” Relationship cuk jgs gksrs gSaA tSls ;fn ,d Employee Class gS vkSj mlesa name uke dk ,d Data Item gS] rks ge ;s dg ldrs gSa fdl Employee dk ,d uke gS ;k ;fn English Language esa dgsa rks dg ldrs gSa fd% Employee “Has a” Name

blh rjg ls ,d Employee Object dk ID gks ldrk gS, Salary gks ldrk gS] vkfnA ;fn ge Relationship ds vk/kkj ij bUgsa Hkh Describe djuk pkgsa rks dg ldrs gSa fd% Employee “Has a” ID Employee “Has a” Salary Object o mlds Features ds chp bl izdkj ds Relationship dks Composition dgk tkrk gS D;ksafd ,d Employee Object bu Features dks Represent djus okys Variables dk ,d Composition gSA

blh rjg ls Stack Class esa Stack ds Data dks Hold djus ds fy, ,d Array dks vkSj Index Number dks Store djus ds fy, ,d top Variable, Member Data ds :i esa gks ldrs gSaA bl Stack Class ds ckjs esa ;fn ge dguk pkgsa rks dg ldrs gSa fd ,d Stack Object ,d Array vkSj ,d Stack-Top Index dk Composition gS ;k dg ldrs gSa fd ,d Stack esa ,d Array gS vkSj ,d top Index Variable gSA ;kuh 286 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Stack “Has a” StackArray Stack “Has a” topIndex

ge fdlh Class esa fdlh nwljh Class ds Object dks Hkh ,d Member Data Variable ds :i esa Declare dj ldrs gSaA ;kuh ;fn ge pkgsa rks fdlh School Class esa fdlh Student Class ds Object dks Hkh Data Member ds :i esa Declare dj ldrs gSaA blh rjg ls ge ,d Bicycle Class esa Frame Object dks Data Member ds :i esa j[k ldrs gSa tks fd fdlh vU; Class dk ,d Object gSA OOPS esa Composition fdlh Real World Object dks bl rjg ls Represent djrk gS] ftlesa ,d Object dbZ vU; Objects dk cuk gqvk gks ldrk gSA ;fn ge ,d Family Relationship ds vk/kkj ij “Has A” Relationship dks Represent djsa rks ge fuEukuqlkj fp= }kjk bl Relationship dks le> ldrs gSa% A Has – A / Part – Of Relationship ( “ds ikl . . . gS” @ “dk ,d Hkkx gS” lEca/k) ,d Human Being Class ds ikl ,d Heart gS vkSj ,d Heart Human Being Class dk

,d Hkkx gSA

Part – Of Human Being

Mammal Has – A

“Has a” Relationship o “Part of” Relationship vkil esa Interchangeable gksrs gSaA “C” Language esa bl “Has a” Relationship dks Structure }kjk Represent fd;k tkrk FkkA ;kuh ,d Structure dbZ vU; Variables o Structures ls Composed gksrk FkkA ysfdu ,d vkSj Relationship gksrh gS ftls “C” Language tSlh Procedural Languages Modal ugha dj ldrs gSaA bl Relationship dks “Kind of” Relationship dgk tkrk gSA

Inheritance: A “Kind of” Relationship OOPS Real World ds ml Concept dks Represent djrk gS] ftls Generalization dgk tkrk gSA ;kuh ;fn ,d Maruti Car gS] ,d Tata Sumo Car gS vkSj ,d Ferrari Car gS] rks ge dg ldrs gSAa ;s rhuksa dkjsa ,d General Concept ftls Car dgrs gSa] ds Specific mnkgj.k gSaA bu lHkh dkjksa esa Wheels gksrs gSa] ysfdu gks ldrk gS fd Maruti Car ds Wheels dh pkSMkbZ de gks vkSj Ferrari Car ds Wheels dh pkSMkbZ vf/kd gksA blh rjg ls gks ldrk gS fd Tata Sumo Car ds Steering dk O;kl vU; dkjksa dh rqyuk esa vf/kd gksA ;kuh rhuksa Cars dh General Specification ds eku esa vUrj gks ldrk gS] tcfd rhuksa Cars ds Attributes leku Features dks Share djrs gSaA ysfdu fQj Hkh ge ;s dg ldrs gSa fd Maruti ,d izdkj dh Car gSA blh rjg ls Tata Sumo Hkh ,d izdkj dh Car gS vkSj Ferrari Hkh ,d izdkj dh Car gSA ;fn ge bls English Language esa dgsa rks dg ldrs gSa fd%

287 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Maruti is a “Kind of” Car Ferrari is a “Kind of” Car Tata Sumo is a “Kind of” Car

blh rjg ls ekuk ge ,d Employee Class cukrs gSaA ysfdu Employee Hkh dbZ izdkj ds gks ldrs gSaA tSls Labor, Manager, Scientist vkfnA ;s lHkh fdlh Company ds Employee gks ldrs gSa] ysfdu ;s lHkh vyx&vyx izdkj ds (Kind of) Employee gSaA fQj Hkh gj Employee dk Employee Class ls ,d lEca/k gS] tks buds vyx&vyx izdkj ds Employee gksus dks Represent gSA ;s nksuksa mnkgj.k Cars o Employees dh General Category dks Represent djrs gSaA ge gekjs nSfud thou esa Hkh Generalization dks dkQh Use djrs gSaA ge tkurs gSa fd ?kksMk] xk;] vkneh] vkSjr vkfn lHkh ltho izdkj ds mnkgj.k gSaA blh rjg ls Car, Bus, Truck vkfn Vehicle izdkj ds mnkgj.k gSaA Macintosh, o PCs Computer izdkj ds mnkgj.k gSaA bu lHkh Relationships dks ;fn ge English Hkk’kk esa Represent djsa rks dg ldrs gSa fd Human Being is “a Kind” of Mammal Dog is “a Kind” of Mammal Horse is “a Kind” of Mammal Maruti is “a Kind” of Car Ferrari is “a Kind” of Car Tata Indica is “a Kind” of Car

;kuh ge dg ldrs gSa fd Real World esa gj Object dk mldh Class ls ,d izdkj dk “Kind of” lEca/k gksrk gS blh rjg ls gj Object Attributes ;k Features dk ,d Composition gksrk gSA tc Real World esa Physically fofHkUu izdkj ds Objects ds chp bl izdkj dk lEca/k gksrk gS] rks Logically ;gh lEca/k gesa Computer esa Hkh Establish djuk t:jh gS rHkh ge fdlh Computer Language dks Object Oriented Language dg ldrs gSaA Inheritance Objects dh Classes ds chp blh Relationship dks Establish djus dh {kerk iznku djrk gSA Kind Of Relationship ( “,d izdkj dk” lEca/k ) bUlku o tkuoj nksuksa gh ltho izk.kh gSaA nksuksa ds gh T;knkrj Characteristics ,d leku gksrs gSaA tSls nksuksa ds ikl nks vka[ksa] ,d ukd] ,d eqag] nks dku gksrs gSa vkSj nksuksa gh py ldrs gSa] Hkkx ldrs gSa] f”kdkj dj ldrs gSa] vkfnA blfy, ge ;s dg ldrs gSa fd bUlku ,d izdkj dk ltho gS vkSj dksbZ tkuoj tSls fd “ksj Hkh ,d izdkj dk ltho gSA bls ge fuEukuqlkj fp= }kjk Hkh n”kkZ ldrs gSa% ,d izdkj dk

bUlku

ltho

bUlku ,d izdkj dk ltho gSA bls vaxzsth Hkk’kk esa Describe djsa rks ge dg ldrs gSa fd%

288 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Human Being is a Kind of Mammal.

blh rjg ls ge ,d “ksj dks Hkh fuEukuqlkj Represent dj ldrs gSa%

Human Being

A Kind Of

Mammal

Is – A Relationship ( “,d . . . gS” lEca/k) fiNys mnkgj.k esa geus ns[kk fd bUlku o “ksj ltho Class ds nks mnkgj.k gSaA vc ge ,d Human Being Class ds Instance ftldk uke Rahul Sharma gS] dks n[krs gSa] tks fd% ,d Human Being gS vkSj ,d izdkj dk ltho gSA ;kuh% Is – A Rahul Sharma

A Kind Of Human Being

Mammal

Is – A Computer eas fdlh Logical Class dks fdlh nwljh Logical Class ls Logically Relate dj ldrs gSa vkSj fofHkUu izdkj dh Relationship dks iz;ksx djrs gq, ge fdlh Class dks fcuk Rewrite fd, gq,] fQj ls Reuse dj ldrs gSaA

,d mnkgj.k }kjk le>sa rks ,d cPps esa mlds ekrk o firk nksuksa ds xq.k vkrs gSa] ftUgsa vkuqokaf”kd xq.k dgrs gSaA blh vkuqokaf”kdrk ds fl)kar dk iz;ksx Object Oriented Concept ds :i esa Computer esa fd;k tkrk gSA vkuqoakf”kdrk ds bl xq.k dks OOPS esa Inheritance dgk tkrk gSA Inheritance ,d ,slk rjhdk gksrk gS] ftlesa ;fn nks leku izdkj ds Objects gksa] rks ,d Object nwljs Object ds Attributers (State) o Behaviors (Ability) dks Use dj ldrk gSA bl fl)kar ds vk/kkj ij gh Object Oriented Programming Languages esa Reusability

dk fodkl fd;k x;k gSA

Superclass and Subclass

Computer ds Inheritance dks ge ,d mnkgj.k }kjk le>us dh dksf”k”k djrs gSaA ekuyks fd ge Railway Reservation dk Software cuk jgs gSaA bl Software esa fdlh Hkh le; nks rjg ds Tickets gks ldrs gSa% 1 2

Confirmed Ticket Waiting Ticket

289 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bu nksuksa izdkj ds Tickets ds dbZ vU; Attributes gks ldrs gSaA tSls% 1 2 3

4

Train Number Date Time Destination

fQj Hkh ,d Confirmed Ticket esa Seat Number uke dk ,d Extra Attribute gksxk] tcfd Waiting Ticket esa ,d Status Attribute gksxk] tks Ticket dh fLFkfr dks n”kkZ,xkA

mijksDr fp= esa geus nks Classes ds Common Structure o Attributes dks ifjHkkf’kr fd;k gS] tks fd Super Class Represent djrk gSA ;kuh Ticket ,d ,slh Common Class gS ftlds Attributes o Behaviors dks blds uhps dh nksuksa Sub Classes Confirmed Ticket o Waiting Ticket izkIr djrh gSaA pwafd Ticket Class dks ge ,d ,slh Class ds :i esa ns[k ldrs gSa] tks fd blds uhps dh nksuksa Classes ds fy, Common Attributes o Behaviors dks Represent djrk gS] blfy, bl Class dks Generalized Class dgrs gSaA tcfd Confirmed Ticket o Waiting Ticket nks ,slh Classes gSa] tks bldh Super Class Ticket ds Attributes o Behaviors dks rks izkIr djrs gh gSa] lkFk gh buds Lo;a ds Hkh dqN Attributes o Behaviors gks ldrs gSa] ;kuh ;s Classes T;knk Modified gks ldrh gSa vkSj fdlh ,d dke dks T;knk Special rjhds ls Represent dj ldrh gSa] blfy, bu Sub Classes dks Specialized Class dgrs gSaA Super Class ,d ,slh Class gksrh gS] ftlls vU; Classes Common Properties dks izkIr djrh gSaA ;s Classes viuh Properties dks vius ls Inherit gksus okyh Classes ds lkFk Share djrh gSaA tcfd ,d Sub Class og Class gksrh gSa] tks fdlh Super Class dh Properties ;kuh Attributes o Methods dks izkIr djrk gS vkSj T;knk Specialized rjhds ls mUgsa Use djrk gSA

dksbZ Hkh Sub Class dHkh Hkh viuh Super Class ds Constructors dks Inherit ugha djrk gS] D;ksafd Contractors dk vius Compiler ds fy, fo”ks’k Meaning gksrk gSA Sub Classes ds Lo;a ds Constructors Hkh Create fd, tk ldrs gSa] tgka Super Class ds Constructor ds ekuksa dks Hkh Initialize fd;k tkrk gSA ,d Sub Class dk mldh Super Class ds Data Members o Member Methods ds vykok Loa; dk Hkh Data Member o Method gks ldrk gSA lkekU;r;k dbZ Programming Languages esa Super Class dks Base Class o Sub Class dks Derived Class Hkh dgk tkrk gSA

290 Any Question or Suggestion, Just Discuss Here...

Java in Hindi fiNys fp= esa geus ns[kk fd Ticket Class ,d Generalized Class gSA ,d Generalized Class dk iz;ksx bl izdkj ds Programs dks fy[kus ds fy, fd;k tkrk gS tks fd cgqr T;knk General ;kuh Common :i ls dke esa vkrs gSaA ekuyks fd geus ,d ,slk Program cuk;k tks fd User ls Input ds :i esa ,d String izkIr djrk gS vkSj Output esa ml String dks Screen ij Print dj nsrk gSA ysfdu vc gekjh Requirement Change gks xbZ gS vkSj gesa Screen ij String ds LFkku ij fdlh Integer eku dks Print djuk gSA bl fLFkfr esa gesa gekjh fiNyh okyh Class dks Modify djuk gksxkA ekuyks fd gekjs ikl Super Class ds :i esa Data Class gS] ftlesa blds eku dks Display djus ds fy, ,d Method gSA Data Class dh Sub Class ds :i esa gekjs ikl Character o Float Class Hkh gSA vc ,d Integer izdkj ds eku dks Screen ij Print djus ds fy, gesa ,d Integer Class Create djuh gksxh] tks fd Data Class dh ,d Sub Class gSA Data Class esa ,d vkSj Sub Class dks Add djus ij Data Class dh igys ls Created Character o Float Sub Class esa dksbZ Effect ugha gksxkA pwafd Super Class Data esa Character Class o Float Class ds ekuksa dks Screen ij Print djus dk Method Super Class Data esa igys ls gh fy[kk tk pqdk gS] blfy, gesa Integer izdkj ds eku dks Screen ij Print djus ds fy, Hkh vyx ls Display() Method fy[kus dh t:jr ugha gSA ge Data Super Class ds Display() Method dks Integer Class esa Inherit djds ,d Integer izdkj ds eku dks Hkh Screen ij Print dj ldrs gSaA Generalization ,d ,slk rjhdk gS] tks gesa Abstraction djus esa enn djrk gSA OOPS esa eq[; egRo ,slh Classes Develop djus dk gksrk gS] tks vkil esa Data o Methods dks Share dj ldsa] lkFk gh Data dh Hkh Security cuh jgsA ;kuh ,d Unauthorized Class fdlh Hkh rjg ls fdlh nwljh Class ds Data dks Access ugha dj ldsA Encapsulation gh og rjhdk gS] ftlls Data dh Security dks izkIr fd;k tk ldrk gSA

fdlh Class dks dc Generalized Form esa Create djuk pkfg,] bldk dksbZ fuf”pr fu;e ugha gSA blfy, fdl izdkj dh Class dks Generalized djuk gS vkSj fdls ugha] bl ckr dk fu.kZ; ysus dh {kerk vuqHko ls izkIr gksrh gSA tkok esa ge dsoy Single Inheritance Concept dks gh Use dj ldrs gSaA ;kuh tkok esa ge dsoy ,d gh Super Class ds Attributes o Behaviors dks ubZ Class esa izkIr dj ldrs gSaA

Implementing Inheritance

Inheritance ds ,d lcls ljy mnkgj.k esa Hkh de ls de nks Classes gksrh gSaA ewy Class dks tkok esa Super Class dgk tkrk gS tcfd “C++” esa bls Base Class dgk tkrk gSA blh rjg ls ewy Class ls Derive dh tkus okyh Class dks tkok esa Sub Class dgk tkrk gS] tcfd “C++” esa Inherit gksus okyh Class dks Derived Class dgk tkrk gSA

tkok esa fdlh Super Class ds xq.kksa dks fdlh ubZ Class esa Derive djus ds fy, gesa extends Keyword dk iz;ksx djuk gksrk gSA tc ge fdlh Super Class ds xq.kksa dks fdlh Sub Class esa Inherit djrs gSa] rc okLro esa ge Super Class ds General xq.kksa dks viuh

291 Any Question or Suggestion, Just Discuss Here...

Java in Hindi t:jr ds vk/kkj ij c ldrs gSa] fd nksuksa gh Classes esa Object ds Data dks Set djus dk gh dke gks jgk gS] fQj Hkh Super Class ds Data o Sub Class ds Data nksuksa dks Set djus ds fy, gesa vyx&vyx uke ds Methods dks Call djuk iM jgk gSA bl fLFkfr esa ge Super Class ds Method dks Override djds ,d Common uke ns ldrs gSa] ftlls gesa nksuksa gh Classes ds Objects dks eku Set djus ds fy, nks vyx Method dks Call djus dh t:jr ugha gksxh cfYd ge nksuksa gh LFkkuksa ij ,d gh uke ds Method dks Use dj ldrs gSaA bl rjg dk ifjorZu djus ij gekjk Program fuEukuqlkj cu tk,xk% Program class Employee { private int ID; private String name; public void setData(int empID, String empName) { ID = empID; name = empName; }

}

public void showData() { System.out.println("\tName : " + name); System.out.println("\tID : " + ID); }

class Scientist extends Employee { private float salary; public void setData(int empID, String empName, float sciSalary) { super.setData(empID, empName); salary = sciSalary; }

299 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

public void showData() { super.showData(); System.out.println("\tSalary : " + salary); }

class InheritanceDemo { public static void main(String args[]) { Employee you = new Employee(); Scientist me = new Scientist(); you.setData(1000, "Mohan"); me.setData(2000, "Govind", 15000); System.out.println("Your Information"); you.showData();

}

System.out.println("\nMy Information"); me.showData();

Output Your Information Name : Mohan ID : 1000 My Information Name : Govind ID : 2000 Salary : 15000.0

bl Modified Program esa geus Super Class o Sub Class nksuksa esa gh leku dke djus okys Methods ds uke leku dj fn, gSaA tc ge Sub Class Scientist dk Object Create djrs gSa] rc bl Object dks Set djus ds fy, bl Class ds Object ds lkFk setData() Method dks Call djrs gSaA ,slk djus ij Sub Class dk setData() Method Call gksrk gS vkSj Sub Class ds setData() Method esa Super Class ds setData() Method dks Call fd;k gSA Super Class ds setData() Method dks Call djus ds fy, gesa super Keyword dk iz;ksx djuk t:jh gksrk gSA ;fn ge super Keyword dk iz;ksx uk djsa] rks Sub Class esa Super Class dk setData() Method rks Call gks tkrk gS] D;ksafd ge bl Method esa nks Argument Pass dj jgs gSa vkSj nks Argument okyk setData() Method Super Class esa gh gSA

300 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ysfdu tc ge showData() Method dks Call djrs gSa] rc pwafd Super Class o Sub Class nksuksa gh Classes esa showData() Method esa dksbZ Argument Pass ugha gks jgk gS] blfy, nksuksa gh Methods ds Signature leku gks x, gSaA bl fLFkfr esa tkok gesa”kk Sub Class ds gh showData() Method dks Execute djrk gS] Super Class ds showData() Method dks ughaA pwafd ge Sub Class ds showData() Method ls Super Class ds showData() Method dks Execute djuk pkgrs gSa] blfy, gesa bl super Keyword dk iz;ksx setData() Method ls igys djuk t:jh gksrk gSA super Keyword ,d ,slk Keyword gS] tks gesa”kk viuh Super Class dks gh Refer djrk gSA blfy, ;fn gesa Super Class ds fdlh ,sls Method dks Call djuk gks] ftldk uke o Parameters dh la[;k o Parameters ds Data Type rhuksa gh leku gksa] rks Super Class ds Method dks Call djus ds fy, gesa ,sls Method dks super Keyword ds lkFk Call djus ij Super Class dk Method Call gksrk gSA

ysfdu ;fn ge super Keyword ds lkFk bl izdkj ds Method dks Call uk djsa] rks Sub Class dk gh Method Call gksrk gSA fiNys Program esa ns[ksa rks showData() Method dk Signature Super Class o Sub Class nksuksa esa gh fuEukuqlkj gS% public void showData();

tcfd setData() Method dk Signature nksuksa gh Classes esa fuEukuqlkj vyx&vyx gSa% // In Super Class public void setData(int empID, String empName) // In Sub Class public void setData(int empID, String empName, float sciSalary)

pwafd nksuksa gh Classes esa setData() Method ds Signature vyx gSa] blfy, tc ge Sub Class esa Super Class ds setData() Method dks Call djuk pkgrs gSa] rc mlesa nks gh Arguments Pass djrs gSa] ftlls tkok Compiler nks Parameter okys setData() dks [kkstrk gS vkSj ;s Method mls Super Class esa izkIr gksrk gSA blfy, tkok Super Class ds setData() Method o Sub Class ds setData() Method esa rks vUrj dj ldrk gSA ysfdu tc ge showData() Method dh ckr djrs gSa] rc tkok ;s r; ugha dj ikrk gS fd mls Super Class ds setData() Method dks Call djuk gS] ;k Sub Class dsA ,slk blfy, gksrk gS D;ksafd tkok Compiler gesa”kk igys Sub Class esa gh setData() Method dks [kkstrk gSA ;fn mls leku Signature dk Method Sub Class esa izkIr ugha gksrk gS] rks tkok Compiler Super Class esa leku Signature ds Method dks [kkstrk gSA pwafd setData() Method dk Signature nksuksa gh Classes esa vyx gS] blfy, tkok igpku ysrk gS fd mls fdl Class ds setData() Method dks Execute djuk gS] ysfdu showData() Method nksuksa gh Classes esa leku gS] blfy, tkok Sub Class ds showData() Method dks Execute djrs le; tSls gh Super Class ds showData() Method dks [kkstrk gS] mls Sub Class dk gh Derive Method fey tkrk gS] D;ksafd nksuksa gh Classes esa bl Method ds Signature leku gSaA

301 Any Question or Suggestion, Just Discuss Here...

Java in Hindi blfy, tkok gesa”kk Sub Class ds showData() Method dks gh Execute djus yxrk gS vkSj ,d izdkj dh Infinite Looping cu tkrh gSA bl izdkj dh fLFkfr ls cpus ds fy, tkok esa super Keyword dks Add fd;k x;k gSA ge ftl Class ds Object ds lkFk Currently izfØ;k dj jgs gksrs gSa] ml Object dks this Object Refer djrk gS] tcfd ge ftl Object ds lkFk Currently izfØ;k dj jgs gSa] ml Object dh Class ds Super Class dks gesa”kk super Object ;k super Keyword Refer djrk gSA ljy “kCnksa esa dgsa rks ge ;s Hkh dg ldrs gSa fd super ,d ,slk Object gksrk gS tks viuh Current Class dh Super Class dk Object gksrk gS vkSj bl Object ds Through ge fdlh Sub Class esa mldh Super Class dks Directly Access dj ldrs gSaA ftl rjg ls ge super Keyword ds lkFk Super Class ds Method dk iz;kssx djds Super Class ds Method dks Call dj ldrs gSa] mlh rjg ls ge super Keyword ds lkFk Super Class ds Data Members dks Hkh Access dj ldrs gSaA ;kuh ;fn ge pkgsa] rks ge Sub Class esa Super Class ds ID o name Field dks fuEukuqlkj Directly Access djds Set dj

ldrs gSa%

super.ID = 5000; super.name = “Gopal”

;fn ge bl Statement dks Sub Class ds setData() Method esa Use djuk pkgsa] rks mijksDr Program dh Sub Class ds setData() Method dks gesa fuEukuqlkj Modify djuk gksxk% public void setData(int empID, String empName, float sciSalary) { super.ID = empID; super.name = empName; salary = sciSalary; }

pwafd ;fn ge Derived Class ;k Sub Class Scientist esa fiNys setData() Method ds LFkku ij bl Method dks Use djuk pkgrs gSa] rks ,slk ge rHkh dj ldrs gSa tc Super Class Employee ds Data Members Public ;k Friend gksaA D;ksafd super Keyword Super Class ds dsoy Friend, Protected o Public Data Members o Methods dks gh Sub Class esa Directly Access djus dh lqfo/kk nsrk gSA

Constructors and Inheritance

fiNys Program esa geus Employee o Scientist nksuksa gh Classes ds Objects dks Initialize djus ds fy, setData() uke ds ,d Member Function dk iz;ksx fd;k gSA ysfdu ge bu Objects dks Constructors dk iz;ksx djds Hkh Initialize dj ldrs gSaA ;fn ge blh Program esa Define dh xbZ Super Class esa Constructors dk iz;ksx djsa] rks Employee Class dks ge fuEukuqlkj Modify dj ldrs gSa% class Employee { 302 Any Question or Suggestion, Just Discuss Here...

Java in Hindi private int ID; private String name; Employee(int empID, String empName) { ID = empID; name = empName; }

}

public void showData() { System.out.println("\tName : " + name); System.out.println("\tID : " + ID); }

vc ;fn ge bl Class ds Object Create djuk pkgsa] rks Object Create djrs gh mls fuEukuqlkj Initialize Hkh dj ldrs gSa% Employee you = new Employee(1000, “Mohan”);

pwafd ge tkurs gSa fd Constructor ,d ,slk Method gksrk gS] ftldk ogh uke gksrk gS] tks ml Method dh Class dk uke gksrk gS] ftlesa Method Define fd;k tkrk gSA tc ge bl izdkj dk Statement fy[krs gSa rc Compiler you Object dks Create djrs le; Employee Class ds 2-Argument Constructor dks Call djrk gS vkSj you Object ds nksuksa Data Members dks os eku Initialize dj nsrk gS] tks eku Arguments ds :i esa Object Create djrs le; Pass fd, tkrs gSaA vc ;fn ge bl Employee Class dks Extend djsa rks Extend gksus okyh Class esa Hkh ge Constructor Define dj ldrs gSaA ;kuh ;fn ge bl Modified Employee Class ds vk/kkj ij Scientist Class dks Hkh Modify djsa] rks bl Class dks Hkh ge fuEukuqlkj Define dj ldrs gSa% class Scientist extends Employee { private float salary; Scientist(int empID, String empName, float sciSalary) { super(empID, empName); salary = sciSalary; }

}

public void showData() { super.showData(); System.out.println("\tSalary : " + salary); }

303 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl Class esa geus fQj ls super Keyword dk iz;ksx fd;k gS] ysfdu pwafd bl ckj super Keyword ls gesa Super Class ds fdlh Method dks Call ugha djuk gS] blfy, bls vdsys gh Use fd;k gSA ge ns[k ldrs gSa fd ;s Hkh ,d rjg dk Method gh gS] D;ksafd blds vkxs ,d Parenthesis gS ftlesa nks Arguments Pass fd, x, gSaA bl Method dks tkok esa super() Method dgk tkrk gS vkSj bl Method dks rHkh Use fd;k tkrk gS] tc gesa fdlh Sub Class esa ml Sub Class dh Super Class ds Constructor dks Call djuk gksrk gSA Scientist Class esa ;s super() Method Super Class Employee ds Constructor dks Call dj jgk gSA ;fn ge pkgsa rks vc ,d main() Method Class dks fuEukuqlkj Define dj ldrs gSa] ftlesa nksuksa gh Class ds Objects Create gks jgs gSa vkSj muds eku Initialize o Display

gks jgs gSa%

class ConstructorInheritance { public static void main(String args[]) { Employee you = new Employee(1000, "Mohan"); Scientist me = new Scientist(2000, "Govind", 15000); System.out.println("Your Information"); you.showData();

}

}

System.out.println("\nMy Information"); me.showData();

bl Program dk Hkh gesa ogh Output izkIr gksrk gS] tks fiNys Program dk gks jgk gSA bl Program esa geusa Employee Class o Scientist Class nksuksa Classes ds gh ,d&,d Object Create fd, gSaA tc ge Employee Class dk Object Create djrs gSa] rc pwafd Employee Class esa nks gh Data Members gSa] blfy, gesa Employee Class ds Constructor esa dsoy nks gh eku nsus gksrs gSa] ysfdu tc ge Scientist Class dk Object Create djrs gSa] rc gesa mlds Constructor esa rhu Arguments Pass djus gksrs gSaA tc ge Scientist Sub Class dk Object Create djrs gSa] rc bl Class dk 3-Argument Constructor Execute gksrk gS] tks fd fuEukuqlkj gS% Scientist(int empID, String empName, float sciSalary) { super(empID, empName); salary = sciSalary; }

bl Constructor ds igys Statement ds :i esa bldh Super Class ds Constructor dks super() Method dk iz;ksx djds Call fd;k x;k gSA pwafd Super Class ds Constructor dks gesa nks eku Pass djus gksrs gSa] ogh nksuksa eku ge super() Method esa Argument ds :i esa ns

304 Any Question or Suggestion, Just Discuss Here...

Java in Hindi nsrs gSaA Super Class ds Data Members Initialize gksus ds ckn Sub Class ds Data Members Initialize gksrs gSaA ,d ckr gesa”kk /;ku j[ksa fd Inheritance dh Hierarchy esa gesa”kk lcls igys Super Class dk Constructor Execute gksrk gSA blfy, fdlh Hkh Sub Class Constructor esa gesa gesa”kk super() Method dks lcls igys Statement ds :i esa Define djuk t:jh gksrk gSA ;fn ge ,slk ugha djrs gSa] rks Compiler Error Generate djrk gS] D;ksafd tkok esa Internally Hkh lcls igys Super Class dk Constructor Execute gksrk gS vkSj Super Class ds Data Members Initialize gksus ds ckn mldh Sub Classes ds Data Members Initialize gksrs gSaA ;kuh ;fn ge mijksDr Code Segment esa fuEukuqlkj ifjorZu djds igys Sub Class ds salary Data Member dks Initialize dj nsa% Scientist(int empID, String empName, float sciSalary) { salary = sciSalary; super(empID, empName); }

rks tkok Compiler gesa fuEukuqlkj Error Message iznku djrk gS] tks gesa crkrk gS fd super() Method dks gesa”kk igys Statement ds :i esa fy[kk tkuk pkfg,A D:\Java\ConstructorInheritance.java:25: cannot resolve symbol symbol : constructor Employee () location: class Employee { ^ D:\Java\ConstructorInheritance.java:27: call to super must be first statement in constructor super(empID, empName); ^ 2 errors

tc ge fdlh Class esa dksbZ Constructor Define ugha djrs gSa] rc Hkh tkok gesa ,d NoArgument Constructor iznku djrk gS] ftls Default Constructor dgrs gSaA blh otg ls geus fcuk fdlh Constructor dks Define fd, gq, Hkh InheritanceDemo Class ds Program esa Employee o Scientist Class ds Objects you o me dks fuEukuqlkj Create dj fy;k Fkk% Employee you = new Employee() Scientist me = new Scientist()

// No-Argument Constructor // No-Argument Constructor

ysfdu tc ge fdlh Hkh Class esa dksbZ Hkh ,slk Constructor cuk nsrs gSa] ftlesa n Arguments gksa] rks Constructor Define djus ds ckn tkok gesa Default Constructor ugha nsrk gSA bl fLFkfr esa Default Constructor Hkh gesa gh cukuk iMrk gSA mnkgj.k ds fy, fiNys Program esa Super Class Employee esa geus ,d 2-Argument Constructor Define fd;k gS] tcfd Sub Class Scientist esa geus ,d 3-Argument Constructor Define fd;k gSA bl fLFkfr esa nksuksa gh Super o Sub Classes dks tkok 305 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Default Constructor iznku ugha djrk gSA blfy, vc ;fn ge fuEukuqlkj Program Create djds Compiler djsa] rks tkok Compiler gesa vxzkuqlkj Error iznku djrk gS% Program class ConstructorInheritance { public static void main(String args[]) { Employee you = new Employee(); Scientist me = new Scientist(); System.out.println("Your Information"); you.showData();

}

}

System.out.println("\nMy Information"); me.showData();

Output D:\Java\ConstructorInheritance.java:41: cannot resolve symbol symbol : constructor Employee () location: class Employee Employee you = new Employee(); ^ D:\Java\ConstructorInheritance.java:42: cannot resolve symbol symbol : constructor Scientist () location: class Scientist Scientist me = new Scientist(); ^ 2 errors Error ds Output esa ge ns[k ldrs gSa fd nksuksa gh Errors esa Compiler gesa crk jgk gS fd mls Default Constructor ugha fey jgk gSA ;fn ge bl Program dks Hkh Bhd rjg ls Run djokuk pkgrs gSa] rks gesa Super Class o Sub Class nksuksa esa gh ,d No-Argument Constructor Define djuk gksxkA ;kuh gesa nksuksa gh Classes esa fuEukuqlkj ifjorZu djuk

gksxk%

Program class Employee { private int ID; private String name; Employee() {} Employee(int empID, String empName) { ID = empID; name = empName;

// No-Argument Constructor // 2-Argument Constructor

306 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

} public void showData() { System.out.println("\tName : " + name); System.out.println("\tID : " + ID); }

class Scientist extends Employee { private float salary;

}

Scientist() {} Scientist(int empID, String empName, float sciSalary) { super(empID, empName); salary = sciSalary; } public void showData() { super.showData(); System.out.println("\tSalary : " + salary); }

//No-Argument Constructor //3-Argument Constructor

class ConstructorInheritance { public static void main(String args[]) { Employee you = new Employee(); Scientist me = new Scientist(); System.out.println("Your Information"); you.showData(); System.out.println("\nMy Information"); me.showData(); } } Output Your Information Name : null ID : 0 My Information Name : null ID : 0 Salary : 0.0

307 Any Question or Suggestion, Just Discuss Here...

Java in Hindi pwafd Object Create djus ds fy, geus No-Argument Constructor dk iz;ksx fd;k gS] blhfy, you o me nksuksa gh Objects Un-Initialized gSa vkSj tc tkok esa dksbZ Class Data Member Un-Initialized jgrk gS] rc og Default ekuksa ls Initialize gks tkrk gSA blhfy, bl Program ds Output esa gesa mijksDr Information izkIr gks jgh gSA tc ge fdlh Class dks Extend djrs gSa] rc Extend gksus okyh Sub Class o mldh Super Class ds chp esa “Kind Of” Relationship gksrh gSA ;kuh ge ;s Hkh dg ldrs gSa fd% Sub Class is a “Kind Of” Super Class

vkSj D;ksafd ,d Super Class Object Super Class ds fdlh Hkh nwljs Object dks Refer dj ldrk gS] D;ksafd ,d gh Class ds lHkh Objects leku Type ds ;k leku izdkj ds (“Kind Of”) gksrs gSa] blhfy, Super Class dk Object Sub Class ds Object dks Hkh Refer dj ldrk gSA D;ksafd Sub Class dk Object Hkh ,d izdkj dk (“Kind Of”) Super Class dk Object gh gksrk gSA ysfdu ,d Sub Class dk Object dHkh Hkh viuh Super Class ds Object dks Refer ugha dj ldrk gS] D;ksafd gj Sub Class Type dk Object viuh Super Class Type dk ugha gksrk gSA tcfd gj Super Class Type dk Object viuh Sub Class Type dk Object rks gksrk gh gSA D;ksafd gj Sub Class esa mldh Super Class ds lHkh xq.k gksrs gh gSa] ysfdu gj Super Class esa mldh fdlh Hkh Sub Class ds lHkh xq.k ugha gks ldrs gSaA ;fn ge cgqr gh ljy “kCnksa esa bl Concept dks dgsa rks ge ;s dg ldrs gSa fd ,d Super Class dk Object viuh Sub Class ds fdlh Object dks Refer dj ldrk gS] ysfdu Sub Class dk dksbZ Hkh Object viuh Super Class dks Refer ugha dj ldrk gSA blh rjg ls fdlh Hkh Method esa fdlh Parameter ds :i esa ;fn fdlh Super Class ds Object dh t:jr gks rks ge ml Parameter esa Argument ds :i esa mldh Sub Class ds Object dks Pass dj ldrs gSa] D;ksafd Super Class dk Object Sub Class ds Object dks Refer dj ldrk gSA ysfdu ;fn fdlh Method esa Parameter ds :i esa fdlh Sub Class ds Object dh t:jr gks] rks ge mldh Super Class ds Object dks Parameter esa Argument ds :i esa Pass ugha dj ldrs gSa] D;ksafd Sub Class dk Object Super Class ds Object dks Refer ugha dj ldrk gSA bl Concept dks ge fuEu Program }kjk le> ldrs gSa% Program class Box { double width; double height; double length; Box(double wid, double hei, double len) { width = wid; height = hei; length = len;

308 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

} void getData() { System.out.println("Width = " + width); System.out.println("height = " + height); System.out.println("length = " + length); } double getVolume() { return width * height * length; }

class DerivedBox extends Box { double weight;

}

DerivedBox(double wid, double hei, double len, double wei) { super(wid, hei, len); weight = wei; } public void getData() { super.getData(); System.out.println("Weight = " + weight); }

class DerivedBoxDemonstration { public static void main(String args[]) { Box cpuCabinet = new Box(10, 20, 30); DerivedBox hardDisk = new DerivedBox(1, 2, 3, 4); double cpuCabinetVolume; double hardDiskVolume; cpuCabinetVolume = cpuCabinet.getVolume(); System.out.println("CPU Cabinet Volume = " + cpuCabinetVolume); cpuCabinet.getData();

}

}

cpuCabinet = hardDisk; hardDiskVolume = cpuCabinet.getVolume(); System.out.println("Hard Disk Volume = " + hardDiskVolume); hardDisk.getData();

309 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Output CPU Cabinet Volume = 6000.0 Width = 10.0 height = 20.0 length = 30.0 Hard Disk Volume = 6.0 Width = 1.0 height = 2.0 length = 3.0 Weight = 4.0 main() Method Class esa geus Box Class dk ,d Object cpuCabinet o DerivedBox Class dk ,d Object hardDisk Create fd;k gSA lkFk gh nksuksa dks Initialize Hkh fd;k gSA fQj double izdkj ds nks Variables cpuCabinet o hardDisk nksuksa Objects ds Volume dks Hold djus ds fy, Define fd;k gSA fQj cpuCabinet dk Volume Calculate djus ds fy, geus Box Class ds Method getVolume() dks cpuCabinet ds lkFk Call fd;k gSA

pwafd cpuCabinet Box Class dk gh Object gS] blfy, ge blds lkFk getVolume() Method dks Call dj ldrs gSaA fQj geus Box Class ds Object cpuCabinet ds Dimensions izkIr djus ds fy, getData() Method dks Call fd;k gSA vxys Statement esa geus Box Class ds Object cpuCabinet esa Box Class dh Sub Class DerivedBox Class ds Object hardDisk dk Reference fuEukuqlkj Statement }kjk iznku fd;k gS% cpuCabinet = hardDisk;

ge ,slk blfy, dj ldrs gSa D;ksafd DerivedBox Class Box Class ds izdkj (“Kind Of”) dh gh gSA tc ge ,slk djrs gSa] rc okLro esa hardDisk Object dks cpuCabinet Object }kjk Refer dj ldrs gSa vkSj hardDisk Object ds fy, tks fd Box Class dh Sub Class dk Object gSa] Box Class ds Methods dks Call dj ldrs gSaA pwafd geusa Sub Class esa getVolume() uke dk Method Create ugha fd;k gS] fQj Hkh ge Super Class Box ds getVolume() Method dk iz;ksx djds Sub Class DerivedBox ds Object dk Volume Hkh Kkr dj ldrs gSa] tSlkfd bl Program ds vxys Statement esa fd;k x;k gSA cpuCabinetVolume = cpuCabinet.getVolume(); cpuCabinet = hardDisk; hardDiskVolume = cpuCabinet.getVolume();

bu nksuksa Statement esa ge ns[k ldrs gSa fd geus nksuksa gh ckj cpuCabinet ds Reference esa gh getVolume() Method dks Call fd;k gSA ysfdu tc igyh ckj cpuCabinet ds fy, getVolume() Method dks Call djrs gSa] rc Box Class dk getVolume() Method Super Class Box ds Object cpuCabinet dk Volume Calculate djrk gS] D;ksafd bl le; cpuCabinet Object esa Box Class ds Object dk Reference gSA

310 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ysfdu tSls gh ge Box Class ds cpuCabinet Object esa DerivedBox Sub Class ds hardDisk Object dk Reference nsrs gSa] cpuCabinet uke dk Super Class dk Object Sub Class ds Object dks Refer djus yxrk gSA blfy, vc fQj ls tc ge bl cpuCabinet Object ds lkFk Super Class ds getVolume() Method dks Call djrs gSa] rks bl ckj cpuCabinet Object Box Class ds Object dh Volume Calculate djus ds ctk; DerivedBox Class ds Object dk Volume Calculate djrk gSA bl Program esa ge ns[k ldrs gSa fd geus Super Class Box ds Object cpuCabinet esa Sub Class DerivedBox ds Object dk Reference Store fd;k gSA ge ,slk dj ldrs gSa] D;ksafd Sub Class gesa”kk “Kind Of” Super Class gksrk gSA ysfdu ;fn ge bl Statement dks mYVk djsa] ;kuh Sub Class ds Object esa Super Class ds Object dk Reference iznku djsa] rks tkok Compiler gesa fuEukuqlkj Compile Time Error nsrk gS% D:\Java\DerivedBoxDemonstration.java:59: incompatible types found : Box required: DerivedBox hardDisk=cpuCabinet; ^ 1 error

tkok Compiler gesa ;s Error blfy, nsrk gS] D;ksafd Super Class dHkh Hkh “Kind Of” Sub Class ugha gksrh gS] cfYd Super Class Sub Class dk ,d Part gksrk gSA blfy, Super Class o Sub Class ds chp “Has A “ o “Part Of “ dh Relationship cu tkrh gSA pwafd ge Super Class ds Object ls fdlh Hkh Sub Class Object dks Refer dj ldrs gSa vkSj ,d Super Class Object ls gh fofHkUu izdkj dh Sub Classes ds Methods dks Call dj ldrs gSa] blfy, tkok esa ;s Process Polymorphism dh lqfo/kk iznku djrk gSA

Multilevel Hierarchy

tkok esa ge fdlh Derive dh xbZ Sub Class dks fQj ls Derive dj ldrs gSaA tc ge fdlh Derive dh xbZ Sub Class dks fQj ls Derive djrs gSa] rks bl Process dks Multilevel Hierarchy dgk tkrk gSA mnkgj.k ds fy, tkok dh lcls Top Level dh Class Object Class gSA Object Class ls awt Class dks Inherit fd;k x;k gSA fQj awt Class ls Component Class dks Derive fd;k gSA fQj Component Class ls Container Class dks Derive fd;k gSA fQj Container Class ls Panel Class dks Derive fd;k gS vkSj vUr esa Panel Class ls Applet Class dks Derive fd;k gSA bl rjg ls ge Applet Class dh Multilevel Hierarchy dks le> ldrs gSaA

Constructor Calling Convention

tkok esa tc ge fdlh Class dks Derive djrs gS] rks Super Class dk Constructor dHkh Hkh Sub Class esa ugha vkrk gSA blfy, gesa gesa”kk Sub Class ds Constructor esa Super Class ds Constructor dks Call djuk iMrk gSA tkok Multiple Hierarchy dks Support djrk gSA blfy, ge pkgs fdlh Hkh Level dh Hierarchy dh Class dks Inherit djsa] ml Inherited Class ds Object Create djrs gh Sub Class dk Constructor Execute gks tkrk gS vkSj

311 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Derived Class dk Constructor Execute gksrs gh Super Class ds Constructor dks Execute djrk gSA

;fn geus Sub Class esa dksbZ Constructor ugha cuk;k gS] rks Class dk Default ;k NoArgument Constructor Execute gksrk gS vkSj Derived Class dk Constructor Base Class ;k Super Class ds Default Constructor dks Execute dj nsrk gSA ;kuh lkjka”k esa dgsa rks ge Hierarchy esa pkgs ftl Level dh Class dk Object Create djsa] gesa”kk Hierarchy ds Top Level Class dk Constructor lcls igys Execute gksrk gS vkSj fQj Øe ls uhps dh Classes ds Constructors Execute gksrs gSaA ;fn fdlh Super Class esa dksbZ n Argument Constructor gks rks gesa Sub Class esa Hkh n Argument Constructor cukuk t:jh gks tkrk gS] tcfd ;fn Sub Class esa dksbZ n Argument Constructor gks rks Super Class esa n Argument Constructor dk gksuk t:jh ugha gksrk gSA tc ,slh fLFkfr gksrh gS] rc Sub Class dk rks n Argument Constructor Execute gksrk gS ysfdu Super Class dk No-Argument Constructor Execute gks tkrk

gSA

fdlh Sub Class ds Constructor esa Super Class ds Constructor dks Call djus ds fy, gesa super() Method dks Call djuk gksrk gSA ysfdu ;fn ge fdlh Sub Class Constructor esa mldh Super Class ds Constructor dks Call uk djsa] rks Hkh Super Class dk Default Constructor rks Execute gksrh gh gS] lkFk gh og Sub Class ds Constructor ls igys Execute gksrk gSA

Dynamic Method Dispatch – The Run Time Polymorphism

Method Overriding tkok dk ,d cgqr gh egRoiw.kZ Concept gS] D;ksafd blds iz;ksx }kjk gesa tkok esa Dynamic Method Dispatch dh lqfo/kk izkIr gksrh gS] tks fd tkok dk lcls egRoiw.kZ o Powerful Concept gSA Dynamic Method Dispatch ,d ,slk rjhdk gS] tks Program ds Runtime esa ;s r; djrk gS fd fdlh Object ds Reference esa dkSulk Method Execute gksxk uk fd Compile Time esaA Dynamic Method Dispatch blhfy, egRoiw.kZ gS D;ksafd ;gh og rjhdk gS ftlls tkok Run Time Polymorphism dks Implement djrk gSA

geus igys Hkh crk;k Fkk fd ,d Super Class dk Object ml Class dh lHkh Sub Classes ds Objects dks Refer dj ldrk gSA tkok bl Concept dks Use djds Program ds Run Time esa ;s r; dj ldrk gS fd mls fdl Method dks Call djuk gSA pfy,] Run Time Polymorphism dh bl rduhd dks le>us dh dksf”k”k djrs gSaA tc fdlh Super Class Object ds Reference esa fdlh Overridden Method dks Call fd;k tkrk gS] rc tkok dks ;s r; djuk iMrk gS fd Object ds fy, bl Overridden Method ds Super Class ds Method dks Call djuk gS ;k Sub Class ds Overridden Method dks Call djuk gSA ;s r; djus ds fy, tkok ml Object dh Class dk irk yxkrk gS vkSj ;s Identify djrk gS fd Overridden Method dks Call djus okyk og Object fdl Class dk gSA ;fn Object Sub Class dk gksrk gS] rks tkok Sub Class ds Overridden Method dks Call dj ysrk gS] tcfd ;fn Object Super Class dk gksrk gS] rks tkok Super Class ds Overridden Method dks Call dj ysrk gSA tkok ;s fu.kZ; Program ds Run Time esa ysrk gS]

312 Any Question or Suggestion, Just Discuss Here...

Java in Hindi blfy, bl izfØ;k dks Dynamic Method Dispatch ;k Run time Polymorphism dgk tkrk gSA pwafd ,d Super Class Object viuh fdlh Hkh Sub Class ds Object dks Refer dj ldrk gS] blfy, ge Super Class ds fdlh Hkh Object dks mlh Class dh fdlh Hkh Sub Class ds Object dk Reference Assign dj ldrs gSaA bl fLFkfr esa tc ge Super Class ds Object ds fy, fdlh Overridden Method dks Call djsaxs] rc tkok ml Super Class ds Object ds Reference ls ;s irk yxk ysxk fd mlesa fdl Sub Class Object dk Reference gSA Super Class ds bl Object esa ftl Sub Class ds Object dk Reference gksxk] tkok mlh Sub Class ds Overridden Method dks Call dj ysxkA bl izdkj dh fLFkfr esa ge gekjs Program esa ,d gh izdkj dk Statement fy[krs gSa] ysfdu gj Statement Run Time esa ;s r; dj ysrk gS fd mls fdl Class ds Overridden Method dks Call djuk gSA blfy, bl izfØ;k dks Polymorphism dgk tkrk gSA Polymorphism dh bl izfØ;k dks ge fuEukuqlkj Program }kjk le> ldrs gSa% Program // File Name: DynamicMethodDispatch.java class TopClass { void callme() { System.out.println("callme Method Called from the TopClass"); } } class MiddleClass extends TopClass { void callme() // Overridden callme() Method { System.out.println("callme Method Called from the MiddleClass"); } } class BottomClass extends MiddleClass { void callme() // Overridden callme() Method { System.out.println("callme Method Called from the BottomClass"); } } class DynamicMethodDispatch { public static void main(String args[]) { TopClass topObject = new TopClass(); MiddleClass middleObject = new MiddleClass(); BottomClass bottomObject = new BottomClass();

// TopClass Object // MiddleClass Object // BottomClass Object

313 Any Question or Suggestion, Just Discuss Here...

Java in Hindi TopClass reference = new TopClass(); reference = topObject; reference.callme();

// TopClass Object

// reference Refers to TopClass Object // Calls TopClass's callme() Overridden Method

reference = middleObject; // reference Refers to MiddleClass Object reference.callme(); // Calls MiddleClass's callme() Overridden Method

}

}

reference = bottomObject; // reference Refers to BottomClass Object reference.callme(); // Calls BottomClass's callme() Overridden Method

Output callme Method Called from the TopClass callme Method Called from the MiddleClass callme Method Called from the BottomClass

bl Program esa ge ns[k ldrs gSa fuEu Statement dks Program esa rhu ckj Use fd;k x;k gS] ysfdu rhuksa gh ckj ,d vyx callme() Method Execute gqvk gS] ftUgsa ge Output esa ns[k ldrs gSa% reference.callme();

bl Statement ls gj ckj vyx Class dk Overridden callme() Method blfy, Execute gqvk gS] D;ksafd gj ckj bl Statement ls igys Øe ls fuEukuqlkj ,d Statement fy[kdj Super Class ds topObject dks Sub Class ds Object dk Reference Assign fd;k x;k gS% reference = topObject; // reference Refers to TopClass Object reference = middleObject; // reference Refers to MiddleClass Object reference = bottomObject; // reference Refers to BottomClass Object

vkSj pwafd tkok Compiler mlh Object dh Class ds callme() Method dks Call djrk gS] ftldh Class ds Object dk Reference Super Class ds Object reference esa gksrk gSA blfy, gj ckj reference.callme() Statement ,d vyx Class ds callme() Method dks Call dj ysrk gSA “C++” esa ;gh dke Virtual Functions djrs gSaA vc loky ;s iSnk gksrk gS fd tkok esa bl Method Overridden Concept dh t:jr D;k gS\ rks bldk tokc ;s gS fd Method Overridden djus ls gesa tkok esa Run Time Polymorphism dh lqfo/kk izkIr gks tkrh gSA Polymorphism fdlh Hkh Object Oriented Programming Language dk ,d cgqr gh egRoiw.kZ fgLlk gksrk gS vkSj gj Object Oriented Programming Language esa Polymorphism dk Support djuk blfy, t:jh gksrk gS] D;ksafd Polymorphism ;s lqfo/kk nsrk gS fd fdlh General Class ds ftrus Hkh Methods mldh lHkh Derived ;k Sub

314 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Classes ds fy, Common gks ldrs gSa] mu lHkh Methods dks Super Class esa Define fd;k tk ldrk gSA Polymorphism }kjk iznku dh tkus okyh bl lqfo/kk ds dkj.k gesa mu lHkh dkeksa dks djus ds fy, tks fd fdlh Super Class dh lHkh Sub Classes ds fy, Common gksa] gj Sub Class esa vyx ls Methods dks Define djus dh t:jr ugha jg tkrh gS] cfYd lHkh izdkj dh Sub Classes ds fy, tks Common Methods gksrs gSa] mUgsa Super Class esa gh Define dj fy;k tkrk gS vkSj tc Hkh fdlh Sub Class esa Super Class ds ml Method dks Access djus dh t:jr gksrh gS] Polymorphism ds Concept ds vk/kkj ij Super Class ds Object esa Sub Class ds Object dk Reference Assign djds Sub Class ds Object ds fy, Super Class ds ml Common Method dks Call dj fy;k tkrk gSA

tkok esa Polymorphism dks Best rjhds ls Apply djuk bl le> ij fuHkZj djrk gS fd Super Class o Sub Class vkil esa feydj ,d izdkj dh Hierarchy Create djrs gSa] tks fd Top Level ls Lower Level dh rjQ vkrs&vkrs General Classes ls Specialized Classes esa Convert gksrs pys tkrs gSaA ;fn Super Class dks vPNh rjhds ls Use fd;k tk,] rks ,d Super Class mldh lHkh Sub Classes dks ;s lqfo/kk nsrk gS fd os Super Class ds lHkh Elements dks Directly Access dj ldrs gSaA Super Class esa mu Methods dks Hkh igys ls gh Define fd;k tk pqdk gksrk gS ftUgsa Derived Classes dks Implement djuk t:jh gksrk gSA Polymorphism Sub Classes dks ;s Flexibility iznku djrk gS fd muesa muds [kqn ds Methods dks Define fd;k tk ldsA bl rjg ls ;fn ge lkjka”k ns[ksa rks ge dg ldrs gSa fd Inheritance dks Overridden Methods ds lkFk Combine djds ,d Super Class ,sls Methods dks Define dj ldrk gS] ftUgsa ml Super Class dh lHkh Classes Common :i

ls mi;ksx esa ysus esa l{ke gksrh gSaA

Dynamic ;k Run Time Polymorphism Object Oriented Programming ds Design dk ,d Most Powerful Mechanism gS] ftlds dkj.k ge lqjf{kr rjhds ls ,d ckj Create fd, x, Codes dks ckj&ckj Reuse djus esa l{ke gks ikrs gSaA OOPS }kjk iznku dh xbZ ;s {kerk ftlls ubZ Classes ds Objects igys ls Exists Code Library ds Methods dks fcuk Recompile fd, gq, fQj ls Call dj ldrs gSa] Object Oriented Programming Design dh ,d Programmer dks feyus okyh ,d cgqr gh tcjnLr lqfo/kk gSA

pfy,] Polymorphism dk ,d vkSj mnkgj.k ns[krs gSa] ftlesa Method Overriding dk iz;ksx fd;k x;k gSA vxys Program esa Figure uke dh ,d Super Class gS] ftlesa fofHkUu 2-D Objects ds Dimension Store gksrs gSaA blesa area() uke dk ,d Method Hkh Define fd;k x;k gS] tks Object ds Area dks Calculate djrk gSA bl Program esa bl Figure Class ls nks Sub Classes Rectangle o Triangle Derive dh xbZ gSaA ;s nksuksa Sub Classes Super Class ds area() Method dks Override djrs gSa] rkfd ;s Method Øe ls Rectangle o Triangle nksuksa dk Area Return dj ldsA Program // File Name: PolymorphismArea.java class Figure {

315 Any Question or Suggestion, Just Discuss Here...

Java in Hindi double dim1, dim2;

}

Figure(double dimension1, double dimension2) { dim1 = dimension1; dim2 = dimension2; } double area() { System.out.println("\nArea of Figure is undefined "); return 0; }

class Rectangle extends Figure { Rectangle(double dimension1, double dimension2) { super(dimension1, dimension2); } double area() // Override area() for Rectangle Class { System.out.println("\nInside Area for Rectangle : "); return dim1 * dim2; } } class Triangle extends Figure { Triangle(double dimension1, double dimension2) { super(dimension1, dimension2); } double area() // Override area() for Right Triangle { System.out.println("\nInside Area for Triangle : "); return dim1 * dim2 / 2; } } class PolymorphismArea { public static void main(String args[]) { Figure newFigure = new Figure(10,10); Rectangle newRectangle = new Rectangle(6,7); Triangle newTriangle = new Triangle(12,23); Figure referenceFigure;

316 Any Question or Suggestion, Just Discuss Here...

Java in Hindi referenceFigure = newRectangle; System.out.println("Area is " + referenceFigure.area()); referenceFigure = newTriangle; System.out.println("Area is " + referenceFigure.area());

}

}

referenceFigure = newFigure; System.out.println("Area is " + referenceFigure.area());

Output Inside Area for Rectangle : Area is 42.0 Inside Area for Triangle : Area is 138.0 Area of Figure is undefined Area is 0.0

Abstract Classes

dbZ ckj ,slh fLFkfr;ka gksrh gSa tc ge tks Super Class cukrs gSa og dsoy ,d General Class ds :i esa gh Use gks ldrh gSA ,slh Class ds Direct Object Create ugha fd, tk ldrs gSaA ,slh Class ,d rjg ls v/kwjh Class gksrh gS] ftlesa Declare fd, x, lHkh Methods dks Define ;k Implement ugha fd;k x;k gksrk gSA ,d ,slh General Class ftlds lHkh xq.kksa dks mldh lHkh Sub Classes Share djsa] ysfdu Lo;a ml General Class dk Object uk Create fd;k tk lds] bl izdkj dh Class dks Abstract Class dgrs gSaA ,d Abstract Class dks gesa gesa”kk Inherit djuk gh gksrk gS] D;ksafd bl izdkj dh Class esa fofHkUu izdkj ds Methods dks Declare rks fd;k tkrk gS] ysfdu mUgsa Implement ;k Define ugha fd;k tkrk gSA cfYd bUgsa mu Sub Classes esa Implement djus ds fy, NksM fn;k tkrk gS] ftUgsa bl izdkj dh Abstract Classes ls Inherit fd;k tkrk gSA Abstract Class ,d ,slh Class gksrh gS tks mldh lHkh Sub Classes dh Common Properties o Behaviors ;kuh Common Attributes o Methods dks Describe djrh gSA pwafd Abstract Class gesa”kk lHkh Derived Classes dh Common Things dks Describe djrh gS] blfy, blds Lora= Objects ugha Create fd, tk ldrs gSaA D;ksafd Objects gesa”kk Special Classes ds Create gksrs gSa vkSj lHkh Sub Classes ds Common Members dks Represent djus okyh Class Hkh ,d Common ;k General Class gksrh gSA

mnkgj.k ds fy, Shape ,d General Class gSA blds Direct Object Create ugha fd, tk ldrs gSa] cfYd ;fn gesa Shape Object Create djuk gks] rks ge Rectangle, Triangle, Circle vkfn Shape Object Create dj ldrs gSaA ysfdu ;fn ge Shape Class dk Object Create djuk pkgsa] rks ge ,slk ugha dj ldrs gSaA D;ksafd Shape Loa; dqN ugha gksrk gSA

317 Any Question or Suggestion, Just Discuss Here...

Java in Hindi lkekU;r;k Abstract Classes rc cukbZ tkrh gSa] tc dksbZ Super Class Lo;a fdlh Meaningful Object dks Represent ugha djrk gS] cfYd fdlh Group Of Objects ds Common Features dks Represent djrk gSA gekjs fiNys mnkgj.k dh Super Class ,d Abstract Class gS vkSj gesa blds Object Create djus dh t:jr ugha gS] D;ksafd blds Objects Meaningful ugha gSaA ;fn ge Figure Class dk dksbZ Object Create djrs gSa] rks Figure Class dk Object Create djus dk dksbZ Meaning ugha gS D;ksafd Figure Loa; dqN ugha gSA ysfdu fQj Hkh ,d Class User fdlh Abstract Class ds Objects Create dj ldrk gSA bl fLFkfr esa ;fn og pkgs rks Abstract Class ds Object ds Reference esa area() Method dks Hkh Call dj ldrk gSA ysfdu pwafd Abstract Class Figure Loa; fdlh Actual Object dks Represent ugha djrk gS] blfy, blds Object ds fy, area() Method dks Call djus dk dksbZ Meaning ugha gSA blhfy, bl Class ds area() Method esa geus ,d Message gh fy[kk gSA pwafd ge tkurs gSa fd fdlh Hkh Abstract Class ds Object Create djus dk dksbZ eryc ugha gksrk gS] fQj Hkh ,d Class User fdlh Abstract Class ds Object Create dj ldrk gSA blfy, ;fn User fdlh Abstract Class ds Object Create djs vkSj User dks dksbZ Error Message izkIr gks] blls csgrj rks ;gh gS fd User dHkh fdlh Abstract Class ds Object Create gh uk dj ldsA ;s lqfo/kk ge tkok ds Abstract Methods ls izkIr dj ldrs gSaA fdlh Class dks Abstract cukus ds fy, gesa Abstract Class esa Define fd, tkus okys lHkh Methods dks Abstract Keyword ds lkFk Declare djuk gksrk gSA tc ge fdlh Class ds lHkh Methods dks Abstract Declare dj nsrs gSa] rks tkok ml Class dks Abstract Class eku ysrk gS vkSj ,d Class User dks ml Abstract Class ds Object Create ugha djus nsrk gSA bl fLFkfr esa User ;fn fdlh Abstract Class ds Object Create djrk gS] rks tkok Compiler mls ,d Error Message iznku djrk gSA fdlh Method dks Abstract Class esa Abstract Declare djus ds fy, gesa fuEukuqlkj Syntax dk iz;ksx djuk iMrk gS% abstract Return_Type Method_Name(Parameter_List);

bl Syntax esa ge ns[k ldrs gSa fd bl Method dh dksbZ Body ugha gS] cfYd Parenthesis ds ckn Semicolon dk iz;ksx djds Method dks Terminate fd;k x;k gSA ftl fdlh Class esa ,d ;k ,d ls vf/kd Abstract Methods gksrs gSa] ml Class dks Hkh gesa Abstract Declare djuk t:jh gks tkrk gSA Class dks Abstract djus ds fy, gesa Class dks fuEukuqlkj Define djuk gksrk gS% abstract class shape { abstract void area(); }

bl izdkj ls tc ge fdlh Class dks Abstract dj nsrs gSa] rc ml Class ds Objects dks new Operator dk iz;ksx djds Directly Create ugha fd;k tk ldrk gSA Abstract Classes o Methods By Default Public gksrs gSa] blfy, buds lkFk fdlh Access Specifier dh

318 Any Question or Suggestion, Just Discuss Here...

Java in Hindi t:jr ugha gksrh gSA fdlh lkekU; Method dh rjg gh ge Abstract Constructor o Abstract Static Method Create ugha dj ldrs gSaA dksbZ Hkh Class tks fd fdlh Abstract Class dks Derive djrk gS] mlesa bu Abstract Methods dks Implement djuk t:jh gksrk gSA ;fn ge ml Derived Class esa lHkh Methods Implement uk djsa] rks og Derived Class Hkh rc rd Abstract Class cuh jgrh gS] tc rd ge mldh Super Class ds lHkh Methods dks Implement uk dj nsaA pfy,] ,d mnkgj.k }kjk ge Abstract Class o Abstract Method dks le>us dh dksf”k”k djrs gSa% Program // File Name: AbstractClassNMethod.java abstract class SuperClass // Abstract Class { abstract void abstractMethod(); // Abstract Method

}

void SimpleMethod() { System.out.println("Abstract Super Class Method CALLED"); }

class SubClass extends SuperClass { void abstractMethod() { System.out.println("Implemented Super Class Method CALLED"); } } class AbstractClassNMethod { public static void main(String args[]) { SubClass objSubClass = new SubClass();

}

}

objSubClass.SimpleMethod(); objSubClass.abstractMethod();

Output Abstract Super Class Method CALLED Implemented Super Class Method CALLED main() Program esa ge ns[k ldrs gSa fd geus Abstract Super Class dk dksbZ Object Create ugha fd;k gSA ;fn ge ,slk djus dh dksf”k”k djrs gSa] rks tkok Compiler gesa ,slk djus Hkh ugha nsrk gSA fdlh Abstract Class ds lHkh Methods Abstract gksa] ,slk t:jh ugha gksrk gSA ge fdlh Abstract Class esa Simple Methods Hkh Define dj ldrs gSa vkSj bl 319 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Simple Method dks main() Method Program esa fdlh Sub Class Object ds lkFk Directly Use Hkh dj ldrs gSa] tSlkfd geus bl Program esa fd;k gSA

gkykafd Abstract Classes ds Object Create ugha fd, tk ldrs gSa] ysfdu fQj Hkh Super Class dk Reference Create fd;k tk ldrk gS] D;ksafd tkok esa Run Time Polymorphism dks Super Class ds Reference }kjk gh Implement fd;k tk ldrk gSA blfy, ;s t:jh gksrk gS fd ge fdlh Abstract Super Class ds Hkh Reference Create dj ldsa] tks ml Abstract Class dh Sub Classes ds Objects dks Refer dj ldsA pwafd geus tks Figure Program cuk;k Fkk] mlesa Hkh Super Class ds Object Create djus dk dksbZ Meaning ugha gSA blfy, ge ml iwjs Program dks Abstract Class ds :i esa fuEukuqlkj Modify dj ldrs gSa% Program // File Name: AbstractClass.java abstract class Figure { double dim1, dim2; Figure(double dimension1, double dimension2) { dim1 = dimension1; dim2 = dimension2; } abstract double area();

} class Rectangle extends Figure { Rectangle(double dimension1, double dimension2) { super(dimension1, dimension2); }

}

double area() // Implementing of Super Class’s Abstract Method { System.out.println("\nInside Area for Rectangle : "); return dim1 * dim2; }

class Triangle extends Figure { Triangle(double dimension1, double dimension2) { super(dimension1, dimension2); }

320 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

double area() // Implementing of Super Class’s Abstract Method { System.out.println("\nInside Area for Triangle : "); return dim1 * dim2 / 2; }

class AbstractClass { public static void main(String args[]) { // Figure newFigure = new Figure(10,10); Rectangle newRectangle = new Rectangle(6,7); Triangle newTriangle = new Triangle(12,23); Figure referenceFigure;

// Object Created // Object Created // Object Created // Reference Created

referenceFigure = newRectangle; System.out.println("Area is " + referenceFigure.area()); referenceFigure = newTriangle; System.out.println("Area is " + referenceFigure.area());

}

// referenceFigure = newFigure; // System.out.println("Area is " + referenceFigure.area()); }

Output Inside Area for Rectangle : Area is 42.0 Inside Area for Triangle : Area is 138.0

tkok esa fdlh Hkh Class ds Object esa gesa”kk fdlh uk fdlh Actual Memory Block dk Reference Store gksrk gSA bldk eryc ;s gksrk gS fd tkok esa fdlh Hkh Class dk Object Lo;a fdlh Memory Block dk uke ugha gksrk gS] cfYd fdlh Memory Block ds Address dk Reference bl Object esa Hold gksrk gSA ;kuh tkok esa rc rd dksbZ Actual Object Create ugha gksrk gS] tc rd fd ge new Operator dk iz;ksx djds Object Create uk djsaA tc ge new Operator }kjk dksbZ Memory Block Create djrs gSa] rc Created Memory Block dk Reference gh ml Class ds Object esa Store gksrk gSA tcfd Abstract Classes ,slh Classes gSa] ftuds Object Create ugha fd, tk ldrs gSa] ysfdu Reference rks Abstract Classes ds Hkh Create fd, tk ldrs gSa vkSj bl Program esa geus Figure uke dh Abstract Class dk Reference gh main() Method esa Create fd;k gSA blfy, ;s Program iwjh rjg ls dke djrk gS vkSj gesa mfpr Output nsrk gSA

321 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl Program esa geus dqN Lines dks Comment cuk;k gSA ;fn ge Program dh igyh Line dks Normal dj nsa] rks ;s Line Figure Class dk Object Create djsxk] tks fd lEHko ugha gSA blfy, Error Generate gksxk] vkSj pwafd Figure Class dk Object Create ugha gks ldrk gS] blh otg ls ge Figure Class ds fdlh Object ds fy, fdlh Hkh Method dks Call ugha dj ldrs gSaA blhfy, Program dh vfUre nks Lines ds Code dks Hkh Comment cuk;k gSA

Final Classes

final tkok dk ,d ,slk Keyword gS] ftldk iz;ksx fdlh dke dks Finalize djus ds fy, fd;k tkrk gSA ftl izdkj ls Abstract Classes ,slh Classes gksrh gSa] ftUgsa Inherit djuk gh iMrk gS] mlh rjg ls dqN Level dh Hierarchy ds ckn dqN ,slh Classes Hkh cu tkrh gSa] ftUgsa fdlh Hkh gkyr esa Inherit ugha fd;k tkuk pkfg, gksrk gSA

tc gesa ,slh Derive dh tkus okyh fdlh Class dks Inheritance Hierarchy dh vfUre Class cukuk gks vkSj blh Class ij Hierarchy dk vUr djuk gks] rks bl izdkj dh Class dks gesa Final Class ds :i esa Derive djuk gksrk gSA ftl rjg ge fdlh Abstract Class ds Object Create ugha dj ldrs gSa mlh rjg ls ge fdlh Final Class dks Inherit ;k Derive djds ubZ Class ugha cuk ldrs gSaA blh rjg ls tc ge ;s pkgrs gSa fd fdlh Super Class dk dksbZ Method dHkh Hkh fdlh Hkh Derived Class esa Override uk fd;k tk lds] rks ge ml Method dks Current Class dh Super Class esa Final Define dj nsrs gSaA fdlh Method dks Final Define djus ds fy, gesa dsoy ml Method ds Return Type ls igys final Keyword dk iz;ksx djuk iMrk gSA tc ge fdlh Method dks final Define dj nsrs gSa vkSj ml Class dks Derive djrs gSa] rks Derived Class esa ml final Define fd, x, Method dks Override ugha fd;k tk ldrk gSA bl izfØ;k dks ge fuEukuqlkj Code Segment }kjk le> ldrs gSa% // File Name: AbstractClass.java class Figure { final double area() { // Other Statements } } class Rectangle extends Figure { double area() // Could not Override final method { } }

322 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl Code Segment esa Sub Class esa Super Class ds final Method area() dks Override djus dh dksf”k”k dh tk jgh gS] tks fd lEHko ugha gSA bl Code Segment dks Run djus ij Error Generate gksxkA // File Name: AbstractClass.java final class Figure { double area() { // Other Statements } } class Rectangle extends Figure // Could not Inherit final Class { }

bl Code Segment esa Super Class dks Inherit fd;k tk jgk gS] tks fd lEHko ugha gSA D;ksafd Super Class ,d Final Class gSA blfy, bl Code Segment dks Run djus ij Error Generate gksxkA ftl rjg ls ge fdlh Class esa Data Member ds :i esa fofHkUu izdkj ds Data Type ds Variables ,d Class esa Compose djrs gSa] mlh rjg ls ge fdlh Class esa Data Member ds :i esa fdlh nwljh Class ds Objects dks Hkh Compose dj ldrs gSaA fiNys v/;k; rd geus Applet Class dks Derive djds vyx&vyx rjg ds Programs Create fd, FksA mlh rjg ls ge viuh Lo;a dh Classes cuk dj mUgsa Hkh fQj ls Inheritance ds Concept dk iz;kssx djds fQj ls ckj&ckj Use dj ldrs gSaA tkok esa ftruh Hkh Classes gSa] mUgsa Object uke dh ,d Class ls Inherit fd;k x;k gSA blfy, Object Class tkok dh fdlh Hkh vU; Class dh Top Level Super Class gSA blfy, ge Object Class ds fdlh Hkh Object ls fdlh Hkh vU; Class dks Refer dj ldrs gSaA D;ksafd Array dks Hkh tkok esa Classes dh rjg gh Implement fd;k tkrk gS] blfy, Object Class ds Objects fdlh Array dks Hkh Refer dj ldrs gSaA ,d Object Class esa fuEu Methods gksrs gSa] tks tkok dh lHkh vU; Classes esa Default :i ls miyC/k gks tkrs gSa] D;ksafd tkok dh lHkh vU; Classes Object Class ls gh Derived gSA Object clone() ;s Method ,d u;k Object Create djds Return djrk gS vkSj Return gksus okyk Object mlh Object dk Clone gksrk gS] ftlds Reference esa bl Method dks Call

fd;k tkrk gSA

boolean equals(Object obj) ;s Method ;s Check djrk gS fd Argument ds :i esa Pass fd;k x;k Object o bl Method dks Call djus okyk Object nksuksa leku Objects gSa ;k ughaA ;fn nksuksa leku Object gksrs gSa] rks ;s Method true Return djrk gS vkSj ;fn nksuksa Objects leku ugha gksrs gSa rks ;s Method false Return djrk gSA 323 Any Question or Suggestion, Just Discuss Here...

Java in Hindi void finalize() ;s Method fdlh Unused Object ds Recycle gksus ls igys Call gksrk gSA Class getClass() ;s Method Program ds Run Time esa fdlh Object dh Class Return djrk gSA int hashCode() ;s Method ml Object ds Hash Code dks Return djrk gS] ftlds Reference esa bl Method dks Call fd;k tkrk gSA void notify() ;s Method Invoke djus okys fdlh Object ij Wait dj jgs fdlh Thread ds Execution dks Resume djus ;kuh fQj ls Execute djus dk dke djrk gSA void notifyAll() ;s Method Invoke djus okys fdlh Object ij Wait dj jgs lHkh Threads ds Execution dks Resume djus ;kuh fQj ls Execute djus dk dke djrk gSA String toString() ;s Method Object dks Describe djus okyk ,d String Return djrk gSA void wait() void wait(long milliseconds) void wait(long milliseconds, int nanoseconds) ;s rhuksa gh Methods Execution ds fdlh nwljs Thread ij Wait djrs gSaA getClass(), notify(), notifyAll() o wait() bu pkjksa Methods dks Final Declare fd;k x;k gSA buds vykok ckdh ds Methods dks ge Override dj ldrs gSaA toString() Method ,d String Return djrk gS] tks fd ml Object dh Description gksrk gS ftlds Reference esa bl Method dks Call fd;k x;k gSA lkFk gh tc ge println() Method dk iz;ksx djds fdlh Object dks Output esa Hkstrs gSa] rc ;s Method Automatically Call gks tkrk gSA

324 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Java Interface For

Multiple Inheritance

325 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Java Interfaces – Multiple Inheritances

lkekU;r;k ,d Abstract Class esa dqN Methods dks Abstract Declare fd;k tkrk gS] tcfd dqN Methods dks lkekU; Method gh j[kk tkrk gSA ;fn ge dksbZ ,slh Abstract Class Define djsa] ftlesa lHkh Methods Abstract gksa] rks okLro esa ge ,d ,slh Class Create dj jgs gksrs gSa] ftls lEHkor;k Interface dgk tk ldrk gSA ;kuh Interface ,d iwjh rjg ls Abstract Class gksrh gS] ftlesa fdlh Hkh Method dks Implement ugha fd;k x;k gksrk gSA ge fdlh Interface dks Hkh Bhd mlh rjg ls Derive dj ldrs gSa] ftl rjg ls fdlh vU; lkekU; Class dks Derive djrs gSaA Interface Hkh ,d lkekU; Class dh rjg gh Class gksrh gSA ;kuh blesa Hkh Data Members o Methods gksrs gSaA ysfdu blds Data Members gesa”kk static final ;kuh Constants gksrs gSa] tcfd blds lHkh Methods iwjh rjg ls Unimplemented gksrs gSaA blds vykok ,d Interface dh tks nwljh lcls cMh fo”ks’krk gksrh gS og ;s gksrh gS fd tkok dh dksbZ Hkh Class ,d ls T;knk ;kuh Multiple Interfaces dks Implement dj ldrk gSA Interface dh bl fo”ks’krk ds dkj.k tkok dh Multiple Inheritance dh deh dh Hkh iwfrZ gks tkrh gSA ;kuh gkykafd tkok Directly Multiple Inheritance dks Support ugha djrk gS] ysfdu Interface dks tkok esa Multiple Inheritance ds Alternate ds :i esa Use fd;k tkrk gS] ftlls tkok esa Multiple Inheritance dh deh ugha yxrh gSA pwafd ,d Class ,d ls T;knk Interfaces dks Implement dj ldrk gS] blfy, og Class Interfaces esa Declare fd, x, lHkh Classes ds Methods dks Implement djds Interface esa Declared lHkh Methods dh Functionality Provide djus esa l{ke gks tkrk gSA gkykafd ;s rjhdk iwjh rjg ls Multiple Inheritance dh lHkh lqfo/kk,a iznku ugha dj ikrk gS] fQj Hkh ;s tkok dk ,d cgqr gh mi;ksxh Feature gS vkSj ;s Feature ;gh gS tks tkok dh Abstract Classes dks Interfaces ls Separate djrk gSA tkok gesa ;s lqfo/kk nsrk gS fd ge fofHkUu Interfaces dks ;kuh Public Methods dks fcuk Implement fd, iwjh rjg ls ,d Abstract Form esa Specify dj ldrs gSaA fQj Interface dk iz;ksx djds ge bu fcuk Implemented Interfaces ds lewg dks fdlh Hkh Class ds fy, Implement dj ldrs gSaA okLro esa Interfaces Abstract Classes ds leku gh gksrs gSa] ysfdu buesa ,d Extra Ability ;s gksrh gS fd dksbZ Hkh Class ,d ls T;knk Interfaces dks Implement dj ldrk gSA tcfd Inheritance esa ,d Abstract Class ls gh fdlh ,d Class dks Inherit fd;k tk ldrk gSA interface Keyword dk iz;ksx djds ge Interface dks mlds Implementation ls iwjh rjg ls Abstract dj ldrs gSaA ,d Interface esa ge ;s Specify djrs gSa fd mls Use djus okyh Class D;k&D;k djus esa l{ke gks ldsxkA Interface esa ge ;s Specify ugha djrs gSa] fd Interface mu dkeksa dks dSls Perform djsxk] ftUgsa Interface ls izkIr djsxkA Interface o Class dks Create djus ds Syntax esa dksbZ fo”ks’k vUrj ugha gksrk gSA ysfdu Interface esa dsoy Constant Variables gh Declare fd, tkrs gSa vkSj Interface esa Declare fd, x, Methods dh Body ugha gksrh gSA

326 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bldk Qk;nk ;s gksrk gS fd ge ftl Class esa fdlh Interface dks izkIr djuk pkgrs gSa] mlh Class esa ml Interface ds lHkh Methods dks Implement dj ysrs gSaA ,d Interface dks ,d ckj Define djus ds ckn ml Interface dks ge ftruh Classes esa pkgsa mruh Classes esa Implement dj ldrs gSaA lkFk gh ge ,d gh Class esa ,d ls T;knk Interfaces dks Implement dj ldrs gSaA ,d Interface dks Implement djus ds fy, gesa Interface esa Declare fd, x, lHkh Abstract Methods dks Class esa iwjh rjg ls Define djuk gksrk gS vkSj gj Class fdlh ,d Interface dks viuh vko”;drkuqlkj Define djus ds fy, iwjh rjg ls Lora= gksrh gSA interface Keyword iznku djds tkok gesa ;s lqfo/kk nsrk gS fd ge “One Interface, Multiple Methods” izdkj ds Polymorphism dks iwjh rjg ls Utilize dj ldsaA D;ksafd Interfaces dks bl rjg ls Design fd;k x;k gS] ftlls gesa tkok esa Run Time esa Dynamic Method Resolution ;kuh Program ds Run Time esa ;s r; djus dh lqfo/kk feyrh gS fd fdl fLFkfr esa dkSulk Method Execute gksuk pkfg,A

lkekU;r;k ,d Class ls nwljh Class esa Methods ds Call gksus ds fy, nksuksa Classes dk tkok Compiler ij Compile Time esa miyC/k gksuk t:jh gksrk gS] rkfd tkok Compiler nksuksa Classes ds Method Signatures dks Compatibility ds fy, Check dj ldsA tkok ds Classing djus ds bl rjhds esa ge ,d Limit esa Bound gks tkrs gSa] D;ksafd fdlh Hkh Sub Class dh Compiling ds fy, mldh lHkh Super Classes dh t:jr gksrh gSA Interfaces dks bl deh dks iwjk djus ds fy, Develop fd;k x;k gSA Interfaces Method ;k Method ds lewg ds Implementations dks Inheritance Hierarchy ls Disconnect dj nsrk gSA D;ksafd Interfaces Classes dh rqyuk esa ,d vyx Hierarchy esa Represent gksrs gSa] blfy, Interfaces Hierarchy ls Unrelated fofHkUu izdkj dh Classes Hierarchy leku izdkj ds Interfaces dks Implement dj ldus esa l{ke gks tkrh gSaA blhfy, ge ,d gh Interface dks vyx&vyx Classes ds fy, Implement dj ldrs gSaA

Declaring Interfaces

ftl izdkj ls ge dksbZ Class Define djrs gSa] mlh rjg ls gesa Interface Hkh Define djuk gksrk gSA ,d Interface dks ge fuEu Syntax ds vuqlkj Create dj ldrs gSa% access interface InterfaceName { Return_Type Method_Name(Parameter_List); //Un-Implemented Methods }

static final Type constantName = Value;

//Constant Data Members

bl Syntax esa access Keyword ;k rks public gksrk gS ;k fQj bls Specify ugha fd;k tkrk gSA tc bls Specify ugha fd;k tkrk gS] rc ;gka Default Access Specifier Friend gksrk gS vkSj ge bl Interface dks dsoy leku Package dh Classes esa gh Use dj ldrs gSaA tcfd public Access Specifier okys Interface dks ge fdlh Hkh Package dh Class ds lkFk Use dj ldrs gSaA interface ,d Keyword gS] tks Interface Create djus dk dke 327 Any Question or Suggestion, Just Discuss Here...

Java in Hindi djrk gSA InterfaceName gekjs Interface dk og uke gksrk gS] ftlls ge bls Access djrs gSaA ;s uke dksbZ Hkh Valid Identifier Name gks ldrk gSA pwafd ,d Interface esa lHkh Methods Abstract gksrs gSa] blfy, Methods ds Declaration esa abstract Keyword dks Use djus dh dksbZ t:jr ugha jgrh gSA fofHkUu Abstract Methods ds Parenthesis ds ckn Semicolon dk iz;ksx djds mUgsa Terminate dj fn;k tkrk gSA bUgsa Implement ugha fd;k tkrk gS] blfy, budh Body ugha gksrh gSA ge fdlh Interface esa fdlh Hkh Method dks Implement ugha dj ldrs gSaA ;fn ge fdlh Interface esa fdlh Method dks Implement ;k Define djrs gSa] rks Compiler Error Generate djrk gS] D;ksafd ,d Interface ds lHkh Methods Abstract gksrs gSa] ftUgsa mlh Class esa Implement fd;k tkrk gS] ftlesa Interface dks Use djuk gksrk gSA lkFk gh ftl fdlh Hkh Class esa gesa ftl fdlh Hkh Interface dks Use djuk gksrk gS] ml Class esa gesa Interface ds lHkh Abstract Methods dks Implement djuk t:jh gksrk gSA ge Interface ds fdlh Hkh Method dks fcuk Implement fd, ugha NksM ldrs gSaA ;fn ge ,slk djrs gSa] rks Compiler Error Generate djrk gSA Interfaces esa ge Variables Hkh Declare dj ldrs gSa] ysfdu fdlh Interface esa ge tks Hkh Variable Declare djrs gSa] os Variables gesa”kk ds fy, Public, Static o Final ;kuh Constants gksrs gSaA blfy, bUgsa Create djrs gh gesa bUgsa Initialize Hkh djuk iMrk gS vkSj pwafd fdlh Interface ds lHkh Variables Constant gksrs gSa] blfy, Interface dks fdlh Class esa Implement djrs le; Hkh ge bu Variables ds eku dks Change ugha dj ldrs

gSaA

;fn fdlh Interface dks Public Declare fd;k tkrk gS] rks mlds lHkh Data Members o Methods By Default Public gks tkrs gSaA Method dk Public gksuk blfy, Hkh t:jh gksrk gS] D;ksafd ftl Class esa Hkh ge Interfaces dks Use djrs gSa] gesa ml Class esa Interface ds lHkh Members dks Implement djus ds fy, Access djuk gh iMrk gSA blfy, ;fn bUgsa Public uk j[kk tk,] rks ge fdlh Interface ds fdlh Method dks fdlh Class esa Implement ugha dj ldsaxs] ftlls Interface dk Meaning gh [kRe gks tk,xkA fdlh Interface dks ge fuEukuqlkj Define dj ldrs gSa% public interface CalculateArea { void area(); }

Extending Interfaces

Classes dh rjg gh ge fdlh Interface dks Hkh Extend djds u;k Sub Interface Create dj ldrs gSaA ge tc Hkh fdlh Interface dks Extend djrs gSa rks Sub Interface esa Super Interface ds lHkh Abstract Methods o Data Members Inherit gks tkrs gSA Interfaces dks Extend djus ds fy, Hkh gesa ogh Syntax Use djuk iMrk gS] ftl Syntax dk iz;ksx ge Class dks Extend djus ds fy, djrs gSaA interface SubInterface extends SuperInterface

328 Any Question or Suggestion, Just Discuss Here...

Java in Hindi { }

// Constant Data Members // Abstract Method

mnkgj.k ds fy, ;fn ge fdlh Interface esa fuEukuqlkj dsoy Constants dks gh Define djsa% interface ItemInformation{ public static int code = 1000; public static String name = “Freeze”; }

rks bl Interface dks ge fuEukuqlkj Extend dj ldrs gSa% interface ItemInformation { int code = 1000; String name = “Freeze”; }

// Abstract Methods

interface Item extends ItemInformation { // Constant Data Members }

void display();

tc ge bl izdkj ls fdlh Interface dks Inherit djrs gSa] rc Sub Interface Item esa Super Interface ItemInformation ds lHkh Data Members o Methods Inherit gks tkrs gSaA ge ns[k ldrs gSa fd geus ItemInformation Interface esa nksuksa Data Members dks lkekU; Variables dh rjg Declare fd;k gSA ge ,slk dj ldrs gSa] ysfdu ge pkgs public static Keywords dk iz;skx djsa pkgs uk djsa] Interface ds lHkh Data Members By Default Constant gh gksrs gSaA gkykafd ge dbZ Classes ls ,d Sub Class dks ,d ckj esa Extend ugha dj ldrs D;ksafd tkok Multiple Inheritance dks Support ugha djrk gSA ysfdu ge dbZ Interfaces ls ,d u, Sub Interfaces dks ,d ckj esa Extend dj ldrs gSa] bl izfØ;k dks tkok Support djrk gSA ;kuh ge pkgsa rks Interfaces dks fuEukuqlkj Extend dj ldrs gSa% interface DataMemberInfo { int code = 1000; String name = “Freeze”; }

// Abstract Methods

329 Any Question or Suggestion, Just Discuss Here...

Java in Hindi interface MemberMethodInfo { // Constant Data Members }

void display();

interface MultipleInterface extends DataMemberInfo, MemberMethodInfo { int code = 1000; String name = “Freeze”; }

// Abstract Methods

gkykafd ge ,d Sub Interface esa ,d ls T;knk Interfaces dks Inherit dj ldrs gSa] ysfdu fQj Hkh ge Sub Interface esa fdlh Hkh Super Interface ds fdlh Hkh Method dks Define ugha dj ldrs gSaA lHkh Sub Interfaces vHkh Hkh Interface dh rjg gh Behave djrs gSa] Class dh rjg ughaA lkFk gh tc ge fdlh Interface dks Implement djrs gSa] rks gesa ml Interface ds lHkh Abstract Methods dks Class esa Implement djuk iMrk gSA ysfdu tc ge fdlh Sub Interface dks Class esa Implement djrs gSa] rc gesa ml Sub Interface ds rks lHkh Methods dks Class esa Implement djuk gh gksrk gS] lkFk gh ml Sub Interface dh lHkh Super Interfaces ds Abstract methods dks Hkh gesa Class esa Implement djuk t:jh gksrk gSA tc gesa fdlh Sub Interface esa ,d ls T;knk Interfaces dks Extend djuk gksrk gS] rc lHkh Super Interfaces dks Comma Operator }kjk Separate j[kk tkrk gSA ,d ckr gesa”kk /;ku j[ksa fd ge dHkh Hkh fdlh Interface esa fdlh Class dks Inherit ugha dj ldrs gSaA D;ksafd Class dks Inherit djus ij Class ds Implemented Methods Interface esa Inherit gks tk,axs] tks fd Interface ds fu;e ds f[kykQ gSA

Implementing Interfaces

D;ksafd Interface fdlh Hkh Class ds fy, dsoy ,d Declaration, Prototype ;k Template gksrk gS] blfy, gesa bl Prototype dks mlh Class esa Implement djuk gksrk gS] ftl Class esa gesa mls Use djuk gksrk gSA fdlh Interface dks Implement djuk ml Class dks Derive djus ds leku gh gksrk gSA ysfdu fdlh Class dks Derive djuk ;k ugha djuk gekjh bPNk ij fuHkZj djrk gS tcfd fdlh Interface dks Use djus ds fy, gesa mlds lHkh Methods dks viuh ml Class esa Implement djuk gh gksrk gS] ftlesa ge Interface dks Use djuk pkgrs gSaA fdlh Interface dks fdlh Class esa Implement djus ds fy, gesa implements Keyword dk iz;ksx djuk gksrk gSA fdlh Interface ds Method dks fdlh Class esa Implement djus dk Syntax fuEukuqlkj gksrk gS%

330 Any Question or Suggestion, Just Discuss Here...

Java in Hindi class ClassName [extends SuperClass] implements InterfaceName1 [,InterfaceName2, ..., InterfaceNameN] { // Class Members // Methods }

;gka ClassName Create gksus okyh ubZ Class gSA ;fn Class fdlh nwljh Super Class ls Inherit gks jgk gks] rks gesa Class dks Extend djus okys Syntax ds ckn Implement Syntax dks fy[kuk gksrk gSA InterfaceName og Interface gS] ftls ClassName uke dh Class esa Implement fd;k tk jgk gSA ge ,d ckj esa dsoy ,d gh Super Class dks Inherit dj ldrs gSa] ysfdu ge ,d ckj esa ,d ls T;knk Interfaces dks Extend dj ldrs gSaA tkok ds Interfaces dh blh lqfo/kk ds dkj.k ge tkok esa Multiple Inheritance Concept ds Alternate ds :i esa Interfaces dks Use dj ldrs gSaA vxys Program esa geus lcls igys Area uke dk ,d Interface Create fd;k gSA bl Interface dks fdlh Hkh Shape dk Area Calculate djus ds fy, Implement fd;k tk ldrk gSA blh Program esa vkxs geus Rectangle o Circle uke dh nks Classes Create dh gSa vkSj bu Classes ds Objects dk Area Calculate djus ds fy, Interface dks bu nksuksa Classes esa Implement fd;k x;k gSA bl Program esa geus Rectangle o Circle nksuksa Classes ds new Operator dk iz;ksx djds Object Create fd, gSa] tcfd blh Program esa geus Interface Area Type dk ,d Reference Create fd;k gSA ge Interface Type dk Object Create dj ldrs gSa] D;ksafd ;s Hkh ,d rjg dh Class gh gS] ysfdu Pure Abstract Class gSA fQj bl Interface Area Type ds Reference esa geus Rectangle Class ds Object dk Reference Area Type ds Reference esa Assign djds computArea() uke ds Method dks Call fd;k gSA ;s Method Interface Class esa Declare fd;k x;k Abstract Method gS] blfy, bls Rectangle Class esa Implement fd;k x;k gSA tc Interface Area Class ds Object esa Rectangle Class dk Reference gksrk gS] rc tkok Rectangle Class ds computArea() Method dks Execute djds Rectangle Object dk Area Calculate dj nsrk gSA blh rjg ls Interface ds computArea() Method dks Circle Class esa Hkh Implement fd;k x;k gS] blfy, tc ge Circle Class ds Object dk Reference Area Interface Class ds Object dks nsrs gSa vkSj mlds Reference esa computArea() Method dks Call djrs gSa] rks D;ksafd Interface Area ds Object esa Circle Class dk Reference gksrk gS] blfy, tkok Circle Class ds computArea() Method dks Call djds Area Class ds Object dk Area Calculate dj ysrk gSA Program // File Name: InterfaceImplementation.java interface Area { final static float PI = 3.14f; float computeArea(float x, float y);

331 Any Question or Suggestion, Just Discuss Here...

Java in Hindi } // Interface Implementation in Rectangle Class class Rectangle implements Area { public float computeArea(float x, float y){ return ( x * y ); } } // Interface Implementation in Circle Class class Circle implements Area{ public float computeArea(float x, float y){ return ( PI * x * y ); } } class InterfaceImplementation{ public static void main(String args[]){ Rectangle myRectangle = new Rectangle(); Circle myCircle = new Circle(); Area shape; shape = myRectangle; System.out.println("Area of Rectangle = "+shape.computeArea(10, 20));

}

shape = myCircle; System.out.println("Area of Rectangle = "+shape.computeArea(10, 20));

Output Area of Rectangle = 200.0 Area of Rectangle = 628.0

ge vyx&vyx izdkj dh fofHkUu Classes esa fdlh Interface dks Implement dj ldrs gSaA fQj Hkh Method dks Implement djus ds fy, gesa Class ds Object dks Interface }kjk Refer djuk t:jh gksrk gSA ge fdlh Class ds Method ls fdlh Implemented Method dks Execute ugha dj ldrs gSaA ,d ckr gesa”kk /;ku j[ksa fd ;fn ge fdlh Class esa fdlh Interface dks Implement djrs gSa] ysfdu ml Interface dh lHkh Methods dks Class esa Implement ugha djrs gSa] rks ftl Class esa ge Interface ds dqN Methods dks Implement djrs gSa] og Class Hkh Abstract Class cu tkrh gS vkSj ge ml Class ds Hkh Object Create ugha dj ldrs gSaA tc ge fdlh Interface dks Implement djrs gSa] rc Interface dks Implement dh tk jgh Class esa Abstract Method dks Public Form esa Implement djuk t:jh gksrk gS] pkgs geus Interface esa Method dks Public Declare fd;k gks pkgs uk fd;k gksA

332 Any Question or Suggestion, Just Discuss Here...

Java in Hindi fiNys mnkgj.k esa geus Rectangle o Circle nksuksa gh Classes esa computArea() Method dks Public Form esa Implement fd;k gS] tcfd Interface Area esa computArea() Abstract Method ds lkFk fdlh Access Specifier dk iz;ksx ugha fd;k gSA ;fn ge ,slk ugha djrs gSa] rks tkok Compiler gesa Error nsrk gSA lkFk gh Interface ds Abstract Method dk Signature o mls ftl Class esa Implement fd;k tk jgk gS] ml Class esa Implement fd, tk jgs Method] nksuksa dk Signature leku gksuk Hkh t:jh gksrk gSA os Classes ftuesa fdlh Interface dks Implement fd;k tk jgk gksrk gS] muesa vU; Non-Interface Methods Hkh Define fd, tk ldrs gSaA ge ,sls Interface Hkh Create dj ldrs gSa] ftlesa dksbZ Hkh Abstract Method uk gks] cfYd mlesa dsoy Constant Variables gh gksa] ftUgsa fofHkUu izdkj dh Classes esa leku :i ls Use fd;k tkuk gksA ;kuh ;fn dqN ,sls Constant eku gksa ftudh t:jr fofHkUu izdkj dh dbZ Classes esa iMrh gS] rks ge bl izdkj ds Constant Members dks Hkh Interface es Specify dj ldrs gSA fQj ftl fdlh Hkh Class esa gesa mu Constant Members dh t:jr gksrh gS] mu Classes esa ml Interface dks Implement dj ysrs gSaA ;s Interfaces okLro esa “C” dh ,d Header File ds leku gh dke djrs gSa] ftlesa fofHkUu izdkj ds #define izdkj ds Constants ;k const Keyword ds lkFk Declare fd, x, Constants dks Store djds j[kk tkrk gSA tc Hkh gesa fdlh Program esa bu Constant ekuksa ds lewg esa ls fdlh eku dh t:jr gksrh gS] ge ml Header File dks vius Program esa Include djds mu Constants dks Use dj ysrs gSa] mlh rjg ls bl izdkj ds Interfaces dks ge ml Class esa Implement dj ysrs gSa] ftuesa bu Interfaces esa Define fd, x, Constants dh t:jr gksrh gSA pwafd ,sls Interfaces esa dksbZ Method ugha gksrk gS] blfy, gesa Interface ds fdlh Hkh Method dks Implement djus dh t:jr ugha gksrh gSA ge Interface ds lHkh Constants dks viuh Class esa Directly Access djds Use dj ysrs gSaA bu Interfaces ds Constants dks ge Class ds fdlh Hkh Method esa Use dj ldrs gSaA bl izfØ;k dks ge fuEukuqlkj Code Segment ls le> ldrs gSa% interface OnlyConstants { int xCoordinate = 200; int yCoordinate = 250; } class ImplementOnlyConstantsInterface implements OnlyConstants { int newCoordinate = xCoordinate; void getNewCoordinate(int center) { ... ... if(yCoordinate < newCoordinate) { ...

333 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

}

}

...

tc ge bl izdkj dk Interface Create djrs gSa] rc Interface ds Data Members ,sls Constants gksrs gSa] tks fofHkUu Classes }kjk vkil esa Share gksrs gSaA bl izdkj ds Interface dks fdlh Class esa Implement djus dk eryc gksrk gS fd ge Interface ds lHkh Constants dks ,d izdkj ls viuh ml Class ds fy, Available dj jgs gSa] rkfd gekjh Class Interface ds mu lHkh Constants dks Use dj ldsA okLro esa bl izdkj ds Interfaces Classes esa fdlh Hkh rjg ls Implement ugha gksrs gSa] cfYd muesa miyC/k ;k Declared lHkh Constants gekjh Class esa miyC/k gks tkrs gSa] ftUgsa Class viuh t:jr ds vuqlkj Use dj ldrk gSA tc ge ,d ,slh Class Create djrs gSa] ftlesa fdlh Interface dks Implement rks fd;k tkrk gS] ysfdu Interface ds lHkh Methods dks Implement ugha fd;k tkrk gS] rc ,slh Class dks gesa Abstract Class Declare djuk t:jh gksrk gSA bl izdkj ds Implementation dks Partial Implementation dgrs gSaA D;ksafd bl fLFkfr esa gekjs lkeus tks Class gksrh gS] og Hkh ,d Abstract Class gksrh gS] D;ksafd Extend gksus ds ckn lHkh Interfaces Class esa vk tkrs gSaA vc ;fn ge Class esa Interface ls Extend gksus okyh lHkh Methods dks Implement ugha djrs gSa] rks Class esa Abstract Method jgrs gS vkSj ftl Class esa Abstract Method jgrs gSa] ml Class dks Abstract Class Declare djuk t:jh gksrk gSA

334 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Java Exceptions For

Error Handling

335 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Java Exception – Error Handling

dksbZ Hkh Program dHkh Hkh First Attempt esa Successfully Run gks tk,] ,slk dHkh dHkkj gh gksrk gSA fdlh Program dks Develop o Type djrs le; mlesa Mistakes jg tkuk LokHkkfod gS vkSj Program esa tc dksbZ Mistake jg tkrh gS] rc Program esa Error Generate gksrk gS vkSj Errors gesa”kk Unexpected Results iznku djrk gSA fdlh Program esa dh xbZ os xyfr;ka tks Program esa Unexpected Results Generate djrs gSa] Errors dgykrs gSaA lkekU;r;k fdlh Hkh Program esa Semantic o Logical nks rjg dh xyfr;ka gksrh gSaA tc Program dks Type djrs le; ge fdlh izdkj dh Typing Mistake djrs gSa] rks bl izdkj dh xyrh gksus ij lkekU;r;k dksbZ Program Compile ugha gksrk gSA bl izdkj dh xyfr;ksa ls tks Error Generate gksrk gS] mls Compile Time Error Hkh dgrs gSaA tcfd dqN xyfr;ka ,slh gksrh gSa] tks Logical gksrh gSaA bl izdkj dh xyfr;ksa ls tks Error Generate gksrk gS] ml Error dks Run Time Error dgrs gSaA tc fdlh Program esa Error gksrk gS] rc ;k rks Program lgh Result iznku ugha djrk gS] ;k fQj Program lkekU; :i ls Run gksrs&gksrs vpkud fdlh fo”ks’k ifjfLFkfr esa Crash gksdj Terminate gks tkrk gSA

Compile Time Errors

os lHkh Errors ftUgsa Program dks Compiler djrs le; Compiler }kjk Identify dj fy;k tkrk gS] Compile Time Errors dgykrs gSaA tc Hkh fdlh Program File esa dksbZ Error gksrh gS] tkok Compiler ml Source File dh .class File Create ugha djrk gSA blfy, tc Hkh fdlh Program dks Compile djrs le; tkok gesa dksbZ Error Display djrk gS] gesa mu Errors dks Debug djuk t:jh gksrk gS] rkfd Program Bhd rjg ls Compile o Run gks ldsA Compile Time Errors lkekU;r;k ;k rks Typing Mistake ds dkj.k Generate gksrs gSa ;k fQj Programming Code Statements dks Misplaced djus ij Generate gksrs gSaA mnkgj.k ds fy, fuEu Code Segment nsf[k,% class ErrorDemo { public static void main(String arg[]) { System.out.printnl(“Hello Java !”); } }

tc gekjs Source Program esa dksbZ Typing Mistake gks tkrh gS] rc tkok Compiler gesa ;s Hkh crkrk gS fd Program dh fdl Line esa Error gSA mnkgj.k ds fy, tc ge fiNys Program dks Compile djrs gSa] rc tkok Compiler gesa fuEukuqlkj Error Message nsrk gS] ftlesa igyh Line esa gh og gesa crk jgk gS fd Program dh 6th Line esa Error gS ftlesa tkok dks ,d ,slk Symbol ;k Statement fey jgk gS] ftls tkok ugha igpkurk gSA geus bl Program esa println() Method ds LFkku ij printnl() Method iz;ksx fd;k gSA

336 Any Question or Suggestion, Just Discuss Here...

Java in Hindi pwafd tkok esa bl uke dk dksbZ Method ugha gS] blfy, tkok ,d Error Message Display dj nsrk gSA lkFk gh tkok ml LFkku ij ,d Caret Symbol ( ^ ) }kjk gesa ;s Hkh Indicate djrk gS fd Error Statement ds fdl LFkku ij gSA D:\Java\ErrorDemo.java:6: cannot resolve symbol symbol : method printnl (java.lang.String) location: class java.io.PrintStream System.out.printnl("Hello Java !"); ^ 1 error

tkok }kjk iznku fd, tk jgs bl Error Output ds vk/kkj ij ge Program esa Appropriate Line ij tkdj ml Error dks lgh dj ldrs gSaA Program esa dbZ ckj dksbZ ,d ,slh Error gksrh gS] tks dbZ vU; nwljh Errors ds Source dk dke djrh gSA mnkgj.k ds fy, fdlh Program esa fdlh Variable dks Declare fd, fcuk gh mls Program esa Use dj fy;k tk,] rks Program gesa “undefined variable” izdkj ds cgqr lkjs Errors Display dj nsrk gS] tcfd ge tSls gh ml Variable dks Declare djrs gSa] Program dh lkjh Errors Bhd gks tkrh gSaA lkekU;r;k fdlh Hkh Program dks Debug djus dk lcls Best rjhdk ;gh gS fd Program dh lHkh Typing lEcaf/kr Errors dks Top ls Bottom dh rjQ pyrs gq, lgh djsaA ,slk djus ij ml izdkj ds Errors cgqr tYnh idM esa vk tkrs gSa] tks dbZ vU; Errors dks Generate djus dk dke djrs gSaA

Run Time Errors

dbZ ckj ,d Program vPNh rjg ls Compile gksrk gS vkSj mldh .class File Hkh curh gSA Program lkekU; rjhds ls Run Hkh gksrk gS] ysfdu fdlh fo”ks’k ifjfLFkfr ds vkrs gh Program Terminate gks tkrk gS] ;k xyr Result iznku djus yxrk gSA bl izdkj dh Errors okLro esa Logical Errors gksrh gSa vkSj bUgsa Debug djuk lcls eqf”dy dke gksrk gSA pwafd ;s Errors Program ds Run Time esa dqN fo”ks’k ifjfLFkfr;ksa esa Generate gksrs gSa] blfy, bl izdkj ds Errors dks Run Time Errors dgk tkrk gSA tc bl izdkj dh Errors Program esa Generate gksrh gSa] rc tkok Interpreter ,d Error Message Generate djrk gS vkSj Program dks Terminate dj nsrk gSA bl izfØ;k dks ge fuEu Program }kjk le> ldrs gSa] ftlesa ,d fLFkfr ds ckn ,d la[;k esa 0 dk Hkkx fn;k tkus yxrk gS] tcfd fdlh Hkh la[;k esa 0 dk Hkkx ugha fn;k tk ldrk gSA bl fLFkfr esa tc rd ,d lkekU; la[;k dk Hkkx fn;k tkrk gS] Program lgh rjhds ls dke djrk gS] tcfd tSls gh la[;k esa 0 dk Hkkx fn;k tkrk gS] Program Error Message nsrk gS vkSj Terminate gks tkrk gSA

Program class ErrorDemo2 { public static void main(String Arg[]) {

337 Any Question or Suggestion, Just Discuss Here...

Java in Hindi int x = 15, y = 5, z = 5, result=0; result = x / (y+z); System.out.println("Value of result = " + result); result = x / (y-z+1); System.out.println("Value of result = " + result);

}

}

result = x / (y-z); // Error: Division by zero System.out.println("Value of result = " + result);

Output Value of result = 1 Value of result = 15 Exception in thread "main" java.lang.ArithmeticException: / by zero at ErrorDemo2.main(ErrorDemo2.java:14)

;s Program Syntactically iwjh rjg ls lgh gS] fQj Hkh Program Run gksrs le; tc ml LFkku ij vkrk gS] ftls geus Program esa Bold fd;k gS] rc tkok ,d Error Message nsrk gS] vkSj Terminate gks tkrk gS] D;ksafd bl Statement esa x esa y-z ;kuh 0 dk Hkkx fn;k x;k gSA tkok tc bl “Division By Zero” okys Statement dks Execute djus dh dksf”k”k djrk gS] rc ,d Error Generate gksrk gS] ftlds Reaction esa Program ,d Error Message nsrk gS vkSj Terminate gks tkrk gSA

Exceptions

tkok Exception ,d Object gksrk gS] tks fdlh Run Time Error dks Represent djrk gSA ;s ,d rjg dk Exception Event Object ;k Abnormal Event Object gS] tks rc Generate gksrk gS] tc Program vius Normal Flow ls vpkud Disturb gks tkrk gSA tkok Program esa tc Hkh dksbZ Run Time Error Generate gksus dh lEHkkouk gksrh gS] rks ml Run Time Error dks Exception dgk tkrk gSA tkok Interpreter Program dks Normal Flow esa Run djrk jgrk gSA ysfdu ;fn fdlh dkj.ko”k tkok Interpreter dks dksbZ Statement Execute djus esa ijs”kkuh gksrh gS] rks tkok Interpreter ml Statement ls lEcaf/kr ijs”kkuh dks ,d Object Create djds Represent djrk gSA bl Object dks Exception Object dgk tkrk gSA tc tkok Interpreter dksbZ Exception Object Create djrk gS] rks lkekU; Hkk’kk esa bls Exception Object Throw djuk dgk tkrk gSA ;kuh tkok dks tc Hkh dHkh fdlh Statement dks Run djus esa ijs”kkuh gksrh gS] tkok ,d Exception Object Create djds Throw djrk gSA ;fn tkok dksbZ Exception Object Throw djrk gS vkSj ml Exception Object dks gekjs Program dk dksbZ Hkh Error Handling Method Catch djds lgh rjhds ls Handle ugha djrk gS] rks og Error Object tkok ds Default Exception Handler ij pyk tkrk gS vkSj tkok dk Default Exception Handler ml Exception dks Handle djus ds Response esa ,d Error Message Display djds Program dks Terminate dj nsrk gSA tc bl izdkj dh 338 Any Question or Suggestion, Just Discuss Here...

Java in Hindi fdlh Error ls Program Terminate gksrk gS] rks bl izfØ;k dks Program dk Crash gksuk dgrs gSaA lkekU;r;k ge ;s dHkh ugha pkgrs gSa fd gekjk Program dHkh Hkh fdlh Hkh fLFkfr esa fcuk Proper Output fn, Terminate gks tk, ;k Crash gks tk,A ge gesa”kk ;gh pkgrs gSa fd gekjk Program gesa”kk lgh rjg ls Run gks vkSj gesa”kk lgh Result gh iznku djsA bl fLFkfr esa ;s t:jh gks tkrk gS fd ;fn dHkh fdlh Program esa fdlh izdkj dh dksbZ Run Time Error Generate gks Hkh tkrh gS] rks Hkh gekjk Program Continue jgs vkSj vius Program esa ;s fLFkfr ge rHkh izkIr dj ldrs gSa] tc ge Program dh fofHkUu Run Time Errors dks Handle djus ds fy, igys ls gh dksbZ uk dksbZ O;oLFkk dj nsaA tkok esa Exceptions dks Handle djus ds fy, ,d lqO;ofLFkr Object Oriented Approach dks Develop fd;k x;k gSA tkok esa tc Hkh dksbZ Exception Generate gksrk gS] tkok ml Exception dks Represent djrk gqvk ,d Object Create djds Throw djrk gSA bl Object esa Generate gksus okyh Error ls lEcaf/kr tkudkfj;ka gksrh gSaA tkok }kjk Throw fd, tkus okys bl Exception Object dks ,d Exception Handler Method esa Catch dj fy;k tkrk gSA pwafd bl Object esa Exception ls lEcaf/kr tkudkfj;ka Hkh gksrh gSa] blfy, bl Object dks Bhd rjhds ls Manage djds Program Control dks fQj ls mlh Statement ls vxys Statement ij Hkst fn;k tkrk gS] ftl Statement ij Exception Generate gqvk FkkA pwafd Exception Handling Method Program Control dks fQj ls ml Statement ls vkxs ds lHkh Statement dks lkekU; rjhds ls Execute djus ds fy, Hkst nsrk gS] tgka Exception Generate gqvk Fkk] blfy, Exception Generate gksus ij Hkh Program Crash gks dj Terminate ugha gksrk gSA Exception dks bl izdkj ls Handle djus dh Process dks “Exception Handling Process” dgk tkrk gSA Exception Handling Process ,d ,slk Mechanism gS] tks gesa fdlh Error dks Detect djus dh lqfo/kk nsrk gS] rkfd ge ml Exception dks Handle dj ldsaA bl Mechanism esa vyx ls ,d Error Exception Handling Code Block fy[kk tkrk gSA ;s Code Block fuEu dke djrk gS% Problem Find djrk gSA (Hit the Exception) dksbZ Exception Generate gksus ij Inform djrk gSA (Throw the Exception) Error dh Information dks Exception Object ls Receive djrk gSA (Catch the Exception) mfpr Action Perform djrk gSA (Handle the Exception)

lkekU;r;k Error Handling Code ds nks Hkkx gksrs gSaA igyk Hkkx Error dks Detect djrk gS vkSj Exception Object Throw djrk gS rFkk nwljk Hkkx Exception dks Handle djus ds fy, Appropriate Actions Perform djrk gSA ge tc Hkh dksbZ Program fy[krs gSa] gesa gesa”kk ;s r; djus dh dksf”k”k djuh gksrh gS fd fdl fLFkfr esa fdl izdkj dk Exception Generate gks ldrk gS vkSj ml Exception dks fdl izdkj ls Handle fd;k tkuk pkfg,A tkok esa Exception Handling dks eq[;r;k ikap Keywords try, catch, throw, throws o finally }kjk Manage fd;k tkrk gSA ge ftl Program Statement dks Exception ds fy, Monitor djuk pkgrs gSa ;k tks Code Statements Exceptions Generate dj ldrs gSa] mu 339 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Statements dks ge try Block esa fy[krs gSaA try Block esa fy[ks x, Code Statements esa ;fn dksbZ Exception Generate gksrk gS] rks try Block ml Exception Object dks Throw djrk gSA try Block }kjk Throw fd, x, Exception Object dks Catch djus ds fy, try Block ls Just uhps catch Block fy[kk tkrk gSA catch Block try }kjk Throw fd, x, Exception Object dks Catch djds Appropriate Actions Perform djrk gS vkSj Program Control dks fQj ls try Block esa ml Statement ls vxys Statement ij Hkst nsrk gS] tgka Exception Generate gqvk FkkA System Generated Exceptions dks tkok Lo;a gh Automatically Java Run Time Environment ij Throw dj nsrk gSA ge Manually Hkh fdlh Exception dks Throw dj ldrs gSaA fdlh Exception dks Manually Throw djus ds fy, gesa tkok ds throw Keyword dk iz;ksx djuk iMrk gSA ;fn dksbZ Method ,slk Exception Generate djus esa l{ke gks] ftls og Method Loa; Handle ugha dj ldrk gS] rks bl izdkj ds Exception dks og Method Handle djrk gS] tks Method Exception Generate djus okys bl Method dks Call djrk gSA

bl izdkj dh fLFkfr ftlesa Method Exception Throw dj ldrk gS] Exception dks Throw djokus ds fy, gesa throws Keyword ds Statement dk iz;ksx djuk iMrk gSA throws Statement dk iz;ksx mu Exceptions dh List Create djus ds fy, fd;k tkrk gS] ftUgsa Method Throw djrk gSA tc Hkh dHkh fdlh Statement ij dksbZ Exception Generate gksrk gS] Program Control ml Statement ls vkxs ds Statements dks Ignore dj nsrk gSA ysfdu dqN fLFkfr;ka ,slh gksrh gSa] ftlesa fdlh Statement ij Exception Generate gksus ds ckotwn Hkh Program ds dqN vU; Statement dk Execution djus ds ckn gh ml Exception dks Handle djuk gksrk gSA bl izdkj ds ftrus Hkh Statements gksrs gSa] ftUgsa fdlh Hkh fLFkfr esa Exception Handling ls igys gh Execute djuk t:jh gksrk gS] mUgsa finally Block esa fy[kk tkrk gSA fdlh Exception dks Handle djus dk General Block fuEukuqlkj gksrk gS% try {

// Block of codes to be monitored for errors } catch(ExceptionType1 excepObj) { // Exception Handler for ExceptionType1 } catch(ExceptionType2 excepObj) { // Exception Handler for ExceptionType2 } ... ... ... catch(ExceptionTypeN excepObj) {

340 Any Question or Suggestion, Just Discuss Here...

Java in Hindi // Exception Handler for ExceptionTypeN } finally(ExceptionType2 excepObj) { // Block of codes which must be executed before try block ends }

;gka ExceptionType og Class gS] ftlds Exception Object Throw gq, gSaA blls vkxs ds v/;k; esa ;gh crk;k x;k gS fd ge Exception Handling dh bl rduhd dks fdl izdkj ls Use dj ldrs gSaA

Exception Types tkok esa ftrus Hkh izdkj dh Exceptions dks Represent djus okyh ExceptionType Classes gSa] os lHkh Built-In Throwable Class dh Sub Classes gSaA vr% Throwable Class Exception Hierarchy Classes dh Top dh Super Class gSA Throwable Class dh nks Sub Classes gSa] tks fdlh Exception dks nks Distinct Branch esa foHkkftr dj nsrk gSA igyh Sub Class dk uke Exception gSA bl Class dk iz;ksx Exceptional Condition ;kuh Exception dks Represent djus okys Object dks Create djds Throw djus ds fy, fd;k tkrk gS] ftls gekjk Program catch Block esa Catch djrk gSA lkFk gh ;fn ge gekjs Lo;a ds Exceptions dh Custom Class cukuk pkgrs gSa] rks og ubZ Class blh Sub Class dh Sub Class gksrh gSA Exception Class dh ,d vkSj cgqr gh egRoiw.kZ Class gS] ftls RuntimeException Class dgk tkrk gSA Division By Zero, Invalid Array Indexing blh izdkj ds Exceptions ds mnkgj.k gSaA fofHkUu izdkj ds Runtime Exceptions gekjs }kjk Create fd, tk jgs fdlh Hkh Program dh Class ds fy, Automatically Define gks tkrs gSaA Throwable Class dh nwljh Sub Class dk uke Error Class gSA ;s mu Exceptions dks Define djrs gSa] ftUgsa Program ds Normal Flow esa Catch fd, tkus dh lEHkkouk ugha gksrh gSA Error izdkj ds Exceptions dks Java Runtime Environment System Loa; Handle djrk gSA Stack Overflow gksuk blh izdkj dh ,d Error gS] ftls tkok Loa; Handle djrk gSA blds fy, ge gekjs Program esa fdlh izdkj dh dksbZ O;oLFkk ugha djrs gSaA

try and catch Block – The Exception Handling Process gkykafd tkok dk Default Exception Handler Debugging ds fy, dkQh mi;ksxh gS] fQj Hkh fdlh Hkh Program esa Generate gksus okys fdlh Hkh Exception dks vDlj ge Lo;a gh Handle djrs gSaA ,slk djus ls nks Qk;ns gksrs gSaA igyk ;s fd gesa Error dks Fix djus dh lqfo/kk fey tkrh gS vkSj nwljk ;s fd blls Program Automatically Terminate ugha gksrkA tc gesa fdlh Code Statement dks Exception ds fy, Monitor djuk gksrk gS] rc ge ml Statement Block dks try Block esa fy[krs gSa vkSj bl Block ds Just vkxs catch Block fy[krs gSa] ftlesa ge ml Exception ds Type dks Specify djrs gSa] ftls ge catch Block esa Catch djuk pkgrs gSaA bl izfØ;k dks le>us ds fy, fuEu Program nsf[k,] ftlesa Division By Zero Exception dks Handle fd;k x;k gS%

341 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Program class ExceptionDivisionByZero { public static void main(String args[]) { int number, divider; try {

divider = 0; number = 10 / divider;

System.out.println(“This will not be printed.”); } catch(ArithmeticException ae) { System.out.println(“Division by zero.”); } System.out.println(“After catch statement”); }

} Output Division by zero. After catch statement

ge ns[k ldrs gSa fd try Block esa fy[kk x;k println() Statement Execute ugha gks ik;k gSA ,slk blfy, gksrk gS] D;ksafd tSls gh Exception Generate gksrk gS] try Block ,d Exception Object Throw djrk gS] ftls catch Block Catch djrk gSA ;kuh Program Control Exception Object ds lkFk gh try Block ls ckgj fudy dj catch Block esa vk tkrk gS] blhfy, try Block dk println() Statement Execute ugha gks ikrk gSA try o catch Block ,d Unit ds :i esa dke djrs gSaA catch Block rHkh Execute gksrk gS] tc try Block esa dksbZ Exception Generate gksrk gSA Throwable Class esa Object Class }kjk Define fd, x, toString() Method dks Override fd;k x;k gS] rkfd Throwable Class Exception dh Description dks String ds :i esa Display fd;k tk ldsA Exception dh Description dks ,d Argument ds :i esa println() Method esa Pass djds Display djok ldrs gSaA ;kuh try Block }kjk Throw fd, tkus okys fdlh Exception Object dks catch Block esa ge fuEukuqlkj fdlh println() Statement }kjk Hkh Display djok ldrs gSa% Program class ExceptionDivisionByZero{ public static void main(String args[]){ int number, divider; try{

divider = 0; number = 10 / divider;

342 Any Question or Suggestion, Just Discuss Here...

Java in Hindi System.out.println("This will not be printed.");

}

}

} catch(ArithmeticException ae){ System.out.println("Exception : " + ae ); } System.out.println("After catch statement");

Output Exception : java.lang.ArithmeticException: / by zero After catch statement

gkykafd bl izdkj ds Description dk User ds fy, dksbZ egRo ugha gksrk gSA ysfdu fQj Hkh tc ge fdlh Program dks Debug dj jgs gksrs gSa] ml le; bl izdkj ds Description dk ,d Programmer ds fy, dkQh mi;ksx gksrk gSA

Multiple catch Blocks dbZ ckj ,slh ifjfLFkfr;ka gksrh gSa fd ,d gh try Block ls ,d ls T;knk izdkj ds Exceptions Generate gks ldrs gSaA bl izdkj dh fLFkfr;ksa dks Solve djus ds fy, ge ,d ls T;knk catch Block dks Use dj ldrs gSa] tgka gj catch Block ,d vyx izdkj ds Exception dks Handle djus dk dke djrk gSA tc try Block dksbZ Exception Object Throw djrk gS] rc fofHkUu catch Blocks esa Throw fd, x, Object ds Type dks Check fd;k tkrk gSA ftl catch Block dk Type Throw fd, x, Object ds leku gksrk gS] og catch Block Execute gks tkrk gS vkSj vU; catch Blocks Bypass gks tkrs gSaA bl izfØ;k dks ge fuEukuqlkj mnkgj.k }kjk le> ldrs gSa% Program class MultipleCatchBlock { public static void main(String args[]) { try { int number = args.length; System.out.println("Command Line Arguments = " + number); int x = 122/number; int y[] = {1}; y[10] = 99; } catch(ArithmeticException ae) {

343 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

}

System.out.println("Arithmetical Exception : Divide by zero"); } catch(ArrayIndexOutOfBoundsException ae) { System.out.println("Array Bound Exception :" + ae); } System.out.println("After try / catch Blocks.");

Output: For ArithmeticException Catch Block Command Line Arguments = 0 Arithmetical Exception : Divide by zero After try / catch Blocks. Output: For ArrayIndexOutOfBoundsException Catch Block Command Line Arguments = 1 Array Bound Exception :java.lang.ArrayIndexOutOfBoundsException After try / catch Blocks.

bl Program esa ;fn dksbZ Command Line Parameter iznku ugha fd;k tk,xk] rks blesa Division By Zero dh Error Generate gksxhA pwafd ;s ,d Arithmetical Type Exception gS] blfy, bl Exception dks Program dk igyk catch Block Catch djsxkA tcfd ;fn User Command Prompt ij ,d Hkh Argument Pass djrk gS] rks Division By Zero dh Exception Generate ugha gksrh gS] cfYd ArrayIndexOutOfBoundsException Generate gksrh gSA pwafd Array dh Size rks 1 gS vkSj ge Index Number 10 ij eku 99 dks Store djuk pkgrs gSa] tks fd lEHko ugha gSA blfy, Array ds Bound ls lEcaf/kr Exception Generate gksrk gS] tks Program ds nwljs catch Block }kjk Handle gksrk gSA tc ge Multiple Catch Block Statement Use djrs gSa] rc gesa bl ckr dk /;ku j[kuk gksrk gS fd Exception Sub Class ds Exception dks Handle djus dk catch Block fdlh Hkh vU; Super Class Block ls igys Define gksuk t:jh gksrk gSA gesa ,slk blfy, djuk t:jh gksrk gS D;ksafd ,d ,slk catch Block tks ,d Super Class dks Use djrk gS] og Super Class ds Exceptions dks rks Catch djsxk] lkFk gh og Sub Class ds Hkh lHkh Exceptions dks Catch dj ysxk] D;ksafd gj Sub Class “Kind Of” Super Class gksrk gS vkSj dksbZ Super Class Reference Object fdlh Hkh Sub Class ds Object dks Refer dj ldrk gSA blfy, ;fn ge fdlh Super Class ds catch Block dks mlds fdlh Hkh Sub Class ds catch Block ls igys Define dj nsaxs] rks Throw fd;k x;k Sub Class Object dHkh Hkh mlds Sub Class catch Block rd ugha igqap ik,xkA blfy, tc Hkh gesa Multiple catch Block dks Use djuk gksrk gS] gesa gesa”kk lcls igys Sub Classes ds catch Block dks Define djuk gksrk gS vkSj lcls vUr esa mudh Super Class ds catch Block dks Define djuk gksrk gSA bl Process dks fuEukuqlkj ,d Program }kjk le>k;k x;k gS% Program class MultipleCatchBlockHiearchy{ public static void main(String args[])

{

344 Any Question or Suggestion, Just Discuss Here...

Java in Hindi try{

int x = 0; int y = 12/x;

} catch(Exception ae){ System.out.println("Generic Exception catch block."); }

}

}

catch(ArithmeticException ae){ System.out.println("This statement never reached"); }

Output D:\Java\MultipleCatchBlockHiearchy.java:17: exception java.lang.ArithmeticException has already been caught catch(ArithmeticException ae) ^ 1 error

;fn ge bl Program dks Compile djus dh dksf”k”k djrs gSa] rks gesa ,d Error Message izkIr gksrk gS] tks ;s crkrk gS fd ftl Exception dks catch djus ds fy, bl catch Block dks fy[kk x;k gS] og Exception Object bl catch Block rd vkus ls igys gh Catch gks jgk gSA D;ksafd ArithmeticException Class Exception Class dh Sub Class gS vkSj geus Exception Class ls lEcaf/kr lHkh Exceptions dks Handle djus ds fy, igys gh catch Block Define dj fn;k gSA pwafd ge tkurs gSa fd lHkh izdkj ds Exception Objects “Kind Of” Exceptions gh gSaA ;kuh ftrus Hkh Exception Object Generate gksrs gSa] mUgsa Super Class Exception }kjk Catch fd;k tk ldrk gS] blfy, ArithmeticException tks fd Exception Class dh Sub Class gS] bl Exception dks Handle djus okys catch Block rd tkok dHkh Hkh ugha igqap ik,xkA bl Exception dks handle djus ds fy, t:jh gS fd ge igys fofHkUu Sub Classes ds Exceptions dks Reverse Hierarchy ds :i esa Define djsa vkSj lcls vUr esa Super Class Exception ds catch Block dks Define djsaA ;kuh gesa blh Program dks fuEukuqlkj Define

djuk gksxk%

Program class MultipleCatchBlockHiearchy { public static void main(String args[]) { try {

int x = 0; int y = 12/x;

345 Any Question or Suggestion, Just Discuss Here...

Java in Hindi } catch(ArithmeticException ae) { System.out.println("Now this statement is reachable."); }

}

}

catch(Exception ae) { System.out.println("Generic Exception catch block."); }

Output Now this statement is reachable.

dbZ ckj ,slh fLFkfr;ka gksrh gSa] fd catch Block dks Define fd, fcuk ge Program dks Normal Flow esa Run ugha dj ldrs gSa vkSj catch Block esa gesa dqN Extra Ordinary dke djuk ugha gksrk gSA bl fLFkfr esa catch Block dks Define rks fd;k tkrk gS] ysfdu ml Block esa dksbZ Statement ugha fy[kk tkrk] cfYd Definition Block dks Empty NksM fn;k tkrk gSA tc gesa fdlh Exception dks Handle ugha djuk gksrk gS] rc ge fuEukuqlkj fdlh Exception dks Skip dj ldrs gSa% Program class NothingToDoInCatch { public static void main(String args[]) { try { }

}

}

int x = 0; int y = 12/x;

catch(ArithmeticException ae) { System.out.println("Hello"); } System.out.println("Nothing done in catch block.");

Output Hello Nothing done in catch block.

346 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Nested try Statement ge try Statement Block dks Hkh Nested dj ldrs gSaA ge tSls gh ,d try Block ls nwljs try Block esa izos”k djrs gSa] fiNys try Block dh lHkh Information Stack esa Store gks tkrh gSaA ;fn ,d Inner try Block dk catch Block uk gks] rks try Block Outer try ds catch Block dks Exception Throw djrk gSA ;fn dksbZ Hkh Outer catch Block Inner try Block ds Exception dks Handle ugha dj ikrk gS] rks tkok Run Time Environment ml Inner Exception Block ds Exception dks Handle dj ysrk gSA

The throw Keyword vHkh rd geus ftrus Hkh mnkgj.k ns[ks gSa] muesa JRE dksbZ Exception Throw djrk gS vkSj Program dk catch Block ml Exception dks Catch djds Handle djrk gSA blds vykok ge fdlh t:jr dks iwjk djus ds fy, vyx ls Hkh fdlh Exception dks throw Statement dk iz;ksx djds Throw dj ldrs gSaA throw Statement, General Form fuEukuqlkj gksrk gS% throw ThrowableObject;

bl Statement esa ThrowableObject Throwable Class ;k mlds fdlh Sub Class dk Object gksrk gSA Basic Data Types tSls fd int, char, float vkfn vkSj blh rjg ls dksbZ Hkh Non-Throwable Class tSls fd String o Object, bUgsa ge Exceptions dh rjg Use djds Throw ugha dj ldrs gSaA fdlh Throwable Object dks izkIr djus ds nks rjhds gks ldrs gSaA igys rjhds esa fdlh Parameter ds :i esa Throwable Object dks Use fd;k tkrk gS] tSlkfd fiNys mnkgj.kksa esa geus fd;k gS vkSj nwljs rjhds esa new Operator dk iz;ksx djds Throwable Class dk ,d Object Create fd;k tkrk gSA dbZ ckj ge dqN fo”ks’k fLFkfr;ksa esa ge Lo;a dksbZ Exception Throw djuk pkgrs gSa] rkfd Program User ;fn dksbZ xyrh djrk gS] rks ml xyrh dks lq/kkj ldsA mnkgj.k ds fy, ekuyks fd User fdlh Password Form ij Login djrs le; xyr Login ID Enter dj nsrk gS vkSj ge pkgrs gSa fd ;fn User xyr Login ID Enter djs] rks ,d Error Message vkuk pkfg,A bl fLFkfr esa ge Lo;a dk Exception Object Throw dj ldrs gSaA tc ge fdlh fo”ks’k ifjfLFkfr esa viuk Lo;a dk Exception Object Throw djrs gSa] rks throw Statement ds rqjUr ckn Program dk Normal Execution :d tkrk gSA tgka ls fdlh Exception dks Throw dj fn;k tkrk gS] ml Statement ls vkxs ds fdlh Hkh Statement dk Execution ugha gksrk gSA fQj lcls ikl ds try Block dks Check fd;k tkrk gS] fd Throw gksus okys Exception dks Handle djus ds fy, bl try Block dk dksbZ catch Block Match djrk gS ;k ughaA ;fn ml try Block ds fdlh catch Block esa Matching Class dk Exception Holder fey tkrk gS] rks Program Control ml Statement ij Transfer gks tkrk gSA ysfdu ;fn dksbZ Matching catch Block izkIr ugha gksrk gS] rks vxyk try Block Check fd;k tkrk gSA ;fn iwjs Program esa dksbZ Hkh Matching Exception Handler ugha feyrk gS] rks Program Crash gks tkrk gS vkSj JRE dk Default Exception Handler Generated Exception dks Handle djds Program dks Terminate dj nsrk gSA bl iwjh izfØ;k dks ge fuEukuqlkj ,d Program }kjk le> ldrs gSa% 347 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Program import java.io.* ; import java.lang.Exception ; public class gradeTest { public static void main( String[] args ) { try { int firstValue = 100, secondValue = 200; if(firstValue < secondValue) { throw new Exception("First Value is Less then Second Value"); }

}

}

} catch( Exception excp ) { System.out.println( "Exception: " + excp.getMessage() ) ; }

bl Program esa geus try Block esa nks Integer izdkj ds Variables Declare fd, gSa] lkFk gh mUgsa Initialize Hkh dj fn;k gSA fQj ,d if Statement Block esa firstValue Variable ds eku dks secondValue Variable ds eku ls Check djok;k gSA pwafd firstValue esa eku 100 gS] tcfd secondValue esa eku 200 gS] blfy, if Condition True gks tkrh gS vkSj if Statement Block dk Execution gks tkrk gSA bl if Statement Block esa Exception Class dk ,d u;k Object Create fd;k x;k gS vkSj mlds Constructor esa ,d Message dks Store fd;k x;k gSA lkFk gh bl Exception Type ds Object dks Throw fd;k x;k gSA bl Exception dks catch Block esa Catch dj fy;k tkrk gSA catch Block bl Exception dks excp Object esa izkIr djrk gSA getMessage() Method Exception Object excp esa Hold gksus okys ml Message dks Return djrk gS] tks Message geus try Block ds Constructor esa Exception Object dks Provide fd;k gSA blfy, tc bl Program dks Execute djrs gSa rc gesa Output esa fuEukuqlkj ,d Message Display gks tkrk gS% Exception: First Value is More then Second Value

bl Program esa rks geus Super Class Exception dk gh Object Throw fd;k gSA ysfdu ;fn gesa irk gks fd fdlh fo”ks’k fLFkfr esa fdl izdkj dk Exception Generate gks ldrk gS] rks ge Particular ml Sub Class ds Hkh Object Create djds Throw dj ldrs gSa vkSj catch Block esa ml Exception dks Catch dj ldrs gSaA

348 Any Question or Suggestion, Just Discuss Here...

Java in Hindi The throws Keyword ;fn gesa ,slk yxrk gS fd ge tks External Function ;kuh ,slk Method tks fdlh Class esa Define ugha fd;k tkrk gS] cfYd Class ds ckgj ,d Lora= Method dh rjg Define fd;k tkrk gS] og Method fdlh uk fdlh rjg dk Exception Generate dj ldrk gS] lkFk gh ge ;s Hkh tkurs gSa fd tks Method Exception Generate dj ldrk gS] og Method ml Exception dks Handle ugha djsxk] rks ge ml Method ds Exception dks throws Keyword }kjk fuEukuqlkj Syntax esa Throw dj ldrs gSa% AccessSpecifier ReturnType FunctionName(ParameterList) throws ExceptionList { // Body }

tc ge bl izdkj ds Syntax ls fdlh Exception dks Throw djrs gSa] rc ge ftl Class esa bl Lora= Function dks Use djrs gSa] bl Function ls Generate gksus okys Exception dks Handle djus dh ftEesnkjh Hkh mlh Class ds catch Block dh gks tkrh gSA bl Syntax esa fuEu nks “kCnksa ds vykok iwjk Function Syntax mlh rjg dk gS] ftl rjg dk fdlh vU; lkekU; Member Method dk Definition Syntax gksrk gS% throws ExceptionList

tc dksbZ Function dksbZ Exception Generate djrk gS] rc og Function fofHkUu izdkj ds Exception dks Throw dj ldrk gSA ;gka ge ExceptionList ds LFkku ij mu fofHkUu izdkj ds Exceptions dks Specify dj ldrs gSa] ftUgsa og Method Throw dj ldrk gSA mnkgj.k ds fy, ekuyks fd geus tks Function Create fd;k gS] og Method Arithmetical o Array ls lEcaf/kr Exceptions dks Throw dj ldrk gSA rks bl Function dks ge fuEukuqlkj Define dj ldrs gSa% public void ExceptionTestFunction() throws ArithmeticalException, IllegalAccessException { // Body throw new ArithmeticalException(“This is Arithmetical Exception”);

}

// Body throw new IllegalAccessException(“This is Illegal Access Exception”);

The finally Code Block lkekU;r;k tc Hkh fdlh try Block esa dksbZ Exception Generate gksrk gS] Program Control try Block dks NksMdj lh/ks gh catch Block esa ml Exception dks Handle djus ds fy, pyk tkrk gSA ysfdu dbZ ckj ,slh fLFkfr gksrh gS] fd try Block esa dksbZ Exception Generate gksus ds ckotwn Hkh gesa try Block ds dqN Statements dk Execution djuk t:jh gksrk gSA 349 Any Question or Suggestion, Just Discuss Here...

Java in Hindi mnkgj.k ds fy, ekuyks fd geus try Block esa fdlh File dks Open fd;k vkSj File dks Save djrs le; dksbZ Exception Generate gks x;kA bl fLFkfr esa ge try Block ls Open dh xbZ File dks Close fd, fcuk gh catch Block esa vk tkrs gSaA ysfdu Open dh xbZ File dks Close fd, fcuk ge Program dks Terminate ugha dj ldrs gSa] D;ksafd ,slk djus ij Program esa nwljh izdkj dh leL;k,a iSnk gks ldrh gSaA blfy, ;s t:jh gS fd Exception Generate gksus dh fLFkfr esa Hkh try Block ds dqN ,sls Statements dk Execution gksuk pkfg,] tks catch Block esa Control ds Transfer gksus ds ckn Hkh File dks Close dj ldsa] rkfd System esa vU; izdkj dh Problem uk gksA bl izdkj ds dke ds fy, ge File dks Close djus dk Statement try Block o catch Block nksuksa esa

fy[kdj djrs gSaA

;fn Exception Generate ugha gksrk gS] rks try Block dk File Close djus dk Statement Execute gks dj File dks Close dj nsrk gS vkSj ;fn Exception Generate gks tkrk gS] rks catch Block esa fy[kk x;k File Close djus dk Statement Execute gks tkrk gS] tks File dks Close dj nsrk gSA ;kuh ge le> ldrs gSa fd File Close djus dk dke ,d ,slk dke gS] tks gksuk gh pkfg,A tkok esa dksbZ Program cukrs le; Hkh ge ,sls dkeksa dks r; dj ldrs gSa] tks fdlh Hkh fLFkfr esa gksus gh pkfg, gksrs gSaA pwafd try o catch nksuksa Block esa t:jh :i ls Execute gksus okys Code Statements dks nks ckj fy[kus ls cpus ds fy, tkok esa finally Code Block dh lqfo/kk iznku dh xbZ gSA ;s ,d ,slk Code Block gksrk gS] ftlesa fy[ks x, Statements dk Execution gksrk gh gS] fQj pkgs try Block esa dksbZ Exception Generate gks pkgs uk gksA tkok esa Program Develop djrs le; ,sls ftrus Hkh Statement gksrs gSa] ftUgsa Execute djuk gh gksrk gS] mUgsa finally Block esa fy[k fn;k tkrk gSA fdlh Hkh try/catch Block tksMs esa finally Block gesa”kk lcls vfUre Block gksrk gSA ;kuh ;fn ge Multiple catch Block okyk Program Develop dj jgs gSa] rks ml Program esa Hkh dsoy ,d gh try o ,d gh finally Block gksrk gS] ysfdu mlesa catch Block ,d ls T;knk gks ldrs gSaA try Block gesa”kk lcls igyk Block gksrk gS tcfd finally Block dks lHkh catch Blocks dks Define djus ds ckn esa Define fd;k tkrk gSA bl Block dks ge fuEukuqlkj Use djuk lh[k

ldrs gSa%

Program import java.io.* ; import java.lang.Exception ; public class gradeTest { public static void main( String[] args ) { try { // Comment Next Statement Line for First Output int firstValue = 100, secondValue = 200;

// Line Number 01

350 Any Question or Suggestion, Just Discuss Here...

Java in Hindi // Un-Comment Next Statement Line for Second Output // int firstValue = 300, secondValue = 200; Line Number 02 if(firstValue < secondValue) { throw new Exception("First Value is More then Second Value"); } if(firstValue > secondValue) { throw new ArithmeticalException("Second Value is Greater."); }

{ }

} catch( ArithmeticalException excp)

System.out.println( "Exception: " + excp.getMessage() ) ;

catch( Exception excp ) { System.out.println( "Exception: " + excp.getMessage() ) ; }

}

}

finally { System.out.println ("This Statement must be executed on any exception."); }

First Output Exception: First Value is Greater then Second Value This Statement must be executed on any exception. Second Output Exception: Second Value is Greatest. This Statement must be executed on any exception.

bl Program ds nks Output crk, x, gSaA First Output izkIr djus ds fy, Program dks T;ksa dk R;ksa Compile djds Run djuk gksrk gSA tcfd Second Output dks izkIr djus ds fy, Program ds try Block ds “Line Number 01” dks Comment cukuk gksrk gS vkSj “Line Number 02” dks Normal Statement cukuk gksrk gSA ge ns[k ldrs gSa] fd nksuksa gh Output esa nwljh Line Common :i ls Display gks jgh gS vkSj bl Line dks geus finally Block esa fy[kk gSA ge ns[k ldrs gSa fd nksuksa gh fLFkfr;ksa esa nks vyx izdkj ds Exception dks Handle djus ds fy, nks catch Block gSa] ysfdu nksuksa catch

351 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Block esa Exceptions dks Handle djus ds ckn Hkh finally Block ds Statement dk Execution gks jgk gSA

;fn try Block esa fdlh Hkh izdkj dk Exception Generate uk gks] rc Hkh finally Block dk Statement Output esa Display gksrk gh gSA ;kuh finally Block dks ge Sequential Statement Block Hkh dg ldrs gSa] D;ksafd Sequential Statement Block ,sls Statements dk Block gksrk gS] tks gesa”kk gh Execute gksrs gSaA

Types of Exceptions – The Java Built – In Exceptions Classes

Java API ds Methods o tkok Lo;a Hkh fofHkUu izdkj ds Exceptions Throw djrk gSA bu Exceptions dks nks Sub Classes Error o Exception esa foHkkftr fd;k tk ldrk gSA bu nksuksa Sub Classes dks Throwable Super Class ls Derive fd;k x;k gSA Error Class o bldh Sub Classes ,slh fLFkfr;ksa dks Represent djrs gSa] ftUgsa lkekU;r;k Solve ugha fd;k tk ldrk gS vkSj lkekU;r;k ;s gekjs Program dks Terminate gh djrs gSaA Java Developer Kit dh fofHkUu Classes fofHkUu izdkj ds Exception o Error Exceptions Throw djrs gSaA

java.lang Exceptions bl Package esa tkok Language dh T;knkrj vk/kkjHkwr Classes gSa] ftu ij tkok vk/kkfjr gSA bu Classes dks “Core of Java” Language Hkh dgk tkrk gSA RuntimeException Class ls Derive fd, x, fdlh Hkh Method ds lkFk throws Keyword dk iz;ksx djds Exception dks Throw djus dh t:jr ugha gksrh gSA buls Generate gksus okys Exceptions Normal Exceptions dgykrs gSa vkSj lkekU;r;k bu Exceptions dks dksbZ Hkh Method Throw dj ldrk gSA fdlh Program esa Generate gksus okyh os Abnormal fLFkfr;ka ftUgsa Solve fd;k tk ldrk gS] Exception dgk tkrk gS] tcfd ftu fLFkfr;ksa dks Solve ugha fd;k tk ldrk gS] mUgsa Errors dgrs gSaA Exceptions Recoverable gksrs gSa tcfd Errors Non-Recoverable gksrs gSaA fuEu Table esa java.lang Package ls Generate gks ldus okys fofHkUu Exceptions o Errors dks muds Short Description ds lkFk n”kkZ;k x;k gS% The java.lang Exceptions Exception ArithmeticException ArrayIndexOutOfBoundsException ArrayStoreException ClassCastException ClassNotFoundException CloneNotSupportedException Exception

Cause Arithmetic error condition (for example, divide by zero). Array index is less than zero or greater than the actual size of the array. Object type mismatch between the array and the object to be stored in the array. Cast of object to inappropriate type. Unable to load the requested class. Object does not implement the cloneable interface. Root class of the exception hierarchy.

352 Any Question or Suggestion, Just Discuss Here...

Java in Hindi IllegalAccessException IllegalArgumentException IllegalMonitorStateException IllegalThreadStateException IndexOutOfBoundsException InstantiationException InterruptedException NegativeArraySizeException NoSuchMethodException NullPointerException NumberFormatException RuntimeException SecurityException StringIndexOutOfBoundsException

Class is not accessible. Method receives an illegal argument. Improper monitor state (thread synchronization). The thread is in an improper state for the requested operation. Index is out of bounds. Attempt to create an instance of the abstract class. Thread interrupted. Array size is less than zero. Unable to resolve method. Attempt to access a null object member. Unable to convert the string to a number. Base class for many java.lang exceptions. Security settings do not allow the operation. Index is negative or greater than the size of the string.

The java.lang Errors Error AbstractMethodError ClassCircularityError ClassFormatError Error IllegalAccessError IncompatibleClassChangeError InstantiationError InternalError LinkageError NoClassDefFoundError NoSuchFieldError NoSuchMethodError OutOfMemoryError StackOverflowError ThreadDeath

UnknownError UnsatisfiedLinkError VerifyError VirtualMachineError

Cause Attempt to call an abstract method. This error is no longer used. Invalid binary class format. Root class of the error hierarchy. Attempt to access an inaccessible object. Improper use of a class. Attempt to instantiate an abstract class. Error in the interpreter. Error in class dependencies. Unable to find the class definition. Unable to find the requested field. Unable to find the requested method. Out of memory. Stack overflow. Indicates that the thread will terminate. May be caught to perform cleanup. (If caught, must be rethrown.) Unknown virtual machine error. Unresolved links in the loaded class. Unable to verify bytecode. Root class for virtual machine errors.

353 Any Question or Suggestion, Just Discuss Here...

Java in Hindi java.io Exceptions java.io Package dh Classes Hkh fofHkUu izdkj ds Exceptions Throw djrh gSa] ftUgsa vkxs FkksMs ls Description ds lkFk n”kkZ;k x;k gSA dksbZ Hkh ,slh Class tks I/O ds fy, Use dh tkrh gS] Recoverable Exceptions Throw dj ldrh gSA mnkgj.k ds fy, fdlh File dks Open djus ;k File esa Write djus dh Process le;≤ ij Fail gksrh jgrh gSA java.io Package fdlh izdkj dk Error Throw ugha djrk gSA The java.io Exceptions Exception IOException EOFException FileNotFoundException InterruptedIOException

Cause Root class for I/O exceptions. End of file. Unable to locate the file. I/O operation was interrupted. Contains a bytesTransferred member that indicates how many bytes were transferred before the operation was interrupted. Malformed UTF-8 string.

UTFDataFormatException

java.net Exceptions ;s Package Network Communications dks Handle djrk gSA ;s Class lkekU;r;k ,sls Exceptions Generate djrk gS] tks Connect Failure ;k blls lEcaf/kr tkudkfj;ka iznku djrs gSaA ;s Package Hkh dksbZ Error Throw ugha djrk gS] ysfdu ;s Package fuEukuqlkj dqN Exceptions Throw djrk gS% The java.net Exceptions Exception MalformedURLException ProtocolException SocketException UnknownHostException UnknownServiceException

Cause Unable to interpret URL. Socket class protocol error. Socket class exception. Unable to resolve the host name. Connection does not support the service.

The java.awt Exceptions bl Class esa ,sls Members gSa ftuesa ls ,d rks Error Throw djrk gS tcfd nwljk Exception Throw djrk gSA ;s Members fuEukuqlkj gSa% •



AWTException AWTError

( ;s Class AWT Class dh Exceptions dks Throw djrk gSA ) ( ;s Class AWT Class dh Errors dks Throw djrk gSA )

354 Any Question or Suggestion, Just Discuss Here...

Java in Hindi The java.util Exceptions bl Package dh Classes fuEu Exceptions Throw djrk gS% • •

EmptyStackException NoSuchElementException

(no objects on stack) (no more objects in collection)

Creating Own Exception Sub Class

gkykafd tkok dh T;knkrj Exception dks Handle djus ds fy, tkok esa igys ls gh fofHkUu izdkj dh Classes miyC/k gSaA ysfdu fQj Hkh ;fn ge pkgsa rks viuh Lo;a dh Hkh Exception Class cuk ldrs gSa] tks fdlh Application ds fdlh veqd Problem dks Solve djus dk dke dj ldrk gSA viuh Lo;a dh Sub Exception Class cukus ds fy, gesa gekjh Sub Class dks tkok dh Built–In Exception Class ls Derive djuk iMrk gSA gekjh Class esa gesa dqN Hkh Implement ugha djuk gksrk gS cfYd System Class igys ls gh tkok esa miyC/k gS] ftlesa fofHkUu izdkj ds Exceptions dks Handle djus dh lqfo/kk,a igys ls gh ekStwn gSaA Exception Class esa mldk Loa; dk dksbZ Hkh Method ugha gSa] cfYd blesa Throwable Class ds gh lHkh Methods miyC/k gSaA vr% gekjh Sub Class esa Hkh Throwable Class ds lHkh Methods miyC/k gks tkrs gSa vkSj os Methods Hkh miyC/k gksrs gSa] ftUgsa ge gekjh vko”;drkuqlkj Create djrs gSaA ge fuEu Program }kjk ,d lkekU; Exception Class Extend djuk o mls Use djuk lh[k ldrs gSa% Program // File Name : OwnException.java class MyException extends Exception{ private String exceptionMessage; MyException(String message){ exceptionMessage = message; }

}

public String toString(){ return "My Exception : " + exceptionMessage; }

class OwnException{ static void sendMessage(String message) throws MyException{ System.out.println("Called sendMessage() Method" ); if(message != "Hello"){ throw new MyException(message); } System.out.println("This is my exception from my class"); } public static void main(String args[]){ try{

355 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

}

sendMessage("Hello"); sendMessage("Buy"); }catch(MyException excp) { System.out.println("Caught from MyException Class : "+excp); }

Output Called sendMessage() Method This is MyException from my class Called sendMessage() Method Caught from MyException Class : My Exception : Buy

356 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Java Inheritance For

Code Reusability

357 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Java Package – Code Reusability

vHkh rd geus ftrus Hkh Chapters ns[ks gSa] mu lHkh esa geus fofHkUu izdkj dh Example Classes Create dh gSaA gj Example Class dk uke Hkh geus vyx&vyx j[kk gSA geus igys Hkh dgk gS fd OOPS dh lcls cMh fo”ks’krk ;gh gS fd ge blds Concepts dks Use djds tc dksbZ Class Create djrs gSa] rks ml Class dks ge ckj&ckj Use dj ldrs gSaA ;kuh OOPS ds Concept ds dkj.k gesa tkok esa Codes ds Reusability dh lqfo/kk izkIr gksrh gSA tkok esa Reusability dh lqfo/kk dks ge nks rjhdksa ls izkIr dj ldrs gSaA igys rjhds esa ge ,d Class dks Inherit djrs gSa vkSj Interfaces dks Implement djrs gSaA bl izfØ;k dks geus fiNys nks v/;k;ksa esa le>k gSA bl izfØ;k esa ge ftl Class dks ftl Program esa Use djuk pkgrs gSa] mlh Program esa Apply djds fdlh Class dks Extend djrs gSaA ;kuh ge lkekU;r;k fdlh Class dh Ability dks crs gSaA ekuyks fd geus JDK Install fd;k gSA tc ge JDK dks mldh Default Location ij Install djrs gSa] rc og “C:” ij Install gksrk gSA vc ekuyks fd ge gekjs Program ls lEcaf/kr tkok Source Files dks blh JDK esa MyApplication uke dk ,d Sub Folder Create djds mlesa Save djrs gSaA vc ekuyks fd ge gekjh dqN Files dk ,d Package Create djuk pkgrs gSa vkSj Package dk uke myFirstPackage j[kuk pkgrs gSaA bl fLFkfr esa gesa MyApplication uke ds Folder esa myFirstPackage uke dk ,d Folder Create djuk gksxkA /;ku jgs fd geus bl uke esa ftl rjg ls Case dks Use fd;k gS] mlh rjg ds Case dks gesa gekjh Program File esa bl Package dh Classes dks Access djus ds fy, Hkh Use djuk gksxkA Folder Create djus ds ckn esa vc gesa mu Source Files dks Create djuk gksrk gS] ftUgsa ge vius Package esa Store djuk pkgrs gSaA tc gesa fdlh Class dks fdlh Package esa Store djuk gksrk gS] rc ml Class dh File esa lcls igys gesa ml Package dk mYys[k djuk gksrk gS] ftlesa ge Class dks Store djuk pkgrs gSaA ekuyks fd gesa MyApplication Folder ds myFirstPackage Subfolder esa MyFirstClass uke dh Class dks Store djuk gSA bl Class dks myFirstPackage esa Store djus ds fy, tc ge MyFirstClass Class dks Define djrs gSa] rks Class File esa lcls igys Statement ds :i esa gesa ;s crkuk gksrk gS fd ge Create dh tkus okyh Class dks fdl Package esa Store djuk pkgrs gSaA tkok Compiler dks Package dh Information nsus ds fy, gesa fuEukuqlkj package Keyword Statement dk iz;ksx djuk gksrk gS% package myFirstPackage;

vc ftl Class dks gesa myFirstPackage esa Store djuk gS] ml Class dks gesa bl Statement ds ckn esa Define djuk gksrk gSA ;kuh Program // File Name // Save In

: :

MyFirstClass.java C:\JDK\MyApplication\myFirstPackage

package myFirstPackage;

361 Any Question or Suggestion, Just Discuss Here...

Java in Hindi class MyFirstClass { void printHello() { System.out.println(“Hello”); } }

ge ns[k ldrs gSa fd geus Class ds lkFk fdlh Access Specifier dk iz;kssx ugha fd;k gSA ;fn ge gekjh Class ds lkFk fdlh Access Specifier dk iz;ksx ugha djrs gSa] rks gekjh Class dsoy myFirstPackage esa fLFkr fofHkUu Classes ds fy, gh Accessible gksxhA ;fn dksbZ vU; Class Program bl Class dks Use djuk pkgsxk] rks og bl Class dks Use ugha dj ik,xkA blfy, gesa bl Class ds lkFk public Access Specifier dk iz;ksx djuk gksxkA tc ge blds lkFk public Access Specifier dk iz;ksx djsaxs] rc bl Package dh fdlh Hkh Public Class dks fdlh Hkh nwljs Package dh dksbZ Hkh Class Access djus esa l{ke gksxhA blh rjg ls ;fn ge Class ds Method ds lkFk Hkh fdlh Access Specifier dk iz;ksx ugha djsaxs] rks gekjh Class ds Methods dsoy mlh Package rd gh Accessible jgsaxsA blfy, gesa gekjh Class ds Member Methods ds lkFk Hkh public Access Specifier dk iz;ksx djuk gksxkA ;kuh gesa bl Code Segment esa fuEukuqlkj Modification djuk gksxk% Program // File Name // Save In

: :

MyFirstClass.java C:\JDK\MyApplication\myFirstPackage

package myFirstPackage; public class MyFirstClass { public void printHello() { System.out.println(“Hello”); } }

vc ;fn ge myFirstPackage Package esa fLFkr MyFirstClass ds Object Create djds Use djuk pkgsa] rks blds fy, ge fuEukuqlkj ,d main() Method Class Create dj ldrs gSa% Program // File Name // Save In

: :

UsingMyFirstClass.java C:\JDK\MyApplication

import myFirstPackage.*; public class UsingMyFirstClass { public static void main(String args[])

362 Any Question or Suggestion, Just Discuss Here...

Java in Hindi {

}

}

MyFirstClass myObject = new MyFirstClass(); myObject.printHello();

ge ns[k ldrs gSa fd geus Package esa Add dh tkus okyh Class dks rks MyApplication Folder ds myFirstPackage uke ds Sub Folder esa Save djds Compile fd;k gS] tcfd UsingMyFirstClass okyh Source File dks MyApplication uke ds Folder esa Save fd;k gSA geus ,slk blfy, fd;k gS D;ksafd fdlh Hkh Package esa dHkh Hkh main() Method okyh Class dks Store ugha fd;k tk ldrk gS] D;ksafd main() Method dh Class Directly Run gksus okyh Class gksrh gSA myFirstPackage Class esa ge mlh Class dks Store dj ldrs gSa] ftlesa ge myFirstPackage ls Directly nwljs tkok Programs esa Access djuk pkgrs gSaA myFirstPackage uke ds Folder esa Store gksus okyh Classes ,d rjg ls Library Classes cu tkrh gSa] ftUgsa Directly fdlh Hkh Source File esa Import djds Use fd;k tk ldrk gSA bl Program esa geus import Statement }kjk myFirstPackage Package dh lHkh Classes dks fuEukuqlkj Statement }kjk UsingMyFirstClass uke dh Source File esa Import fd;k gS% import myFirstPackage.*;

bl Statement ls myFirstPackage esa Stored lHkh Classes gekjs Program ds fy, Accessible gks tkrh gSaA tcfd ;fn ge dsoy MyFirstClass uke dh Class dks gh bl Package ls vius Program esa Access djuk pkgrs gSa] rks ge fuEukuqlkj import Statement Hkh fy[k ldrs gSa% import myFirstPackage.MyFirstClass;

bl Program esa ge ns[k ldrs gSa fd geus MyFirstClass uke dh Class dks myFirstPackage uke ds Package esa Store fd;k gS vkSj gekjh Current Source File esa ;s Class Defined ugha gS] fQj Hkh ge main() Method esa fuEukuqlkj Statement }kjk bl Class ds Object Create dj ik jgs gSa vkSj ml Object ds Reference esa printHello() uke ds Method dks Hkh Access dj ik jgs gSa] tks fd MyFirstClass dk Method gSA ,slk blhfy, lEHko gS] D;ksafd ;s Class gesa myFirstPackage uke ds Package ls izkIr gks jgh gSA ;fn ge pkgsa rks vc bl Package dks fdlh Hkh vU; Program esa import Statement }kjk Use dj ldrs gSaA lkFk gh ge bl Package esa vkSj Classes Hkh Add dj ldrs gSaA blds fy, gesa dsoy bruk gh djuk gksxk fd ftl fdlh Hkh Class dks ge bl Package esa Store djuk pkgrs gSa] ml Package dks gesa public cukuk gksxk vkSj ml Class ls igys gesa package Statement }kjk ;s crkuk gksxk fd ge gekjh Class dks fdl Package esa Store djuk pkgrs gSaA

363 Any Question or Suggestion, Just Discuss Here...

Java in Hindi blh rjg ls tc gesa ml Package dh Class dks Access djuk gksxk] rc gesa import Statement }kjk ml Package dks ;k ml Package dh fdlh Class dks viuh Source File esa Import djuk gksxkA ;kuh ;fn ge pkgsa rks fuEukuqlkj ,d vkSj Class bl Package esa Store dj ldrs gSa% Program // File Name // Save In

: :

MySecondClass.java C:\JDK\MyApplication\myFirstClass

package myFirstPackage; public class MySecondClass { public void printBuy() { System.out.println("Huy and Buy"); } }

bl Class dks Hkh myFirstPackage Folder esa Save djds Compile djus ij bl Package esa bldh Hkh Class File Create gks tkrh gSA vc ge fuEukuqlkj ,d main() Method Program esa bl Package dh nksuksa Classes ds Objects Create djds mUgsa Use dj ldrs gSa% Program // File Name // Save In

: :

UsingMyFirstClass.java C:\JDK\MyApplication

import myFirstPackage.*;

//For importing all classes of the package

public class UsingMyFirstClass { public static void main(String args[]) { MyFirstClass myObject1 = new MyFirstClass(); MySecondClass myObject2 = new MySecondClass(); myObject1.printHello(); myObject2.printBuy(); } } Output Hello Huy and Buy

,d ckr /;ku j[ksa fd ge ftl Package dks Create dj jgs gSa] og Package Directory ml Directory dh Subdirectory gksuh pkfg,] ftlesa ge ml Create dh tkus okyh Package dh Classes dks Import djus okyh Source Files dks Save djsaxsA ;fn ge mu Source Files

364 Any Question or Suggestion, Just Discuss Here...

Java in Hindi dks fdlh nwljh Directory esa Store djrs gSa] tgka Import dh tkus okyh Package dh Subdirectory miyC/k ugha gS] rks ge ml Package dks vius Source Program esa Use ugha dj ldrs gSaA ljy “kCnksa esa dgsa rks ftl Source File esa ge Package dks Use dj jgs gSa] og Package Directory Source Files dh Directory dh Subdirectory gksuh pkfg,A ;fn ge Packages dh Hierarchy Create djuk pkgrs gSa] rks Package dh Hierarchy dh Files dks Access djus ds fy, gesa Dot Operator dk iz;ksx djuk iMrk gSA ekuyks fd gekjh myFirstPackage esa ,d vkSj Sub Package mySecondPackage gS] rks bl Package dh Subdirectory dks gesa myFirstPackage dh Subdirectory esa Create djuk gksxk vkSj bl Sub Package esa Classes dks Save djds Compile djuk gksxkA Class Files dks Sub Package esa Hkstus ds fy, gesa fuEukuqlkj Statement fy[kuk gksxk% Program // File Nam :MyThirdClass.java // Save In :C:\JDK\MyApplication\myFirstPackage\mySecondPackage package myFirstPackage.mySecondPackage; public class MyThirdClass { public void printOK() { System.out.println(“OK”); } }

blh rjg ls fdlh Sub Package dh Class dks Access djus ds fy, Hkh gesa fuEukuqlkj Dot Operator dk iz;skx djds Classes dks viuh Source File esa import djuk gksrk gS% Program // File Name // Save In

: :

UsingMyFirstClass.java C:\JDK\MyApplication

import myFirstPackage.mySecondPackage.*; public class UsingMyThirdClass { public static void main(String args[]) { MyThirdClass myObject3 = new MyThirdClass();

}

}

myObject3.printOK();

365 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ge ,d gh Class Definition File esa ,d ls T;knk Classes dks Define djds mls fdlh Package esa Store dj ldrs gSaA ,sls esa ml Class Definition File esa dsoy ,d gh public Class gksrh gS vkSj tks Class Public gksrh gS] Class Definition File dk uke Hkh ogh gksrk gS] tks ml Public Class dk gksrk gSA ;kuh ;fn ge mijksDr rhuksa Classes dks ,d gh ckj esa ,d gh Class Definition File }kjk myFirstPackage Package esa Store djuk pkgsa] rks fuEu Class File dks myFirstPackage esa Save djds ;s dke dj ldrs gSa% Program // File Name: // Save In :

MyFirstClass.java C:\JDK\MyApplication\myFirstPackage

package myFirstPackage; public class MyFirstClass{ public void printHello(){ System.out.println("Hello"); } } class MySecondClass{ public void printBuy(){ System.out.println("Huy and Buy"); } } class MyThirdClass{ public void printOK(){ System.out.println("OK"); } }

tSlkfd ge bl Class File esa ns[k ldrs gSa] blesa dsoy ,d gh Public Class gSA blfy, ;fn ge Packages ds vykok fdlh vU; Class esa MyThirdClass dk Object Create djuk pkgsa] rks ugha dj ldrs gSa] D;ksafd ;s Public ugha gSA MyThirdClass dks Public Form esa Package esa Add djus ds fy, gesa MyThirdClass dks Package esa vyx ls Store djuk gksxk vkSj blds fy, vyx ls Class File cukuh gksxhA Access Specifier ds lEca/k esa gesa gesa”kk lko/kku jguk pkfg,A ge fdlh Package dh Public Classes dks gh fdlh Outside Package Class esa Directly Access dj ldrs gSaA Package gesa”kk ,d Container dh rjg dke djrk gS] blfy, bldh Classes dks ;fn gesa vU; Classes esa Use djuk gS] rks Package dh bu Classes dk Public gksuk t:jh gksrk gSA tks Classes Public ugha gksrh gSa] mUgsa dsoy mlh Package dh vU; Classes }kjk gh Access fd;k tk ldrk gSA Packages dk iz;ksx gesa”kk Classes o vU; Sub Packages dks Store djus ds fy, ,d Container dh rjg fd;k tkrk gSA tcfd Classes dk iz;ksx Data Members o Methods

366 Any Question or Suggestion, Just Discuss Here...

Java in Hindi dks Store djus ds fy, fd;k tkrk gSA blfy, Class Members ds lkFk private, protected, public ;k Default Access Specifier dk iz;ksx fd;k tk ldrk gSA tc ge fiNys mnkgj.k dh rjg ,d gh File ls dbZ Classes dks Package esa Add djrs gSa] rc Public Class ds vykok lHkh Classes dsoy mlh Package dh vU; Classes ds fy, gh Accessible gksrh gSa vkSj ;s Classes Package ls ckgj dh Classes ds fy, Hidden jgrh gSaA blfy, ge fdlh ,slh Class esa buds Object Create ugha dj ldrs gSa] tks bl Package ls ckgj gksA

367 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Java Multithreaded Programming

368 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Java Multithreaded Programming

T;knkrj Computer Games esa Graphics o Sounds dk iz;ksx gksrk gSA fdlh Hkh Game esa Graphics, Sounds o Score lHkh dqN ,d lkFk fn[kkbZ nsrs gSaA ekuyks fd Game esa lcls igys Screen Change gks fQj Score Update gks vkSj vUr esa Music lqukbZ ns] rks Game dSlk yxsxkA tkfgj lh ckr gS fd ,slk gksus ij gesa Game vPNk ugha yxsxkA fdlh Hkh Game ds ;s fgLls ,d lkFk Process gksrs gSaA nwljs “kCnksa esa dgsa] rks ,d Program rhu Sub Programs esa Divided gS] vkSj gj Sub Program dks ,d Thread }kjk Handle fd;k tkrk gSA tkok ,d ,slh Programming Language gS] tks Multithreading Technique dks Support djrk gSA ,d ,slk Program ftlesa dbZ Sub Programs gksa vkSj gj Sub Program ,d lkFk Execute gksrk gks] Multithreaded Program dgykrk gSA Multithreading Multitasking dk gh ,d fof”k’V :i gSA Multitasking ls ge lHkh ifjfpr gSaA vkt ftrus Hkh Operating Systems miyC/k gSa] os lHkh Multitasking Operating Systems gSaA ge Multitasking dks Hkh Process Based Multitasking o Thread Based Multitasking

nks Hkkxksa esa ckaV ldrs gSaA bu nksuksa ds chp dk vUrj le>uk dkQh t:jh gSA

fdlh Computer esa ,d le; ij ftrus Hkh Programs Execute gks jgs gksrs gSa] Operating System dh Hkk’kk esa os lHkh Process dgykrs gSaA Process Based Multitasking ,d ,slk Feature gS] ftlds dkj.k ,d Computer esa ,d gh le; esa ,d ls T;knk Programs Run gks ldrs gSaA mnkgj.k ds fy, ftl le; ge fdlh Word Processor esa Typing dj jgs gksrs gSa] mlh le; ge fdlh Song dks Hkh Play dj ldrs gSaA Process Based Multitasking esa ,d Program og Smallest Unit gksrk gS] ftls Operating System dk Scheduler Processor ij Dispatch djds Process djrk gSA Thread Based Multitasking Environment esa fdlh Program dk ,d Thread og Smallest Unit gksrk gS] ftls Operating System dk Scheduler Processor ij Process djus ds fy, Dispatch djrk gSA bldk eryc ;s gqvk fd ,d Single Program ,d ls T;knk Tasks dks leku le; esa leku :i ls Execute dj ldrk gSA

mnkgj.k ds fy, ,d Song Player esa Song Play gks jgk gksrk gS] mlh le; ge fdlh nwljs Song dks Song Player esa vxys Song ds :i esa Play gksus ds fy, Select Hkh dj ldrs gSaA lkFk gh Song Play gksrs le; gh ge Song ds Tempo dks Hkh Change dj ldrs gSa vkSj Volume dks Hkh de ;k T;knk dj ldrs gSaA ;s lHkh dke Thread Based Multitasking ds dkj.k gh lEHko gks ikrs gSaA Multitasking Processes dh rqyuk esa Multitasking Thread T;knk ljy gksrs gSaA Processes Heavyweight Tasks gksrs gSa ftUgsa Separate Address Spaces dh t:jr gksrh gSA ,d Process ls nwljs Process ij Move gksus ;kuh Context Switching Hkh Costly gksrk gSA tcfd Threads Lightweight Tasks gksrs gSa vkSj ,d Program ds lHkh Threads leku Address Space dks Share djrs gSaA lkFk gh lHkh Threads leku Heavyweight Process dks Hkh Share djrs gSaA

369 Any Question or Suggestion, Just Discuss Here...

Java in Hindi gkykafd tkok Process Based Multitasking dks Use djrk gS] ysfdu fQj Hkh tkok esa Process Based Multitasking Programs Develop ugha fd, tk ldrs gSa] fQj Hkh tkok Multithreading Based Multitasking dks Support djrk gSA Multithreading dh Techniques gesa ,sls Programs Write djus dh lqfo/kk nsrk gS] ftuls ge CPU dk Maximum Use dj ldrs gSa] D;ksafd bl rduhd esa Processor ds Idle Time dks Minimum j[kk tkrk gSA ;s O;oLFkk eq[; :i ls Interactive Network Based Applications ds fy, cgqr mi;ksxh gksrh gS] D;ksafd tkok mlh Environment esa dke djrk gS] tgka Idle Time cgqr T;knk gksrk gSA

mnkgj.k ds fy, Network ij Data ds Transmission dh xfr CPU ij Data ds Process gksus dh xfr dh rqyuk esa cgqr gh /kheh gksrh gSA fdlh Single Threaded Program esa gesa ,d Second Task ds “kq: gksus ls igys First Task ds lekIr gksus dk Wait djuk iMrk gS] fQj pkgs CPU Idle Mode esa gh D;ksa uk gksA Multithreading dh rduhd gesa CPU ds bl Idle time dks Utilize djus dh lqfo/kk iznku djrk gSA

Java Thread Model

tkok dk Run-Time System dbZ phtksa ds fy, Threads ij fuHkZj djrk gS vkSj tkok dh lHkh Class Libraries dks Multithreading Techniques dks fnekx esa j[k dj Develop fd;k x;k gSA okLro esa tkok Threads dk iz;ksx iwjs tkok Environment dks Synchronize djus ds fy, djrk gSA ;s izfØ;k CPU ds Idle Time dks Use djus esa gksus okyh Inefficiencies dks de djrk gSA Single Threaded Systems esa Event Loop With Polling dk rjhdk Use fd;k tkrk gSA bl Model esa Controls dk ,d Single Thread ,d Infinite Loop esa Run gksrk gSA Polling ,d Single Event Queue gksrk gS] tks ;s r; djrk gS fd Next D;k djuk gSA ,d ckj tc ;s Polling Mechanism fdlh Signal ds lkFk Return gksrk gS] mnkgj.k ds fy, Network dh File Ready gS] bl Signal ds lkFk Polling Mechanism Return gksrk gS] rc Event Loop Control dks Appropriate Event Handler ij Dispatch dj nsrk gSA tc rd ;s Event Handler Return ugha gksrk gS] rc rd System esa dksbZ Hkh nwljk dke ugha gks ldrk gSA ;gha ij CPU dk Time Waste gksrk gSA bldk ge ;s ifj.kke Hkh izkIr dj ldrs gSa fd Program dk dsoy ,d gh Event lkjs System dks Use dj jgk gS vkSj fdlh vU; Events dks Process djus ls jksd jgk gSA

lk/kkj.krkSj ij fdlh Single Threaded Environment esa tc ,d Thread fdlh Resource dk Wait djrk gS] rc og Suspend Mode esa pyk tkrk gS vkSj tc rd Program dk og Thread fdlh Resource dk Wait djrk jgrk gS] rc rd iwjk Program Stop Mode esa jgrk gSA tkok ds Multithreading dk Qk;nk ;s gS fd blesa Main/Polling Loop ds Mechanism dks Eliminate dj fn;k x;k gSA blesa fdlh Program dk ,d Thread Program ds fdlh nwljs Thread dks Stop fd, fcuk fdlh System Resource dks izkIr djus ds fy, Suspend Mode esa Pause gks ldrk gSA mnkgj.k ds fy, ftl le; Network ls dksbZ File Read gks jgh gksrh gS ;k ftl le; Program dk dksbZ fgLlk User ds Input dk Wait dj jgk gksrk gS] ml le; Program esa 370 Any Question or Suggestion, Just Discuss Here...

Java in Hindi fdlh Image dh Processing dk dke ;k Animation ds Animate gksus dk dke Continue jg ldrk gSA bl le; esa Hkh CPU dksbZ uk dksbZ nwljk dke djrk jgrk gS vkSj dsoy og Thread gh Suspend jgrk gS] ftls fdlh System Resource dh t:jr gksrh gSA ,d Thread dbZ fLFkfr;ksa esa gks ldrk gSA ,d Thread Running Mode esa gks ldrk gSA tSls gh ,d Thread dks CPU dk Time feyrk gS] og Run gksus dh fLFkfr ;kuh Ready to Run gks ldrk gSA dksbZ Running Thread Suspend gksdj viuh Current Activity dks dqN le; ds fy, Pause dj ldrk gSA ,d Suspended Thread dks ;s crk dj fd mls dgka fQj ls viuk dke pkyw djuk gS] og Thread Resume gks ldrk gSA fdlh Hkh le; dksbZ Thread Terminate gks ldrk gS] ftlls ml Thread dk Execution rqjUr Halt gks ldrk gSA ,d ckr /;ku j[ksa fd ,d Thread tc ,d ckj Terminate gks tkrk gS] rc ogh Thread okil Resume ugha gks ldrkA

Thread Priorities

tkok gj Thread dks ,d Priority iznku dj nsrk gS] ftlls ;s r; gks tkrk gS fd ,d Thread nwljs Thread dh rqyuk esa fdl izdkj ls Treat gksxkA Thread Priorities Integer eku gksrs gSa tks Relative Thread dh ,d nwljs ls Priority dks r; dj nsrs gSaA ,d Absolute Value ds :i esa Priority dk eku Meaningless gksrk gSA ,d Higher Priority dk Thread Lower Priority ds Thread dh rqyuk esa fdlh Hkh rjg ls rst xfr ls Run ugha gksrk gSA blds ctk; Thread Priority ;s r; djrk gS fd fdl Thread ds ckn dkSulk Thread Run gksxkA bl izfØ;k dks Thread Context dgrs gSaA

The Thread Class and the Runnable Interface

tkok dk Multithreading System Thread Class] mlds Methods o Runnable Interface ij vk/kkfjr gksrk gSA ,d Thread esa Execute gksus okyk Sub Program Encapsulated gksrk gSA pwafd tkok esa ge fdlh Hkh Running Thread dh fLFkfr dks Refer ugha dj ldrs gSa] blfy, gesa blds Proxy ;kuh Thread Class dks Extend djds mlds Objects ds lkFk Deal djuk gksrk gSA ,d u;k Thread Create djus ds fy, gesa Thread Class dk Sub Class Create djuk gksrk gS ;k fQj Runnable Interface dks Implement djuk gksrk gSA Thread Class esa cgqr lkjs Methods gksrs gSa] ftudk iz;ksx Threads dks Manage djus ds fy, fd;k tkrk gSA

The Main Thread

tc ,d tkok Program Start gksrk gS] rks rqjUr gh ,d tkok Thread Run gksus yxrk gSA bl lcls igys Run gksus okys Thread dks tkok esa Main Thread dgrs gSa] D;ksafd ;gh og igyk Thread gksrk gS] tks Program ds Start gksrs gh Run gksus yxrk gSA Main Thread nks dkj.kksa dh otg ls cgqr Important gS% 1 ;gh og Thread gksrk gS] ftlesa vU; Child Thread Swap gksrs gSaA 2 lkekU;r;k ;gh og vfUre Thread Hkh gksrk gS] tks Program dks Shut Down djus ls lEcaf/kr fofHkUu izdkj ds Finalization Tasks Perform djrk gSA

371 Any Question or Suggestion, Just Discuss Here...

Java in Hindi gkykafd tc gekjk Program Start gksrk gS] rc ;s Thread Automatically Create gksrk gS] fQj Hkh bls ,d Thread Object }kjk Control fd;k tk ldrk gSA ,slk djus ds fy, gesa bl Thread dk ,d Reference izkIr djuk gksrk gSA bl Thread dk Reference izkIr djus ds fy, gesa currentThread() Method dks Call djuk gksrk gS] tks fd Thread Class dk ,d Public o Static Method gSA bl Method dk Syntax fuEukuqlkj gksrk gS% static Thread currentThread();

;s Method ml Thread dk Reference Return djrk gS] ftlesa bl Method dks Call fd;k tkrk gSA ,d ckj tc gesa Main Thread dk Reference izkIr gks tkrk gS] mlds ckn ge bl Thread dks Hkh mlh rjg ls Control dj ldrs gSa] ftl rjg ls fdlh vkSj Thread dks Control djrs gSaA pfy,] bl izfØ;k dks ,d mnkgj.k }kjk le>us dh dksf”k”k djrs gSa% Program // File Name : ControllingTheMainThread.java class ControllingTheMainThread { public static void main(String args[]) { Thread mainThread = Thread.currentThread(); System.out.println(“Current Thread : “ + mainThread); // Change the name of the thread mainThread.setName(“MyThread”); System.out.println(“After Changing the Name : “ + mainThread); try {

}

}

for(int i=5; i>0; i--) { System.out.println(i); Thread.sleep(1000); }

} catch(InterruptedException excp) { System.out.println(“Main Thread Interrupted”); }

Output Current Thread : Thread[main,5,main] After Changing the Name : Thread[MyThread,5,main] 5 4 3 2 1 372 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl Program esa currentThread() Method dks Call djds Current Thread ;kuh main Thread dk Reference izkIr fd;k x;k gS vkSj bl Reference dks ,d Local Thread Object mainThread esa Store fd;k x;k gSA faQj Program main Thread dh Information Display djrk gSA fQj Program main Thread ds Internal uke dks Change djus ds fy, setName() Method dks Call djrk gSA fQj main Thread dh Information dks fQj ls Display fd;k x;k gSA fQj ,d Loop 5 ls 1 rd fxurh Count djrk gS vkSj gj Counting esa sleep() Method }kjk ,d Second dk le; ysrk gSA sleep() Method esa Argument ds :i esa Milliseconds esa eku fn;k x;k gSA /;ku nsa fd Loop dks try/catch Block esa Define fd;k x;k gS] D;ksafd Thread esa sleep() Method InterruptedException throw dj ldrk gSA ;s Exception rc Throw gks ldrk gS] tc dksbZ nwljk Thread bl Sleeping dks Interrupt djuk pkgrk gSA bl Program esa ;fn dksbZ Exception Generate gksrk gS] rks ;s Program dsoy ,d Message Display djrk gS] tcfd fdlh Real Program esa gesa bl Exception dks Bhd ls Handle djuk t:jh gksrk gSA bl Program ds Output esa ge ns[k ldrs gSa fd geus Thread izdkj ds Object mainThread dks println() Method esa Argument ds :i esa Pass fd;k gS vkSj tc ;s Object Output esa Print gksrk gS] rc ;s ,d Øe esa Display gksrk gSA ;s Øe fuEukuqlkj gS% Thread [ThreadName, TreadPriority, ThreadGroupName] By Default main Thread dk uke main gSA bldh Priority 5 gS tks fd Default Value gS vkSj main ml Group dk uke gS] ftldk main Thread ,d lnL; gSA Thread Group ,d Data Structure gS] tks Threads ds Collections dh fLFkfr dks Control djrk gSA bl Process dks tkok ds Run Time Environment }kjk Handle fd;k tkrk gSA

pfy,] bl Program esa Use fd, x, Methods dks FkksMk vkSj le>us dh dksf”k”k djrs gSaA sleep() Method ml Thread dks Argument esa fn, x, Milliseconds rd ds le; ds fy, Suspend Mode esa ys tkrk gS] ftlds fy, bl Method dks Call fd;k x;k gSA bl Method dk Syntax fuEukuqlkj gksrk gS% static void sleep(long milliseconds) throws InterruptedException sleep() Method dk ,d nwljk :i Hkh gS] tks gesa Periods dks Milliseconds o Nanoseconds esa Specify djus dh lqfo/kk nsrk gSA bl Method dk Syntax fuEukuqlkj gS% static void sleep(long milliseconds, long nanoseconds) throws InterruptedException

;s Method rHkh mi;ksxh gksrk gS] tc Environment Nanoseconds ftrus NksVs Period dks Support djrk gksA fiNys mnkgj.k esa geus ns[kk fd ge setName() Method dk iz;ksx djds Thread dk uke Set dj ldrs gSa vkSj getName() Method dk iz;ksx djds Thread dk uke izkIr dj ldrs gSaA ;s Methods Thread Class ds Members gSa vkSj bl Class esa bUgsa fuEukuqlkj Declare fd;k x;k gS%

373 Any Question or Suggestion, Just Discuss Here...

Java in Hindi final void setName(String threadName) final String getName()

;gka threadName ml Thread dk uke gS] ftldk uke cnyuk gSA

Two Kinds of Threads

tkok esa ge nks rjg ds Threads Create dj ldrs gSaA lcls ljy rjhdk rks ;gh gS fd fdlh Hkh Existing Class dks ysa vkSj mls Thread esa Convert dj nsaA ge ,slk djus ds fy, Class dks bl rjg ls Modify dj ldrs gSa] fd og Runnable Interface dks Implement djs] ftlesa run() uke dk ,d Method gksrk gS] ftldh t:jr lHkh Threads dks gksrh gSA run() Method esa os Codes fy[ks tkrs gSa] ftUgsa ,d Thread Execute djrk gSA Thread Create djus ds nwljs rjhds esa gesa tkok dh Thread Class dks Derive djds ,d Completely Separate Class Create djuh gksrh gSA D;ksafd ,d Thread Class Lo;a gh Runnable Interface dks Implement djrk gS] blfy, blesa igys ls gh ,d run() Method

gksrk gSA

gkykafd ;s run() Method dqN Hkh ugha djrk gSA blfy, gesa vDlj bl Method dks viuh Derived Class esa Override djuk gksrk gS] rkfd ge mu lHkh Coding dks ml Thread esa fy[k ldsa] ftUgsa Thread ds Execution ds lkFk Execute djuk gSA

Converting a Class to a Thread fdlh Class dks ,d Thread esa Convert djus ds fy, tc ge igyk jkLrk pqurs gSa] rc gesa dbZ dke djus gksrs gSaA blesa gesa ,d ,slh Class Create djuh gksrh gS] tks Runnable Interface dks Implement djrk gksA tc ge fdlh Class esa Runnable Interface dks Implement djrs gSa] rc og Class ,d Thread esa Convert gks tkrh gSA fdlh Class dks Thread esa Convert djus ds fy, gesa fuEu Øe esa dke djuk gksrk gS% 1 ,d Class dks Declare djrs le; mlesa Runnable Interface dks Implement djus dk Statement fy[kk tkrk gSA 2 fQj ml Class esa Runnable Interface ds run() Method dks Implement fd;k tkrk gS] tks fd Runnable Interface dk Only Method gksrk gSA 3 fQj Thread Class ds ,d Object dks Data Member dh rjg blh Class esa Declare fd;k tkrk gSA 4 fQj Thread Class dk Object Create djds mlds Reference esa start() Method dks Call fd;k tkrk gSA vkSj 5 vUr esa Thread dk dke lekIr gks tkus ds ckn Thread dk stop() Method Call fd;k tkrk gSA pfy,] bu lHkh Steps dks FkksMk foLrkj ls le>rs gSaA

374 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Declaring the Class as Implementing the Runnable Interface fdlh Regular Class dks ,d Thread esa Convert djus ds fy, gesa ml Class esa Runnable Interface dks Implement djuk gksrk gSA mnkgj.k ds fy, ekuyks fd gekjs ikl fuEukuqlkj ,d igys ls Existing Applet Class gS% public class MyApplet extends Applet { // Body of the class. }

bl Class dks Thread esa Convert djus ds fy, gesa blesa Runnable Interface dks fuEukuqlkj Implement djuk gksrk gS% public class MyApplet extends Applet implements Runnable { // Body of the class. }

blh rjg ls ;fn gesa fdlh vU; lk/kkj.k Class dks Thread esa Convert djuk gks] rks ge ;s dke fuEukuqlkj dj ldrs gSa% public class MyFirstThread implements Runnable { // Body of the class. }

Implementing the run() Method fiNys Statement }kjk ge tkok Compiler dks ;s crk nsrs gSa fd ge Class esa Runnable Interface dks Implement djds bl Class dks Thread esa Convert dj jgs gSa] blfy, gesa bl Class esa Runnable Interface ds lHkh Methods dks Implement djuk t:jh gks tkrk gSA pwafd Runnable Interface esa run() uke dk dsoy ,d gh Method gS] blfy, Create dh tk jgh bl Class esa gesa dsoy blh Method dks Implement djuk gksrk gSA bl Method dk Syntax fuEukuqlkj gksrk gS% public void run() { // Thread’s Executables codes goes here. }

bl Method esa gesa mu Codes dks fy[kuk gksrk gS] ftUgsa ge Thread ds :i esa Execute djuk pkgrs gSaA run() Method ,d cgqr gh egRoiw.kZ Method gSA ;s Method fdlh Hkh vU; Method dks Call dj ldrk gS vkSj fdlh Hkh Class dks Use dj ldrk gSA lkFk gh ;s fofHkUu izdkj ds Variables Hkh Declare dj ldrk gSA

375 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ;kuh run() Method Bhd mlh rjg ls os lkjs dke dj ldrk gS] tks dke ,d main() Method djus esa l{ke gksrk gSA vUrj dsoy bruk gS fd main() Method Execute gksus okyk lcls igyk Thread gksrk gS] tks vU; Threads dks lekukUrj :i ls Run dj ldrk gS] tcfd run() Method vU; lekukUrj Threads ds fy, Entry Point Establish djrk gSA ;kuh lHkh Threads dk Execution run() Method ls gh gksrk gS vkSj Thread rHkh Terminate gksrk gS tc run() Method Terminate gksrk gSA tc ge gekjs u, Thread dks Start djrs gSa] rc tkok Thread ds run() Method dks gh Call djrk gS] blfy, gesa fdlh Tread }kjk Perform gksus okys lHkh dkeksa ds Statements dks run() Method esa gh fy[kuk gksrk gSA run() Method okLro esa fdlh Program ds ,d Sub Program dh rjg dke djrk gS] blfy, run() Method esa ge os Code Statements fy[krs gSa] ftUgsa ge lkekukUrj :i ls Execute djuk pkgrs gSaA bl run() Method dks MyFirstThread Class esa fuEukuqlkj Implement fd;k tk ldrk gS% Program class MyFirstThread implements Runnable { // This is the entry point of the second thread. public void run() { try { for(int i=0; ik;k x;k gSA ftrus Hkh Servers gksrs gSa] os lHkh fdlh Client ds Connect gksus dk Wait djrs jgrs gSaA tc Connection LFkkfir gks tkrk gS] rc Connection }kjk Produce gksus okys Socket ds fy, ,d InputStream o ,d OutputStream Object dks Create fd;k tkrk gSA fQj bu nksuksa izdkj ds Objects dks Reader o Writer izdkj ds Objects esa Convert djds BufferedReader o PrintWriter Class ds Object esa Store fd;k tkrk gSA blds ckn BufferedReader Object ls tks dqN Hkh Read fd;k tkrk gS] og lcdqN PrintWriter Object esa rc rd Echo fd;k tkrk gS] tc rd fd Line dk “END” ugha feyrk gSA tc Line dk End fey tkrk gS] rc Connection Close gks tkrk gSA blh rjg ls ,d Client tc ,d Server ls Connection cukrk gS] rc og Hkh ,d InputStream Object o ,d OutputStream Object Create djrk gS vkSj Server ls Return gksus okys Data dks Server dh rjg gh bu nksuksa izdkj ds Objects dks Reader o Writer izdkj ds Objects esa Convert djds BufferedReader o PrintWriter Class ds Objects esa Store djrk gSA Client o Server nksuksa gh leku Port Number dks Use djrs gSa vkSj Client Local Computer ds IP Address dks Use djrk gS] blfy, bl Program dks Test djus ds fy, bls Network ij Store djus dh t:jr ugha gksrh gS] ge ,d gh Computer ij Client o Server nksuksa dks Test dj ldrs gSaA gekjs Program dk Server fuEukuqlkj gS% Program // Very simple server that just // echoes whatever the client sends. import java.io.*;

428 Any Question or Suggestion, Just Discuss Here...

Java in Hindi import java.net.*; public class Server { // Choose a port outside of the range 1-1024: public static final int PORT = 8080; public static void main(String[] args) throws IOException { ServerSocket s = new ServerSocket(PORT); System.out.println("Started: " + s); try { // Blocks until a connection occurs: Socket socket = s.accept(); try { System.out.println("Connection accepted: "+ socket); BufferedReader in = new BufferedReader( new InputStreamReader( socket.getInputStream())); // Output is automatically flushed by PrintWriter: PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter( socket.getOutputStream())),true); while (true) { String str = in.readLine(); if (str.equals("END")) break; System.out.println("Echoing: " + str); out.println(str); }

}

}

}

// Always close the two sockets... } finally { System.out.println("closing..."); socket.close(); }

finally { s.close(); }

429 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl Program esa ge ns[k ldrs gSa fd ServerSocket dks dsoy ,d Port Number dh gh t:jr gksrh gSA tc ge bl Server esa accept() Method dks Call djrs gSa] rc ;s Method rc rd ds fy, Block gks tkrk gS] tc rd fd dksbZ Client bl Server ls Connect gksus dh dksf”k”k ugha djrk gSA ;kuh ;s Method fdlh Client Program ds Connect gksus dk Wait djrk jgrk gSA tc dksbZ Client blls Connect gksrk gS] ;kuh tc Connection Accept gks tkrk gS] rc accept() Method ,d Socket Object Return djrk gS] tks fd Server/Client ds chp ds bl Connection dks Represent djrk gSA bl Program esa Sockets dks Clean up djus dk dke dkQh lko/kkuhiwoZd fd;k x;k gSA ;fn ServerSocket Constructor Fail gks tkrk gS] ;kuh ;fn ServerSocket Port Number ls Connect ugha gks ikrk gS] rks Program Terminate gks tkrk gSA ge ;gka ij ;s eku dj py jgs gSa fd ;fn ServerSocket Constructor Fail gks tkrk gS] rks bl Socket ls Connected dksbZ Hkh Network Socket Open ugha jguk pkfg,A blfy, main() Method }kjk ,d IOException Throw djok;k x;k gS] rkfd Try Block dh t:jr uk jgsA ;fn ServerSocket dk Constructor Successful gksrk gS] rks ftrus Hkh vU; Methods Call gksrs gSa] mUgsa ,d Try…Finally Block esa ;s fuf”pr djus ds fy, Monitor fd;k tkrk gS] fd Control }kjk Blocks dks pkgs fdlh Hkh rjg ls NksMk tk,] ServerSocket mfpr rjhds ls Close gksuk gh pkfg,A blh Logic dks accept() Method }kjk Return gksus okys Socket ij Hkh Apply fd;k tkrk gSA ;fn accept() Method Fail gks tkrk gS] rks gesa ;s ekuuk gksrk gS fd ;k rks Socket Exist ugha gS ;k fQj fdlh vU; Resource dks Hold dj jgk gS] blfy, bls Clean djus dh t:jr ugha gSA ;fn ;s Method Successful gksrk gS] rks Hkh blls vkxs ds Statements ,d Try…Finally Block esa gksus pkfg,] rkfd ;fn ;s Fail Hkh gks tk,] rks Hkh Socket Clean gks tk,A ;s lko/kkuh j[kuk blfy, t:jh gS D;ksafd Sockets dbZ egRoiw.kZ ysfdu Non-Memory Resources dks Use djrs gSaA tkok esa bl dke dks djus ds fy, dksbZ Destructor ugha gksrk gSA accept() Method }kjk Produce gksus okys ServerSocket o Socket nksuksa dks System.out Statement }kjk Print fd;k x;k gSA ;kuh buds toString() Methods Automatically Call gks

tkrs gSaA

Program dk vxyk fgLlk Bhd mlh rjg fn[kkbZ nsrk gS] tSls ge Reading o Writing ds fy, dksbZ File Open dj jgs gksa] ctk; blds fd ge Socket Object ds vk/kkj ij InputStream o OutputStream Objects dks Create dj jgs gSaA InputStream o OutputStream nksuksa Objects dks Øe”k% InputStreamReader o OutputStreamWriter Converter Classes dk iz;ksx djds Reader o Writer Class esa Convert fd;k x;k gSA

bl Program esa geus PrintWriter Class ds Constructor esa nwljs Argument ds :i esa “true” Pass fd;k gS] tks fd ,d boolean Flag gS vkSj ;s bl ckr dks Signify djrk gS fd

430 Any Question or Suggestion, Just Discuss Here...

Java in Hindi gj println() Method ds ckn Output dks Flush dj fn;k tkuk pkfg,A ,slk dsoy println() Method ds lkFk gh gksrk gS] print() Method ds lkFk ;s izfØ;k Apply ugha gksrh gSA ge ftruh ckj Hkh “out” Object esa Data Write djrs gSa] gesa blds Buffer dks Flush djuk t:jh gksrk gSA bl Example esa Flush djuk blfy, t:jh gksrk gS] D;ksafd Client o Server nksuksa gh Proceed djus ;k vkxs csa rks Socket Network ij Run gks jgs nks Running Programs ds 2-Way Communication dk ,d Endpoint gksrk gSA Socket gesa”kk ,d Port Number ls Bound gksrk gS] ftlls TCP Layer ml Application dks Identify dj ysrk gS] ftlds fy, Data dks Hkstk x;k gksrk gSA java.net Package gesa Socket uke dh ,d Class Provide djrk gS] ftldk iz;ksx djds ge Client/Server Technology ij vk/kkfjr Application dk Client Program Create dj ldrs gSa] tks fd Network ds Server End ls Connect gks ldrk gSA

tkok gesa ServerSocket uke dh Hkh ,d Class Provide djrk gS] ftldk iz;ksx djds ge Server Side dk Application Create dj ldrs gSaA bl Class dk iz;ksx djds ge Server Side dk tks Socket Create djrs gSa] mldk iz;ksx djds Server Program Client Program dh Request dks Listen djds Client Program ls Connect gks ldrk gSA tc ge Web ls Connect gksuk pkgrs gSa] rc gesa URL Class ls Related Classes (URLConnection, URLEncoder) dk iz;ksx djuk pkfg,] D;ksafd ;s Sockets dh rqyuk esa T;knk lqfo/kktud gksrh gSaA okLro esa ULR Classes Socket Classes dh rqyuk esa Web ds fy, High Level Classes gksrh gSa] tks fd Socket Classes dks Underlying Implementation ;k Low Level Classes ds :i esa Use djrh gSaA

Reading From a Socket and Writing To a Socket

pfy,] ge ,d mnkgj.k }kjk le>us dh dksf”k”k djrs gSa fd fdl izdkj ls ,d Client Program fdlh Server Program ls Socket Class dk iz;ksx djds Connection LFkkfir dj ldrk gS vkSj Connection LFkkfir djus ds ckn Socket dk iz;ksx djds dSls Server dks Data Hkst ldrk gS vkSj Server ls Data dks Receive dj ldrk gSA bl mnkgj.k esa ,d Client Program dks Implement fd;k x;k gS] ftldk uke EchoClient gS vkSj ;s Program EchoServer uke ds Server Program ls Connect gksrk gSA Echo Server lkekU;r;k vius Client ls Data dks Receive djrk gS vkSj fQj ls mlh Data dks Client dks Return dj nsrk gSA Client, Echo Server ls Port Number 7 ij Contact dj ldrk gSA EchoClient, EchoServer ls Connect gksus ds fy, ,d Socket Create djrk gSA ;s User ls Standard Input Stream ls Input izkIr djrk gS vkSj izkIr gksus okys Input Texts dks Socket esa Write djds Echo Server ij Hkst nsrk gSA Server ij tks Text Hkstk tkrk gS] Server mlh Texts dks fQj ls Socket ds ek/;e ls Client ij Hkst nsrk gSA tc Server ls Data Client ij vk tkrk gS] rc Client ml Data dks Socket ls Read djds fQj ls Display dj nsrk gSA Program import java.io.*; import java.net.*; public class EchoClient

434 Any Question or Suggestion, Just Discuss Here...

Java in Hindi {

public static void main(String[] args) throws IOException { Socket echoSocket = null; PrintWriter out = null; BufferedReader in = null; try{ echoSocket = new Socket("taranis", 7); out = new PrintWriter(echoSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host: taranis."); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: taranis."); System.exit(1); } BufferedReader stdIn = new BufferedReader( new InputStreamReader(System.in)); String userInput; while ((userInput = stdIn.readLine()) != null) { out.println(userInput); System.out.println("echo: " + in.readLine()); }

}

}

out.close(); in.close(); stdIn.close(); echoSocket.close();

bl Program esa ge ns[k ldrs gSa fd EchoClient Program, EchoServer Program ls Data dks Receive djus ds fy, Data dks Socket ls gh Read djrk gS vkSj EchoClient Program, EchoServer Program dks Data Send djus ds fy, Hkh Data dks Socket esa gh Write djrk gSA bl Program ds try Block esa rhu ,sls Statements fy[ks x, gSa] tks Client Program o Server Program ds chp Socket Connection Establish djus dk dke djrs gSa vkSj Socket ds fy, ,d PrintWriter o ,d BufferedWriter Object Create djrs gSaA try { 435 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

echoSocket = new Socket("taranis", 7); out = new PrintWriter(echoSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));

bl Try Block dk igyk Statement ,d u;k Socket Object Create djrk gS vkSj mldk uke echoSocket Assign djrk gSA bl Statement esa Socket Constructor dks Argument ds :i esa ml Computer ds uke o Port Number dh t:jr gksrh gS] ftlls ge EchoClient Program dks Connect djuk pkgrs gSaA bl mnkgj.k esa geus Host Name ds :i esa “Kuldeep” “kCn dks Use fd;k gSA ;s uke gekjs Local Network ds dsoy ,d Imaginary Host Computer dks Refer dj jgk gSA tc ge bl Program dks Network ij Run djrs gSa] rc gesa bl uke ds LFkku ij Network ds fdlh Actual Host dk uke Specify djuk gksrk gSA /;ku j[ksa fd Host Name ml Host Computer dk ,d Fully Qualified IP Name gksuk t:jh gksrk gS] ftlls ge Connect gksuk pkgrs gSaA nwljs Argument ds :i esa gesa Socket ds ml Port dk Number nsuk gksrk gS] ftlls gekjk Program Connect gksuk gSA Port Number 7 og Port gS] ftl ij Echo Server Listen djrk gSA bl mnkgj.k esa geus Readers o Writers Classes dk iz;ksx fd;k gS] rkfd ;s Socket ij Unicode Characters dks Write dj ldsA Socket ds Through Server ij Data dks Hkstus ds fy,] EchoClient Program dks dsoy PrintWriter ij Data dks Write djuk gksrk gS vkSj Server Program dk Response izkIr djus ds fy,] EchoClient Program BufferedReader dks Read djrk gSA Try … Catch Block ds ckn ,d vkSj BufferedReader izdkj dk ,d Object stdIn gS] tks fd Keyboard ls izkIr Data dks Store djrk gSA blls vkxs ,d while Loop dk iz;ksx fd;k x;k gSA ;s Loop Keyboard ls ,d ckj esa ,d Line Read djrk gS vkSj mls String izdkj ds ,d Object userInput esa Store dj nsrk gSA fQj bl String izdkj ds Object esa Stored String dks lh/ks gh PrintWriter Type ds ,d Object out esa Write dj nsrk gSA ,slk djus ij out Object esa Hkstk x;k Data Server ij igqap tkrk gS] D;ksafd PrintWriter Type ds Object dks Try Block ds nwljs Statement }kjk Server ds Socket ls Connect fd;k x;k gSA while Loop dk vfUre Statement BufferedReader Object in ls ,d Line dks Read djrk gS] tks fd Try Block ds rhljs Statement }kjk Socket ls Connected gSA bl Statement esa iz;ksx fd;k x;k readLine() Method rc rd Wait djrk jgrk gS] tc rd fd Server Program Information dks fQj ls Client Program esa ugha Hkst nsrk gSA tc readLine() Method Return gksrk gS] rc EchoClient Program ds While Loop dk vfUre Statement Server ls Return gksus okys Text dks fQj ls Monitor ij Display dj nsrk gSA Program ds vUr esa lHkh Streams dks Close fd;k x;k gSA

buds Close djus dk Øe dkQh egRoiw.kZ gksrk gSA Socket dks Close djus ls igys gesa Socket ls Connected lHkh Streams dks Close djuk t:jh gksrk gSA ;kuh Socket dks gesa”kk Program ds vfUre Statement esa Close djuk pkfg,A bl rjg ls ,d Client Program dks fuEukuqlkj ikap Steps esa Develop fd;k tkrk gS% 1

lcls igys ,d Socket Open fd;k tkrk gSA

436 Any Question or Suggestion, Just Discuss Here...

Java in Hindi 2 3 4

5

Socket ij ,d Input Stream o ,d Output Stream dks Open fd;k tkrk gSA Server ls Data dks Read djus o Server ij Data dks Write djus ds fy, bUgha Streams dk iz;ksx fd;k tkrk gSA Streams dks Close fd;k tkrk gSA Socket dks Close fd;k tkrk gSA

Working With URL

URL Internet ij miyC/k fdlh Resource dk ,d Reference ;k Address gksrk gSA tc ge gekjs Web Browser esa fdlh Web Resource dks izkIr djus ds fy, ml Web Resource dk Address (Web Address OR URL ) Input djrs gSa] rc ge ml Web Resource rd igqap tkrs gSa] ftls ge vius Web Browser esa Use djuk pkgrs gSaA Bhd blh rjg ls ;fn ge dksbZ ,slk Program Develop djrs gSa] tks Web ij miyC/k Resources dks Use djrk gS] rks ge Web ds Resource dks Find djus ds fy, vius Program esa Hkh mlds Web Address ;kuh URL dks Use dj ldrs gSaA

tkok esa URL uke dh ,d Class gksrh gS] tks fd java.net uke ds Package esa miyC/k gksrh gSA bl Class dk iz;ksx djds ge gekjs Web Based Application esa fdlh Hkh Web Resource ds URL Address dks Represent dj ldrs gSaA okLro esa URL ,d ,slh Class gS] ftlds Object esa ge fdlh Hkh Web ij fLFkr fdlh Resource dk ;k fQj gekjs Local Computer esa fLFkr fdlh Resource dk Absolute ;k Relative Address Specify djds ml Resource dks vius Program esa Use dj ldrs gSaA

What Is a URL URL ,d Internet ;k gekjs Local Computer esa miyC/k fdlh Resource ds Address dk ,d String Representation gksrk gSA URL ds nks eq[; fgLls gksrs gSa% 1

og Protocol, ftldk iz;ksx djds fdlh Resource dks Access fd;k tkuk lEHko gks ikrk gSA vkSj 2 Resource dh Location dk Address URL ds nksuksa fgLlksa dks ge fuEukuqlkj Describe dj ldrs gSa%

bl Description esa http og Protocol gS] ftldk iz;ksx djds ,d Server //java.sun.com uke ds Internet ij mifLFkr Resource dks ,d Client Computer ij Send djrk gSA bl mnkgj.k esa http (Hyper Text Transfer Protocol) dks Use fd;k x;k gS] tks fd Client Computer ij Web Documents tks fd Hyper Text Documents gksrs gSa] dks Send djus dk dke djrk gSA http ,d ,slk Protocol gS] tks Net ij miyC/k fofHkUu izdkj ds Resources dks Transfer djus esa l{ke gksrk gSA

437 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ge ns[k ldrs gSa fd Resource Name esa Resource dk Complete Address Specify fd;k x;k gSA Resource dk uke Specify djus dk Format ewy :i ls Use fd, tk jgs Protocol ij fuHkZj djrk gS] ysfdu http ds lkFk gh dbZ vU; Protocols esa Resource ds uke esa fuEukuqlkj dbZ vkSj Components miyC/k gksrs gSa% Host Name File Name Port Number Reference

ml Server Computer dk uke ftl ij Resource Stored gSA Server Computer ij fLFkr File dk iwjk Path Name og Port Number ftlls Client dks Connect gksuk gksrk gSA (Optional) Resource esa miyC/k fdlh Specific Location dk Identifier (Optional)

dbZ Protocols dks fdlh Resource dks Access djus ds fy, Host Name o File Name dh t:jr gksrh gS] tcfd bu Protocols dks Use djrs le; gesa Port Number o Reference Field dks Specify djuk t:jh ugha gksrk gSA mnkgj.k ds fy, tc ge HTTP Protocol dk iz;ksx djds fdlh Resource dks izkIr djuk pkgrs gSa] rc gesa Network ij fLFkr Server (Host Name) o Server ij mifLFkr Resource (Document) dk Path (File Name) gh Specify djuk gksrk gSA gkykafd ge blds lkFk Port Number o Reference dks Hkh Specify dj ldrs gSaA tc ge fdlh Web Site dk URL fy[krs le; mlds lkFk fdlh Document ds uke dk iz;ksx ugha djrs gSa] rc lkekU;r;k ml Web Site ds Index.htm uke dk Document gh Client dks izkIr gksrk gS] tks fd lkekU;r;k fofHkUu izdkj dh Web Sites ds fy, Default Web Document ds leku gksrk gSA ;fn ge fdlh Specific Document dks izkIr djuk pkgsa] rks mijksDr URL dks fuEukuqlkj Hkh Use dj ldrs gSa% http://java.sun.com/index.html

Creating and Manipulating URL tc ge gekjs fdlh Application esa URL dks Use djuk pkgrs gSa] rc gesa ml URL dks Access djus ds fy, URL Class dk ,d Object Create djuk gksrk gS vkSj bl Class ds Constructor dks Use djds Specific URL Address dks ,d String Argument ds :i esa Constructor esa Pass djuk gksrk gSA mnkgj.k ds fy, ekuyks fd gesa fuEu Web Address dks ,d URL Object esa Store djuk gks% http://www.indiaresults.com/

rks bls URL Object esa Store djus ds fy, gesa fuEukuqlkj Statement fy[kuk gksrk gS% URL indiaresults = new URL (“http://www.indiaresults.com/“);

bl Statement }kjk tks URL Object Create fd;k x;k gS] og URL ,d Absolute URL gSA ,d Absolute URL esa fdlh Resource rd igqapus ls lEcaf/kr lHkh t:jh Fields gksrs gSaA ;fn ge pkgsa rks ,d ,slk URL Object Hkh Create dj ldrs gSa] tks fd fdlh nwljs URL ls Relative URL Address gksrk gSA

438 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Relative URL Object esa dsoy bruh gh tkudkjh gksrh gS] ftruh Current URL ls vkxs ds fdlh vU; Resource rd igqp a us ds fy, t:jh gksrh gSaA Relative URL Specifications dks lkekU;r;k HTML Files esa Use fd;k tkrk gSA

mnkgj.k ds fy, ekuyks fd ge HelloHomePage.html uke dk ,d HTML Page cukrs gSa] ftlls nks MyMusic.html o MyPicture.html uke ds nks vU; Web Pages Linked gSa vkSj ;s nksuksa Linked Web Pages mlh Computer ds mlh Folder esa Stored gSa] ftlesa HelloHomePage.html Web Page Stored gSaA bl fLFkfr esa HelloHomePage.html Web Page esa bu nksuksa vU; Web Pages dks Link djus ds fy, gesa dsoy fuEukuqlkj Statement gh fy[kuk gksrk gS% My Music My Picture

;s URL Relative URL gSa] ftuesa URL dh iwjh Location dks Specify ugha fd;k x;k gS] cfYd dsoy ml Current Folder ds Reference esa Specify fd;k x;k gS] ftlesa HelloHomePage.html Stored gSA ge gekjs tkok Program esa ,d ,slk URL Object Hkh Create dj ldrs gSa] tks fd fdlh nwljs URL Specification ls Relative gksrk gSA mnkgj.k ds fy, ekuyks fd ge Results dh ,d Web Site ds nks jkT;ksa ds Web Pages dk Address tkurs gSa] tks fd fuEukuqlkj gSa% http://www.indiaresults.com/maharastra_results.html http://www.indiaresults.com/rajasthan_results.html

ge bu nksuksa Pages ds fy, fuEukuqlkj ,d Relative URL Object Create dj ldrs gSa% URL results = new URL(“http://www.indiaresults.com/”); URL raj_result = new URL(results, “maharastra_results.html”); URL mah_result = new URL(results, “rajasthan_results.html”)

;s Code Segment ,d ,sls URL Constructor dks Use dj jgk gS] tks gesa ,d Base URL Address ls Relative URL Object dks Create djuh dh lqfo/kk iznku dj jgk gSA ;s Constructor fuEukuqlkj gksrk gS% URL(URL baseURL, String relativeURL)

bl Constructor dk igyk Argument Create gksus okys u, URL dk Base Specify djrk gS] tcfd nwljk Argument ,d String Format esa ml Resource dks Specify djrk gS] tks fd Base URL ls Relative gSA ;fn baseURL null gks] rks ;s Constructor relativeURL dks ,d Absolute URL dh rjg Use djrk gSA blh rjg ls ;fn relativeURL esa Absolute URL gks] rks ;s Constructor baseURL dks Ignore dj nsrk gSA ;s Constructor fdlh File esa fLFkr ,d Named Anchor dks Refer djus okyk URL Object Create djus esa Hkh mi;ksxh gksrk gS] ftls Reference dgrs gSaA mnkgj.k ds fy, ekuyks fd HelloHomePage.html File esa BOTTOM uke dk ,d Named Anchor gS vkSj ge Directly Anchor dks Refer djus okyk URL Object Create djuk pkgrs gSaA bl fLFkfr esa ge Relative URL Constructor dks fuEukuqlkj Use dj ldrs gSa%

439 Any Question or Suggestion, Just Discuss Here...

Java in Hindi URL r = new URL(HelloNetwork, “BOTTOM”);

bu Constructors ds vykok URL Objects Create djus ds fy, URL Class esa nks vkSj Constructors gksrs gSaA ;s Constructors ml fLFkfr esa mi;ksxh gksrs gSa] tc ge HTTP tSls fdlh ,sls URL ds lkFk dksbZ izfØ;k dj jgs gksrs gSa] ftlesa Host Name, File Name, Prot Number o References Components gksrs gSaA ;s nks Constructors rc mi;ksxh gksrs gSa] tc gekjs ikl fdlh Incomplete URL dk String Representation gksrk gS] ftlesa lHkh Components ugha gksrs gSa vkSj gesa bl URL ds lHkh Components dh t:jr gksrh gSA mnkgj.k ds fy, ekuyks fd ge ,d Network Browsing Panel cukuk pkgrs gSa] tks User dks Protocol, Host Name, Port Number o File Name Select djus dh lqfo/kk nsrk gSA Panel esa Select fd, x, Components ds vk/kkj ij ;fn ge URL Create djuk pkgsa] rks bl fLFkfr esa gesa fuEukuqlkj Constructor dks Use djuk gksrk gS% new URL(“http”, “www.indiaresults.com”, “/homepage.html”);

blh URL dk Equivalent URL fuEukuqlkj Create fd;k tk ldrk gS% new URL(“http://www.indiaresults.com/homepage.html”);

bl URL esa igyk Argument Protocol dks] nwljk Argument Host Name dks o rhljk Argument File ds Path Name dks Specify dj jgk gSA URL dk tks vfUre Constructor gksrk gS] mlesa ge bl Protocol dh Argument List esa Port Number dks Hkh Specify dj ldrs gSaA ;fn ge blh URL dks Port Number ds lkFk Use djuk pkgsa] rks blfy, fy, fuEukuqlkj URL Object Create dj ldrs gSa% new URL(“http”, “www.indiaresults.com”, 80, “/homepage.html”);

;k bldk Equivalent URL fuEukuqlkj Create fd;k tk ldrk gS% new URL(“http://www.indiaresults.com:80/homepage.html”);

;fn ge buesa ls fdlh Constructor dks Use djds dksbZ URL Create djrs gSa] rks ge ml URL dks ,d String Representation ds :i esa izkIr djus ds fy, gesa URL Object ds fy, toString() ;k toExternalForm() Method dks Use djuk gksrk gSA URL Create djus ds fy, ftrus Hkh Constructors dks geus Discuss fd;k gS] os lHkh URLs ,d MalformedURLException uke dk Exception Throw dj ldrs gSaA ;s Exception rc Throw gksrk gS] tc Constructor fdlh NULL URL dks ;k Unknown Protocol dks Refer djrk gSA bl Exception dks Catch o Handle djus ds fy, URL Create djrs le; gesa try . . . catch Block dk iz;ksx djuk gksrk gS] tks fd ge fuEukuqlkj dj ldrs gSa% try { URL myURL = new URL(. . .) } catch (MalformedURLException e){

440 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

}

... // exception handler code here ...

URL Objects ,sls Objects gksrs gSa] ftUgsa ,d ckj Create dj nsus ds ckn blds fdlh Attribute (Protocol, Host Name, File Name, Prot Number) dks Change ugha fd;k tk ldrk gSA ;kuh tc ge ,d URL Create djds Use dj ysrs gSa] rks mlh URL esa u;k Web Address Specify djds mls fQj ls Reuse ugha dj ldrs gSa] cfYd nwljs Web Address dks Store djus ds fy, gesa ,d vkSj u;k URL Object Create djuk t:jh gksrk gSA URL Class gesa dbZ ,sls Methods Provide djrk gS] ftudk iz;kssx djds ge fdlh URL Object ds fdlh Hkh Part (Protocol, Host Name, File Name, Prot Number) dks Extract dj ldrs gSaA blds fy, ge fuEukuqlkj Methods dks Use dj ldrs gSa% getProtocol() ;s Method URL Objects esa ls Protocol Identifier dks Return djrk gSA getHost() ;s Method URL Objects esa ls Host Name Component dks Return djrk gSA getPort() ;s Method URL Objects esa ls Port Number Component dks Return djrk gSA ;s Method ,d Integer Number Return djrk gS] tks fd Port dks Specify djrk gSA ;fn Port dks Set uk fd;k x;k gks] rks ;s Method -1 Return djrk gSA getFile() ;s Method URL Objects esa ls File Name Component dks Return djrk gSA getRef() ;s Method URL Objects esa ls Reference Component dks Return djrk gSA

,d ckr gesa”kk /;ku j[ksa fd lHkh izdkj ds URL Addresses esa ;s lHkh Components ugha gksrs gSaA URL Class esa bu Methods dks blfy, Provide fd;k x;k gS] D;ksafd HTTP URL esa ;s lHkh Components gksrs gSa vkSj ;s lcls T;knk Use fd;k tkus okyk URL gksrk gSA URL Class dks dqN gn rd HTTP Protocol dks /;ku esa j[kdj gh Develop fd;k x;k gSA bu fofHkUu izdkj ds URL Components dks vyx djus dh izfØ;k dks ge fuEu Program }kjk le> ldrs gSa% Program import java.net.*; import java.io.*; public class ParseURL { public static void main(String[] args) throws Exception { URL aURL = new

441 Any Question or Suggestion, Just Discuss Here...

Java in Hindi URL("http://java.sun.com:80/docs/books/tutorial/intro.html#DOWNLOADING");

}

}

System.out.println("protocol = " + aURL.getProtocol()); System.out.println("host = " + aURL.getHost()); System.out.println("filename = " + aURL.getFile()); System.out.println("port = " + aURL.getPort()); System.out.println("ref = " + aURL.getRef());

Output protocol = http host = java.sun.com filename = /docs/books/tutorial/intro.html port = 80 ref = DOWNLOADING

,d URL Object Create dj ysus ds ckn ge URL ds openStream() Method dks Call djds ge URL esa Specify fd, x, Web Document ds Contents dks ,d Stream ds :i esa izkIr dj ldrs gSaA ;s Method ,d java.io.InputStream Class dk ,d Object Return djrk gS] blfy, URL esa Specify fd, x, Web Document ds Content dks Read djuk mruk gh ljy gksrk gS] ftruk fdlh Input Stream dks Read djuk gksrk gSA

442 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Java RMI Remote Method Invocation

443 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Java RMI – Remote Method Invocation RMI Applications

RMI Applications esa lkekU;r;k nks Separate Programs gksrs gSa] ftUgsa Server Program o Client Program dgk tkrk gSA bl izdkj ds Applications esa ,d Server Application dqN Remote Objects Create djrk gS] mUgsa Accessible cukus ds fy, dqN References Create djrk gS vkSj bl ckr dk Wait djrk gS] fd dksbZ Client Software bu Remote Objects ds Methods dks Invoke djsA

blh rjg ls ,d Client Application, Server Application ds ,d ;k ,d ls T;knk Remote Objects dk Reference izkIr djrk gS vkSj fQj mu Objects ds Methods dks Invoke djrk gSA RMI og rjhdk iznku djrk gS] ftldk iz;skx djds Client o Server Communication djrs gSa vkSj ,d nwljs dks Information Pass djrs gSaA bl izdkj ds Applications dks dbZ ckj Distributed Object Application dgrs gSaA Distributed Applications os Applications gksrs gSa] tks dbZ Host Computers ij Execute gksrs gSaA fdlh ,d Host ij Execute gksus okyk Object fdlh nwljs Remote Host ds Method dks Invoke dj ldrk gSA Remotely Invoke fd;k tkus okyk Method fdlh Local Computer dks Requirement ds vk/kkj ij dksbZ eku Return dj ldrk gSA Distributed Application Develop djus ds fy, dbZ Approaches gSa] ftuesa ls fdlh dks Hkh Use fd;k tk ldrk gSA Internet o Web Distributed System ds mnkgj.k gSa] ftls Client/Server Approach ds vk/kkj ij Develop fd;k x;k gSA Data dk Transfer gksuk fdlh Hkh Distributed System dk ,d cgqr gh egRoiw.kZ Process gksrk gSA tkok esa Message Passing ds Default System ds vk/kkj ij ,d gh Java Virtual Machine esa Calling Object fdlh nwljs Called Object dks Data Transfer djrk gSA ,d Host ls fdlh nwljs Host ij Data Hkstus ds fy, Remote Method Invocation (RMI) Approach dks Use dj ldrs gSaA RMI Objects dks og lqfo/kk iznku djrk gS] ftlls os ,d Host ls nwljs Host ij Messages Hkst ldrs gSa vkSj Receive dj ldrs gSaA RMI Objects dks fofHkUu izdkj ds Hosts ls lEcaf/kr fofHkUu JVMs dks Message Hkstus o Receive djus dh lqfo/kk nsrk gSA

fdlh Hkh Distributed Object Application dh fuEu vko”;drk,a gksrh gSa% 1 Locate Remote Object ,d Application nks esa ls fdlh ,d rjhds dk iz;ksx djds fdlh Remote Object dk Reference izkIr dj ldrk gSA ,d Application vius Remote Objects dks rmiregistry dh Simple Naming Facility dk iz;ksx djds RMI ls Register djok ldrk gS vFkok ,d Application Remote Objects ds References dks Return ;k Pass djus ds fy, vius Application esa Normal Operation Define dj ldrk gSA 2

Communicate with Remote Objects Remote Objects ds lkFk dh tkus okyh Communications dh Details dks RMI }kjk Handle fd;k tkrk gSA Programmer ds n`f’Vdks.k ls ns[ksa rks Remote Communication fdlh Standard Java Method Invocation Process dh rjg gh fn[kkbZ nsrk gSA ;kuh bl rduhd esa fdlh Object ds fy, fdlh Remote Method dks Hkh mlh rjg ls Invoke fd;k tkrk gS] ftl rjg ls fdlh lkekU; Object ds Method dks Invoke fd;k tkrk gSA

444 Any Question or Suggestion, Just Discuss Here...

Java in Hindi 3

Local Class Bytecodes For Objects That Are Passed Around RMI ,d Caller Method dks ;s lqfo/kk Provide djrk gS] fd og Remote Objects ij Hkh fdlh Local Object dks Pass dj ldrk gSA RMI fdlh Object Code ds lkFk&lkFk Object ds Data dks Load djus ds fy, Hkh t:jh Mechanism Provide djrk gSA

RMI Distributed Application ,d Registry dk iz;ksx djds fdlh Remote Object dk Reference izkIr djrk gSA Server Application Registry dks Call djds Remote Object ls ,d uke Associate ;k Bind djrk gSA Client Program Remote Objects ds uke dks Server dh bl Registry esa [kkstrk gS vkSj uke fey tkus ij Server ij ,d Method dks Invoke djrk gSA tc t:jr gksrh gS rc fdlh Object ds fy, RMI System ,d Existing Web Server dks Use djds Class ds Bytecodes dks Server ls Client esa o Client ls Server esa Load djrk gSA bl izfØ;k dks ge fuEu fp= }kjk Hkh le> ldrs gSa%

Advantage of Dynamic Code Loading

RMI dh ,d eq[; fo”ks’krk ;s gS fd ;fn fdlh Object dh Class dks Client dh Virtual Machine ij Define uk fd;k x;k gks] rks ;s Client dh Virtual Machine esa Object dh Class ds Bytecodes dks Download dj nsrk gSA

;kuh fdlh Object dh Class o Behavior, tks fd igys fdlh ,d gh Virtual Machine ij miyC/k gksrs gSa] mUgsa RMI dk iz;ksx djds nwljs ;k Remote Virtual Machine ij Hkh Transmit fd;k tk ldrk gSA RMI Objects dks mudh okLrfod Class ;k Type ds lkFk Pass djrk gS] blfy, mu Objects ds Behaviors rc Change ugha gksrs gSa] tc mUgsa nwljh Machine ij Hkstk tkrk gSA ;s izfØ;k nwljh Machine ij ,d u;k Type ;k Class miyC/k djok nsrk gS] ;kuh ,d Application ds Behaviors dks Dynamically Extend dj nsrk gSA

Remote Interfaces, Objects and Methods

fdlh Hkh vU; Application dh rjg gh] Java RMI ds vk/kkj ij Develop fd, tkus okys ,d Distributed Application esa Hkh Interfaces o Classes dk iz;kssx gksrk gSA Interfaces esa Methods dks Declare fd;k tkrk gS vkSj Classes esa mu Methods dks Implement fd;k tkrk gS] lkFk gh dqN Additional Methods dks Hkh Define fd;k tkrk gSA

445 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ,d Distributed Application esa dqN ,sls Methods Define fd, tkrs gSa] ftUgsa Remote Virtual machine ij Implement fd;k tkrk gSA os Objects ftuesa ,sls Methods gksrs gSa] ftUgsa nks vyx Virtual Machines ij Cross Form esa Call fd;k tk ldrk gS] Remote Objects dgykrs gSaA ,d Object ml le; Remote Object cu tkrk gS] tc mlesa Remote Interface dks Implement fd;k tkrk gSA fdlh Remote Object dh fuEu Characteristics gksrh gSa% • •

,d Remote Interface java.rmi.Remote Interface dks Extend djrk gSA Interface dk gj Method fdlh Hkh vU; Application Specific Exceptions ds lkFk java.rmi.RemoteException dks Hkh mlds throws Class esa Declare djrk gSA

tc fdlh Remote Object dks ,d Virtual Machine ls nwljs Virtual Machine ij Pass fd;k tkrk gS] rc RMI bl Remote Object dk ,d Non-Remote Object dh rqyuk esa vyx rjhds ls Treat djrk gSA tc fdlh Remote Object dks ,d Virtual Machine ls fdlh nwljh Virtual machine esa Pass fd;k tkrk gS] rc RMI fdlh Remote Object ds Implementation dh Receiving Virtual Machine esa ,d Copy cukus ds ctk; Remote Object ds fy, ,d Remote Stub Pass djrk gSA ;s Stub, Remote Object ds ,d Local Representative ;k Proxy dh rjg dke djrk gS vkSj Caller ds fy, Stub Remote Object dk Remote Reference gksrk gSA Caller, Remote Method dks Local Stub ij Invoke djrk gS] tks fd Remote Object dk ,d Representative gksrk gSA Remote Object ds fy, ,d Stub mlh izdkj ds Remote Interfaces dk Set Implement djrk gS] ftl izdkj dk Set Remote Object Implement djrk gSA ;s izfØ;k Stub dks ;s lqfo/kk Provide djrh gS] fd og Remote Object }kjk Implement fd, tkus okys fdlh Hkh Interface ds :i esa Cast gks ldrk gSA gkykafd bldk eryc ;s Hkh gS fd dsoy os gh Methods Call gksus ds fy, Receiving Virtual Machine ij miyC/k gksrs gSa] ftUgsa Remote Interface esa Define fd;k x;k gksrk gSA

Creating Distributed Application Using RMI

tc ge RMI dk iz;ksx djds dksbZ Distributed Application Develop djuk pkgrs gSa] rc gesa fuEukuqlkj Steps Follow djus gksrs gSa%

Design and Implement the components of Distributed Application lcls igys gesa gekjs Application ds Architecture dks r; djuk gksrk gS vkSj ;s r; djuk gksrk gS fd Application ds dkSuls Components Local Objects gksaxs vkSj fdu Components dks Remotely Accessible cukuk gksxkA bldk fu.kZ; ge fuEukuqlkj ys ldrs gSa% •

Defining The Remote Interfaces ,d Remote Interface mu Methods dks Specify djrk gS] ftUgsa Client }kjk Remotely Invoke fd;k tk ldrk gSA Design ds bl fgLls esa mu Local Objects dks Determine fd;k tkrk gS] ftUgsa bu Methods ds fy, Parameter o Return Values ds :i esa Use fd;k tkuk gksrk gSA

446 Any Question or Suggestion, Just Discuss Here...

Java in Hindi •

Implementing The Remote Objects Remote Objects dks ,d ;k ,d ls T;knk Remote Interfaces dks Implement djuk gksrk gSA Remote Object dh Class esa vU; Local Methods o (Local ;k Remote) Interfaces ds Implementations gks ldrs gSaA ;fn fdlh vU; Local Class ds Object dks Parameter ;k Return Value ds :i esa bu Methods esa Use fd;k tk jgk gS] rks mUgsa Hkh Implement djuk t:jh gksrk gSA



Implementing The Clients os Clients, tks fd Remote Objects dks Use djrs gSa] mUgsa Remote Interfaces dks Define djus ds ckn fdlh Hkh le; Implement fd, tk ldrs gSa] fQj pkgs Remote Objects dks Deploy gh D;ksa uk dj fn;k x;k gksA

Compile Sources and Generate Stubs ;s ,d 2-Step Process gSA igys Step esa ge javac Compiler dks Use djds mu Source File dks Compile djrs gSa] ftuesa Remote Interfaces] Server Classes o Client Classes dks Implement fd;k x;k gksrk gSA nwljs Step esa ge rmic Compiler dks Use djds Remote Objects ds fy, Stubs Create djrs gSaA RMI, Remote Objects dh bl Stub Class dks Client Program esa ,d Proxy dh rjg Use djrk gS] rkfd Client fdlh Particular Remote Object ls Communicate dj ldsA Make Classes Network Accessible bl Step esa ge Remote Interfaces ls Associated Class Files, Stubs o vU; Class Files, ftUgsa Clients esa Download djuk gksrk gS vkSj tks Web Server }kjk Accessible gksrs gSa] dks Create djrs gSaA Start The Application Application dks Start djus ds fy, RMI Remote Object Registry, Server o Client Programs dks Start djuk gksrk gSA pfy,] ,d mnkgj.k }kjk ge bl iwjh izfØ;k dks le>us dh dksf”k”k djrs gSaA ge tks Program ;gka ij Create dj jgs gSa] blds Server esa ,d Remote Object gS] tks Clients ls fdlh Request dks izkIr djrk gS] mls Process djrk gS vkSj Client dks Result Return djrk gSA Client dh Request ml Virtual Machine ij Process gksrh gS] ftl ij Server Run gks jgk gSA bl Program dh fo”ks’krk ;s gS fd bl Program dk Server tks dke djrk gS] mls mlh Server esa Define djus dh t:jr ugha gksrh gSA

fdlh Hkh le; u, izdkj ds dke dks Perform djus ds fy, Coding dks Create fd;k tk ldrk gS vkSj mls Server ij Run gksus ds fy, Hkstk tk ldrk gSA fdlh dke dks iwjk djus ds fy, gesa ml dke ls lEcaf/kr Class esa fdlh Particular Interface dks Implement djuk gksrk gSA fdlh dke ls lEcaf/kr Class dks Server ij Hkstdj ml dke dks iwjk djok;k tk ldrk gS] fQj pkgs ml dke dks iwjk djus okyh Class dks Server Class Create o Start djus ds dkQh ckn esa Create fd;k x;k gksA dke dks iwjk djus ds fy, ftu Codes dh t:jr gksrh gS] mls RMI System }kjk Server Program esa Download fd;k tk ldrk gS vkSj fQj 447 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Server ml dke dks ml Machine ds Resources dks Use djds Run djrk gS] ftl ij Server Run gks jgk gksrk gSA Random izdkj ds dkeksa dks iwjk djus dh lqfo/kk tkok Platform ds Dynamic Nature ds dkj.k izkIr gksrh gS] ftlesa RMI dk iz;ksx djds tkok ds Platform dks Network ij Extend fd;k tkrk gSA RMI fofHkUu izdkj ds Tasks dks] fcuk ml Class dh Prior Knowledge ds Dynamically Server ds Virtual Machine esa Load o Run djrk gS] ftlesa Task dks Implement fd;k x;k gSA ,d ,slk Application ftlesa Codes dks Dynamically Download djus dh {kerk gks] Behavior Based Application dgykrk gSA

Creating RMI Server

gekjk Server, Client ls tks dh Requests dks Accept djrk gS] mls Process djrk gS vkSj Client dks Results Return djrk gSA bl Server esa ,d Interface o ,d Class gSA Interface esa mu Methods dks Define fd;k x;k gS] ftUgsa Client }kjk Call fd;k tk ldrk gSA Designing A Remote Interface ge tks Server Create dj jgs gSa] ml Server dk vk/kkj ,d Protocol gS tks fdlh Job dks Server ij Submit djus] Server }kjk ml Job dks Run djus o Generate gksus okys Result dks fQj ls Client ij Hkstus dh lqfo/kk nsrk gSA bl Protocol dks ,d Interface esa Express fd;k x;k gS] ftls Server o Server ij Hksts tkus okys Object Support djrk gSA bl izfØ;k dks ge fuEu fp= }kjk le> ldrs gSa%

gj Interface esa ,d Single Method gksrk gSA Server dk Interface Job dks Process djrk gS o Generate gksus okys Result dks Submit djus dh lqfo/kk nsrk gSA tcfd Client dk Interface ;s fuf”pr djrk gS fd Server Submit fd, x, Job dks fdl izdkj ls iwjk djrk gSA comput.Comput Interface Remotely Accessible Part dks Define djrk gS] tks fd Lo;a Server gksrk gSA bldk Code fuEukuqlkj gS% Program // File Name : compute.java package compute; import java.rmi.Remote; import java.rmi.RemoteException; public interface Compute extends Remote { Object executeTask(Task t) throws RemoteException; }

448 Any Question or Suggestion, Just Discuss Here...

Java in Hindi java.rmi.Remote Interface dks Implement djds] ;s Interface Lo;a dks bl ckr ds fy, Specify djrk gS fd blds Method dks fdlh Hkh Virtual Machine }kjk Call fd;k tk ldrk gSA bl Interface dks Implement djus okyk dksbZ Hkh Object ,d Remote Object cu tkrk

gSA

Remote Interface ds ,d Member ds :i esa Define fd;k x;k executeTask Method ,d Remote Method cu tkrk gSA blfy, bl Method dks ,slk Define djuk t:jh gks tkrk gS] tks java.rmi.RemoteException dks Throw dj ldsA

bl Exception dks RMI System }kjk ml le; Throw fd;k tkrk gS] tc dksbZ Remote Method Call ;k rks Communication LFkkfir uk dj ik, ;k fQj tc dksbZ Protocol Error Generate gks tk,A RemoteException ,d Checked Exception gksrk gS] blfy, dksbZ Hkh ,slk Code tks bl Remote Method dks Call djrk gS] mls bl Exception dks Catch djds Handle djuk

t:jh gksrk gSA

nwljs Interface dh t:jr Server ds fy, Task Type dks Define djus ds fy, gksrh gSA bl Type dk iz;ksx Compute Interface ds executeTask() Method esa Argument ds :i esa fd;k tkrk gSA comput.Task Interface, Server o Perform fd, tkus okys Job ds chp Job dks Start djus dk rjhdk iznku djrk gSA bldk Code fuEukuqlkj gS% package compute; import java.io.Serializable; public interface Task extends Serializable { Object execute(); } Task Interface execute() uke dk ,d Single Method Define djrk gSA ;s Method Return Value ds :i esa ,d Object Return djrk gS vkSj blesa dksbZ Parameter Pass ugha

fd;k tkrk gSA

;s Method fdlh rjg dk dksbZ Exception Hkh Throw ugha djrk gSA D;ksafd ;s Interface Remote Class dks Inherit ugha djrk gS] blfy, bl Interface ds bl Method ds lkFk java.rmi.RemoteException dks blds throws Clause ds lkFk List djus dh t:jr ugha gksrh gSA

Compute ds executeTask() Method o Task ds execute() Method ds Return Value dks Object Type dk Declare fd;k x;k gSA bldk eryc ;s gS fd tks Hkh Task fdlh Primary Type ds Value (int, float, char) dks Return djuk pkgrk gS] mls bu ekuksa dks muds Equivalent Wrapper Class ds Type (Integer, Float, Character) esa Convert djds mldk Object Return djuk gksxkA

449 Any Question or Suggestion, Just Discuss Here...

Java in Hindi geus Task Interface esa java.io.Serializable Interface dks Extend fd;k gSA RMI Object Serialization Mechanism dk iz;ksx djds Java Virtual Machines ds chp esa Objects dks By Value Transport dj ldrk gS] tks fd lkekU;r;k By Reference gh Transport gksrs gSaA Compute Object }kjk fofHkUu izdkj ds mu Tasks dks Run fd;k tk ldrk gS] ftuesa Task Type dks Implement fd;k x;k gksrk gSA tks Classes bl Interface dks Implement djrh gSa] muesa Computation ls lEcaf/kr fofHkUu izdkj ds vU; Data o Methods gks ldrs gSa] tks Computation ds fy, t:jh gSaA

RMI Technology

RMI bl Specification ds vk/kkj ij Develop fd;k x;k gS fd Local Objects o Remote Objects vkil esa feydj Interoperate dj ldrs gSaA Local Objects os Objects gksrs gSa] tks Local Computer ij Execute gksrs gSa vkSj Remote Objects os Objects gksrs gSa] tks vU; Host Machines ij Execute gksrs gSaA Remote Registry Server (rmiregistry) ,d ,slk Software gksrk gS] tks Server ij Run gksrk gSA ;s Remote Registry Server vU; Hosts dks ;s lqfo/kk nsrk gS] fd os blds Registered Objects dks Remotely Access dj ldsaA Remote Registry Server esa ,d Database gksrk gS] ftlesa mu lHkh Objects dk uke gksrk gS] tks Remote Registry Server ls Register gksrs gSaA Remote Registry Server dks Start djus ds fy, gesa Command Prompt ij “Start rmiregistry” Command fy[kdj Enter djuk gksrk gSA ;s Server Port 1099 ij Listens djrk gSA

os Objects ftUgsa Remote Access ds fy, Register fd;k tkuk gksrk gS] mUgsa RemoteInterface dks Implement djuk t:jh gksrk gSA ;s Interface mu Objects dks Identify djrk gS] ftUgsa Remotely Access fd;k tkuk gksrk gSA og gj Method ftls Remotely Invoke fd;k tkuk gksrk gS] mls ,d RemoteException Throw djuk t:jh gksrk gSA bl Exception dk iz;ksx mu Errors dks Handle djus ds fy, fd;k tkrk gS] tks Remote Method dks Invoke djrs le; Generate gksrs gSaA tkok dk RMI Approach Client/Server Framework ds vk/kkj ij Organized gksrk gSA ,d Local Object tks fd Remote Method dks Invoke djrk gS] Client Object dgykrk gS vkSj og Object ftldk Method Remotely Invoke gksrk gS] Server Object dgykrk gSA tkok dk RMI Approach Stubs o Skeletons dks Use djrk gSA Stub Client Computer dk ,d Local Object gksrk gS] tks Remote Object ds fy, ,d Proxy dh rjg dke djrk gSA Stub Remote Object ds Methods Provide djrk gSA Local Object Stub ds Methods dks bl rjg ls Invoke djrk gS] tSls fd og Remote Object dk gh Method gksA Stub bu Methods dks Invoke djds Communicate djus ds fy, ,d Skeleton dk iz;ksx djrk gS] ftls Remote Host ij Implement fd;k tkrk gSA Skeleton Client Computer dk Proxy gksrk gS] tks fd Remote Host Computer ij fLFkr gksrk gSA Stub o Skeleton ,d Remote Reference Layer ds Through Communicate djrs gSaA ;s Layer Stub dks og Capability Provide djrk gS] ftlls og ,d Transport Protocol dk iz;ksx djds Skeleton ls Communicate djrk gSA RMI TCP Protocol dks Use djds Information dks Transport djrk gSA

450 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Java Database Management

451 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Java Database Management

T;knkrj Web-Based Application Programs dks Database Management System (DBMS) ls Interact djus dh t:jr iMrh gSA DBMS os Software gksrs gSa ftudk iz;ksx Application }kjk Use dh tkus okyh Information dks Store djus ds fy, fd;k tkrk gSA mnkgj.k ds fy, ;fn ge fdlh Search Engine ls fdlh Web Site ds URL dks Search djrs gSa] rks og URL fdlh uk fdlh DBMS Software esa gh Stored jgrk gSA blh rjg ls ekuyks fd ge Online Ticket Management djus ds fy, ,d Software cukuk pkgrs gSaA rks bl izdkj dk Software cukus ds fy, ;s t:jh gksrk gS fd Software ls lEcaf/kr Data dks fdlh uk fdlh ,d O;ofLFkr rjhds ls Manage fd;k tk,A ge gesa”kk gekjs Important Data dks ,d File ds :i esa Store djds vPNh rjg ls Manage ugha dj ldrs gSaA ,sls esa Data dks Manage djuk dkQh dfBu dke gksrk gSA Data dks Manage djus ds fy, fofHkUu izdkj ds vf/kd lqjf{kr o Manageable Software cuk, x, gSaA bu Software dks DBMS Software dgk tkrk gSA gekjk Application ftu Data dks Access djrk gS] mUgsa Store djus ds fy, ge Database Management Software dk iz;ksx djrs gSaA ysfdu User vklkuh ls vius Data ds lkFk fofHkUu izdkj dk Interaction dj lds] blds fy, ,d ljy User Interface dh Hkh t:jr gksrh gSA

tc ge Data dks Store djus ds fy, SQL, Oracle ;k fdlh vU; izdkj ds DBMS Software dks pqurs gSa rc ge User Interface Development ds fy, tkok dks Use dj ldrs gSaA tc ge tkok dks User Interface Develop djus ds fy, Use djrs gSa] rc tkok dks Front-End Software o DBMS Software dks Back-End Software dgk tkrk gSA

Database Management System Software

Database vkil esa Logically Related Information dk ,d Collection gksrk gS vkSj bl Collection dks ftl izdkj ds Software }kjk Handle o Manage fd;k tkrk gS] ,sls Software dks Database Management System (DBMS) Software dgrs gSaA ;s Software gesa os Mechanism iznku djrs gSa] ftudk iz;ksx djds ge fdlh Database ds Data dks Database ls Retrieve djus] Modify djus ;k Database esa Add djus esa l{ke gks

ikrs gSaA

vkt Data dks Store djus ds fy, fofHkUu izdkj ds DBMS Software miyC/k gSa vkSj ge ftl DBMS Software dks Use djuk pkgsa] mls Use dj ldrs gSa] ysfdu fofHkUu izdkj ds DBMS Software gekjs Data dks muds Lo;a ds izdkj esa Store djrs gSaA mnkgj.k ds fy, MS-Access esa Store fd;k tkus okyk Data .MDB Format esa Save gksrk gS] tcfd MSSQL Server esa Store fd;k tkus okyk Data .DAT Format esa Save gksrk gSA DBMS Software ,d ,slk Software gksrk gS] ftls fdlh nwljs Computer ij Data dks Store djus ds fy, Install fd;k tkrk gS vkSj fdlh vkSj Computer ij fLFkr fdlh vU; Front-End ls bl Computer ds Database esa Data dks Use fd;k tk ldrk gSA ;kuh

452 Any Question or Suggestion, Just Discuss Here...

Java in Hindi User Interface o Database nksuksa vyx&vyx Computer ij Stored gksrs gSa] fQj Hkh vkil esa feydj ,d Unit dh rjg dke dj ldrs gSAa

Database Connectivity

ge le> ldrs gSa fd gekjs Application dk Data ,d vyx Software esa Store jgrk gS tcfd ml Data dks Access djus ds fy, tks Functionality gesa DBMS Software }kjk izkIr gksrh gS] mls Use djds gekjk Front-End Software Back-End Database ls Data dks Access djus esa l{ke gks ikrk gSA ;kuh gekjk User Interface o Database nksuksa nks vyx Computer ij gks ldrs gSaA bl fLFkfr esa nks vyx Software ds chp vkil esa Data dk Interchange gksrk jgrk gSA ;kuh Front-End User Interface ls Input fd;k x;k Data Back-End Database esa Store gksrk gS vkSj t:jr iMus ij Back-End Database ls Required Data Front-End User Interface esa vkrk gSA ;s izfØ;k rHkh lEHko gks ldrh gS] tc Back-End Database o Front-End User Interface nksuksa vkil esa fdlh rjhds ls Connected gksaA User Interface dks Database ls Connect djus ds fy, ,d fof”k’V rjhds dh t:jr gksrh gSA bl rjhds dks Windows Platform ds fy, Microsoft us ODBC ds :i esa gesa iznku fd;k gSA ODBC ,d ,slk Middle Level Software gksrk gS] tks ,d Back-End Database dks ,d Front-End User Interface ls Connect dj nsrk gSA bls Open Database Connectivity (ODBC) dgk tkrk gS] tks fd Back-End Database o Front-End User Interface ds chp ,d Protocol ;k ,d Standard ds leku dke djrk gS vkSj buds chp vkil esa Communication djokus dh lqfo/kk iznku dj nsrk gSA

ODBC Application Programming Interface ( ODBC API)

ODBC API Library Routines ;k Operating System ds Functions dk ,d ,slk lewg gksrk gS rks gekjs Program dks fofHkUu izdkj ds Databases ls Connect gksus o muls Communication djus dh {kerk iznku djrk gSA dksbZ Database fdlh User Interface ls Communicate dj lds] blds fy, gesa dsoy ml DBMS Software ds ODBC Driver dks Install djuk gksrk gS] ftls ge Back-End ds :i esa Use djuk pkgrs gSaA

ekuyks fd ge Back-End ds :i esa Oracle dks Use djuk pkgrs gSaA blds fy, gesa lcls igys Oracle Database dks Computer esa Install djuk gksxk vkSj fQj vius Front-End ls Oracle dks Connect djus ds fy, vius Computer System esa Oracle ds ODBC Driver dks Install djuk gksxkA tc ge Program dks bl rjg ls Develop djrs gSa] ftlds nks fgLls gksrs gSaA igyk fgLlk Back-End Database gksrk gS] tks Data Server dh rjg dke djrk gS] tcfd nwljk fgLlk Front-End User Interface gksrk gS] tks fd Client dh rjg dke djrk gS] rc ;fn ge User Interface dks Upgrade djrs gSa] rks gesa Database esa Upgrade djus dh t:jr ugha gksrh gS vkSj ;fn ge Database dks Upgrade djrs gSa] rks gesa User Interface dks Upgrade djus dh

453 Any Question or Suggestion, Just Discuss Here...

Java in Hindi t:jr ugha gksrh gSA ODBC Application Architecture dks ge fuEukuqlkj fp= ds :i esa eku ldrs gSa%

JDBC Application Programming Interface ( JDBC API)

Java Database Connectivity (JDBC) gesa ,sls Database-Programming API Provide djrk gS] ftldk iz;ksx djds ge tkok Programs dks Front-End dh rjg Use djus esa l{ke

gks ikrs gSaA

pwafd ODBC APIs dks “C” Language tSlh Programming Language esa Develop fd;k x;k gksrk gS] ftuesa Pointers o vU; izdkj ds Concepts dk iz;ksx fd;k tkrk gS] blfy, tkok bu ODBC APIs dks Direct Support ugha djrk gS vkSj buls Directly Communication djus esa l{ke ugha gks ikrk gS] D;ksafd tkok Pointers tSls Concept dks Support ugha djrk gSA bl fLFkfr esa tkok Front-End ds :i esa dke djs vkSj Back-End ds :i esa fLFkr DBMS Software ls Communication dj lds] blds fy, JavaSoft Company us JDBC-ODBC Bridge Driver API Develop fd, gSa] tks fd JDBC API dks ODBC API esa Translate djus dk dke djrs gSaA budk iz;ksx ODBC Driver APIs ds lkFk esa fd;k tkrk gSA JDBC Drivers vkt gesa dbZ Categories esa miyC/k gSa] tks fd fuEukuqlkj gSa% • • • •

JDBC-ODBC Bridge + ODBC Driver Native API Partly Java Driver JDBC-Net Pure Java Driver Native Protocol Pure Java Driver

JDBC Application Architecture dks ge fuEukuqlkj fp= ds :i esa eku ldrs gSa%

454 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

JDBC Driver Manager

JDBC Driver Manager JDBC Architecture dk eq[; vk/kkj gSA JDBC Driver Manager ds Functions gekjs Application esa Specify fd, x, Appropriate Driver ls gekjs Java Application dks Connect djus dk dke djrs gSaA

JDBC-ODBC Bridge Sun Microsystems us gesa JDBC ds ,d fgLls ds :i esa ,d ,slk Driver Provide fd;k gS] ftldk iz;ksx djds fdlh ODBC Data Source dks JDBC }kjk Access fd;k tk ldrk gSA ;s Driver ODBC Data Source o Java Application ds chp ,d Bridge dk dke djrk gS] blfy, bl Driver dks JDBC-ODBC Bridge uke fn;k x;k gSA bl Bridge dks JdbcOdbc.class ds :i esa Implement fd;k x;k gS vkSj ODBC Drivers dks Access djus ds fy, blesa ,d Native Library dk iz;ksx fd;k x;k gSA Windows Platform ds fy, bl Native Library dk uke JDBCODBC.DLL gksrk gSA

Installing The ODBC Driver

ODBC Driver dks Configure djus ds fy, gesa lcls igys Control Panel esa tkuk gksrk gSA Control Panel esa fuEukuqlkj ,d Data Source (ODBC) Driver Configuration Icon gksrk gS] ftls Double Click djuk gksrk gSA

bl Icon ij Double Click djus ij gekjs lkeus fuEukuqlkj ,d ODBC Data Source Administrator Dialog Box Display gksrk gS%

455 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

ekuyks fd gekjk Database geus Microsoft Access esa cuk;k gSA bl fLFkfr esa gesa User DSN Tab ds “User Data Source:” uke dh List esa fn[kkbZ nsus okys “MS Access Database” uke ds dks pquuk gksrk gSA bl Option dks puus ds ckn “Configure…” uke ds Button ij Click djuk gksrk gSA tc ge bl Button dks Click djrs gSa] rc gekjs lkeus fuEukuqlkj vxyk Dialog Box Display gksrk gS%

bl Dialog Box ij gesa dbZ Buttons fn[kkbZ nsrs gSaA ;fn ge u;k Database Create djuk pkgsa] rks gesa “Create…” uke ds Button dks Click djuk gksrk gSA ysfdu pwafd ge ;s eku jgs gSa fd geus gekjk Database igys gh Create dj fy;k gS] blfy, ml Created Database dks vius Data Source ls Connect djus ds fy, gesa “Select…” Button ij Click djuk gksrk gSA tc ge bl Button ij Click djrs gSa] rc gekjs lkeus fuEukuqlkj ,d vkSj Dialog Box Display gksrk gS%

456 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

bl Dialog Box esa gesa ml Database dks Select djuk gksrk gS] ftls ge tkok Front-End ls Connect djuk pkgrs gSaA okafNr Database dks Select djus ds ckn gesa OK Button ij Click djuk gksrk gSA tc ge OK Button ij Click djrs gSa] rc ge fQj ls fiNys Dialog Box ij igqap tkrs gSaA bl Dialog Box ij Hkh ,d OK Button gksrk gS] ftl ij gesa Click djuk gksrk gSA tc ge OK ij Click djrs gSa] rc ge lcls igys Dialog Box ij igqap tkrs gSaA ;gka ij Hkh gesa OK ij gh Click djuk gksrk gS vkSj gekjk Database “MS Access Database” uke ds User DSN ls Connect gks tkrk gSA ;fn ge fdlh vkSj uke dk ,d u;k ODBC Data Source Create djuk pkgsa] rks ;s dke djus ds fy, gesa “ODBC Data Source Administrator” Dialog Box esa “Configure…” Button ds LFkku ij “Add…” Button dks Click djuk gksrk gSA tc ge “Add…” Button ij Click djrs gSa] rc gekjs lkeus fuEukuqlkj “Create New Data Source” uke dk Dialog Box vkrk gSA bl Dialog Box esa ge ml Database ds ODBC Driver Select djrs gSa] ftlls Front-End dks Connect djuk gksrk gSA pwafd gesa ;gka ij MSAccess ls Front-End dks Connect djuk gS] blfy, ge ;gka ij fuEukuqlkj “Microsoft Access Driver (*.mdb)” Option dks Select djrs gSaA

bl Option dks Select djds Finish Button ij Click djrs gh gekjs lkeus fuEukuqlkj ,d vkSj u;k Dialog Box Display gks tkrk gSA bl Dialog Box esa gesa gekjs u, Data Source DSN dk uke Specify djuk gksrk gS vkSj “Select…” Button ij Click djds ml Database dks Select djuk gksrk gS] ftls ge Front-End ls Connect djuk pkgrs gSaA

457 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

ge ftl Database dks Select djrs gSa] ml Database dk uke fp= esa n”kkZ, x, Rectangle ds LFkku ij fn[kkbZ nsus yxrk gSA Data Source dk uke nsus vkSj Database Select djus ds ckn gesa bl Dialog Box ij fLFkr OK Button dks Click djuk gksrk gSA tc ge OK Button ij Click djrs gSa] rc gekjs lkeus fuEukuqlkj fiNyk Dialog Box Display gksrk gS] ftlesa ,d u;k “User Data Source” fn[kkbZ nsus yxrk gSA

bl Dialog Box ij fLFkr OK Button ij Click djds ge bl Dialog Box dks Hkh Close dj ldrs gSaA tc ge bl iwjh izfØ;k dks T;ksa dk R;ksa viukrs gSa] rc gesa gekjs Database ls Connect gksus dk ,d Open Connection izkIr gks tkrk gS] ftlesa gekjk Database Embedded gksrk gSA ge bl Data Source Connection dk iz;ksx djds fdlh Hkh FrontEnd Application ls Connect gks ldrs gSa vkSj Connected Database ds Data dks Access djus esa l{ke gks tkrs gSaA

Connection to A Database

tkok esa java.sql uke ds Package esa fdlh Database ls Connection LFkkfir djus ls lEcaf/kr Classes Define dh xbZ gSaA ge fdlh ,d Application esa ,d ;k ,d ls T;knk Databases ls Connection LFkkfir djus ds fy, ,d ;k ,d ls T;knk Connection Objects Create dj ldrs gSaA Database ls Connection Establish djus ds fy, gesa JDBC-ODBC Driver dks Operating System esa Register djokuk gksrk gSA

458 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl Driver dks Register djokus ds fy, gesa Class uke dh Class ds forName() uke ds Method dks Call djuk gksrk gSA Driver dks Operating System esa Register djokus ds ckn DriverManager Class ds getConnectoin() Method dks Call djds Data Source o Front End ds chp Connection Establish djuk gksrk gSA fdlh Database dks Identify djus ds fy, gesa ml Database dh Location dk irk yxkuk gksrk gSA JDBC URL ,d String gksrk gS] tks fdlh Database dks Identify djrk gSA ;s JDBC URL fuEukuqlkj rhu fgLlksa esa caVk gksrk gS% ::

bl String esa ,d JDBC URL esa bl LFkku ij gesa”kk jdbc gksrk gSA Database ls Front-End dks fdl izdkj ls Connect fd;k tk jgk gS] bl Connectivity ds Mechanism dks bl LFkku ij Specify fd;k tkrk gSA lkekU;r;k tc Database ls Data dks Retrieve djus dk rjhdk ODBC-JDBC Bridge gksrk gS] rc bl SubProtocol ds LFkku ij odbc dk iz;ksx fd;k tkrk gSA

bl LFkku ij gesa ml Database dk uke Specify djuk gksrk gS] ftlls ge Front-End dks Connect djuk pkgrs gSaA

ekuyks fd ge Java Front-End ls MS-Access esa cuk, x, Address uke ds Database dks Connect djus ds fy, ODBC AddressDSN dk iz;ksx djuk pkgrs gSaA bl ODBC Driver dk iz;ksx djds AddressDSN uke ds Database dks Java Front-End ls Connect djus ds fy, gesa fuEukuqlkj Statements fy[kus gksrs gSa% lcls igys JDBC URL Create djuk gksrk gS] tks fd bl fLFkfr esa fuEukuqlkj gksrk gS% String connectionURL = “jdbc:odbc:AddressDSN”;

vc Database ls Connection Establish djus ds fy, gesa Class uke dh Class ds forName() Method dks Call djds vius Operating System dks ;s crkuk gksrk gS fd ge fdl Driver dk iz;ksx djds Front-End ls Databases dks Connect djuk pkgrs gSaA pwafd ge tkok ds “JdbcOdbcDriver” dk iz;ksx djds tkok Front-End ls Data Source dks Connect djuk pkgrs gSa] blfy, gesa tkok Compiler dks fuEukuqlkj Driver Specify djuk gksrk gS% Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Driver Specify djus ds ckn gesa ,d Connection Object Create djuk gksrk gSA fQj Data Source ls Connection LFkkfir djus ds fy, DriverManager ds fy, getConnectoin() Method dks Call djds mlesa JDBC URL Argument ds :i esa Pass djuk gksrk gSA blds fy, gesa fuEukuqlkj Statement fy[kuk gksrk gS% 459 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Connection conDatabase = DriverManager.getConnection(connectionURL);

bu rhuksa Statements dks ge fuEukuqlkj ,d lkFk Specify dj ldrs gSa% String connectionURL = “jdbc:odbc:AddressDSN”; Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connection conDatabase = DriverManager.getConnection(connectionURL);

Querying A Database

Database ls Connection LFkkfir gks tkus ds ckn ge ml Database esa u, Data dks Store dj ldrs gSa vkSj Database esa Stored fdlh Required Data dks Retrieve dj ldrs gSaA ge tc Database ij dksbZ Query Hkstrs gSa] rks Database ml Query dks Process djrk gS vkSj Generate gksus okys Result dks Return djrk gS] ftls Result Set dgrs gSaA Database ls Query djus ds fy, gesa Database ij SQL Statement Hkstus iMrs gSaA SQL Statements dks Database ij Hkstus ds fy, ge tks SQL Statements fy[krs gSa] mu SQL Statements dks Represent djus ds fy, JDBC gesa rhu rjg dh Classes iznku djrk gSA

ge bu rhu rjg dh Classes ds Objects Create djds fdlh SQL Statement dks Database ij Request ds :i esa Hkst ldrs gSa] ftlds Result ds :i esa Database FrontEnd Client Software dks Result Set Return djrk gSA ;s rhu rjg dh Statement Classes ds Objects fuEukuqlkj gSa% The Statement Object

Statement Object Create djus ds fy, gesa Connection Object ds lkFk createStatement() Method dks Call djuk gksrk gSA

The PreparedStatement Object

PreparedStatement Object Create djus ds fy, gesa Connection Object ds lkFk preparedStatement() Method dks Call djuk gksrk gSA PreparedStatement Object esa Methods dk ,d ,slk lewg gksrk gS] ftudks INPUT Parameters ds lkFk Use djds Queries dks Database ij Hkstk tk ldrk gSA

The CallableStatement Object

CallableStatement Object Create djus ds fy, gesa Connection Object ds lkFk prepareCall() Method dks Call djuk gksrk gSA bl Object esa os Functionalities gksrh gSa] ftudk iz;ksx fdlh Database esa fLFkr “Stored Procedures” dks Call djus ds fy, fd;k tk ldrk gSA ge CallableStatement Object dk iz;ksx djds INPUT o OUTPUT nksuksa Parameters dks leku :i ls Handle dj ldrs gSaA

460 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Using The Statement Object ge Statement Object dks Use djds Database ij lkekU; Queries dks Process gksus ds fy, Hkst ldrs gSa vkSj Database }kjk Return gksus okys Result Set dks Front-End esa Use dj ldrs gSaA Program // File Name : StatementObjectQueryApp.java import java.sql.*; public class StatementObjectQueryApp { public static void main(String args[]) { try { String connectionURL = "jdbc:odbc:AddressDSN"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conDatabase = erManager.getConnection(connectionURL); Statement sqlQuery = conDatabase.createStatement(); sqlQuery.executeQuery("SELECT * FROM Contacts");

}

}

} catch(Exception excp) { System.out.println("Error : " + excp); }

tc ge bl Program dks Run djrs gSa] rc gesa Output esa dqN Hkh izkIr ugha gksrk gSA ,slk blfy, gksrk gS] D;ksafd Statement Object dh Query Database ij Run rks gksrh gS] ysfdu Database ls Return gksus okys Result dks Hold djus ds fy, geus dksbZ Object Create ugha fd;k gS] ftlls Return gksus okys Result dks Output esa Display fd;k tk ldsA bl Program esa 1

geus Database ls Connection LFkkfir djus ds fy, JDBC-ODBC Bridge Driver dks Load fd;k gSA 2 getConnection() Method dk iz;ksx djds Connection Object dks Initialize fd;k gSA 3 createStatement() Method dk iz;ksx djds Statement Object Create fd;k gSA vkSj vUr esa 4 executeQyery() Method dk iz;ksx djds Statement Object esa Stored Query dks Execute fd;k gSA The Statement Object Statement Object dk iz;ksx lkekU; izdkj dh Queries dks Database ij Run djus ds fy, fd;k tkrk gSA bl Object ds rhu Methods gksrs gSa] ftudk iz;ksx Database ij Query dks Run djus ds fy, fd;k tk ldrk gSA

461 Any Question or Suggestion, Just Discuss Here...

Java in Hindi 1 executeQuery() Method ;s Method ,d Simple SELECT Query Execute djrk gS vkSj Database bl Method ds Execute gksus ij ,d Single ResultSet Object Return djrk gSA 2 executeUpdate() Method ;s Method ,d SQL INSERT, UPDATE o DELETE Statement Execute djus esa l{ke gksrk gS 3 execute() Method ;s Method ,d ,slk SQL Statement Execute djrk gS] ftlds dbZ Results Return gks ldrs gSaA The ResultSet Object ResultSet Object gesa ,sls Methods Provide djrk gS] ftudk iz;ksx ge ResultSet Object ds lkFk djds fdlh Table ds Data dks Access dj ikus esa l{ke gksrs gSaA ge tc Hkh Database ij fdlh Statement dks Execute djrs gSa] Database ls ,d ResultSet Return gksrk gSA ResultSet Object Database ls Return gksus okys Data dks ,d Temporary Table ds :i esa Represent djrk gSA blesa ,d Cursor gksrk gS] tks Data ds Current ROW dks Point djrk gSA tc Database ls ResultSet Return gksrk gS] rc Initially ;s Cursor First Row ls igys dh Position ij Placed gksrk gSA

;kuh ;fn First Row dks 0 ekuk tk,] rks Cursor igyh Row ds Record ls igys ;kuh -1 ij Placed jgrk gSA next() Method Cursor dks Record dh vxyh Row ij ys tkrk gSA ge fdlh ResultSet Object ls Data dks izkIr djus ds fy, getXXX() Methods dks Call dj ldrs gSa] tgka XXX Database ls Return gks jgs fdlh Field dk Data Type gksrk gSA vxys Program esa geus fiNys Program dks gh Modify djds mlesa ResultSet Object dks Use fd;k gSA Program // File Name : StatementObjectQueryApp.java import java.sql.*; public class StatementObjectQueryApp { public static void main(String args[]) { ResultSet result; try {

String connectionURL = "jdbc:odbc:AddressDSN"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conDatabase = DriverManager.getConnection(connectionURL);

462 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Statement sqlQuery = conDatabase.createStatement(); result = sqlQuery.executeQuery("SELECT * FROM Contacts"); System.out.print("SrNo. \tFName \tLName \tAddress \tCity \tState \tPin \tCountry \n" ); System.out.print("-------------------------------------------------------------------\n" ); while(result.next()) { for(int i=1; isaxsA bl rjhds ls Events dks Handle djus dh lcls cMh deh ;s Fkh fd fdlh Event dks ml Component }kjk Hkh Handle fd;k tk ldrk Fkk] tks fd Event ;k mlds Container ls Initiated gksrs FksA ,slk gksus ls Object Oriented Programming Concept ds ml fu;e dk mYya?ku gksrk Fkk] ftlesa fdlh Object dh Functionality mldh Class esa gh fLFkr gksrh gSA bl rjhds dh nwljh deh ;s Fkh fd blesa Containment Hierarchy }kjk Unimportant Events dks Hkstus ls CPU Cycles Waste gksrs FksA bl Model esa dksbZ Hkh ,slk rjhdk ugha Fkk ftlls Unimportant Events dks Ignore fd;k tk ldrk gksA bu dfe;ksa ls NqVdkjk ikus ds fy, JDK 1.1 esa “Delegation Event Model” dks Develop fd;k x;kA

Delegation Event Handling Model bl Model esa ge mu Objects dks Specify dj ldrs gSa] ftUgsa fdlh Event ds Generate gksus ij Notify fd;k tk lds fd Generate gksus okyk Event fdl Object ds fy, gSA ;fn Generate gksus okyk Event fdlh Hkh Object ls lEcaf/kr uk gks] rks og Event Discard gks tkrk gSA JDK 1.2 dk Model ;kuh Delegation Event Model eq[;r% pkj Components ij vk/kkfjr gksrk gS% 1 2 3

4

Event Classes Event Listeners Explicit Event Handling Adapters

476 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Event Classes

Event Class Hierarchy esa EventObject Class lcls igyh ;k Top dh Class gksrh gSA ;s Class java.util Package ls Related Class gSA Event ls lEcaf/kr T;knkrj vU; Classes java.awt.event Package ls Related Class gksrh gSaA java.util.EventObject Class o java.awt.AWTEvent Class java.awt.event Package ls lEcaf/kr Classes ugha gSaA JDK 1.2 dh Event Class dh Hierarchy dks ge fuEukuqlkj n”kkZ ldrs gSa%

os Classes tks Events dks Represent djrh gSa] tkok ds Event Handling Mechanism dh Fundamental Classes gSaA EventObject tkok ds Event Classes dh Hierarchy dh Top Level Class gS] ftls java.util Package esa Define fd;k x;k gSA ;s lHkh Event Classes dh Super Class gSA bldk ,d Constructor fuEukuqlkj gS% EventObject(Object src);

bl Constructor esa src og Object gS] tks Event Generate djrk gSA EventObject Class esa getSource() o getID() uke ds nks Methods gSaA EventObject Class dk getSource() Method ml Object dks Return djrk gS] ftlus Event dks Generate fd;k gksrk gSA bl Method dk General Form fuEukuqlkj gksrk gS% Object getSource()

pwafd toString() Method Generate gksus okys Event dk String Representation Return djrk gSA blfy, ge bl Method dks Use djds ml Object dk uke izkIr dj ldrs gSa] ftlus Event Generate fd;k gksrk gS ;k fQj ge viuh t:jr ds vuqlkj fdlh Event dh Type Casting djds mls vyx rjhds ls Hkh Use dj ldrs gSaA java.awt Package esa AWTEvent uke dh ,d Sub Class dks Define fd;k x;k gS] tks fd EventObject Class dh ,d Sub Class gSA ;s Class Delegation Event Model esa (Directly ;k Indirectly) Use dh tkus okyh lHkh AWT – Based Event Classes dh Super Class gksrh gSA EventObject Class dk getID() Method ml Event ID dks Return djrk gS] tks Event dh izd`fr dks fu/kkZfjr djrk gSA bl Method dk General Form fuEukuqlkj gksrk

gS%

int getID() 477 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ekuyks ;fn ,d Mouse Event Generate gksrk gS] rks ge bl Method dks Use djds ;s irk yxk ldrs gSa fd fdl Class ds Object ls Event Generate gqvk gSA ;kuh Event Object ls Click Event Generate gqvk gS ;k Drag Event Generate gqvk gS ;k Move Event Generate gqvk gS ;k Mouse Button dks Release fd;k x;k gSA tSlkfd ge fiNys fp= esa ns[k ldrs gSa] fd ftruh Hkh Event Classes gSa] mu lHkh Event Classes dks AWTEvent Class ls Derive fd;k x;k gSA ;kuh ;fn lkjka”k esa dgsa rks EventObject Class lHkh Event dh Super Class gS vkSj AWTEvent lHkh AWTEvent Class lHkh AWT Event Classes dh Super Class gS] ftUgsa Delegation Event Model esa Use fd;k tkrk gSA java.awt.event Package esa fofHkUu izdkj ds Events dks Handle djus dh Classes dks Define fd;k x;k gSA fdl fLFkfr esa dkSulk Event Generate gksrk gS] bldh tkudkjh gesa

fuEu fcUnqvksa ls izkIr gks ldrh gS%

• tc dksbZ Component Activate gksrk gS] dksbZ Button Press gksrk gS] dksbZ List Item Double Clicked gksrk gS ;k fdlh Menu Item dks Select fd;k tkrk gS] rc ActionEvent Object Generate gksrk gSA • tc Scrollbar ;k fdlh Adjustable Element dks Use fd;k tkrk gS] rc AdjustmentEvent Generate gksrk gSA • tc dksbZ Component Hide, Visible, Move ;k Resize fd;k tkrk gS] rc ComponentEvent Generate gksrk gSA • tc fdlh Container esa dksbZ Object Add fd;k tkrk gS ;k fdlh Container ls fdlh Object dks Delete fd;k tkrk gS] rc ContainerEvent Object Generate gksrk gSA • tc dksbZ Component Input ds fy, Focus Receive djrk gS ;k tc fdlh Component ls Focus fdlh nwljs Component ij Move gksrk gS] rc FocusEvent Object Generate gksrk gSA • lHkh Input Component dh Input Classes dh InputEvent Class Super Class gSA blfy, fdlh Hkh Input Object esa Input djus ij ;s Event Generate gksrk gSA • tc fdlh List Box, Choice Box ;k Check Box ls fdlh Item dks Select fd;k tkrk gS] rc ItemEvent Object Generate gksrk gSA • tc Keyboard ls fdlh Key dks Press djds Input izkIr fd;k tkrk gS] rc KeyEvent Object Generate gksrk gSA • tc fdlh Window ls lEcaf/kr Activities tSls fd Window dks Activate, Close, Deactivate, Deiconified, Iconified, Open, Restore, Minimize ;k Maximize vkfn djus ij WindowEvent Object Generate gksrk gSA • tc Mouse dks Click, Press, Release, Drag, ;k Move fd;k tkrk gS] rc MouseEvent Object Generate gksrk gSA • tc dksbZ Component Paint gksrk gS] rc PaintEvent Object Generate gksrk gSA • tc fdlh Text Component ds Text dks Modify fd;k tkrk gS] rc TextEvent Object Generate gksrk gSA • tc Mouse ds Scroll Wheel dks Move fd;k tkrk gS] rc MouseWheelEvent Generate gksrk gSA ;s Event dsoy tkok ds 1.4 o blds ckn ds Version esa gh miyC/k gSA

478 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Event Listeners

Delegation Event Model dks eq[;r;k nks Hkkxksa Source o Listeners esa foHkkftr fd;k x;k gSA fdlh Event dks Generate djus okys fofHkUu izdkj ds Source Objects dks Create djus okyh Classes dks java.awt Package esa Define fd;k x;k gS] tcfd tkok ds java.awt.event Package esa Define fd, x, ,d ;k ,d ls vf/kd Interfaces dks Implement djds Listeners Objects dks Create fd;k tkrk gSA Event Listener ,d ,slk Object gksrk gS tks fdlh Event ds Generate gksus ij Notify gksrk gSA tc dksbZ Event Generate gksrk gS] rc Event Generate djus okyk Source Object Listener esa Define fd, x, fdlh Appropriate Method dks Invoke djrk gS vkSj ml Method esa Argument ds :i esa ,d Event Object iznku djrk gSA fdlh Hkh Event Listener dh eq[;r% nks Requirement gksrh gSa%

1 bls ,d ;k ,d ls vf/kd Source Objects ds lkFk Register fd;k tk,] rkfd ;s mu Source Objects }kjk Generate gksus okys Events ls Notify gks lds vkSj 2 bu Notifications dks izkIr djds mUgsa Process djus ds fy, Methods Implement fd, tk,aA os Methods tks Source Objects ls Generate gksus okys Events dks Receive o Process djrs gSa] Interfaces ds ,d lewg ds :i esa java.awt.event uke ds Package esa Specify fd, x, gSaA mnkgj.k ds fy, MouseMotionListener Interface esa Mouse Move gksus ds Notifications dks Receive djus ds fy, nks Methods Define fd, x, gS vkSj ;s nksuksa Methods rc Notification izkIr djrs gSa tc Mouse dks Drag ;k Move fd;k tkrk gSA Mouse dks Drag ;k Move djus ij Mouse Move Event Generate gksrk gS vkSj bl Event dks Handle djus ds fy, gesa MouseMotionListener Interface ds nksuksa Methods dks Implement djuk gksrk gSA ;fn fdlh Class esa bl Interface dks Implement fd;k x;k gks] rks ml Class dk dksbZ Hkh Object bu nksuksa esa ls fdlh ,d ;k nksuksa Events dks Receive djrs gq, Notify gks ldrk gSA fofHkUu izdkj ds Events dks Handle djus ds fy, Common :i ls Use fd, tkus okys Interfaces o muesa Define fd, tkus okys Methods dks ge fuEu Description ls le> ldrs gSa%

ActionListener Interface bl Interface esa actionPerformed() uke dk ,d Method Define fd;k tkrk gS] tks fd Argument ds :i esa fdlh ActionEvent Object dks Receive djrk gSA ;s Method rc Invoke gksrk gS] tc dksbZ ActionEvent Object Generate gksrk gS vkSj ;s Object rc Generate gksrk gS] tc fdlh Command Button ij Click fd;k tkrk gS] ;k fdlh Menu Item dks Select fd;k tkrk gS ;k fQj fdlh List Item dks Double Click fd;k tkrk gSA bl Method dk Syntax fuEukuqlkj gksrk gS% void actionPerformed(ActionEvent actnEvnt)

479 Any Question or Suggestion, Just Discuss Here...

Java in Hindi AdjustmentListener Interface bl Interface esa adjustmentValueChanged() uke ds ,d Method dks Define fd;k tkrk gS] tks Argument ds :i esa fdlh AdjustmentEvent Object dks Receive djrk gSA ;s Method rc Invoke gksrk gS tc dksbZ Adjustment Event Generate gksrk gSA bl Method dk General Syntax fuEukuqlkj gksrk gS% void adjustmentValueChanged (AdjustmentEvent adjEvnt)

ComponentListener Interface bl Interface esa pkj Method dks Define fd;k tkrk gS] tks fdlh Component dh Hidden, Moved, Resized ;k Visible fLFkfr dks Identify djrs gq, Execute gksrs gSaA bu Methods dk General Syntax fuEukuqlkj gksrk gS% void componentResized(ComponentEvent compEvnt) void componentMoved(ComponentEvent compEvnt) void componentShown(ComponentEvent compEvnt) void componentHidden(ComponentEvent compEvnt)

ContainerListener Interface bl Interface esa nks Method dks Define fd;k tkrk gS] tks Container esa fdlh Component Add gksus ;k Container ls fdlh Component ds Remove gksus dh fLFkfr dks Identify djrs gq, Execute gksrs gSaA ;kuh tc fdlh Container esa dksbZ Component Add fd;k tkrk gS] rc componentAdded() Method Execute gksrk gS vkSj tc fdlh Container ls dksbZ Component Remove fd;k tkrk gS] rc componentRemoved() Method Execute gks tkrk gSA bu Methods dk General Syntax fuEukuqlkj gksrk gS% void componentAdded(ContainerEvent contEvnt) void componentRemoved(ContainerEvent contEvnt)

FocusListener Interface bl Interface esa nks Method dks Define fd;k tkrk gSA ;s Methods fdlh Component ds Keyboard Focus Receive djrs le; o Focus dks Lost djrs le; Execute gksrs gSa] ;kuh tc dksbZ Component Keyboard dk Focus Receive djrk gS] rc focusGained() Method Execute gksrk gS vkSj tc dksbZ Component Keyboard ds Focus dks Lost djrk gS] rc focusLost() Method Execute gksrk gSA bu Methods dk General Syntax fuEukuqlkj gksrk gS% void focusGained(FocusEvent focusEvnt) void focusLost(FocusEvent focusEvnt)

480 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ItemListener Interface bl Interface esa ,d Method dks Define fd;k tkrk gS] tks fdlh Component dh ml fLFkfr dks Identify djrk gS] tc Component ds fdlh Item dks Change fd;k tkrk gSA ;kuh fdlh Component ds fdlh Item dks Change djus ij bl Listener esa Define fd;k x;k itemState() uke dk Method Execute gks tkrk gSA bl Method dk General Syntax fuEukuqlkj gksrk gS% void itemState(ItemEvent itmEvnt)

KeyListener Interface bl Interface esa rhu Method dks Define fd;k tkrk gS vkSj ;s rhuksa Method rc Execute gksrs gSa] tc fdlh Keyboard ls dksbZ Key Press fd;k tkrk gSA tc dksbZ Key Press fd;k tkrk gS] rc keyPressed() Method Execute gksrk gSA tc Key dks Release fd;k tkrk gS] rc keyReleased() Method Invoke gksrk gS vkSj tc Keyboard ls dksbZ Key Type fd;k tkrk gS] rc keyTyped() Method Invoke gksrk gSA mnkgj.k ds fy, tc Keyboard ls dksbZ Key Press fd;k tkrk gS] rc Key Pressed, Key Typed o Key Released Events ds Øe esa rhu Events Generate gksrs gSaA ;fn User HOME Key dks Press djds Release djrk gS] rks dsoy nks Events Key Pressed o Key Released ds Øe esa Generate gksrs gSaA bl Interface ds rhuksa Methods dk General Syntax fuEukuqlkj gksrk gS% void keyPressed(KeyEvent keyEvnt) void keyReleased(KeyEvent keyEvnt) void keyTyped(KeyEvent keyEvnt)

MouseListener Interface bl Interface esa ikap Methods dks Define fd;k tkrk gS] tks Mouse ds fdlh Component ij Click gksus] Component esa Enter gksus] Component ls Exit gksus] Component ds Press gksus vkSj Component ds Release gksus dks Identify djrs gSaA ;kuh 1 tc User Mouse ds fdlh Button dks fdlh Point ij Press djds mlh Point ij Release dj nsrk gS] rks mouseClicked() Method Invoke gksrk gSA 2 tc Mouse Pointer fdlh Component ij Enter gksrk gS] rc mouseEntered() Method Invoke gksrk gSA 3 tc Mouse Pointer fdlh Component ls Exit gksrk gS] rc mouseExited() Method Invoke gksrk gSA 4 tc Mouse ds fdlh Button dks Press fd;k tkrk gS] rc mousePressed() Method Invoke gksrk gSA 5 tc Mouse ds fdlh Button dks Release fd;k tkrk gS] rc mousePressed() Method Invoke gksrk gSA 481 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bu Methods dk General Syntax fuEukuqlkj gksrk gS% void mouseClicked(MouseEvent mousEvnt) void mouseEntered(MouseEvent mousEvnt) void mouseExited(MouseEvent mousEvnt) void mousePressed(MouseEvent mousEvnt) void mouseReleased(MouseEvent mousEvnt)

MouseMotionListener Interface bl Interface esa nks Method dks Define fd;k tkrk gSA tc Mouse dks Drag fd;k tkrk gS rc mouseDragged() Method Invoke gksrk gS vkSj tc Mouse dks Move fd;k tkrk gS] rc mouseMoved() Method Invoke gksrk gSA bu nksuksa Methods dk General Syntax fuEukuqlkj gksrk gS% void mouseDragged(MouseEvent mousEvnt) void mouseMoved(MouseEvent mousEvnt)

MouseWheelListener Interface bl Interface esa ,d Method Define fd;k tkrk gS] tks rc Invoke gksrk gS] tc Mouse ds Wheel dks ?kqek;k ;k Move fd;k tkrk gSA bl Method dk General Form fuEukuqlkj gksrk gS% void mouseWheelMoved(MouseEvent mousEvnt)

TextListener Interface bl Interface esa ,d Method Define fd;k tkrk gSA tc fdlh TextField ;k TextArea Object esa Text dks Change fd;k tkrk gS] rc textChanged() Method Invoke gksrk gSA bl Method dk General Syntax fuEukuqlkj gksrk gS% void textChanged(TextEvent txtEvnt)

WindowFocusListener Interface bl Interface esa windowGainedFocus() o windowLostFocus() Methods dks Define fd;k tkrk gS] tks Øe”k% Window ds Focus izkIr djus o Lost djus ij Execute gksrs gSaA budk General Syntax fuEukuqlkj gksrk gS% void windowGainedFocus(WindowEvent wndEvnt) void windowLostFocus(WindowEvent wndEvnt)

482 Any Question or Suggestion, Just Discuss Here...

Java in Hindi WindowListener Interface bl Interface esa lkr Methods Define fd, tkrs gSa] tks Window ds Activate gksus] Close gksus] Deactivate gksus] Deiconified gksus] Open gksus] Iconified gksus o Quit gksus ij Execute gksrs gSaA 1 tc dksbZ gSA 2 tc dksbZ gksrk gSA 3 tc dksbZ gSA 4 tc dksbZ gksrk gSA 5 tc dksbZ 6 tc dksbZ 7 tc dksbZ gksrk gSA

Window Activate gksrk gS] rc windowActivated() Method Invoke gksrk Window Deactivate gksrk gS] rc windowDeactivated() Method Invoke Window Iconified gksrk gS] rc windowIconified() Method Invoke gksrk Window Deiconified gksrk gS] rc windowDeiconified() Method Invoke Window Open gksrk gS] rc windowOpend() Method Invoke gksrk gSA Window Close gksrk gS] rc windowClosed() Method Invoke gksrk gSA Window Close gks jgk gksrk gS] rc windowClosing() Method Invoke

bu lHkh Methods ds General Syntax fuEukuqlkj gksrs gSa% void windowActivated(WindowEvent wndEvnt) void windowDeactivated(WindowEvent wndEvnt) void windowIconified(WindowEvent wndEvnt) void windowDeiconified(WindowEvent wndEvnt) void windowOpend(WindowEvent wndEvnt) void windowClosed(WindowEvent wndEvnt) void windowClosing(WindowEvent wndEvnt)

Using The Delegation Event Model - Handling An Event

fofHkUu izdkj ds Event dks Represent djus okyh Classes o fofHkUu izdkj ds Events dks Handle djus ds fy, Implement fd, tkus okys Interfaces dh Basic tkudkjh izkIr djus ds ckn vc ge bUgsa Practically Use djuk lh[ksaxsA Delegation Event Model esa tc dksbZ Object fdlh Event dks Generate djrk gS] rks ml Event dks Handle djus ds fy, gesa ,d Event Listener Class Create djuk gksrk gSA ;s Event Listener Class ml Object ls Generate gksus okys Events dks Handle djus ds fy, fofHkUu izdkj ds Interfaces dks Implement djrk gSA ftl Object ls Generate gksus okys Events dks Handle djus ds fy, ge tks Listener Class Develop djrs gSa] ml Listener Class ls Source Object dks Register fd;k tkrk gSA

;kuh Listener dks ;s crk;k Response djsxk ;k fdl Component ls Generate ls T;knk Listener gks ldrs

tkrk gS fd og fdl Object ls Generate gksus okys Events dks Object ls Generate gksus okys Events ls Notify gksxkA ,d gksus okys fofHkUu izdkj ds Events dks Handle djus ds fy, ,d gSaA

483 Any Question or Suggestion, Just Discuss Here...

Java in Hindi tkok esa fofHkUu izdkj ds GUI Component Objects fofHkUu izdkj ds Events ls Associated gksrs gSaA mnkgj.k ds fy, tc User fdlh Command Button dks Press djrk gS] rks Command Button ls Associated Click Event Object Generate gksrk gSA dksbZ Listener Object rHkh fdlh Component ls Associated Event dks Listen ;k Hear djrk gS ;k lqurk gS] tc igys ml Listener Object dks Component ds lkFk Register fd;k x;k gksrk gSA mnkgj.k ds fy, ;fn fdlh MouseListener Object mouseListener dks fdlh Button Component Object myButton ls Generate gksus okys Event Object dks Hear djuk gks] rks igys mouseListener Object ds lkFk myButton Component dks Register djuk gksrk gSA fdlh Component dks MouseListener Object mouseListener ds lkFk Register djus ds fy, gesa fuEukuqlkj Statement Use djuk gksrk gS% myButton.addMouseListener(mouseLister);

The ActionEvent Class ,d ActionEvent rc Generate gksrk gS] tc User fdlh Command Button dks Press djrk gS] ;k fdlh List Item dks Double Click djrk gS ;k fQj tc fdlh Menu Item dks Select djrk gSA ActionEvent Class esa pkj Integer Constants (ALT_MASK, SHIFT_MASK, CTRL_MAST, META_MASK) dks Define fd;k x;k gS] ftudk iz;ksx fdlh Action Event ds lkFk Use fd, x, fdlh Modifier dks Represent djus ds fy, fd;k tkrk gSA bu Constants ds vykok bl Class esa ACTION_PERFORMED uke dk ,d vkSj Integer Constant gksrk gS] ftldk iz;ksx fdlh Action Event dks Identify djus ds fy, fd;k tk ldrk gSA ActionEvent Class ds rhu Constructors fuEukuqlkj gSa% ActinoEvent(Object src, int type, String cmd) ActinoEvent(Object src, int type, String cmd, int modifiers) ActinoEvent(Object src, int type, String cmd, long when, int modifiers) src

;s Argument ml Object dks Represent djrk gS] ftlus Event Generate fd;k gksrk gSA

type

;s Argument Represent gksus okys Event ds Type dks Represent djrk gSA

cmd

;s Argument ml Object ds uke dks Represent djrk gS] ftlus Event Generate fd;k gksrk gSA

modifiers

tc ge fdlh CTRL, SHIFT, ALT, META Keys ;k buds Key Combination dks Use djds bl Event dks Generate djrs gSa] ;kuh fdlh List Item ij Double Click djrs gSa ;k fdlh Menu Item dks Select djrs gSa] rc bl modifier esa ml Special Key ;k Key Combination dh Information gksrh gSA

484 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ftl Command es ActionEvent Generate fd;k x;k gksrk gS] ml Command dk uke ge getActionCommand() Method dks Use djds izkIr dj ldrs gSaA bl Method dk Syntax fuEukuqlkj gksrk gS% String getActionCommand()

mnkgj.k ds fy, tc fdlh Button dks Press fd;k tkrk gS] rc ,d ActionEvent Generate gksrk gS vkSj ml Command dk uke tks fd ml Command Button ij fn[kkbZ nsus okyk Label gksrk gS] bl Method }kjk Return fd;k tk ldrk gSA ifj.kker% ge bl Method dks Use djds ml Command dk uke izkIr dj ldrs gSa] ftlus ActionEvent Generate fd;k gksrk gSA fdl Modifier (Alt, Ctrl, Shift, Meta) dks Use djrs gq, ActionEvent dks Generate fd;k x;k gS] ml Modifier dh tkudkjh izkIr djus ds fy, ge getModifiers() Method dk iz;ksx dj ldrs gSaA bl Method dk Syntax fuEukuqlkj gksrk gS% int getModifiers()

dksbZ ActionEvent fdl le; ij Generate gqvk gS] bl ckr dh tkudkjh izkIr djus ds fy, ge getWhen() Method dks Use dj ldrs gSaA ;s Method fuEukuqlkj gksrk gS% long getWhen()

ekuyks fd ge ,d Applet Create djrs gSa vkSj ge pkgrs gSa fd tSls gh bl ij fLFkr ,d Command Button dks Click fd;k tk,] Command Button dk Label Change gks tk,A pwafd Command Button dks Click djus ij ActionEvent Generate gksrk gS] blfy, bl Event dks Handle djus ds fy, gesa ActionListener Interface dks Implement djuk gksrk gSA bl Interface dks ge fuEukuqlkj ,d ubZ Class esa Implement dj ldrs gSa% class MyFirstListener implements ActionListener { public void actionPerformed(ActionEvent actnEvnt) { // Executable codes goes here. } } Command Button ls Generate gksus okys ActionEvent dks Handle djus ds fy, ActionListener Interface dks Implement dj ysus ds ckn gesa Command Button dks Listener ls Register djuk gksrk gSA

ge pkgrs gSa fd Applet ij fLFkr Command Button ds Events dks ;s Listener Listen djs] blfy, gesa ,d Applet Create djuk gksxk vkSj ml Applet esa ,d Command Button Create djds mls bl Listener ls Register djuk gksxkA ;s dke ge fuEukuqlkj dj ldrs gSa% class UsingMyFirstListener extends Applet { public void init() 485 Any Question or Suggestion, Just Discuss Here...

Java in Hindi {

Button btnOK = new Button(“OK”);

// Creating Button Object

// Create Listener Object MyFirstListener listenCommandButtonEvent = new MyFirstListener(); // Register Command Button with Listener so that // it can here Command Button’s Events btnOK.addActionListener(listenCommandButtonEvent);

}

}

// Add the Button to the Applet add(btnOK);

bl Applet Coding esa geus Applet ds init() Method dks Override fd;k gSA bl Method esa geus btnOK uke dk ,d u;k Button Object Create fd;k gS] ftl ij Label “OK” Display djus ds fy, Button Class ds Constructor dks Use fd;k gSA pwafd Command Button ls Generate gksus okys Events dks Here djus ds fy, geus MyFirstListener uke dh ,d Class dks Define fd;k gS] ftlesa Command Button ls Generate gksus okys Events dks Listen djus ds fy, ActionListener Interface dks Implement fd;k gSA blfy, gesa bl Listener Class ds ,d Object ls Command Button dks Associate djuk gksrk gSA bl Listener ls Command Button dks Associate djus ds fy, geus listenCommandButtonEvent uke dk MyFirstListener Class dk ,d Object Create fd;k gSA pwafd Command Button ActionEvent Object Generate djrk gS] tks fd Action Event dks Represent djrk gSA blfy, bl Action Event dks listenCommandButtonEvent Listener Object ls Register ;k Associate djus ds fy, addActionListener() Method dks Button Class ds btnOK Button Object ds fy, Invoke djuk gksrk gS vkSj Argument ds :i esa ;s listenCommandButtonEvent Listener Object nsuk gksrk gS] tks Button ls Generate gksus okys Events dks Handle djrk gSA ;kuh pwafd Command Button ls Generate gksus okys Action Events dks MyFirstListener Class dk listenCommandButtonEvent uke dk Listener Object Handle djrk gS] D;ksafd ;s Object ml Listener Class dk Object gS] ftlesa Command Button ls Generate gksus okys Action Event Object dks Handle djus ds fy, ActionListener Interface dks Implement fd;k x;k gS] blfy, btnOK Button ls listenCommandButtonEvent Object dks Register djus ds fy, addActionListener() Method esa Argument ds :i esa listenCommandButtonEvent Listener Object dks Pass djuk gksrk gSA gekjs bl Program esa geus ;s dke fuEu Syntax }kjk fd;k gSA btnOK.addActionListener(listenCommandButtonEvent);

bl iwjh izfØ;k dks gesa fuEu Steps ds vuqlkj Follow djuk gksrk gS%

486 Any Question or Suggestion, Just Discuss Here...

Java in Hindi 1 pwafd Button Object ActionEvent Generate djrk gS] blfy, bu Actions dks Listen djus ds fy, lcls igys gesa ,d Listener Class cukuh gksrh gS] ftlesa ActionListener Interface dks Implement djuk gksrk gSA 2 Listener Create djus ds ckn gesa Button Object Create djuk gksrk gS vkSj bl Button Object ls Generate gksus okys Events Handle djus ds fy, ftl Listener Class esa ActionListener Interface dks Implement fd;k gksrk gS] ml Class dk ,d Object Create djuk gksrk gSA ;kuh gesa og Source Object Hkh Create djuk gksrk gS] tks Events Generate djrk gS vkSj og Listener Object Hkh Create djuk gksrk gS] tks Source ls Generate gksus okys Events dks Listen djrk gSA 3 Event Generate djus okyk Source Object o Event Listen djus okyk Listener Object nksuksa Object dks Create djus ds ckn gesa Source Object dks Listener Object ls Register djuk gksrk gS] rkfd Source ls Generate gksus okys Events dks Listener Objects Listen dj lds vkSj Event ds Response esa Appropriate dke iwjk dj ldsA blds fy, gesa Component Package ds addTypeListener() Method dks Source ds fy, Invoke djuk gksrk gS vkSj Argument ds :i esa Listener Object nsuk gksrk gSA bl dke dks ge fuEu Syntax vuqlkj Perform djrs gSa% SourceObject.addTypeListener(ListenerObject);

bl iwjs Event Handling Mechanism dk lkjka”k ;s gS fd tc Hkh dksbZ Event Generate gksrk gS] ml Event dks Represent djrk gqvk ,d Appropriate Event Object Create gksrk gSA ml Event dks Listen djus ds fy, ,d Appropriate Listener Interface dks Implement djuk gksrk gS vkSj vUr esa Event Generate djus okys Source o Event dks Listen djus okys Listener nksuksa dk ,d & ,d Object Create djuk gksrk gSA fQj Source ls Listener dks Register djus ds fy, ,d Appropriate Method dks Use djuk gksrk gSA ;kuh gj Event ls lEcaf/kr ,d Interface o ,d Registration Method gksrk gSA fofHkUu izdkj ds Events, muds Listener o Registration Method vkil esa Closely Related gksrs gSa] ftUgsa ge fuEukuqlkj Represent dj ldrs gSa% 1 tc ActionEvent Generate gksrk gS] rc Event dks Listen djus ds fy, gesa ActionListener Interface dks Implement djuk gksrk gS vkSj Source ls Listener dks Associate ;k Register djus ds fy, Source ds lkFk addActionListener() Method dks Use djuk gksrk gSA bl Method dks ge fuEukuqlkj Use djrs gSa% SourceObject.addActionListener(ListenerObject);

2 tc AdjustmentEvent Generate gksrk gS] rc Event dks Listen djus ds fy, gesa AdjustmentListener Interface dks Implement djuk gksrk gS vkSj Source ls Listener dks Associate ;k Register djus ds fy, Source ds lkFk addAdjustmentListener() Method dks Use djuk gksrk gSA bl Method dks ge fuEukuqlkj Use djrs gSa%

487 Any Question or Suggestion, Just Discuss Here...

Java in Hindi SourceObject.addAdjustmentListener(ListenerObject);

3 tc ComponentEvent Generate gksrk gS] rc Event dks Listen djus ds fy, gesa ComponentListener Interface dks Implement djuk gksrk gS vkSj Source ls Listener dks Associate ;k Register djus ds fy, Source ds lkFk addComponentListener() Method dks Use djuk gksrk gSA bl Method dks ge fuEukuqlkj Use djrs gSa% SourceObject.addComponentListener(ListenerObject);

4 tc ContainerEvent Generate gksrk gS] rc Event dks Listen djus ds fy, gesa ContainerListener Interface dks Implement djuk gksrk gS vkSj Source ls Listener dks Associate ;k Register djus ds fy, Source ds lkFk addContainerListener() Method dks Use djuk gksrk gSA bl Method dks ge fuEukuqlkj Use djrs gSa% SourceObject.addContainerListener(ListenerObject);

5 tc FocusEvent Generate gksrk gS] rc Event dks Listen djus ds fy, gesa FocusListener Interface dks Implement djuk gksrk gS vkSj Source ls Listener dks Associate ;k Register djus ds fy, Source ds lkFk addFocusListener() Method dks Use djuk gksrk gSA bl Method dks ge fuEukuqlkj Use djrs gSa% SourceObject.addFocusListener(ListenerObject);

6 tc ItemEvent Generate gksrk gS] rc Event dks Listen djus ds fy, gesa ItemListener Interface dks Implement djuk gksrk gS vkSj Source ls Listener dks Associate ;k Register djus ds fy, Source ds lkFk addItemListener() Method dks Use djuk gksrk gSA bl Method dks ge fuEukuqlkj Use djrs gSa% SourceObject.addItemListener(ListenerObject);

7 tc KeyEvent Generate gksrk gS] rc Event dks Listen djus ds fy, gesa KeyListener Interface dks Implement djuk gksrk gS vkSj Source ls Listener dks Associate ;k Register djus ds fy, Source ds lkFk addKeyListener() Method dks Use djuk gksrk gSA bl Method dks ge fuEukuqlkj Use djrs gSa% SourceObject.addKeyListener(ListenerObject);

8 tc MouseEvent Generate gksrk gS] rc Event dks Listen djus ds fy, gesa MouseListener Interface dks Implement djuk gksrk gS vkSj Source ls Listener

488 Any Question or Suggestion, Just Discuss Here...

Java in Hindi dks Associate ;k Register djus ds fy, Source ds lkFk addMouseListener() Method dks Use djuk gksrk gSA bl Method dks ge fuEukuqlkj Use djrs gSa% SourceObject.addMouseListener(ListenerObject);

9 tc MouseWheelEvent Generate gksrk gS] rc Event dks Listen djus ds fy, gesa MouseWheelListener Interface dks Implement djuk gksrk gS vkSj Source ls Listener dks Associate ;k Register djus ds fy, Source ds lkFk addMouseWheelListener() Method dks Use djuk gksrk gSA bl Method dks ge fuEukuqlkj Use djrs gSa% SourceObject.addMouseWheelListener(ListenerObject);

10 tc TextEvent Generate gksrk gS] rc Event dks Listen djus ds fy, gesa TextListener Interface dks Implement djuk gksrk gS vkSj Source ls Listener dks Associate ;k Register djus ds fy, Source ds lkFk addTextListener() Method dks Use djuk gksrk gSA bl Method dks ge fuEukuqlkj Use djrs gSa% SourceObject.addTextListener(ListenerObject);

11 tc WindowEvent Generate gksrk gS] rc Event dks Listen djus ds fy, gesa WindowListener Interface dks Implement djuk gksrk gS vkSj Source ls Listener dks Associate ;k Register djus ds fy, Source ds lkFk addWindowListener() Method dks Use djuk gksrk gSA bl Method dks ge fuEukuqlkj Use djrs gSa% SourceObject.addWindowListener(ListenerObject);

vc ;fn ge iwjk Example Applet Create djsa] rks bl Applet ds Source Code fuEukuqlkj gksaxs% Program // File Name : UsingMyFirstListener.java import java.awt.*; import java.applet.*; import java.awt.event.*; public class UsingMyFirstListener extends Applet { public void init() { Button btnOK = new Button(" OK ");

//Creating Button Object

// Create Listener Object

489 Any Question or Suggestion, Just Discuss Here...

Java in Hindi MyFirstListener listenCommandButtonEvent = new MyFirstListener(); // Register Command Button with Listener so that // it can here Command Button's Events btnOK.addActionListener(listenCommandButtonEvent);

}

}

// Add the Button to the Applet add(btnOK);

class MyFirstListener implements ActionListener { public void actionPerformed(ActionEvent actnEvnt) { Button source = (Button)actnEvnt.getSource(); source.setLabel("Clicked"); } }

bl Source Code esa ge ns[k ldrs gSa] fd geus MyFirstListener Listener Class esa actionPerformed() Method dks Modify fd;k gSA ActionEvent Class esa getSource() uke dk ,d Method gksrk gSA ;s Method ml Component dk Reference Return djrk gS] ftlus Event Generate fd;k gSA ;kuh Applet Window ij fLFkr Command Button dks Click djus ij tks Click Event Generate gksrk gS] ml Click Event dks Generate djus okys Command Button ds Reference dks getSource() Method }kjk izkIr fd;k tk ldrk gSA pwafd ge Listener esa ftl Object dk Reference izkIr djuk pkgrs gSa] og ,d Command Button gS] blfy, geus MyFirstListener Class esa Button Class dk source uke dk ,d u;k Object Create fd;k gS] rkfd btnOK Button dks bl Class ds actionPerformed() Method esa source uke ds Object }kjk Access dj ldsaA ;s dke geus fuEu Statement }kjk fd;k gS% Button source = (Button)actnEvnt.getSource();

tc Applet Run gksrk gS vkSj ge Applet ij fLFkr btnOK Button ij Click djrs gSa] rks ,d Action Event Generate gksrk gSA bl Action Event dks Listener Listen djrk gS vkSj ftl Object us Event Generate fd;k gS] ml Source Object dks Argument ds :i esa actnEvnt uke ds Object esa izkIr djrk gSA pwafd bl Applet esa btnOK Button gh Action Event Generate dj jgk gS] blfy, actnEvnt uke dk Object btnOK Button dk Reference gh Hold djrk gSA blfy, tc getSource() Method dk iz;ksx djds ml Source Object dk irk yxkuk gksrk gS] ftlus Event Generate fd;k gS] rks btnOK Button dk Reference gh Return gksrk gSA

490 Any Question or Suggestion, Just Discuss Here...

Java in Hindi pwafd gesa bl Reference dks ,d u, Button izdkj ds Object source esa Store djuk gksrk gS] rkfd Source }kjk btnOK Button dks Refer fd;k tk lds] blfy, Return gksus okys Source Object ds uke dks Button izdkj ds eku esa Convert djus ds fy, (Button) “kCn ls Type Casting fd;k x;k gSA bl rjg ls source uke ds Object esa btnOK Button dk Reference Store gks tkrk gSA ;kuh ;s Object Hkh mlh Memory Location dks Refer djrk gS] tsls btnOK Button Object djrk gSA blfy, ge btnOK Object ds LFkku ij bl source Object dk iz;ksx djds ;fn Button ds Label dks Change djrs gSa] rks btnOK Button dk Label gh Change gksxkA D;ksafd nksuksa gh Objects leku Memory Location dks Refer dj jgs gSaA blfy, btnOK Button dk Label Change djus ds fy, geus fuEu Statement Use fd;k gS% source.setLabel("Clicked");

tc ge btnOK Button ij Click djrs gSa] rc mldk Label “OK” ls Change gksdj “Clicked” gks tkrk gSA bl Program dks fuEukuqlkj Modify djds ge nks Button Objects ls Generate gksus okys Action Events dks vyx&vyx rjhds ls Handle dj ldrs gSaA Program // File Name : UsingMyFirstListener.java import java.awt.*; import java.applet.*; import java.awt.event.*; public class UsingMyFirstListener extends Applet { public void init() { Button btnOK = new Button(" OK "); Button btnCancel = new Button(" Cancel ");

// Creating Button Object

// Create Listener Object MyFirstListener listenCommandButtonEvent = new MyFirstListener(); // Register Command Button with Listener so that // it can here Command Button's Events btnOK.addActionListener(listenCommandButtonEvent); btnCancel.addActionListener(listenCommandButtonEvent);

}

}

// Add the Button to the Applet add(btnOK); add(btnCancel);

class MyFirstListener implements ActionListener { public void actionPerformed(ActionEvent actnEvnt)

491 Any Question or Suggestion, Just Discuss Here...

Java in Hindi {

}

}

Button source = (Button)actnEvnt.getSource(); if(source.getLabel() == " OK ") source.setLabel("Clicked"); if(source.getLabel() == " Cancel ") source.setLabel("UnClick");

bl Program ds Listener dks ge fuEukuqlkj Modify dj ldrs gSa] tgka getLabel() Method ds LFkku ij getActionCommand() Method dks Use fd;k x;k gSA ;s Method ml Source Command dk Label Return djrk gS] ftlus Action Event dks Generate fd;k gksrk gSA pwafd gekjs Program esa Command Button gh Acton Event Generate dj jgk gS] blfy, bl Method ls Applet ij fLFkr nksuksa Buttons esa ls ml Button dk uke gh Return gksrk gS] ftlus Event Generate fd;k gksrk gSA ;s Modified Listener fuEukuqlkj gS% class MyFirstListener implements ActionListener { public void actionPerformed(ActionEvent actnEvnt) { Button source = (Button)actnEvnt.getSource(); if(source.getActionCommand() == " OK ") source.setLabel("Clicked");

}

}

if(source.getActionCommand() == " Cancel ") source.setLabel("UnClick");

ge fdlh Applet esa ,d nwljs rjhds ls Hkh fofHkUu izdkj ds Events dks Handle dj ldrs gSaA tc ge fdlh Applet esa Delegation Event Model dks Use djuk pkgrs gSa] rc gesa fuEukuqlkj dke djus gksrs gSa% 1 Appropriate Interface dks Applet esa gh Implement djuk gksrk gS] rkfd ;s Interface Desire izdkj ds Event dks Receive dj ldsA 2 ;fn t:jh gks rks Listener dks Event Notification izkIr djus ds fy, ,d Recipient dh rjg Register ;k Un-register djus ds fy, Code Implement djsaA ,d Source Object ,d ls T;knk izdkj ds Event Generate djus esa l{ke gksrk gS vkSj Source }kjk Generate fd, tk ldus okys gj Event dks Handle djus okys fofHkUu Event Handling Methods dks Interface esa vyx ls Define fd;k tkrk gSA blh rjg ls fdlh ,d gh Source Object dks ,d ls vf/kd izdkj ds Events dks Receive djus ds fy, Register fd;k tk ldrk gS] ysfdu tc bl izdkj dh fLFkfr gksrh gS] rc Object }kjk Receive fd, tkus okys fofHkUu izdkj ds Events ftl Interface ls lEcaf/kr gksrs gSa] mu

492 Any Question or Suggestion, Just Discuss Here...

Java in Hindi lHkh Interfaces dks Implement djuk t:jh gksrk gSA Delegation Event Model fdl izdkj ls dke djrk gS] bls le>us ds fy, ge lcls T;knk Event Generate djus okys Source Keyboard o Mouse dks Handle djuk lh[ksaxsA

Handling Mouse Events Mouse ls lEcaf/kr Events dks Handle djus ds fy, gesa MouseListener o MouseMotionListener Interfaces dks Implement djuk gksrk gSA blds lkFk gh ge MouseWheelListener Method dks Hkh Implement dj ldrs gSaA ysfdu pwafd lHkh yksx Scroll Mouse dk iz;ksx ugha djrs gSa] blfy, ;fn ge bl Interface dks Implement djrs Hkh gSa] rks Hkh Scrolling ls lEcaf/kr Events dsoy Scroll Mouse Use djus okys Computers ij gh Generate o Access gks ikrs gSaA ge vkxs tks Example Applet Develop dj jgs gSa] mlesa Mouse ls lEcaf/kr fofHkUu Events dks Handle fd;k x;k gSA bl Applet Program esa Mouse ds Pointer dh Current Coordinate Position dks Applet ds Status Bar esa Display fd;k x;k gSA bl Applet Example Program esa tc Hkh Mouse ds Button dks Press fd;k tkrk gS] rks Mouse Pointer dh Current Position ij “Down” Word Display gksrk gSA tc Hkh Mouse ds Button dks Release fd;k tkrk gS] rks Mouse Pointer dh Current Position ij “Up” Word Display gksrk gSA blh rjg ls tc Hkh Mouse ds Button dks Click fd;k tkrk gS] rks Applet ds Top-Left Corner ij “Mouse Clicked” Word Display gksrk gSA blh rjg ls tc Mouse dk Pointer Applet Window dh Border ls ckgj tkrk gS ;k Applet Window ds Display Area esa vkrk gS] Applet ij ,d Message Display gksrk gSA tc Program // File Name : MouseListeners.java import java.awt.*; import java.awt.event.*; import java.applet.*; public class MouseListeners extends Applet implements MouseListener, MouseMotionListener { String message = ""; int xPosition = 0, yPosition = 0; //Coordinates of Mouse Pointer public void init() { addMouseListener(this); addMouseMotionListener(this); } // Handle Mouse Click Event public void mouseClicked(MouseEvent mousEvnt) {

493 Any Question or Suggestion, Just Discuss Here...

Java in Hindi // Save Coordinates xPosition = 0; yPosition = 10; message = "Mouse Clicked"; repaint(); } // Handle Mouse Enter Event in Applet Window Display Area public void mouseEntered(MouseEvent mousEvnt) { // Save Coordinates xPosition = 0; yPosition = 10; message = "Mouse Entered"; repaint(); } // Handle Mouse Exit Event From Applet Window Border public void mouseExited(MouseEvent mousEvnt) { // Save Coordinates xPosition = 0; yPosition = 10; message = "Mouse Exited"; repaint(); } // Handle Mouse Button Press Event in Applet Window public void mousePressed(MouseEvent mousEvnt) { // Save Coordinates xPosition = mousEvnt.getX(); yPosition = mousEvnt.getY(); message = "Down"; repaint(); } // Handle Mouse Button Released Event in Applet Window public void mouseReleased(MouseEvent mousEvnt) { // Save Coordinates xPosition = mousEvnt.getX(); yPosition = mousEvnt.getY(); message = "Up"; repaint(); } // Handle Mouse Drag Event in Applet Window public void mouseDragged(MouseEvent mousEvnt)

494 Any Question or Suggestion, Just Discuss Here...

Java in Hindi { // Save Coordinates xPosition = mousEvnt.getX(); yPosition = mousEvnt.getY(); message = "*";

}

showStatus("Dragging mouse at "+ xPosition + ", " + yPosition); repaint();

// Handle Mouse Moved Event in Applet Window public void mouseMoved(MouseEvent mousEvnt) { // Show Status showStatus("Dragging mouse at " + mousEvnt.getX() + ", " + mousEvnt.getY()); repaint(); } // Display Message in Applet Window public void paint(Graphics g) { // Show Status g.drawString(message, xPosition, yPosition); } } Output

bl mnkgj.k Applet Program esa geus MouseListener o MouseMotionListener nksuksa Interfaces dks Implement fd;k gSA bu nksuksa Interfaces esa os Methods Include fd, x, gSa] ftUgsa Implement djds ge fofHkUu izdkj ds Mouse Events dks Handle dj ldrs gSaA pwafd ,d Applet esa gh fofHkUu izdkj ds Mouse Events Generate gksrs gSa] blfy, Applet gh fofHkUu izdkj ds Mouse Events dk Source gksrk gS vkSj fofHkUu izdkj ds Mouse Events dks Listen djus okyk Listener Hkh Applet gh gksrk gSA

495 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl fLFkfr esa geus Applet ds init() Method dks Override djds Event Generate djus okys Source ;kuh Applet ds lkFk fQj ls blh Applet dks Listener ds :i esa fuEukuqlkj Register fd;k gS% public void init() { addMouseListener(this); addMouseMotionListener(this); }

pwafd ge gekjh Applet Class esa gh Mouse ds gekjk Applet gh Generate gksus okyh fofHkUu Class esa gksrs gSa] mlh Class dks Refer djus blfy, Listener ds Reference ds :i esa geus

Listeners dks Implement dj jgs gSa] blfy, Events dk Listener gksrk gS vkSj ge ftl ds fy, this Object dks Use dj ldrs gSa] this Object dks Use fd;k gSA

blh rjg ls ge ftl Class esa gksrs gSa] ml Class ds Object ds fy, fdlh Hkh Methods dks fcuk Object ds lkFk Dot Operator dk iz;ksx fd, gq,] Directly Use dj ldrs gSaA blhfy, geus addMouseListener() o addMouseMotionListener() nksuksa dks fcuk fdlh Object ds Directly Call fd;k gSA ;fn ge fdlh vU; Class esa blh dke dks djuk pkgrs rks gesa] fuEukuqlkj Syntax dk iz;ksx djuk iMrk% SourceObject.addMouseListener(ListenerObject);

tc bl Applet dks Run djds Mouse ls Events dks Generate djrs gSa] rc fofHkUu Events Generate djus okyk Source Object Applet gh gksrk gS vkSj fofHkUu izdkj ds Events dks Handle djus ds Methods dks blh Applet Class esa Implement fd;k x;k gS] blfy, ;s Applet gh fofHkUu izdkj ds Events dks Listen Hkh djrk gS vkSj gj Event ds Response esa Appropriate Method dks Invoke dj nsrk gSA ftl rjg ls ge fdlh Applet esa mijksDr nks rjhdksa ls Delegation Event Handling dks Perform dj ldrs gSa] mlh rjg ls ge fdlh Application esa Hkh Delegation Event Handling dks Apply dj ldrs gSaA bl izfØ;k dks ge fuEukuqlkj Example }kjk le> ldrs

gSa%

Program // File Name : MyListenrFrame.java import java.awt.*; import java.awt.event.*; public class MyListenerFrame extends Frame { Button btnOK, btnCancel; // The main Method public static void main(String args[]) { MyListenerFrame window = new MyListenerFrame(); }

496 Any Question or Suggestion, Just Discuss Here...

Java in Hindi // Constructor public MyListenerFrame() { super("My First Event Handled Window"); setLayout(null); // Creating Event Generator Source Button Objects btnOK = new Button("OK"); btnCancel = new Button("Cancel"); btnOK.setBounds(40,45,50,25); btnCancel.setBounds(100,45,50,25); add(btnOK); add(btnCancel); // Creating Listener Object so that it can Listen Button's Events MyFirstListener listenCommandButtonEvent = new MyFirstListener(); // Register Buttons with Listener btnOK.addActionListener(listenCommandButtonEvent); btnCancel.addActionListener(listenCommandButtonEvent);

}

}

// Display the window in a separate size setVisible(true); setSize(200,100);

// The Listener Class class MyFirstListener implements ActionListener { public void actionPerformed(ActionEvent actnEvnt) { Button source = (Button)actnEvnt.getSource(); if(source.getActionCommand() == "OK") source.setLabel("Clicked");

}

}

if(source.getActionCommand() == "Cancel") source.setLabel("UnClick");

Output

497 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

blh Program dks ge ,d vkSj rjhds ls fuEukuqlkj fy[k ldrs gSa] ftlesa eq[; Class esa gh ActionListener dks Implement dj fy;k x;k gSA ;s Program fuEukuqlkj gS% Program // File Name : MyListenrFrame.java import java.awt.*; import java.awt.event.*; public class MyListenerFrame extends Frame implements ActionListener { Button btnOK, btnCancel; // The main Method public static void main(String args[]) { MyListenerFrame window = new MyListenerFrame(); } // Constructor public MyListenerFrame() { super("My First Event Handled Window"); setLayout(null); // Creating Event Generator Source Button Objects btnOK = new Button("OK"); btnCancel = new Button("Cancel"); btnOK.setBounds(40,45,50,25); btnCancel.setBounds(100,45,50,25); add(btnOK); add(btnCancel); // Register Buttons with Listener btnOK.addActionListener(this); btnCancel.addActionListener(this);

}

// Display the window in a separate size setVisible(true); setSize(200,100);

498 Any Question or Suggestion, Just Discuss Here...

Java in Hindi public void actionPerformed(ActionEvent actnEvnt) { Button source = (Button)actnEvnt.getSource(); if(source.getActionCommand() == "OK") source.setLabel("Clicked");

}

}

if(source.getActionCommand() == "Cancel") source.setLabel("UnClick");

gekjs MyListenerFrame Class esa gh ActionListener dks tc ge bl rjg ls fdlh Interface dks Implement djrs gSa] rc Event Listener gksrk gS] blfy, ftu Event Generate djus okys gesa Listener ls Register djuk gksrk gS] mu lHkh dks addActionListener() Method }kjk Current Frame ls gh Register fd;k tkrk gS vkSj Current Frame dks Refer djus ds fy, this Object dk iz;ksx fd;k tkrk gSA bl Program esa geus Implement dj fy;k gSA Current Frame gh gekjk Source Objects dks

Handling Keyboard Events Keyboard Events dks Handled djus ds fy, Hkh gesa leku Architecture dks Use djuk gksrk gS] ftls geus Mouse Events dks Handle djus ds fy, Use fd;k gSA vUrj dsoy bruk gS fd tc ge Keyboard ds Events dks Handle djrs gSa] rc gesa KeyListener Interface dks Implement djuk gksrk gSA tSlkfd ge tkurs gSa fd tc Keyboard ls fdlh Key dks Press fd;k tkrk gS] rc KEY_PRESSED Event Generate gksrk gS] ftls Handle djus ds fy, keyPressed() Method Invoke gksrk gSA blh rjg ls tc Keyboard ds fdlh Key dks Press djds Release djrs KEY_RELEASED Event Generate gksrk gS vkSj bl Event dks Handle djus keyReleased() Method Invoke gksrk gSA tc Keyboard ls KEY_TYPED Generate gksrk gS] rc bl Event dks Handle djus ds fy, keyTyped() Method gksrk gSA

gSa] rc ds fy,

Event Invoke

User tc Hkh Keyboard ij fdlh Key dks Press djrk gS] rc de ls de nks Events KEY_PRESSED o KEY_RELEASED rks Generate gksrs gh gSa] fQj Hkh vDlj rhuksa Events Generate gks tkrs gSaA

tc gesa dsoy Key ds Character dks gh Process djuk gksrk gS] rc gesa KEY_PRESSED o KEY_RELEASED bu nksuksa Events dks Handled djus dh t:jr ugha gksrh gSA ysfdu tc gesa Special Keys ds lkFk Processing djuh gksrh gS] rc gesa KEY_PRESSED Event dks gh Handle djuk gksrk gSA dksbZ Key Process djus ls igys gesa ,d dke vkSj djuk iMrk gSA gesa ftl Object ds fy, Key dks Press djuk gksrk gS] ml Object ds fy, Input Focus dks izkIr djuk gksrk gS] rkfd Input gksus okyh Key ml Object ij gh tk,A Input Focus dks izkIr djus ds fy, gesa 499 Any Question or Suggestion, Just Discuss Here...

Java in Hindi requestFocus() Method dks Use djuk gksrk gS] ftls Component Package esa Define

fd;k x;k gSA

;fn ge bl Method }kjk vius Application ds fy, Focus izkIr ugha djsaxs] rks gekjk Program Press fd, x, Key dks Receive ugha djsxkA vxys Program esa geus Keyboard Input dks vius Applet esa izkIr fd;k gS vkSj Keyboard ls vkus okyh Key dks Applet ij Display fd;k gS] lkFk gh Generate gksus okys Event dks Hkh Applet ij n”kkZ;k gSA Program // File Name : KeyStrockDemonstracton.java import java.awt.*; import java.awt.event.*; import java.applet.*; public class KeyStrockDemonstracton extends Applet implements KeyListener { String message = ""; int xPosition = 10, yPosition = 20; // Output Coordinates public void init() { addKeyListener(this); requestFocus(); }

// Register Listener with Applet // Request Input Focus for current program

public void keyPressed(KeyEvent keyEvnt) { showStatus("Key Pressed"); } public void keyReleased(KeyEvent keyEvnt) { showStatus("Key Released"); } public void keyTyped(KeyEvent keyEvnt) { message = message + keyEvnt.getKeyChar(); repaint(); }

}

public void paint(Graphics g) { g.drawString(message, xPosition, yPosition); }

Output

500 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

bl Program esa geus Applet esa Keyboard ds rhuksa Events dks Handle fd;k gSA pwafd ;s Applet Event Generate djus okyk Source Hkh gS vkSj Event Listen djus okyk Listener Interface Hkh blh Applet Class esa Implement fd;k x;k gS] blfy, Source Applet Class dks mlh Listener Applet Class ls Register djus ds fy, geus Applet ds init() Method dks Override djds fuEukuqlkj Define fd;k gS% public void init() { addKeyListener(this); requestFocus(); }

// Register Listener with Applet // Request Input Focus for current program

Applet fofHkUu Keystroke Events dks izkIr dj lds] blds fy, geus requestFocus() Method dks Hkh blh Method esa Call fd;k gSA showStatus() Method Applet ds Status Bar dks Represent djrk gS] blfy, fofHkUu izdkj ds Messages dks Display djus ds fy, geus bl Method dks Use fd;k gSA getKeyChar() Method Keyboard ls Press fd, x, Key ds Character dks Return djrk gS] blfy, bl Method }kjk geus Keyboard ls vkus okys Characters dks Message uke ds String Object esa izkIr fd;k gSA fQj paint() Method esa bl Message esa Stored Message dks Applet ij Draw fd;k gSA

tc ge Keyboard ls fdlh Key dks Type djrs gSa] rc ,d KeyEvent Object Generate gksrk gS vkSj KeyTyped() Method Invoke gksrk gSA bl KeyEvent Object esa Type fd, x, Key dk Character gksrk gSA bl Character dks izkIr djus ds fy, keyEvnt Object ls getKeyChar() Method dks fuEukuqlkj Use djds message uke ds String Object esa izkIr fd;k x;k gSA public void keyTyped(KeyEvent keyEvnt) { message = message + keyEvnt.getKeyChar(); repaint(); }

pwafd tc repaint() Method paint() Method dks Execute djds Applet dh Screen dks Repaint djrk gS] rc message uke ds Object esa tks Hkh String gksrh gS] og Screen ij Draw gks tkrh gSA blfy, fiNyk Message Delete gks tkrk gS vkSj u;k Message Paint gks tkrk gS] tks fd message uke ds Object esa gksrk gSA bl Method esa geus message Object dks ftl rjg ls gj KEY_TYPE Event ij Update fd;k gSA

501 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ,slk blfy, fd;k x;k gS] rkfd message dk iqjkuk Character Hkh Applet ij Draw gks tk,A ;fn ge bl message Object dks bl izdkj ls Update uk djsa] rks gj ckj message esa Currently Press fd;k x;k] Character gh gksxk vkSj dsoy ,d gh Character Screen ij Display gksxkA bl Applet dks Run djrs le; ;fn ge fdlh Special Key tSls fd Shift, Ctrl, Alt ;k fdlh Function Key dks Press djrs gSa] rks gekjh Screen ij dqN Hkh Display ugha gksrk gSA bu Keys dks Respond djus ds fy, gesa keyPressed() Handler dks Use djuk gksrk gSA bu Keys dks keyTyped() Method }kjk Manage ugha fd;k tk ldrk gSA bl Keys dks Identify djus ds fy, gesa buds Virtual Codes dks Use djuk gksrk gSA bl izfØ;k dks ge vxys Program }kjk le> ldrs gSaA Program // File Name : SpecialKeyStrockDemonstracton.java import java.awt.*; import java.awt.event.*; import java.applet.*; public class SpecialKeyStrockDemonstracton extends Applet implements KeyListener { String message = ""; int xPosition = 10, yPosition = 20; // Output Coordinates public void init(){ addKeyListener(this); requestFocus(); }

// Register Listener with Applet // Request Input Focus for current program

public void keyPressed(KeyEvent keyEvnt){ showStatus("Key Pressed"); int key = keyEvnt.getKeyCode(); switch(key) { case KeyEvent.VK_F1: message += ""; break; case KeyEvent.VK_F2: message += ""; break; case KeyEvent.VK_F3: message += ""; break; case KeyEvent.VK_PAGE_DOWN:

502 Any Question or Suggestion, Just Discuss Here...

Java in Hindi message += ""; break; case KeyEvent.VK_PAGE_UP: message += ""; break; case KeyEvent.VK_LEFT: message += ""; break; case KeyEvent.VK_UP: message += ""; break;

}

} repaint();

public void keyReleased(KeyEvent keyEvnt) { showStatus("Key Released"); } public void keyTyped(KeyEvent keyEvnt) { message = message + keyEvnt.getKeyChar(); repaint(); }

}

public void paint(Graphics g) { g.drawString(message, xPosition, yPosition); }

Output

Adapters tc ge Listeners Create djus ds fy, Interfaces dk iz;ksx djrs gSa] rc Listener Class dks mu lHkh Methods dks Override djuk gksrk gS] ftUgsa Interface esa Declare fd;k x;k gSA 503 Any Question or Suggestion, Just Discuss Here...

Java in Hindi dbZ Interfaces esa dsoy ,d Method gksrk gS] tcfd dbZ Interfaces esa dbZ Methods gksrs gSaA gkykafd ge dsoy ,d gh Event dks Handle djuk pkgrs gSa] ysfdu fQj Hkh gesa Interface ds lHkh Methods dks Override djuk iMrk gSA bl leL;k ls cpus ds fy, Event Package gesa lkr Adapter Classes Provide djrk gSA Adapter Classes gesa fdlh Event Listener Interface ds lHkh Methods dh Empty Implementation Provide djrk gSA ;kuh fdlh Event Listener Interface ds lHkh Methods dks Adapter Classes esa igys ls gh Implement fd;k tk pqdk gksrk gS] ftudh Body Empty jgrh gSA pwafd Interface ds lHkh Methods dh Body Empty jgrh gS] blfy, dksbZ Hkh Method dksbZ dke ugha djrk gSA

tc gesa fdlh Interface ds fdlh Method dks Implement djuk gksrk gS] rc ge mldh Adapter Class dks Inherit djds dsoy ml Interface dks Implement dj ysrs gSa] ftldh gesa t:jr gksrh gSA bl izdkj ls ge fdlh Event Listener Interface ds lHkh Methods dks Implement djus dh t:jr ugha gksrh gS] cfYd dsoy mu Methods dks Implement djuk gksrk gS] ftudh gekjs Program esa t:jr gksrh gSA mnkgj.k ds fy, ekuyks fd gesa gekjs fdlh Program esa Mouse ds MouseMotionListener Interface dks Implement djuk gSA vc ;fn ge bl Interface dks Use djuk pkgrs gSa] rks gesa gekjs Program esa blds nksuksa Methods mouseDragged() o mouseMoved() dks Implement djuk t:jh gksrk gSA fQj pkgs gesa gekjs Program esa dsoy mouseDragged() Method dh gh t:jr D;ksa uk gksA bl fLFkfr ls cpus ds fy, ge MouseMotionAdapter Class dk iz;ksx dj ldrs gSa] D;ksafd bl Adapter Class esa bu nksuksa Methods dks igys ls gh Implement fd;k tk pqdk gS] ftudh Body Empty gSA gesa bl Class ds ,d ubZ Class esa Inherit djuk gSA ,slk djus ij Mouse ds nksuksa Empty Implemented Methods gekjh ubZ Class esa Inherit gks tkrs gSaA vc bl ubZ Class esa ge Mouse ds nksuksa Methods esa ls ftl Method dks Implement djuk pkgrs gSa] mls Override djds Implement dj ysrs gSa vkSj MouseMotionListener Interface ds nksuksa Methods dks Implement djus ls cp tkrs gSaA bl rjhds esa ge ftl Method dks Implement ugha djrs gSa] mls Adapter Class esa Define fd;k x;k Empty Body okyk Method Handle djrk gSA java.awt.event Package esa fuEukuqlkj lkr Adapter Classes dks Define fd;k x;k gS] tks Generally Use gksrs gSaA lkFk gh ;s Hkh crk;k x;k gS fd os fdl Listener Interface dks Implement dj jgs gSaA

504 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

Event Listener Interface Classes o Event Listener Adapter Classes nksuksa gh izdkj dh Classes Applet dk ,d Reference Save djrh gSaA ;s Information ,d Argument ds :i esa muds Constructor dks Pass fd;k tk ldrk gS vkSj budk iz;ksx ckn esa showStatus() Method dks Invoke djus ds fy, fd;k tk ldrk gSA

pfy,] Adapter Classes dk iz;ksx djrs gq, Events dks ,d Example Program }kjk Handle djuk lh[krs gSaA vHkh rd geus ftrus Hkh Application Create fd, gSa] mu lHkh ds Window ds Close Button ij Click djus ij Hkh os Window Close ugha gksrs gSaA ;s Window rc Close gksrs gSa] tc ge Command Window dks Close djrs gSaA Display gksus okyk Frame Window mlds Close Button dks Click djus ij Close gks lds] blds fy, gesa Frame Window ds Closing Event dks Handle djuk t:jh gksrk gSA fuEu Program esa geus ;gh fd;k gSA Program // File Name : AdapterClassesDemonstracton.java import java.awt.*; import java.awt.event.*; public class AdapterDemonstrationApp extends Frame { public static void main(String args[]) { AdapterDemonstrationApp window = new AdapterDemonstrationApp();

505 Any Question or Suggestion, Just Discuss Here...

Java in Hindi }

window.setBounds(10,10,150,100);

// Constructor public AdapterDemonstrationApp() { // Register the listener for the window super("The window adapter");

}

}

WindowListener listenWindowEvent = new WindowListener(); addWindowListener(listenWindowEvent); setVisible(true);

class WindowListener extends WindowAdapter { // Event handler for the window closing event

}

public void windowClosing(WindowEvent wndEvnt) { AdapterDemonstrationApp source; source = (AdapterDemonstrationApp)wndEvnt.getSource(); source.dispose(); System.exit(0); }

bl Program esa Main Class ds main() Method esa geus ,d Frame Window Create fd;k gSA bl Frame Window ds Constructor esa gh geus ,d Listener Object Create fd;k gS vkSj Current Class dks ml Listener Object ls Register fd;k gSA pwafd Current Class ,d Window Create djrk gS] blfy, Current Class esa Current Window ls lEcaf/kr tks Hkh Event Generate gksxk] mls og Listener Object Listen djsxkA Listener Object Current Window ds Closing Events dks Listen dj lds] blds fy, geus Window Adapter Class dks Extend fd;k gS vkSj bl Class esa windowClosing() Method dks Implement fd;k gSA ;s Method rc Invoke gksrk gS] tc Frame Window dks Close fd;k tkrk gSA

tc Frame Window dks Close fd;k tkrk gS] rc Window dks Close djus dk Event Generate gksrk gSA bl Event dks listenWindowEvent Object Listen djrk gS vkSj bl Event ds Response esa Extended dh xbZ WindowListener Listener Class dk windowClosing() Method Execute gksrk gSA tks Event Generate gksrk gS] ml Event dks ;s Listener wndEvnt Object esa izkIr djrk gSA pwafd tks Event Generate gksrk gS] og Event AdapterDemonstrationApp Class ds Object esa Generate gksrk gS] blfy, bl Event dks Listener Class esa Refer djus ds fy, gesa Listener Class esa fQj ls blh Class dk source uke dk ,d Object Create djuk

506 Any Question or Suggestion, Just Discuss Here...

Java in Hindi gksrk gSA tc ge leku Class dk nwljk Object Create djds mlesa wndEvnt Object ls mlds Generator Object dks getSource() Method }kjk Return djokrs gSa] rc og Object Refer gksrk gS] ftlus Event Generate fd;k gksrk gSA pwafd og Object AdapterDemonstrationApp Class dk Object gS] blfy, blh Class dk source uke dk Object mls Refer dj ldrk gS vkSj ge source Object ds Reference esa tks Method Call djrs gSa] og Method Event Generate djus okys Object ds Reference esa gh Call gksrk gS vkSj Window Close gks tkrk gSA WindowListener Class ftls geus Adapter Class ls Extend fd;k gS] bl Class esa ge ns[k ldrs gSa fd geus dsoy windowClosing() Method dks gh Implement fd;k gS] tcfd Window ls lEcaf/kr lkr Methods gksrs gSaA

,slk blhfy, lEHko gS] D;ksafd ckdh ds Methods dks Empty Body ds lkFk WindowAdapter Class esa igys ls gh Implement fd;k tk pqdk gSA blfy, tc Window Closing ds vykok Window ls lEcaf/kr dksbZ vU; Events Generate gksrs gSa] rc mUgsa Adapter ds Empty Body okys Methods Handle dj ysrs gSaA ge Applet esa Hkh Event Handling djus ds fy, Adapter Classes dks Use dj ldrs gSaA bl izfØ;k dks ge fuEu Applet }kjk le> ldrs gSa% Program // File Name : AdapterApplet.java import java.awt.*; import java.awt.event.*; import java.applet.*; public class AdapterApplet extends Applet { public void init() { addMouseListener(new MyMouseListener(this)); } } class MyMouseListener extends MouseAdapter { AdapterApplet adapterApplet; public MyMouseListener(AdapterApplet adapterApplet) { this.adapterApplet = adapterApplet; }

}

public void mousePressed(MouseEvent mousEvnt) { adapterApplet.showStatus("Mouse Pressed"); }

507 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl Program esa MouseAdapter Class dks Extend djds MyMouseListener Class Create fd;k x;k gSA bl Class dk Object Applet esa Generate gksus okyh Mouse Events dks Listen djrk gSA MouseListener esa dqy ikap Methods gksrs gSa] ftUgsa Implement djuk gksrk gSA pwafd ge MouseAdapter Class dks Extend dj jgs gSa] blfy, gesa bl Class esa ;s lqfo/kk feyrh gS fd gesa Mouse ds ftl Method dks Use djuk gksrk gS] ge dsoy mlh Method dks Implement dj ldrs gSa vkSj gesa “ks’k Methods dks Implement djus dh t:jr ugha gksrh gSA pwafd gekjk ;s Listener ftl Applet ds Events dks Listen djus okyk gS] ml Applet Class ds ,d Reference Object dh t:jr bl Listener dks gksrh gS] rkfd ;s Listener ml Applet ds fy, fofHkUu Methods dks Invoke dj ldsA blfy, MyMouseListener Class esa geus AdapterApplet Class dk ,d Object adapterApplet Create fd;k gSA AdapterApplet og Applet Class gS] ftlds fy, MyMouseListener Class dks Extend fd;k x;k gSA tc ge mousePressed() Method esa bl adapterApplet Object ds fy, showStatus() Method dks Invoke djrs gSa] rks ;s Method Display gksus okys Actual Applet ds Status Bar dks Refer djrk gS vkSj tks Message Display gksuk gksrk gS] og Display gksus okys Applet ds Status Bar ij fn[kkbZ nsrk gSA

tc ;s Program Run djrs gSa] rc lcls igys Applet Initialize gksrk gSA Applet Initialize djus ds fy, Applet dk fuEu init() Method Execute gksrk gS% public void init() { addMouseListener(new MyMouseListener(this)); }

;fn ge pkgsa rks bl Method dks fuEukuqlkj Hkh Define dj ldrs gSa% public void init() { MyMouseListener listenAppletEvent = new MyMouseListener(this); addMouseListener(listenAppletEvent); } Applet Initialize gksrs gh nks dke gksrs gSaA lcls igys MyMouseListener Class dk ,d Object listenAppletEvent Create gksrk gSA tc ;s Object Crete gksrk gS] rc bl Object ds Constructor esa AdapterApplet Class dk ,d Object Argument ds :i esa Pass fd;k tkrk gSA ,slk blfy, fd;k tkrk gS] rkfd Listener dks ;s irk py tk, fd mls fdl Class ls Generate gksus okys Events dks Listen djuk gSA

pwafd ;s Object Current Applet ls Generate gksus okys Events dks Handle djus ds fy, Create fd;k x;k gS] blfy, bl Constructor esa this Object Pass fd;k x;k gS] tks Current Applet dks Represent djrk gSA Listener Class dk Object Create djus ds fy, tkok MyMouseListener Class dk 1-Argument Constructor Execute djrk gS] tks fd fuEukuqlkj gS%

508 Any Question or Suggestion, Just Discuss Here...

Java in Hindi public MyMouseListener(AdapterApplet adapterApplet) { this.adapterApplet = adapterApplet; }

tc MyMouseListener Class dk Object Create djus ds fy, tc ;s Constructor Execute gksrk gS] rc Argument ds :i esa ml Class dk Reference ysdj vkrk gS] ftlds Events dks bls Listen djuk gSA pwafd Applet Class esa bl Constructor ds fy, this Object ;kuh AdapterApplet Class dk Reference Pass fd;k x;k gSA ,slk blfy, fd;k tkrk gS] rkfd MyMouseListener Class esa Create fd, x, adapterApplet Object dks this Object esa vkus okys Reference dks Store fd;k tk ldsA tc ge Listener Class esa Create fd, x, AdapterApplet Class ds Object esa Applet Class dk Reference Pass djrs gSa] rc ml Actual Applet dks Listener esa Create fd;k x;k ;s Object Hkh Refer djus yxrk gSA blfy, vc ;fn ge bl Listener Class esa adapterApplet Object ds lkFk fdlh Method dks Invoke djsa] rks og Method okLro esa Actual Applet Object ds fy, Call gksrk gSA Applet ls Generate gksus okys Events dks Listener Object ls Register djus ds fy, Applet ds init() Method esa addMouseListener() Method dks Call fd;k gSA ;s Method Applet dks mlds Listener ls Connect ;k Register dj nsrk gSA bl rjg ls ge ,d Applet esa Hkh Adapter Classes dks Use dj ldrs gSaA

Inner Classes and Anonymouse Inner Classes for Simplifying Adapter Classes Inner Class ,d ,slh Class gksrh gS] ftls fdlh Class ds vUnj Define fd;k tkrk gSA bUgsa Nested Class Hkh dgrs gSaA budk iz;ksx djds ge Program dh Coding esa Additional Clarity izkIr dj ldrs gSaA ,d Inner Class dsoy mlh Class ds fy, Available gksrh gS] ftlesa Inner Class dks Define fd;k x;k gksrk gSA Inner Class dk Object Outer Class ds Members dks Access djus esa l{ke gksrk gSA ;kuh ge Inner Class ds Object ls Outer Class ds Data Members o Member Methods dks Directly Access dj ldrs gSaA tcfd Outer Class ;fn Inner Class ds Members dks Access djuk pkgs] rks og ;s dke Inner Class dk ,d Object Create djds ml Object ds lkFk Inner Class ds Members dk iz;ksx djds dj ldrk gSA vc ge ;s tkusaxs fd ge fdl izdkj ls ,d Inner Class dks Event Handling ds fy, Use djds ge Event Adapter Classes dks Use djrs le; fdl rjg ls viuh Coding dks Simple cuk, j[k ldrs gSaA fiNys Program }kjk bl Technique dks le>us dh dksf”k”k djrs gSa] ftlesa Listener Class dks Applet Class ls ckgj Define fd;k x;k gSA bl Applet Class dk eq[; Purpose ;s gS fd tc Applet ij Mouse ds fdlh Key dks Press fd;k tk,] rc Applet ds Status Bar esa “Mouse Pressed” String Display gksuh pkfg,A

509 Any Question or Suggestion, Just Discuss Here...

Java in Hindi bl Program esa nks Top Level Classes Define dh xbZ gSaA ,d Event Source Class dks Applet Class ls Extend fd;k x;k gS tcfd Event Listener Class dks MouseAdapter Class ls Extend fd;k x;k gSA bl Program esa ge ns[k ldrs gSa fd Applet dk Reference Argument ds :i esa MyMouseListener Constructor dks fn;k x;k gSA bl Reference dks ckn esa mousePressed() Method esa Use djus ds fy, ,d adapterApplet Object esa Store djds j[kk x;k gSA tc Mouse dk dksbZ Button Press fd;k tkrk gS] rc mousePressed() Method ml Applet ds showStatus() Method dks Invoke djrk gS] ftlds Reference dks adapterApplet uke ds AdapterApplet Class ds Object esa Store djds j[kk x;k gSA nwljs “kCnksa esa dgsa rks showStatus() Method dks Actual Applet ds Reference Object adapterApplet ds Reference }kjk Call fd;k x;k gSA blh dke dks ge ,d Inner Class dk iz;ksx djds Hkh dj ldrs gSa] ftls vxys Program esa Explain fd;k x;k gSA Program // File Name : InnerAdapterApplet.java import java.awt.*; import java.awt.event.*; import java.applet.*; public class InnerAdapterApplet extends Applet{ public void init(){ addMouseListener(new MyMouseListener()); }

}

class MyMouseListener extends MouseAdapter{ public void mousePressed(MouseEvent mousEvnt){ showStatus("Mouse Pressed"); } }

;s Program Hkh ogh dke djrk gS] tks fiNyk Program djrk gSA bl Program ds Applet ij Hkh tc ge Click djrs gSa] rc Applet ds Status Bar esa “Mouse Pressed” String Display gksrk gSA ysfdu ge ns[k ldrs gSa] fd bl Program esa gesa fdrus de dke djus iMrs gSaA ftl rjg ls ge fdlh Applet esa Inner Adapter Classes Define djds Applet ds Events Handle dj ldrs gSa] mlh rjg ls ge fdlh Application esa Hkh dj ldrs gSaA bl izfØ;k dks ge fuEu Program }kjk le> ldrs gSa] ftlesa ,d Frame Window dks Close djus ds fy, Window ds windowClosing() Method dks Implement fd;k tk jgk gSA Program // File Name : InnerAdapterApp.java import java.awt.*; import java.awt.event.*; public class InnerAdapterApp extends Frame

510 Any Question or Suggestion, Just Discuss Here...

Java in Hindi {

// main() Method public static void main(String args[]) { InnerAdapterApp window = new InnerAdapterApp(); } // Constructor of the InnerAdapterApp Class public InnerAdapterApp() { // Register the Frame Window with the Listener MyWindowListener listenWindowEvent = new MyWindowListener(); addWindowListener(listenWindowEvent);

}

}

setVisible(true); setSize(150,100);

// Inner Class Definition class MyWindowListener extends WindowAdapter { // Window Closing Event Handler public void windowClosing(WindowEvent wndEvnt) { InnerAdapterApp source = (InnerAdapterApp)wndEvnt.getSource(); source.dispose(); System.exit(0); } }

bl Program dks Execute djus ij lcls igys main() Method Execute gksrk gSA bl Method esa InnerAdapterApp Class dk ,d Object Create fd;k x;k gSA tc bl Class dk Object Create fd;k tkrk gS] rc bl Class dk Constructor Execute gksrk gSA ;s Frame Window Event Generate djus okys Source dh rjg dke djrk gSA Window ls Generate gksus okys Window Events dks Listen djus ds fy, blh Class esa ,d Inner Class Define dh xbZ gS vkSj bl Inner Class dks WindowAdapter Class ls Derive fd;k x;k gSA Current InnerAdapterApp Class ls Generate gksus okys Events dks Listener ij Hkstus ds fy, addWindowListener() Method dk iz;ksx fd;k x;k gS vkSj Argument ds :i esa bl Method esa MyWindowListener Class ds listenWindowEvent Object dks Pass fd;k x;k gSA

pwafd Current Class dks gh Event Generator ds :i esa Use fd;k tk jgk gS] blfy, blds Object ds lkFk bl Registration Method dks Call djus dh t:jr ugha gSA ge Directly addWindowListener() Method dks Call dj ldrs gSaA

511 Any Question or Suggestion, Just Discuss Here...

Java in Hindi tc Window dks Close djus ds fy, Window ds Close Button ij Click djrs gSa] rc ,d WindowEvent Generate gksrk gSA ;s Window Event Listener Object Listen djrk gS vkSj Event ds Response esa Listener Class dk windowClosing() Method Execute gksrk gSA bl Method ds Execute gksrs gh blesa Frame Window Class dk source uke dk ,d Object Create fd;k tkrk gSA pwafd wndEvnt Window Event Object esa ml Window dks Reference gksrk gS] ftlus Event Generate fd;k gksrk gSA blfy, getSource() Method dk iz;ksx djds ml Window dk Reference izkIr dj fy;k tkrk gS] ftlus Event Generate fd;k gksrk gSA vc Event Generate djus okys Window dks ge source Object }kjk Refer dj ldrs gSaA blfy, tc ge source Object ds fy, dispose() Method dks Call djrs gSa] rks og Actual Frame Window ds fy, Call gksrk gS vkSj Frame Window dks Close dj nsrk gSA bl rjg ls ge fdlh Application esa Hkh Inner Class ds :i esa Adapter Class dks Extend djds Event Handling dj ldrs gSaA bl mnkgj.k esa geus ns[kk fd Events dks Handle djus ds fy, ge ,d Separate Inner Class Define dj ldrs gSa] tks fd Outer Class ls Generate gksus okys Events dks Listen djus ds fy, Required Listener Interfaces dks Implement djrk gSA fiNys Program esa geus Outer Class ds Constructor esa Inner Class dk ,d Object Create fd;k gSA pwafd eq[; Class esa geus Listener Class dks Inner Class dh rjg Define fd;k gS vkSj ge le> ldrs gSa fd nksuksa gh Classes ,d nwljs ls Unrelated gSa] tcfd nksuksa Classes vkil esa feydj Event Handling dk dke djrh gSaA ;kuh eq[; InnerAdapterApp Frame Class Event Generate djus okyh Source Class gS] tcfd Inner Class Outer Class ls Generate gksus okyh Events dks Listen djus okyh Listener Class gSA nks Unrelated Classes dks vkil esa Related djus ds fy, gesa eq[; Class esa nwljh Class dk ,d Object Create djuk iMrk gS] fQj pkgs og nwljh Class dksbZ Inner Class gks ;k dksbZ vU; Class gksA ;kuh gesa Composition Concept dks Use djuk gksrk gSA tc ge fdlh Class esa fdlh nwljh Unrelated Class dk Object Create djds nksuksa Classes ds chp fdlh izdkj dk Relation cukrs gSa] rkfd nksuksa Classes vkil esa feydj fdlh dke dks iwjk dj ldsa] rks bl izfØ;k dks nwljh Class dk igyh Class esa Compose gksuk dgrs gSaA gekjs Program dh eq[; Class ;k Outer Class ds Constructor esa geus Inner Class dk Object Create djds mls eq[; Class esa Compose fd;k gSA ,slk djus ij nks Unrelated Classes vkil esa Relate gks tkrh gSaA Inner Class dk ,d Object Outer Class esa ,d Data Member dh rjg Create djus ds fy, geus new Operator dks Use fd;k gSA ;fn ge pkgsa rks nks Unrelated Classes dks vkil esa fuEukuqlkj Coding }kjk Hkh Relate dj ldrs gSa% OuterClass out = new OuterClass(“Title”); out.InnerUnrelatedClass inUnrelated = new OuterClass().InnerUnrelatedClass();

ge fdlh Method dh Body esa Hkh fdlh Class dks Define dj ldrs gSaA bl fLFkfr esa Inner Class ml Method dh Body esa Define fd, x, Variables dks Hkh Access djus esa l{ke

512 Any Question or Suggestion, Just Discuss Here...

Java in Hindi gks tkrh gS] ftlesa Inner Class dks Define fd;k x;k gSA tc ge bl izfØ;k dks Use djuk pkgrs gSa] rc gesa Inner Class dks gesa”kk Method ds Variables dks Declare djus ds ckn Define djuk pkfg,] rkfd Inner Class Method ds mu Variables dks Access dj ldsA lkekU;r;k ge ftu Class dks Inner Classes ds :i esa Define djrs gSa] os Classes Current Outer Class ds vykok fdlh Hkh vU; Outer Class ds fy, Accessible ugha gksrh gSaA blfy, ge ,slh Classes dks fcuk mudk uke Specify fd, gq, Hkh Define dj ldrs gSaA ;kuh ge Inner Classes Create djrs le; Classes dks Nameless Classes ds :i esa Define dj ldrs gSaA ,d ,slh Inner Class ftldk dksbZ uke ugha gksrk gS] Anonymous Class dgykrh gSA Event Handling ds fy, ge ftu Inner Classes dks Define djrs gSa] mu Classes dks Anonymous Class ds :i esa Hkh ifjHkkf’kr fd;k tk ldrk gSA fuEu Program esa geus Status bar esa “Mouse Pressed” String Display djus okys Program dks gh ,d Anonymous Class dk Use djrs gq, Modify fd;k gSA Program fuEukuqlkj gS% Program // File Name : AnonymousInnerApplet.java import java.awt.*; import java.awt.event.*; import java.applet.*; public class AnonymousInnerApplet extends Applet { public void init() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mousEvnt) { showStatus("Mouse Pressed"); } }); } }

bl Program esa AnonymousInnerApplet uke dh ,d gh Top-Level Class gSA bl Program esa Applet ds init() Method esa addMouseListener() Method dks Call fd;k x;k gSA ;s Method Event Generate djus okys Source Class ;kuh AnonymousInnerApplet Applet Class dks Event Listener djus okyh Listener Class ;kuh AnonymousInnerApplet Applet Class ls Register djrk gSA bl Method esa Argument ds :i esa geus ,d Inner Class dks Define fd;k gS] tks fd ,d Anonymous Class gS] ftldk dksbZ uke ugha gSA pfy,] addMouseListener() Method ds bl Argument dks le>us dh dksf”k”k djrs gSaA new MouseAdapter() {. . . } Statement Compiler dks ;s Instruction nsrk gS fd Braces ds chp Define fd, x, Syntaxes ,d Anonymous Inner Class ds Statements gSaA

513 Any Question or Suggestion, Just Discuss Here...

Java in Hindi blfy, ;s Inner Class MouseAdapter Class dks Extend djrk gSA bl ubZ Class dk dksbZ uke ugha gksrk gS] ysfdu tSls gh ;s Expression Execute gksrk gS] MouseAdapter Class Inherit gks tkrk gSA pwafd bl Inner Class dks AnonymousInnerApplet Class ds Scope esa Define fd;k x;k gS] blfy, ;s Inner Class AnonymousInnerApplet Class ds fdlh Hkh Data Member o Method dks Access djus esa l{ke gSA blhfy, ;s Class AnonymousInnerApplet Class showStatus() Method dks Directly Call dj ldrk gSA ;fn ge ljy “kCnksa esa dgsa rks addMouseListener() Method Event Generate djus okyh Source AnonymousInnerApplet Class dks MouseAdapter Listener Class ls Directly Register dj nsrk gS] D;ksafd bl Method esa Argument ds :i esa gesa”kk Listener Class ds ,d Object dk Reference Argument ds :i esa fn;k tkrk gS] tcfd bl Program esa geus Directly MouseAdapter Class dk ,d Nameless Object “new MouseAdapter()” Statement }kjk Pass dj fn;k gSA blfy, Create gksus okys Nameless Listener Object ls Current Applet Class Register gks tkrk gS vkSj bl Applet esa ftrus Hkh Events Generate gksrs gSa] mUgsa og Nameless Listener Listen djrk gSA

Window Fundamentals of JAVA

Event Handling Mechanism ds rhu rjhdksa ds ckjs esa tkuus ds ckn vc ge igys tkok ds Window Basics dks le>saxsA tkok ds AWT esa fofHkUu izdkj ds Window Create djus ls lEcaf/kr Classes Define dh xbZ gSaA ge fdlh GUI Application esa ftrus Hkh GUI Components ns[krs gSa] mu lHkh Components dks ge Window dg ldrs gSaA Panel Class ls nks lcls T;knk Use fd, tkus okys Window ftls ge Applet o Frame dgrs gSa] Use fd;k tkrk gSA ;s nksuksa Classes Standard Window Create djus ds fy, Use dh tkrh gSaA bu nksuksa Classes ls gesa ftruh Functionalities gksrh gSa] muesa ls T;knkrj Functionalities budh Super Classes ls Derived gksrh gSaA

Container Class ;s Class Component Class dh Sub Class gS] ftlesa dqN Additional Methods gksrs gSa] tks vU; Component Objects dks Container esa Nest djus dh lqfo/kk iznku djrs gSaA D;ksafd fofHkUu izdkj ds GUI Components dh Base Class Container Class gksrh gS] blfy, ge fofHkUu izdkj ds GUI Components dks Container Object esa Store dj ldrs gSaA ,d Container Object esa fLFkr fofHkUu izdkj ds GUI Objects ds Layout dks Set djus dh lkjh ftEesnkjh Container dh gksrh gSA fofHkUu izdkj ds GUI Components dks Container esa Layout ;k Position djus ds fy, ,d Container Object fofHkUu izdkj ds Layout Objects dk iz;ksx djrk gSA

514 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Panel Class

Panel Class Container Class dh ,d Sub Class gSA ;s ,d ,slk Component gksrk gS] tks Lo;a ,d Visual Component ugha gksrk gS vkSj blesa dksbZ u;k Method ugha gksrk gS] cfYd ;s dsoy Container Class dks gh Implement djrk gSA Panel Class ds Object dk iz;ksx ge lkekU;r;k Container ij fLFkr fofHkUu GUI Components ds Layout dks Set djus ds fy, djrs gSaA Panel Class Applet Class dh Super Class gksrh gSA Panel Class ,d ,sls Window dks Represent djrk gS] ftlesa Title Bar, Menu Bar o Border ugha gksrh gSA pwafd bl Window dh dksbZ Border ugha gksrh gS vkSj blesa Title Bar o Menu Bar Hkh ugha gksrk gS] blhfy, ;s Window Screen ij fn[kkbZ ugha nsrk gSA tc ge fdlh Applet dks Appletviewer dk iz;ksx djds Run djrs gSa] rc gekjk Applet Program Appletviewer ds Title Bar o Border dks Use djrk gSA Panel Object esa fdlh Hkh vU; GUI Component dks Add djus ds fy, gesa add() Method dks Use djuk gksrk gSA ;s Method bl Panel Class esa Container Class ls Inherit gksrk gSA ,d ckj fdlh GUI Component dks Panel esa Add dj ysus ds ckn ml Component dks Panel esa Manually Position djus ;k Resize djus ds fy, ge Component Class ds setLocation(), setSize() ;k setBounds() Method dks Use dj ldrs gSaA

Window Class Window Class ,d Top-Level Window Create djrk gSA ,d Top-Level Window fdlh Hkh Container Object esa Store ugha gks ldrk gS] cfYd ,slk Object Directly Desktop ij Place gksrk gSA lkekU;r;k ge Window Class dk Object Create ugha djrs gSa] cfYd ge Frame Class dk Object Create djrs gSaA Frame Class ,d “Window” esa tks Hkh fo”ks’krk,a gksrh gSa] mu fo”ks’krkvksa dks Frame Class esa Encapsulate fd;k x;k gSA ;s Window Class dh ,d Sub Class gksrk gS vkSj blesa ,d Title Bar, ,d Menu Bar, ,d Border o Resizing Corner gksrs gSaA ;fn ge fdlh Applet Window ds vUnj dksbZ Frame Window Create djrs gSa] rks bl Frame Window ds Status Bar esa “Java Applet Window” Message Display gksrk gSA ;s Message User dks crkrk gS fd tks Window Display gks jgk gS] og Window ,d Applet }kjk Start gqvk gS uk fd Computer ij Run gksus okys fdlh Software }kjkA tc ,d Frame Window dks fdlh Program }kjk Create fd;k tkrk gS] uk fd fdlh Applet }kjk] rks og Frame Window ,d Normal Window gksrk gSA Canvas Class gkykafd Canvas Class Applet o Frame Window dh Hierarchy dk fgLlk ugha gS] fQj Hkh ;s ,d vU; izdkj dk Window gS] tks fd gekjs fy, dkQh mi;ksxh lkfcr gksrk gSA Canvas Class esa ,d ,slk Blank Window Encapsulate gksrk gS] ftl ij ge Drawing dj ldrs gSaA

515 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Frame Windows

Frame Window ,d ,slk Window gksrk gS] tks Stand-Alone Application Programs cukus ds fy, Use fd;k tkrk gSA gkykafd ge bldk iz;ksx Applet Window esa dj ldrs gSaA Applet Window ds ckn ;fn ge lcls T;knk fdlh Window dks Use djrs gSa] rks og Frame Window gh gksrk gSA

ge lkekU;r;k bu Windows dk iz;ksx fdlh Applet ds Child Window dks Create djus ds fy, djrs gSa] ;k fQj fdlh Application ds Main Window ;k Child Window dks Create djus ds fy, djrs gSaA tc ge Frame Window Create djrs gSa] rc gesa Standard Style dk Window izkIr gksrk gSA Frame Class esa nks Constructors gksrs gSa] ftuds Syntax fuEukuqlkj gSa% Frame() Frame(String title)

igyk Constructor ,d ,slk Window Create djrk gS] ftlds Title Bar ij dksbZ Title ugha gksrk gSA tcfd nwljs Constructor }kjk ge Create gksus okys Window dks ,d “Title” iznku dj ldrs gSaA /;ku nsa fd ge fdlh Frame ds Constructor esa ml Frame Window dh Size ;k Dimension dks Specify ugha dj ldrs gSa] cfYd Frame Window dh Size rc r; dj ldrs gSa] tc Window Create gks tkrk gSA fdlh Frame Window ds lkFk ge fofHkUu izdkj ds Methods dks Use dj ldrs gSaA fdlh Frame Window ds lkFk lcls T;knk Use fd, tkus okys dqN Methods dks ge fuEukuqlkj Describe dj ldrs gSa% setSize() Method – Specifying Window’s Dimension setSize() Method dk Window ds Dimension ;k Height o Width dks r; djus ds fy, fd;k tkrk gSA bl Method dk Signature fuEukuqlkj gksrk gS% void setSize(int newWidth, int newHeight) void setSize(Dimension newSize)

igys Method esa gesa Create gksus okys Window dh ubZ Size dks Specify djuk gksrk gSA ;fn ge pkgsa rks Height o Width ds Dimension dks ,d Dimension Object ds :i esa Hkh Specify dj ldrs gSa vkSj Window ds u, Dimension dks bl Method esa Argument ds :i esa Pass dj ldrs gSaA Dimensions dks Pixels dh la[;kvksa ds :i esa Specify fd;k tkrk gSA Window dh Current Size ;k Dimension izkIr djus ds fy, ge getSize() Method dks Use dj ldrs gSaA bl Method dk Signature fuEukuqlkj gksrk gS% Dimension getSize()

;s Method Window ;k fdlh Hkh vU; GUI Component dh Current Size dks Height o Width ds ,d Dimension Object ds :i esa Return djrk gSA setVisible() Method – Show / Hide Window or GUI Component

516 Any Question or Suggestion, Just Discuss Here...

Java in Hindi fdlh Frame Window dks Create djus ds ckn mls Screen ij Display djus ds fy, gesa bl Method dks Use djuk gksrk gSA tc rd ge bl Method dks Call ugha djrs gSa] gekjk Frame Window Invisible gh jgrk gSA bl Method dk Signature fuEukuqlkj gksrk gS% void setVisible(boolean visibleFlag)

bl Method esa ;fn visibleFlag dk eku true gksrk gS] rks Component Visible gksrk gS] vU;Fkk Component Hidden jgrk gSA setTitle() Method – Setting Window’s Title fdlh Frame Window ds Title dks Change djus ds fy, ge setTitle() Method dk iz;ksx dj ldrs gSaA bl Method dk Signature fuEukuqlkj gksrk gS% void setTitle(String newTitle) newTitle og String gS] ftls ge Frame ds u, Title ds :i esa Define djuk pkgrs gSa

Closing a Frame Window tc ge fdlh Frame Window dks Use dj jgs gksrs gSa vkSj ml Frame Window dks Close djuk pkgrs gSa] rks gesa ml Frame Window dks Screen ls Remove djuk iMrk gSA fdlh Frame Window dks Screen ls Remove djus ds fy, ge setVisible(false) Method dks Call djrs gSaA fdlh Window dks Close djus ds fy, gesa windowClosing() Method dks Implement djuk gksrk gS] ftls WindowListener Interface esa Define fd;k x;k gSA fdlh Frame Window dks Close djus ds fy, bl method dks geus gekjs fiNys mnkgj.k esa Implement fd;k gSA gkykafd ge Frame Class dk Object Create djds ,d Frame Window Create dj ldrs gSa] ysfdu bl izdkj ds Window dk ge dksbZ fo”ks’k mi;ksx ugha dj ldrs gSaA mnkgj.k ds fy, bl izdkj ds Frame Window esa Generate gksus okys Events dks Receive o Process ugha fd;k tk ldrk gS] uk gh bl ij vklkuh ls fdlh Output dks Place fd;k tk ldrk gSA lkekU;r;k ge fdlh Frame Window dks Create djus ds fy, Frame Class dks Extend djrs gSaA Frame Class dh Sub Class Create djus ij ge Frame Class ds Methods dks Override dj ldrs gSa vkSj Event Handling dj ldrs gSa] ftlls gesa Create gksus okys Frame Window ij vf/kd Control izkIr gksrk gSA fdlh Applet Window esa fdlh Frame Window dks Create djuk dkQh ljy dke gksrk gSA lcls igys gesa Frame Class dks Inherit djuk gksrk gSA mlds ckn ge Applet ds fdlh Hkh Standard Method tSls fd init(), start(), paint(), stop() vkfn dks Override dj ldrs gSaA vUr esa WindowListener Interface dks Derived Frame Class esa Implement djuk gksrk gS vkSj windowClosing() Method dks Override djds mlesa setVisible(true) Method dks Call djds Window dks Screen ls Remove djuk gksrk gSA ,d ckj Frame Class dh Sub Class Create djus ds ckn ge ml Sub Class dk ,d Object Create dj ldrs gSaA tc ge ,slk djrs gSa] rc ,d Frame Window Create gksrk gS] ysfdu ;s Window Memory esa Create gksrk gS] blfy, Object Create djrs gh ;s Frame 517 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Window gesa fn[kkbZ ugha nsrk gSA Frame Window dks Screen ij Visible cukus ds fy, gesa setVisible() Method dks Call djuk t:jh gksrk gSA tc ge setVisible() Method dks Call djds Frame Window dks Display djrs gSa] rc Frame Window viuh Default Size esa Display gksrk gSA Display gksus okys Frame Window dks Resize djus ds fy, ge setSize() Method dks Use dj ldrs gSaA

fuEu Applet Program esa geus Frame Class dks Inherit fd;k gSA fQj Applet ds init() Method esa bl Frame Window dk ,d Instance Create fd;k gSA Frame Window Create djus ds fy, Frame Class dk Constructor Call gksrk gS] tks fd ,d Standard Frame Window Create djrk gS] ftldk Title bl Constructor esa Argument ds :i esa Pass fd;k x;k gSA bl Applet Program esa geus Applet ds start() o stop() Method dks Child Frame Window dks Show o Hide djus ds fy, Use fd;k gSA tc ge Applet dks Terminate djrs gSa] rc Frame Window Hkh Automatically Memory ls Remove gks tkrk gSA Program // File Name : FrameInApplet.java import java.awt.*; import java.awt.event.*; import java.applet.*; class MyWindowAdapter extends WindowAdapter{ MyFrame source; public MyWindowAdapter(MyFrame frameWindow) this.source = frameWindow; }

}

{

public void windowClosing(WindowEvent wndEvnt){ source.setVisible(false); }

class MyFrame extends Frame{ MyFrame(String title){ super(title);

}

}

MyWindowAdapter adapter = new MyWindowAdapter(this); addWindowListener(adapter);

public void paint(Graphics g){ g.drawString("This Text is in Frame Window", 10, 35); }

public class FrameInApplet extends Applet{ Frame myFrameWindow;

518 Any Question or Suggestion, Just Discuss Here...

Java in Hindi public void init(){ myFrameWindow = new MyFrame("My Frame Window");

}

myFrameWindow.setSize(250,150); myFrameWindow.setVisible(true); setSize(300, 200);

public void start(){ myFrameWindow.setVisible(true); } public void stop(){ myFrameWindow.setVisible(false); }

}

public void paint(Graphics g){ g.drawString("This Text is in Applet Window", 10, 40); }

Output

User Interface Control Fundamentals

AWT gesa fofHkUu izdkj ds User Interface Controls iznku djrk gS] ftudk iz;ksx djds ge GUI User Interface Create dj ldrs gSaA AWT dh Classes dk iz;ksx djds ge Menu o Menu Bar Hkh Design dj ldrs gSaA ge AWT ls Dialog Box o File Dialog Box Components Hkh Create dj ldrs gSa] ftlesa gesa ,d vyx rjhds ls Event Handling dk

dke djuk iMrk gSA

User Interface Controls mu Objects dks dgrs gSa] tks User dks Program ls Graphically Interact djus dh lqfo/kk iznku djrs gSaA mnkgj.k ds fy, Push Button ,d Common :i ls Use fd;k tkus okyk User Interface Control gSA

tkok esa Layout Manager ,d ,slk Control gksrk gS] tks fofHkUu izdkj ds User Interface Controls dks fdlh Application ds Frame Window ij ;k Applet ds Canvas ij fofHkUu izdkj ds Objects dks Position o Manage djus dk dke djrk gSA vr% ge dg ldrs gSa fd

519 Any Question or Suggestion, Just Discuss Here...

Java in Hindi fdlh Window dk Appearance bl ckr ij fuHkZj djrk gS fd geus fdlh Window ij fdu Controls dks fdl izdkj ds Layout Managers dk iz;ksx djrs gq, Place fd;k gSA vU; Controls ds vykok ,d Frame Window ds lkFk fdlh Menu Bar dks Hkh Attach fd;k tk ldrk gSA Menu Bar dk gj Option ,d u, Drop Down Menu dks Display djrk gS] ftlesa fLFkr fofHkUu Options dks User Choose dj ldrk gSA ,d Menu Bar gesa”kk fdlh Window ds Top ij gh Position gksrk gSA Menu Bar ds fofHkUu Options Hkh vU; GUI Components dh rjg gh dke djrs gSaA gkykafd ge fofHkUu izdkj GUI Components dks Container esa Manually Position dj ldrs gSa] ysfdu ,slk djuk dkQh dfBu dke gksrk gSA Layout Manager bl dke dks vklkuh ls Automatic rjhds ls dj nsrk gSA

Adding and Removing Controls

fdlh Window esa dksbZ GUI Component Add djus ds fy, gesa lcls igys fdlh Control dks Create djuk gksrk gSA fQj ml Control dks Container Class esa Define fd, x, add() Method dk iz;ksx djds Window esa Add djuk gksrk gSA add() Method dbZ rjg ls Overloaded gSA bl Method dk General Syntax fuEukuqlkj gksrk gS% Component add(Component compObj)

bl Syntax esa compObj ml Control dk ,d Instance gksrk gS] ftls ge Window ij Add djuk pkgrs gSaA bl Method ls Add fd, x, Component Object dk ,d Reference Return gksrk gSA tc ge fdlh Window esa fdlh Component dks Add dj nsrs gSa] rks tc Hkh ml Component okyk Parent Window Display gksrk gS] ;s Control Hkh Display gksrk gSA dbZ ckj ge fdUgha ifjfLFkfr;ksa esa fdlh Control dks Window ls Remove djuk pkgrs gSaA ml fLFkfr esa gesa remove() Method dks Call djuk gksrk gSA bl Method dks Hkh Container Class esa gh Define fd;k x;k gS vkSj bl Method dk General Syntax fuEukuqlkj gksrk gS% void remove(Component compObj)

bl Syntax esa Hkh compObj ml Object dks Refer djrk gS] ftls gesa Window ls Remove djuk gksrk gSA fdlh Window ij Placed lHkh Components dks Window ls Remove djus ds fy, ge removeAll() Method dks Call dj ldrs gSaA Labels ;s ,d ,slk Control gS] tks fdlh izdkj dk dksbZ Event Generate ugha djrk gSA ;s Control Window esa fdlh Label ;k Message dks Display djus ds fy, Use fd;k tkrk gSA blds rhu Constructors fuEukuqlkj gksrs gSa% Label() Label(String str) Label(String str, int how)

520 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ;fn ge igys Constructor ds vuqlkj dksbZ Label Create djrs gSa] rks Add gksus okyk Control ,d Blank Label gksrk gSA nwljs Constructor esa str og String gS] ftls Label }kjk Display djuk gksrk gSA tcfd rhljs Constructor ds how Argument }kjk ge ;s r; djrs gSa fd Label esa Display gksus okyh String dk Alignment fdl izdkj dk gksxkA bl Argument esa Label.LEFT, Label.CENTER ;k Label.RIGHT esa ls dksbZ eku gksrk gSA Label esa fn[kkbZ nsus okyh String dks ge setText() Method dk iz;ksx djds Set ;k Change dj ldrs gSaA blh rjg ls Label ds Current Text dks izkIr djus ds fy, ge getText() Method dks Use dj ldrs gSaA bu Methods dk Syntax fuEukuqlkj gksrk gSa% void setText(String str) String getText() setText() Method esa str Argument u, Label dks Specify djrk gS] tcfd getText() Method esa Label dk Current Label Return gksrk gSA Label ds Alignment dks fQj ls Set djus ds fy, ge setAlignment() Method dks Use dj ldrs gSaA tcfd Current Alignment dks izkIr djus ds fy, ge getAlignment() Method dks Use dj ldrs gSaA bu nksuksa Methods ds Syntax fuEukuqlkj gksrs gSa% void setAlignment(int how) int getAlignment()

;gka how Argument esa Label.LEFT, Label.CENTER ;k Label.RIGHT esa ls dksbZ gh dksbZ eku gksrk gSA Buttons

Push Button fdlh Hkh Window esa Generally Use fd;k tkus okyk lcls Common Component gSA Push Button ,d ,slk Component gksrk gS] ftlesa ,d Label gksrk gS vkSj ;s Control User ds Interaction ij dksbZ Event Generate djus esa l{ke gksrk gSA Push Buttons Button Class ds Objects gksrs gSaA Button Class esa fuEukuqlkj nks Constructors

gksrs gSa%

Button() Button(String str)

igyk Constructor ,d Empty String okyk Button Object Create djrk gS] tcfd nwljs Constructor esa Button ij fn[kkbZ nsus okyk Label String ds :i esa Specify fd;k tkrk gSA ,d Button dks Create djus ds ckn ge ml Button dk Label setLabel() Method dk iz;ksx djds Set ;k Change dj ldrs gSaA tcfd fdlh Button dk Label izkIr djus ds fy, gesa getLabel() Method dks Use djuk gksrk gSA bu nksuksa Methods ds Syntax fuEukuqlkj gksrs gSa% void setLabel(String str) String getLabel()

tc gesa fdlh Button dk Label Change djuk gksrk gS] rc ge str esa og u;k Label Specify djrs gSa] ftls gesa Button ij Display djuk gksrk gSA

521 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Button Object gesa”kk ,d Action Event Generate djrk gSA bl Event dks Handle djus ds fy, Event dks Button ls Registered o igys ls Defined fdlh Listener Object esa Hkstuk gksrk gSA ftrus Hkh Listeners dks Button ls Registered fd;k x;k gksrk gS] mu lHkh Listeners esa ActionListener Interface dks Implement fd;k x;k gksrk gSA

bl Interface esa actionPerformed() Method dks Define fd;k tkrk gSA ;s Method rc Invoke gksrk gS] tc bl Listener ls Registered fdlh Button dks Push fd;k tkrk gSA bl Method esa ActionEvent Class dk ,d Object Argument ds :i esa Pass fd;k tkrk gSA bl ActionEvent Object esa Event Generate djus okys Button dk o Button ij fLFkr Label dk nksuksa dk Reference gksrk gSA bu nksuksa esa ls fdlh Hkh Value dk iz;kssx djds ge ;s irk yxk ldrs gSa] fd fdl Button ls Event Generate gqvk gSA Check Boxes ;s ,d ,slk Control gksrk gS tks fdlh Option dks ON ;k OFF djus dk dke djrk gSA ;s ,d NksVs ls Box dh rjg gksrk gS] ftl ij Click djus ij mlesa Check Mark Display gksus yxrk gSA tc fdlh Check Box esa Check Mark Display gksrk gS] rc og Control ON Position esa gksrk gSA Check Box ds lkFk ,d Label Associated jgrk gS] tks Check Box ds Option dks Represent djrk gSA Check Box dh fLFkfr dks Change djus ds fy;k ;kuh Option dks ON ;k OFF djus ds fy, gesa Check Box ij Click djuk gksrk gSA ge Check Boxes dks ,d Group ds :i esa Hkh Use dj ldrs gSa vkSj Single Check Box ds :i esa Hkh Use dj ldrs gSaA Check Boxes Checkbox Class ds Objects gksrs gSaA tc Check Box Checked gksrk gS] rc og True Condition dks Represent djrk gS] tcfd Unchecked fLFkfr esa og False Condition n”kkZrk gSA ,d Check Box ds fuEukuqlkj ikap Constructors gksrs gSa% Checkbox() Checkbox(String str) Checkbox(String str, boolean on) Checkbox(String str, boolean on, CheckboxGroup cbGroup) Checkbox(String str, CheckboxGroup cbGroup, boolean on)

igyk Constructor ,d ,slk Check Box Create djrk gS] ftldk Label Initially Blank gksrk gSA nwljk Constructor ,d ,slk Check Box Create djrk gS] ftlds lkFk og Label Associated jgrk gS] tks ge Argument ds :i esa Constructor esa Specify djrs gSaA rhljk Constructor ,d ,slk Check Box Create djrk gS] tgka ge nwljs Argument esa true Specify djds ,d Checked Check Box izkIr dj ldrs gSaA pkSFks vkSj ikapos Constructor }kjk ,d ,slk Check Box Create gksrk gS] ftldk uke str }kjk Specify fd;k x;k gksrk gS vkSj Check Box ds Group dks cbGroup Argument }kjk Specify fd;k tkrk gSA ;fn Create fd;k tkus okyk Check Box fdlh Group dk Part uk gks] rks cbGroup Argument esa null Specify djuk gksrk gSA Boolean Variable on }kjk ;s Specify fd;k tkrk gS] fd Create gksus okyk Check Box Checked gksxk ;k ughaA Check Box dh Current State dk irk yxkus ds fy, gesa getState() Method dks Use djuk gksrk gS] tcfd fdlh Check Box dh State dks Change djus ds fy, gesa setState()

522 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Method dks Use djuk gksrk gSA fdlh Check Box ds lkFk Associated Current Label dks izkIr djus ds fy, ge getLabel() Method dks Use dj ldrs gSa] tcfd Check Box ds Label dks fQj ls Set djus ds fy, gesa setLabel() Method dks Use djuk gksrk gSA bu pkjksa Methods ds Syntax fuEukuqlkj gksrs gSa% boolean getState() void setState(boolean on) String getLabel() void setLabel(Sting str)

;gka] ;fn ge on dk eku true j[krs gSa] rks Check Box Checked gks tkrk gS] tcfd ;fn bldk eku false gks] rks Check Box Clear gks tkrk gSA str esa Pass dh tkus okyh String Check Box ls Associated Label dks Change dj nsrk gSA ftruh ckj Hkh ge fdlh Check Box dks Select ;k Deselect djrs gSa] ,d Item Event Generate gksrk gSA ;s Item Event ml Listener ij Event Handling ds fy, Hkstk tkrk gS] ftls Check Box ls Register fd;k x;k gSA bl Listener esa ItemListener Interface dks Implement fd;k x;k gksrk gSA bl Interface esa itemStateChanged() uke dk ,d Method Implement fd;k tkrk gS vkSj ;s Method rc Invoke gksrk gS] tc fdlh Check Box dks Select ;k Deselect fd;k tkrk gSA Generate gksus okys ItemEvent Object dks Handle djus ds fy, Argument ds :i esa bl Method esa Pass fd;k tkrk gSA Check Box dks Select ;k Deselect djus ij Generate gksus okys bl ItemEvent Object es bl ckr dh tkudkjh gksrh gS] fd Item dks Select fd;k x;k gS ;k Deselect fd;k x;k gSA

Choice Controls Choice Class dk iz;ksx Options dh ,d Pop-up List Create djus ds fy, fd;k tkrk gS] ftlesa ls User fdlh ,d Option dks Choose dj ldrk gSA ;kuh Choice dks ge ,d Menu dh rjg eku ldrs gSa] ftlesa cgqr lkjs Options gksrs gSa] ysfdu ge ,d le; esa dsoy ,d gh Option dks Choose dj ldrs gSaA Choice Control esa ge ftl Item dks Select djrs gSa] ogh Item Window ij Display gksrk gS] Choice Control ds “ks’k Items Hide gks tkrs gSaA bl Control dks Drop-Down List Control Hkh dgk tkrk gSA tc User bl Control ij Click djrk gS] rks bl Control dh List ds lHkh Options Pop-up gks tkrs gSaA bl List esa ls User ftl Item dks Select djrk gS] dsoy ogh Item Choice Control esa Highlight gksus yxrk gSA List esa ftrus Hkh Items Display gksrs gSa] os lHkh Items ,d Left-Justified Label String gksrs gSa vkSj ;s mlh Øe esa Choice Control esa Display gksrs gSa] ftl Øe esa bUgsa Choice Control esa Add fd;k x;k gksrk gSA Choice Class esa dsoy ,d gh Default Constructor gksrk gS] ftldk Syntax fuEukuqlkj gS% void add(String itemName)

bl Constructor esa itemName og Option gS] ftls ,d Label ds :i esa Choice Control esa Add djuk gSA Choice Control esa ,d ls T;knk Items dks Add djus ds fy, gesa bl

523 Any Question or Suggestion, Just Discuss Here...

Java in Hindi add() Method dks dbZ ckj Call djuk iMrk gS vkSj ge ftl Øe esa add() Method dks Call djds Items dks Add djrs gSa] os Items Choice Control esa mlh Øe esa fn[kkbZ nsrs gSaA

;s irk djus ds fy, fd Choice Control esa Currently fdl Item dks Select fd;k x;k gS] ge getSelectedItem() ;k getSelectedIndex() Method dks Use dj ldrs gSaA bu nksuksa Methods dk Syntax fuEukuqlkj gksrk gS% String getSelectedItem() int getSelectedIndex() getSelectedItem() Method Currently Selected Item dk uke ,d String Object ds :i esa Return djrk gSA tcfd getSelectedIndex() Method Currently Selected Item dk Index Number Return djrk gSA Choice Control esa igyk Item gesa”kk Index Number 0 ij gksrk gS] ;kuh Choice Control ds Index Numbers dh Counting gesa”kk 0 ls “kq: gksrh gSA Choice Control esa tks Hkh igyk Item Add fd;k tkrk gS] og Item Default :i ls Selected

jgrk gSA

fdlh Choice Object esa fLFkr dqy Items dh la[;k Kkr djus ds fy, ge getItemCount() Method dks Use dj ldrs gSaA blh rjg ls Choice Control ds fdlh Item dks Select djus ds fy, ge select() Method dks Use dj ldrs gSa] ftlesa Argument ds :i esa ge Item dk Index Number ns ldrs gSa] ;k fQj ,d String ds :i esa Item ds uke dks Specify dj ldrs gSaA bu Methods dk Syntax fuEukuqlkj gksrk gS% int getItemCount() void select(int index) void select(String itemName) getItem() Method esa Argument ds :i esa fdlh Item dk Index Number Specify djds ge ml Item dk uke String Object ds :i esa izkIr dj ldrs gSaA bl Method dk Syntax

fuEukuqlkj gksrk gS%

String getItem(int index)

ge ftruh ckj fdlh Choice Control ds fdlh Item dks Select djrs gSa] ,d ItemEvent Generate gksrk gSA ;s Event ,d ,sls Listener ij Hkstk tkrk gS] ftls igys gh Choice Control Object ls Register dj fn;k x;k gksrk gSA bl Listener esa ItemListener Interface dks Implement fd;k x;k gksrk gSA bl Interface esa itemStateChanged() uke dk ,d Method Implement fd;k x;k gksrk gSA tc ItemEvent Generate gksrk gS] rc ;s Method Execute gksrk gS vkSj Generate gksus okyk ItemEvent Object dks Argument ds :i esa izkIr djrk gSA List Control List Class gesa ,d ,sls Scrollable Items dh List Provide djrk gS] ftlesa ge ,d ls T;knk Items dks Select dj ldrs gSaA Choice Control esa ge ,d le; esa dsoy ,d gh Selected Item dks Display dj ldrs gSa] tcfd bl Control esa ge ,d ls T;knk List Items dks

524 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Display dj ldrs gSaA List Class gesa rhu Constructors Provide djrk gS] tks fuEukuqlkj

gSa%

List() List(int numRows) List(int numRows, boolean multipleSelect)

bu Constructors esa tks igyk Constructor gS] og Constructor gesa ,d le; esa dsoy ,d gh Item Select djus dh lqfo/kk nsrk gSA nwljk Constructor gesa mrus Rows Window ij gesa”kk Display djrk gS] ftruh la[;k ge numRows Argument esa Specify djrs gSaA List ds “ks’k Items Scrollable gksrs gSa] ftUgsa Scroll djds ns[kk tk ldrk gSA rhljs Constructor esa ;fn ge multipleSelect Boolean Variable esa true Set djrs gSa] rks ge List Control esa ,d ls T;knk Items dks Select dj ldrs gSaA List esa fdlh Item dks Select djus ds fy, ge fuEu esa ls fdlh add() Method dks Call dj ldrs gSa% void add(String itemName) void add(String itemName, int index)

bu Syntaxes esa itemName og String gS] ftls ge List Item ds :i esa List Object esa Add djuk pkgrs gSaA tc gesa fdlh Item dks List ds fdlh Specific Index Number ij Add djuk gksrk gS] rc nwljs Argument ds :i esa ge og Index Number Specify dj nsrs gSa] tgka ij ge u, Item dks Add djuk pkgrs gSaA ;fn ge fdlh Item dks List ds vfUre Item ds :i esa Specify djuk pkgsa] rks gesa Index Number ds :i esa -1 nsuk gksrk gSA tc ge ,slh Lists Create djrs gSa] ftuesa dsoy ,d gh Item dks Select fd;k tk ldrk gS] ,slh List ds fdlh List dks Select djus o Selected Item dks izkIr djus ds fy, ge getSelectedItem() o getSelectedIndex() Methods dks mlh rjg ls Use dj ldrs gSa] ftl rjg ls bUgsa Choice Control ds lkFk Use djrs gSaA ;fn fdlh List esa fdlh Item dks Select uk fd;k x;k gks] rks getSelectedItem() Methods null Return djrk gS tcfd fdlh Multiple Selection okyh List esa tc ,d ls T;knk Items dks Select fd;k x;k gks ;k fdlh Item dks Select uk fd;k x;k gks] rks getSelectedIndex() Method -1 Return djrk gSA ,slh Lists ftlesa ,d ls T;knk Items dks Select fd;k tk ldrk gS] gesa fuEu esa ls fdlh Format okys getSelectedItem() ;k getSelectedIndex() Method dks Use djuk pkfg,% String[] getSelectedItem() int[] getSelectedIndex()

;gka igyk Method Selected Items dh Strings dk ,d Array Return djrk gS] tcfd nwljk Method Selected Items ds Index Numbers ds Integers dk ,d Array Return djrk gSA fdlh List Object esa fLFkr dqy Items dh la[;k Kkr djus ds fy, ge getItemCount() Method dks Use dj ldrs gSaA blh rjg ls List Control ds Currently Selected Item dks Set djus ds fy, ge select() Method dks Use dj ldrs gSa] ftlesa Argument ds :i esa ge Item dk Index Number ns

525 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ldrs gSa] ;k fQj ,d String ds :i esa Item ds uke dks Specify dj ldrs gSaA bu Methods dk Syntax fuEukuqlkj gksrk gS% int getItemCount() void select(int index) void select(String itemName) getItem() Method esa Argument ds :i esa fdlh Item dk Index Number Specify djds ge ml Item dk uke String Object ds :i esa izkIr dj ldrs gSaA bl Method dk Syntax

fuEukuqlkj gksrk gS%

String getItem(int index) List ls Generate gksus okys Events dks Handle djus ds fy, gesa Action Listener Interface dks Implement djuk gksrk gSA tc Hkh fdlh List Item ds fdlh Item dks Double Click fd;k tkrk gS] ,d ActionEvent Object Generate gksrk gSA ActionListener Interface dk getActionCommand() Method dk iz;ksx djds ge Currently Selected Item dk uke

izkIr dj ldrs gSaA

lkFk gh ge fdlh List Control esa ftruh ckj Hkh fdlh Item dks Select ;k Deselect djrs gSa] ,d ItemEvent Object Generate gksrk gSA ItemListener Interface ds getStateChange() Method dks Use djds ge ;s irk dj ldrs gSa fd List esa fdlh Item dks Select ;k Deselect fd;k x;k gS ;k ughaA tcfd getItemSelectable() Method ml Object dk Reference Return djrk gS] ftlus Event Trigger fd;k gksrk gSA

Scroll Bars Scrollbars dk iz;ksx fdlh Specified Minimum o Maximum Values ds chp dh fdlh Value dks Select djus ds fy, fd;k tkrk gSA Scrollbars dks Horizontally o Vertically nksuksa rjhdksa ls Organize fd;k tk ldrk gSA ,d Scrollbar okLro esa cgqr lkjs Individual Parts dk Composite :i gksrk gSA blds nksuksa rjQ ,d Arrow gksrk gS] ftl ij Click djds ge Scrollbar dh Value dks Current Value ls Increase ;k Decrease djrs gSaA Scrollbar dh Current Value mldh Minimum o Maximum Value ls Related gksrh gS] ftls Scrollbar ds Slider ls Represent fd;k tkrk gSA Slider Box dks User viuh t:jr ds vuqlkj Scroll djds ubZ Position ij Change dj ldrk gSA

,slk djus ij Scrollbar ubZ Value dks Represent djus yxrk gSA tc User dks Default Increment Value 1 ls vf/kd Scroll djuk gksrk gS] rc og Scrollbar ds Slider esa Click dj ldrk gSA bl Action dks lkekU;r;k Page Up o Page Down ds :i esa le>k tk ldrk gSA tkok esa Scrollbars dks Scrollbar Class esa Encapsulated fd;k x;k gSA bl Class esa rhu Constructs gSsa] tks fuEukuqlkj gksrs gSa% Scrollbar() Scrollbar(int style) Scrollbar(int style. int initialValue, int thumbSize, int min, int max)

526 Any Question or Suggestion, Just Discuss Here...

Java in Hindi igyk Constructor ,d Vertical Scrollbar Create djrk gSA nwljk Constructor Scrollbar ds Direction dks Specify djrk gSA ;fn style Argument esa Scrollbar.VERTICAL Constant eku gks] rks Vertical Scrollbar Create gksrk gS] tcfd blesa Scrollbar.HORIZONTAL Constant eku gksus ij Horizontal Scrollbar Create gksrk gSA rhljs Constructor esa Scrollbar dh Initial Value dks initialValue Argument esa Specify fd;k tkrk gSA Slider esa fn[kkbZ nsus okys Thumb dh Size dks thumbSize Argument esa Specify fd;k tkrk gS vkSj Scrollbar dh Minimum o Maximum Values dks min o max uke ds Argument }kjk Specify fd;k tkrk gSA tc ge bu esa ls fdlh Constructor dks Use djds Scrollbar Create djrs gSa] rc gesa setValues() Method dks Use djds Scrollbar ds Parameters dks Set djuk gksrk gSA bl Method dk General Syntax fuEukuqlkj gksrk gS% void setValues(int initialValue, int thumbSize, int min, int max) Scrollbar dh Current Values dks izkIr djus ds fy, ge getValue() Method dks Call dj ldrs gSaA ;s Method Scrollbar dh Current Settings dks Return djrk gSA tcfd Current Value dks Set djus ds fy, ge setValue() Method dks Use dj ldrs gSaA bu nksuksa Methods dk Syntax fuEukuqlkj gksrk gS% int getValue() void setValue(int newValue)

bl Method esa newValue og eku gS] ftls Scrollbar ds fy, Specify fd;k tkrk gSA tc ge dksbZ Value Set djrs gSa] rks Scrollbar dk Slider Box ml u, eku dks Represent djrs gq, Slider esa u, LFkku ij Place ;k Set gks tkrk gSA Scrollbar dh Minimum o Maximum Values dks izkIr djus ds fy, ge getMinimum() o getMaximum() Method dks Use dj ldrs gSa] ftudk Syntax fuEukuqlkj gksrk gS% int getMinimum() int getMaximum() Scrollbar esa Increase ;k Decrease gksus okyh By Default Value 1 gksrh gS] tks ,d Line dks Up ;k Down djrh gSA ge bl Incrementing Value dks setUnitIncrement() Method dk iz;ksx djds Change dj ldrs gSaA tcfd Page-Up o Page-Down dh By Default Value 10 gksrh gS] ftls Change djus ds fy, ge setBlockIncrement() Method dks Use dj ldrs gSaA ;s Methods fuEukuqlkj gksrs gSa% void setUnitIncrement(int newIncr) void setBlockIncrement(int newIncr) Scrollbar }kjk Trigger gksus okys Events dks Handle djus ds fy, gesa AdjustmentListener Interface dks Implement djuk gksrk gSA tc Hkh User Scrollbar ls Interact djrk gS] ,d AdjustmentEvent Object Generate gksrk gSA bldk getAdjustmentType() Method dk iz;ksx djds ge ;s tku ldrs gSa fd fdl izdkj dk AdjustmentEvent Generate gqvk gSA Generate gksus okys AdjustmentEvent fuEu izdkj

ds gks ldrs gSa%

527 Any Question or Suggestion, Just Discuss Here...

Java in Hindi BLOCK_DECREMENT BLOCK_INCREMENT TRACK UNIT_DECREMENT UNIT_INCREMENT

Page-Down Page-Up Absolute Tracking Event Line-Down Line-Up

TextField Control TextField Class ls ge ,d Single Line Text Entry Area Create dj ldrs gSa] ftls Edit Control Hkh dgrs gSaA TextField User dks Strings dks Enter djus o mls Modify ;k Edit djus dh lqfo/kk nsrk gSA bl Control esa fy[ks x, Texts dks Mouse ls Select fd;k tk ldrk gS vkSj ml Text ij Cut, Copy o Paste tSls Operations Perform fd, tk ldrs gSaA TextField Class TextComponent Class dh Sub Class gSA TextField Class esa fuEu Constructors dks Define fd;k x;k gS% TextField() TextField(int numChars) TextField(String str) TextField(String str, int numChars)

igyk Constructor ,d Default Text Field Create djrk gSA nwljk TextField Create djrk gS] ftldh Size numChars Argument esa Characters ds cjkcj gksrh gSA rhljk Constructor str Argument esa Characters dks Create gksus okys Default TextField esa Fill dj Constructor numChars ds cjkcj Characters dks Hold dj ldus okyk djrk gS vkSj mlesa str Argument esa fn, x, String dks Fill dj nsrk gSA

Constructor ,slk Specify fd, x, Specify fd, x,

nsrk gS vkSj pkSFkk TextField Create

TextField Class o bldh Super Class TextComponent Class nksuksa TextField dks fofHkUu rjhdksa ls Use djus ls lEcaf/kr fofHkUu izdkj ds Methods Provide djrs gSaA TextField esa Currently Specify fd, x, Characters dh String dks Return djus ds fy, ge getText() Method dks Use djrs gSa] tcfd TextField esa fdlh Text dks Fill djus ds fy, gesa setText() Method dks Use djuk gksrk gSA bu nksuksa Methods dk Syntax fuEukuqlkj gksrk gS% String getText() void setText(String str) User TextField ds fdlh fo”ks’k Text dks Mouse ls Select dj ldrk gSA lkFk gh ge Program ds Run Time esa Hkh TextField dh String ds fdlh fgLls dks select() Method dk iz;ksx djds Select dj ldrs gSaA TextField esa Currently Selected Text dks izkIr djus ds fy, ge getSelectedText() Method dks Use dj ldrs gSaA bu Methods dk Syntax

fuEukuqlkj gksrk gS%

String getSelectedText() void select(int startIndex, int endIndex)

528 Any Question or Suggestion, Just Discuss Here...

Java in Hindi getSelectedText() Method dks ge TextField esa Currently Select fd, x, Text dks izkIr djus ds fy, Use dj ldrs gSaA tcfd select() Method startIndex ls endIndex-1 rd ds Characters dks Select djus dk dke djrk gSA ge setEditable() Method dk iz;ksx djds ;s r; dj ldrs gSa fd fdlh TextField ds Text Edit gks ldrs gSa vFkok ughaA tcfd dksbZ TextField Editable gS vFkok ugha bl ckr dk irk yxkus ds fy, ge isEditable() Method dks Use dj ldrs gSaA ;s nksuksa Methods fuEukuqlkj gksrs gSa% boolean isEditable() void setEditable(boolean canEdit)

;fn fdlh TextField ds Text dks Change fd;k tk ldrk gks] rks isEditable() Method true Return djrk gS] tcfd ;fn dksbZ TextField Read Only Mode esa gks] rks ;s Method false Return djrk gSA tcfd setEditable() Method esa ;fn ge true Pass djrs gSa] rks bldk eryc gksrk gS] fd TextField ds Text dks Edit fd;k tk ldrk gS] tcfd ;fn ge blesa Argument ds :i esa false Pass dj nsa] rks bldk eryc ;s gS fd ge bl TextField ds Text dks Edit, Alter ;k Modify ugha dj ldrs gSaA dbZ ckj gesa ,slh t:jr gksrh gS] fd User fdlh TextField esa tks Text Enter djrk gS] og Text fn[kkbZ ugha nsuk pkfg,A tSls fd User fdlh TextField esa ;fn Password Input djrk gS] rks og Password fn[kkbZ ugha nsuk pkfg,A User fdlh TextField esa tks Characters Input djrk gS] ;fn ge mu Texts dks TextField esa Display djokus ls jksduk pkgrs gSa] rks gesa setEchoChar() Method dks Use djuk gksrk gSA ;s Method ml Single Character dks Specify djrk gS] ftls TextField esa Enter djrs le; Display fd;k tkuk gksrk gSA ;s Method fuEukuqlkj gksrk gS% void setEchoChar(char ch)

bl Method esa ;fn ge Argument ch esa “ * ” Specify dj nsa] rks User bl TextField esa dksbZ Hkh Character Input djs] bl TextField esa og Character “ * ” dh Series ds :i esa gh fn[kkbZ nsrk gSA ;fn gesa ;s irk djuk gks fd dksbZ TextField bl Method ls Set fd;k x;k gS ;k ugha] rks ge ;s tkudkjh izkIr djus ds fy, echoCharIsSet() Method dks Use dj ldrs gSaA ;s Method fuEukuqlkj gksrk gS] boolean echoCharIsSet()

;fn gesa ;s tkuuk gks fd fdlh TextField dks fdl Character ls Set fd;k x;k gS] rks ge getEchoChar() Method dks Use dj ldrs gSa] tks fd fuEukuqlkj gksrk gS% char getEchoChar()

lkekU;r;k TextField ls dke djus ls lEcaf/kr fofHkUu izdkj ds Functions TextField Class esa gh Define fd, x, gSa] blfy, blds lkFk dke djus ds fy, gesa fdlh Interface dks Implement djus dh t:jr ugha gksrh gSA ysfdu ;fn ge pkgrs gSa fd Enter Key Press djus

529 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ij Focus fdlh nwljs TextField ij Move gks] rks blds fy, gesa Generate gksus okys ActionEvent Object dks Handle djuk gksrk gSA

TextArea Control dbZ ckj gekjk dke Edit Control dh Single Line esa ugha gks ikrk gSA bl fLFkfr esa gesa ,sls Control dh t:jr gksrh gS] ftlesa ge ,d ls T;knk Lines dk Text Type dj ldsaA tkok ds AWT esa bl dke dks iwjk djus okys Control dks TextArea Control dgk tkrk gSA bldh Class esa fuEukuqlkj ikap Constructors gksrs gSa% TextArea() TextArea(int numLines, int numChars) TextArea(String str) TextArea(String str, int numLines, int numChars) TextArea(String str, int numLines, int numChars, int sBars)

bu Constructors esa numLines Arguments TextArea Control dh Height dks Lines dh la[;k ds :i esa Specify djrk gS] tcfd numChars Argument TextArea dh Width dks Characters dh la[;k ds :i esa Specify djrk gSA tc gesa fdlh TextArea dks Create djrs gh mlesa dqN Text Specify ;k Fill djuk gksrk gS] rc gesa og Text str Argument ds :i esa Constructor esa Specify djuk gksrk gSA ikapos Constructor ds vfUre Argument sBars esa ge fuEu esa ls dksbZ Constant eku iznku dj ldrs gSa] tks TextArea ds lkFk Scrollbars dks Display djus ls lEcaf/kr gksrk gS% SCROLLBARS_BOTH SCROLLBARS_NONE SCROLLBARS_HORIZONTAL_ONLY SCROLLBARS_VERTICAL_ONLY TextArea Class Hkh TextComponent Class dh ,d Sub Class gSA blfy, ;s Hkh getText(), setText(), getSelectedText(), select(), isEditable() o setEditable() Methods dks TextField Control dh rjg gh Support djrk gSA buds vykok TextArea Class esa fuEu Methods vkSj Define fd, x, gSa% void append(String str) void insert(String str, int index) void replaceRange(String str, int startIndex, int endIndex ) append() Method str esa Specify dh xbZ String dks Current Text ds End esa Append dj nsrk gSA insert() Method str esa Specified String dks Specify fd, x, Index Number ij Insert dj nsrk gSA

tcfd fdlh TextArea Control esa Select fd, x, Text ds LFkku ij str esa Specified u, Text dks Replace djus ds fy, replaceRange() Method dks Use fd;k tk ldrk gSA ;k ge ,slk Hkh dg ldrs gSa fd str esa Stored String dks startIndex ls endIndex-1 rd ds Text ds LFkku ij Replace dj fn;k tkrk gSA TextArea Controls ds Events dks Hkh gesa

530 Any Question or Suggestion, Just Discuss Here...

Java in Hindi vyx ls Handle djus dh t:jr ugha gksrh gSA ;s Control dsoy LOST_FOCUS Event gh Generate djrs gSaA

GOT_FOCUS

o

CheckboxGroup Control bl Control dks lkekU;r;k Radio Buttons Hkh dgrs gSaA Radio Buttons dk iz;ksx cgqr lkjs Options esa ls fdlh ,d Option dks Select djus ds fy, fd;k tkrk gSA bl Control dks Create djus ds ckn gesa bl Control esa vko”;drkuqlkj Options dks Add djuk gksrk gSA bls Create djus ds fy, ge fuEu Constructor Statement dk iz;kssx dj ldrs gSa% CheckboxGroup radioGroup = new CheckboxGroup() CheckboxGroup Object Create djus ds ckn gesa ,d Checkbox Create djuk gksrk gS] ftlds Constructor ds nwljs Argument ds :i esa gesa bl radioGroup Object dk Reference nsuk gksrk gSA ;s dke ge fuEukuqlkj Statement }kjk dj ldrs gSa% check1 = new Checkbox(“C Language”, radioGroup, true); check2 = new Checkbox(“C++ Language”, radioGroup, true); check3 = new Checkbox(“Java Language”, radioGroup, true); check4 = new Checkbox(“Visual Basic Language”, radioGroup, true);

mijksDr Code Segment pkj Radio Buttons Create djrk gS vkSj ;s lHkh Radio Buttons ,d gh Group radioGroup Object ds lnL; gksrs gSaA ge ,d le; esa bl Group ds fdlh ,d gh Option dks Select dj ldrs gSaA bu Radio Buttons dks fdlh Container esa Add djus ds fy, gesa fuEukuqlkj add() Method dks Use djuk gksrk gSA add(check1) add(check2) add(check3) add(check4) radioGroup Object ls Generate gksus okys Events dks Handle djus ds fy, Hkh gesa mlh Process dks Use djuk gksrk gS] ftl Process dk iz;ksx gesa fdlh Checkbox ls Generate gksus okys Events dks Handle djus ds fy, djuk gksrk gSA

Layout Manager Layout Manages ,d fo”ks’k izdkj ds Objects gksrs gSa tks ;s r; djrs gSa fd Application ;k Applet ds Window esa fofHkUu izdkj ds Components fdl izdkj ls Organize gksaxsA tc ge fdlh Applet ;k Application dks Create djrs gSa] rc tkok Automatically ,d Default Layout Manager Create djrk gS vkSj gekjs Applet ;k Application dks og Default Layout Manager Object Assign dj nsrk gSA lkekU;r;k ;s Default Layout Manager Flow Layout Object gksrk gSA geus blh v/;k; esa ns[kk gS fd dqy ikap rjg ds Containers gksrs gSa] ftuesa ls Panel Hkh ,d izdkj dk Container gSA ysfdu ;s ,d ,slk Container gS] tks Visually Display ugha gksrk gSA

531 Any Question or Suggestion, Just Discuss Here...

Java in Hindi blfy, bl Container dk iz;ksx lkekU;r;k fofHkUu izdkj ds Controls ds Group dks vU; Visually Display gksus okys Containers ij Organize (Localize and Sized) djus ds fy, fd;k tkrk gSA tc ge fofHkUu Components dks Applet ;k fdlh vU; Container ij Place djrs gSa] rc ftl rjhds ls ;s fofHkUu Controls Screen ij ;k Applet ij Organize gksrs gSa] muds Organize gksus dk rjhdk cgqr gh Variable gksrk gSA Applet ;k Application ij fn[kkbZ nsus okys fofHkUu izdkj ds Components fuEu fLFkfr;ksa ls izHkkfor gksrs gSa% 1 Applet Window dh Size ls 2 vU; Components o Containers dh Size ls 3 Use fd, tkus okys Layout Manager ls

Flow Layout Manager tkok esa ftrus Hkh Container Controls gksrs gSa] mu lHkh ds lkFk ,d Layout Manager Associated gksrk gSA Layout Manager Layout Class dk ,d Object gksrk gS] ftlesa LayoutManager Interface dks Implement fd;k x;k gksrk gSA fdlh Layout dks Set djus ds fy, gesa setLayout() Method dks Use djuk gksrk gSA ;fn ge fdlh Container ds lkFk fdlh Layout dks Set ugha djrs gSa] rks ml Container ds lkFk ,d Default Layout Manager Set gks tkrk gS] ftldk uke FlowLayout gksrk gSA ge tc Hkh fdlh Container Object dks Resize djrs gSa] Container ls Associated LayoutManager ml Container ds lHkh Objects dks Relatively Resize djds Container esa fQj ls Set dj nsrk gSA tkok esa Multiplatform ij Use fd, tkus okys GUI Applications ;k Applets cuk, tkrs gSaA tcfd fofHkUu izdkj ds Platforms ij GUI leku fn[kkbZ ugha nsrs gSaA

tkok esa Layout Manager s dk iz;ksx blhfy, fd;k x;k gS] rkfd ge tkok ds Programs dks fdlh Hkh Platform ij Execute djsa] os lHkh Platform ij leku fn[kkbZ nsaA tc ge fdlh Container ds fy, fdlh Layout dks Manually Set djuk pkgrs gSa] rks gesa fuEukuqlkj Statement Use djuk gksrk gS% void setLayout(LayoutManager layoutObj)

bl Statement esa layoutObj ml Layout Object dk Reference gS] ftls ge Container ds fy, Set djuk pkgrs gSaA ;fn ge fdlh Container ds fy, fdlh Layout dks Use djuk ugha pkgrs] cfYd ge Controls dks mudh Actual Position ij Place djuk pkgrs gSa] rks gesa layoutObj Argument esa null Specify djuk gksrk gSA ysfdu ;fn ge fdlh Container ds fy, Layout dks null dj nsrs gSa] rks Container esa Place gksus okys lHkh Components dh Size o Position dks gesa gh Specify djuk t:jh gks tkrk gS] vU;Fkk gesa Container esa dksbZ Hkh Component fn[kkbZ ugha nsrk gSA fofHkUu Components dh Size r; djus ds fy, gesa setBounds() Method dks Use djuk iMrk gS] lkFk gh fofHkUu Components dks Container ds fy, Visible Hkh cukuk iMrk gSA

532 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ge ftl fdlh Hkh Layout Manager dks Use djrs gSa] og Layout Manager ml Components ds uke dk Record ;k Track j[krk gS vkSj ge tSls gh fdlh Container esa fdlh Component dks Add djrs gSa] og Layout Manager Notify gks tkrk gSA tc Hkh ge ml Container dks Resize djrs gSa] Layout Manager minimumLayoutSize() o preferredLayoutSize() Method dks Use djds Container ds lHkh Components dh Size dks vuqikr esa de dj nsrk gSA tks Hkh Component fdlh Layout Manager }kjk Manage gks jgk gksrk gS ;kuh tks Hkh Component fdlh Container esa Add fd;k tkrk gS] ml Component esa getPreferredSize() o getMinimumSize() uke dk Method gksrk gSA ;s nksuksa Methods fdlh Component }kjk Display gksus okyh Preferred o Minimum Size dks Return djrs gSaA tgka rd lEHko gksrk gS] Layout Manager lHkh Objects dks vius fu;eksa ds vuqlkj Manage djrk gSA tkok esa fofHkUu izdkj ds Layout Manager gSa] ftudk iz;ksx djds ge gekjh t:jr dks iwjk dj ldrs gSaA lkFk gh ge gekjh t:jr ds vuqlkj u;k Layout Manager Hkh Define dj ldrs gSaA

FlowLayout Manager tkok esa dbZ rjg ds Layout Managers gSa] ftudk iz;ksx djds Applet ij Place gksus okys fofHkUu Controls dh Location o Size esa Required ifjorZu fd;k tk ldrk gSA FlowLayout Class Applet dk Default Layout Manager gksrk gS] ftldk iz;ksx Automatically vHkh rd ds lHkh Applet Programs ds Applets esa gqvk gSA FlowLayout esa fofHkUu Components mlh rjg ls Applet ij Place gksrs pys tkrs gSa] ftl rjg ls fdlh Page ij fofHkUu “kCn Print gksrs pys tkrs gSaA tSls gh Page dh Line iwjh gksrh gS] ckdh ds “kCn vxyh Line esa Print gksus yxrs gSaA Bhd blh rjg ls tSls gh Applet esa txg Hkj tkrh gS] fofHkUu Controls vxyh Line esa Place gksus yxrs gSaA Applet ds fofHkUu Components dks FlowLayout esa Setup djus ds fy, gesa FlowLayout Class dk ,d Object Create djds bls ,d Argument ds :i esa setLayout() Method esa Pass fd;k tkrk gSA ;kuh bl Layout dks ;fn ge Manually Set djuk pkgsa] rks gesa fuEukuqlkj Statement fy[kus gksrs gSa% FlowLayout myLayout = new FlowLayout(); setLayout(myLayout); FlowLayout Class fdlh Applet ds fy, ,d Default Layout Manager gksrk gSA Flow Layout Manager fofHkUu Controls dks Applet ij mlh Sequence esa ,d Horizontal Row esa Place djrk gS] ftl Sequence esa os init() Method esa add() Method dk iz;ksx djds Add fd, tkrs gSaA

tSls gh ;s Manager Applet ds Right Border rd igqaprk gS] ;s ckdh ds Controls dks vxys Horizontal Row esa Place djuk “kq: dj nsrk gSA ;s Layout viuh Default fLFkfr esa fofHkUu Controls dks Applet ds Center esa Place djrk gSA FlowLayout Class ds rhu Constructors gSa tks fd fuEukuqlkj gSa% public FlowLayout(); public FlowLayout(int align); public FlowLayout(int align, int hgap, int vgap);

// No-Argument Constructor // 1-Argument Constructor

533 Any Question or Suggestion, Just Discuss Here...

Java in Hindi //3-Argument Constructor No-Argument Constructor ,d u;k FlowLayout Manager Object Create djrk gS vkSj Applet ij Place fd, tkus okys lHkh Controls dks Applet ds Center esa Place djrk gSA lkFk gh lHkh Controls vkil esa By-Default Vertically o Horizontally 5-5 Pixels nwj Place gksrs gSaA 1-Argument Constructor }kjk Create gksus okyk Layout Manager Object ml fn”kk ls Controls dks Applet ij Place djuk “kq: djrk gS] ftl fn”kk dk ge 1-Argumnet Constructor esa mYys[k dj nsrs gSaA tcfd bl Constructor dk iz;ksx djus ij Hkh fofHkUu Controls Default :i ls Horizontally o Vertically 5-5 Pixels nwj Place gksrs gSaA 3-Argument Constructor }kjk ge ,slk Layout Object Create dj ldrs gSa] ftls Set djds ge ;s r; dj ldrs gSa] fd Controls fdl fn”kk ls Form ij Place] gksaxs vkSj fofHkUu Controls ds chp Horizontally o Vertically fdruk Gap jgsxkA align bl Argument ds LFkku ij gesa fuEu esa ls fdlh ,d Constant dks Use djuk gksrk gS% FlowLayout.LEFT FlowLayout.RIGHT FlowLayout.CENTER -

tc Controls dks Left ls Place djuk gks tc Controls dks Right ls Place djuk gks tc Controls dks Center esa Place djuk gks

hgap, vgap bu Arguments ds LFkku ij ge mu Pixels dh la[;k dks Specify djrs gSa] ftrus Pixels dh nwjh gesa Horizontally o Vertically nks Controls ds chp j[kuh gksrh gSA mnkgj.k ds fy, ;fn gesa Applet ij fofHkUu Controls dks Left ls Place djuk gks lkFk gh lHkh Controls ds chp dh nwjh dks 10 Pixel Horizontally o 5 Pixels Vertically j[kuk gks] rks fuEu Applet esa ge ;s

dke fuEukuqlkj dj ldrs gS%a

Program // File Name: ButtonNTextBoxApplet.java import java.awt.*; import java.applet.*; public class ButtonNTextBoxApplet extends Applet{ TextField txtBox1 = new TextField(10), txtBox2 = new TextField(10); Button OKButton = new Button("OK"); FlowLayout organizeControls = new FlowLayout(FlowLayout.LEFT, 10, 5);

}

public void init(){ setLayout(organizeControls); add(txtBox1); add(txtBox2); add(OKButton); }

Output

534 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

FlowLayout Manager dk iz;ksx ge fdlh Specific Container tSls fd Panel Object ds fy, Hkh dj ldrs gSaA ;s dke ge setLayout() Method dk iz;ksx djds dj ldrs gSaA ;kuh ge fdlh Hkh Layout dks setLayout() Method dk iz;ksx djds fdlh Hkh Container ls Associate dj ldrs gSaA ;fn gesa fdlh Layout dks fdlh Panel Object ls Associate djuk gks] rks ge ;s dke fuEukuqlkj Statement }kjk dj ldrs gSa% Panel inputArea = new Panel(); FlowLayout inputLayout = new FlowLayout(); inputArea.setLayout(inputLayout);

bu Statements dk eryc ;s gS fd ge tks Hkh Controls add() Method dk iz;ksx djds Add djsaxs] os lHkh Controls FlowLayout Manager ds inputLayout Object ls Associate gks tk,axs vkSj bl FlowLayout Manager Object dks ge setLayout() Method dk iz;ksx djds Panel Object inputArea ls Associate dj nsaxsA ftlls inputLayout uke ds Object esa Associated lHkh Controls inputArea uke ds Panel Object ls Associate gks tk,axsA dsoy FlowLayout Manager dk iz;ksx djds ge fdlh Applet ij fLFkr fofHkUu Controls dks Bhd ls Organized ugha dj ldrs gSaA fofHkUu Controls dks Applet ij Bhd ls Organize djus ds fy, gesa de ls de ,d vkSj Layout Manager dh t:jr gksrh gSA bl Layout ds vykok Hkh tkok esa dqN vkSj mi;ksxh Layout Manager s gSaA

BorderLayout Manager ;s Layout Top-Level Windows ds fy, ,d Common Layout Implement djrk gSA bl Layout essa Window ds pkjksa rjQ pkj Fixed Width Components gksrs gSa] tcfd blds Center esa ,d cMk Area gksrk gSA Window ds pkjksa Sides dks North, South, East o West uke ls rFkk e/; Hkkx dks Center uke ls Identify fd;k tkrk gSA BorderLayout Manager esa Define fd, tkus okys Constructors fuEukuqlkj gS% BorderLayout() BorderLayout(int hori, int vert)

igyk Constructor ,d Default Border Layout Create djrk gS] tcfd nwljk Constructor Container ds Horizontal o Vertical Controls ds chp NksMs tkus okys Space dks Define djus dh lqfo/kk iznku djrk gSA bl Layout esa ge fuEu Constant ekuksa dk iz;ksx djds Container dh Regions dks Specify dj ldrs gSa% BorderLayout.CENTER BorderLayout.EAST

BorderLayout.SOUTH BorderLayout.WEST

535 Any Question or Suggestion, Just Discuss Here...

Java in Hindi BorderLayout.NORTH

tc ge Components dks Container esa Add djrs gSa] rc gesa bu Components dks Container esa Add djus ds fy, fuEukuqlkj Syntax dk iz;ksx djuk gksrk gS% void add(Component compObj, Object regions)

;gka compObj og Object gS ftls Container esa Add fd;k tkuk gS vkSj regions og LFkku Specify djrk gS] tgka Component Add fd;k tkus okyk gSA

GridLayout Manager GridLayout Class fdlh Container ds lHkh Components dks ,d Specific Rows o Columns esa Organize djrk gSA ;kuh bl Layout dk lcls ljy fu;e ;s gS fd Applet ;k Container ds Display gksus okys Area dks Programmer viuh vko”;drkuqlkj Rows o Columns dh la[;k lqfuf”pr djds Rows o Columns esa ckaV nsrk gSA User ftl la[;k dks lqfuf”pr djrk gS] og la[;k Display gksus okys dqy Rows o Columns dh la[;k gksrh gSA ;kuh ;fn User Grid dh la[;k (2, 3) r; djrk gS] rks Display Area dqy ( 2 * 3 ) 6 Hkkxksa (Cells) esa foHkkftr gks tkrk gS] vkSj lHkh Cells ,dne cjkcj gksrs gSaA

bl Layout esa Controls Display Area ds First Cell ls Place gksuk “kq: gksrs gSa vkSj tc Display Area esa vkSj Controls ds fy, Space ugha cprk gS] rc Controls vxyh Line ds Left Most Cell ls Place gksuk “kq: gksrs gSaA bl Layout esa gesa fuEu Constructors izkIr gksrs gSa% GridLayout() GridLayout(int numRows, int numColumns) GridLayout(int numRows, int numColumns, int hori, int vert)

rhljk Constructor gesa Display gksus okys fofHkUu Components ds chp NksMs tkus okys Vertical o Horizontal Space dks Specify djus dh lqfo/kk iznku djrk gS] fQj pkgs numRows o numColumns dk eku 0 gh D;ksa uk gksA numRows dk eku 0 Specify djus dk eryc gksrk gS fd ge Unlimited-Length Rows Specify dj jgs gSa] tcfd numColumns dk eku 0 Specify djus dk eryc gksrk gS] ge Unlimited-Length Column Define dj jgs gSaA Menu Bars and Menus ,d Top-Level Window ds lkFk ,d Menu Associate fd;k tk ldrk gSA ,d Menu Bar Top-Level Menu Choices dh ,d List Display djrk gSA gj Choice ,d Drop-Down Menu ls Associated gksrk gSA Menu Bar ds Concept dks tkok esa MenuBar, Menu o MenuItem Classes dk iz;ksx djds Implement fd;k tkrk gSA lkekU;r;k Menu Bar esa ,d ;k ,d ls vf/kd Menu Objects gksrs gSaA gekjs Menu Object esa ,d MenuItem Object gksrk gSa vkSj gj MenuItem Object dqN Options Display djrk gS] ftUgsa User Select dj ldrk gSA

536 Any Question or Suggestion, Just Discuss Here...

Java in Hindi pwafd Menu Class MenuItem Class dh Sub Class gS] blfy, Nested Sub Menus dh Hierarchy Create dh tk ldrh gSA lkFk gh ge fdlh Menu esa Checkable Menu Items Hkh Create dj ldrs gSaA bl izdkj ds Checkable Menu Items dks CheckboxMenuItem dgrs gSa vkSj tc bUgsa Select fd;k tkrk gS] rc buds lkFk ,d Check Mark Associated gks tkrk gSA Menu Bar Create djus ds fy, gesa lcls igys MenuBar Class dk ,d Object Create djuk gksrk gSA bl Class esa dsoy ,d Default Constructor gksrk gSA fQj gesa Menu Class dk ,d Object Create djuk gksrk gS] tks fd mu Menus dks Define djrk gS] tks Menu Bar ij Display gksrs gSaA Menu Class esa fuEu Constructors gksrs gSa% Menu() Menu(String optionName) Menu(String optionName, boolean removable)

;gka optionName Menu Selection ds uke dks Specify djrk gSA ;fn removable Argument esa true Specified gks] rks Pop-up Menu dks Menu Bar ls Remove fd;k tk ldrk gSA igyk Constructor ,d Empty menu Bar Create djrk gSA gj Individual Menu Item MenuItem Class dk Object gksrk gSA bl Class esa fuEu Constructors gksrs gSa% MenuItem() MenuItem (String itemName) MenuItem (String itemName, MenuShortcut keyAccel)

bu Constructors esa itemName og uke gS tks Menu esa Option ds :i esa fn[kkbZ nsrk gS vkSj keyAccel Menu ds ml Option dks Shortcut gksrk gSA ge fdlh Menu Item dks setEnabled() Method dk iz;ksx djds Enable ;k Disable dj ldrs gSaA ;s Method fuEukuqlkj gksrk gS% void setEnabled(boolean enabledFlag)

;fn enabledFlag Argument esa true gks rks og Menu Item Enabled jgrk gS vkSj ;fn blesa false gks rks og Menu Item Disabled gks tkrk gSA dksbZ Menu Item Enabled gS ;k Disabled bl ckr dh tkudkjh izkIr djus ds fy, ge isEnabled() Method dks Use dj ldrs gSa] ftldk Syntax fuEukuqlkj gksrk gS% boolean isEnabled()

;fn Check fd;k tkus okyk Menu Item Enabled gks rks ;s Method true Return djrk gS] vU;Fkk false Return djrk gSA fdlh Menu Item ds Label dks Change djus ds fy, ge setLabel() Method dks Use dj ldrs gSa vkSj fdlh Menu Item ds Label dks izkIr djus ds fy, ge getLabel() Method dks Use dj ldrs gSaA buds Syntax fuEukuqlkj gSa% void setLabel(String newName) String getLabel() Checkable Menu Item Create djus ds fy, gesa MenuItem dh Subclass CheckboxMenuItem dks Use djuk gksrk gSA blds Constructors fuEukuqlkj gSa%

537 Any Question or Suggestion, Just Discuss Here...

Java in Hindi CheckboxMenuItem() CheckboxMenuItem(String itemName) CheckboxMenuItem(String itemName, boolean on)

;gka itemName og uke gS ftls Menu esa Checkable Form esa Display djuk gksrk gSA ;fn gesa Menu esa fdlh Item dks Checked j[kuk gksrk gS] rks gesa on Argument esa true Pass djuk gksrk gSA igys nks Constructors ,d Unchecked MenuItem Create djrs gSaA fdlh Checkable Menu Item dh Status izkIr djus ds fy, gesa getState() Method dks Use djuk gksrk gSA tcfd fdlh Menu Item dh State dks Set djus ds fy, ge setState() Method dks Use dj ldrs gSaA budk Syntax fuEukuqlkj gS% boolean getState() void setState(boolean checked)

tc dksbZ Menu Item Checked gksrk gS] rc getState() Method true Return djrk gS] tcfd Unchecked gksus ij false Return djrk gSA blh rjg ls tc gesa fdlh Unchecked Menu Item dks Check djuk gks ;k Checked Menu Item dks Unchecked djuk gks] rc ge setState() Method dks Use djrs gSaA Menu Item Create djus ds ckn gesa bu Menu Items dks Menu Object esa add() Method }kjk Add djuk gksrk gSA blds fy, ge add() Method dks fuEu rjhds ls Use djrs gSa% MenuItem add(MenuItem item)

bl Statement esa item og Item gS] ftls menu esa Add djuk gSA ge ftl Øe esa add() Method dks Call djrs gSa] Menu esa mlh Øe esa Menu Items Add gksrs gSaA tc ,d ckj ge fofHkUu Menu Items dks Add dj ysrs gSa] mlds ckn ge ml MenuItem Object dks Menu Bar esa Add dj ldrs gSaA blds fy, Hkh gesa add() Method dks Call djuk gksrk gS] tks fd

ge fuEukuqlkj djrs gSa%

Menu add(Menu menu) Menus gesa”kk rHkh Event Generate djrs gSa] tc User fdlh MenuItem ;k CheckboxMenuItem ds fdlh Option dks Select djrk gSA ge tc Hkh fdlh Menu Item dks Select djrs gSa] ,d ActionEvent Object Generate gksrk gS vkSj ge tc Hkh fdlh CheckboxMenuItem dks Select djrs gSa] ,d ItemEvent Object Generate gksrk gSA blfy, gesa ActionListener o ItemListener Interface dks bu Generate gksus okys Events dks Listen djus ds fy, Implement djuk gksrk gSA ItemEvent Object dk getItem() Method ml Item dk Reference Return djrk gS] ftlus Event Object dks Generate fd;k gksrk gSA bl Method dk Syntax fuEukuqlkj gksrk gS% Object getItem()

pfy,] vc Menu Creation dh bl iwjh izfØ;k dks Practically le>rs gSaA tkok esa Menu Bar Create djus ds fy, lcls igys gesa MenuBar Class dk ,d Object Create djuk gksrk gSA ;s dke ge fuEukuqlkj Statement }kjk djrs gSa% MenuBar myFirstMenu = new MenuBar(); 538 Any Question or Suggestion, Just Discuss Here...

Java in Hindi MenuBar Class dk Object Create djus ds ckn gesa bl Menu Bar dks fdlh Frame Window ls Attach djuk gksrk gSA fdlh Frame Window ls Menu Bar Object dks Connect djus ds fy, lcls igys gesa Frame Class dk ,d Object Create djds Frame Create djuk gksrk gSA ;s dke ge fuEukuqlkj djrs gSa% Frame myFrame = new Frame(“Frame with Menu”); Frame Create djus ds ckn Create fd, x, Menu Bar Object dks bl Frame ls Attach djus ds fy, gesa setMenuBar() Method dks Use djuk gksrk gSA bl Method dk iz;ksx djds ge Create gksus okys Menu Bar dks Frame Window ls Attach dj ldrs gSaA bl method dks gesa fuEukuqlkj Use djuk gksrk gS% myFrame.setMenuBar(myFirstMenu);

pwafd] vHkh geus Frame ls tks Menu Connect fd;k gS] og Menu Bar iwjh rjg ls Empty gS] D;ksafd mlesa vHkh rd dksbZ Hkh Menu ugha gSA bl Menu Bar esa u;k Menu Attach djus ds fy, vc gesa Menu Class dk Object Create djuk gksrk gSA gesa Menu Bar esa ftrus Menu Attach djus gksrs gSa] mrus Menu Object Create djus gksrs gSaA Menu Class dk Object djus ds fy, gesa fuEukuqlkj Menu Objects Create djus gksrs gSa% Menu fileMenu = new Menu(“File”); Menu editMenu = new Menu(“Edit”); Menu optionMenu = new Menu(“Options”); Menu Class ds Constructor esa gesa Menu Bar ij fn[kkbZ nsus okys uke dks Specify djuk gksrk gSA bl Constructor esa ge tks String Pass djrs gSa] og String Caption ds :i esa Menu Bar ij fn[kkbZ nsrk gSA Menus dks Create djus ds ckn gesa bu Menus dks Menu Bar Object ls Attach djuk gksrk gSA Menus dks MenuBar Object ls Attach djus ds fy, gesa add() Method dks Use djuk gksrk gSA ;s dke ge fuEukuqlkj dj ldrs gSa% myFirstMenu.add(fileMenu); myFirstMenu.add(editMenu); myFirstMenu.add(optionMenu);

fofHkUu Menus dks Menu Bar ls Connect djus ds ckn gesa Menus esa fn[kkbZ nsus okys Items dks Create djuk gksrk gSA Menu Items dks Create djus ds fy, gesa MenuItem Class dks Use djuk gksrk gSA MenuItem Object Create djus ds fy, gesa fuEukuqlkj Statements Use djuk gksrk gS% MenuItem mOpen = new MenuItem(“Open”) MenuItem mClose = new MenuItem(“Close”) MenuItem mUndo = new MenuItem(“Undo”) MenuItem mRedo = new MenuItem(“Redo”) MenuItem mOption1 = new MenuItem(“Option1”) MenuItem mOption2 = new MenuItem(“Option2”)

539 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ;fn ge fdlh Checkbox Menu Item dks Create djuk pkgsa] rks gesa CheckboxMenuItem Class dk Object Create djuk gksrk gSA ;s Object ge fuEukuqlkj Create dj ldrs gSa% CheckboxMenuItem mOption3= new CheckboxMenuItem(“mOption3”)

dbZ Menus ds fofHkUu Items ds chp gesa ,d Line Use djuh gksrh gSA bl Line dks Separator dgrs gSaA ge bl Separator dks Hkh ,d MenuItem Object dh rjg Create djds Menu esa Add dj ldrs gSaA Separator Create djus ds fy, gesa fuEukuqlkj Statement Use djuk gksrk gS% MenuItem mSeparator = new MenuItem(“-”)

//Separator

fofHkUu izdkj ds Menu Items Create djus ds ckn bu Items dks muls lEcaf/kr Menu ls Attach djuk gksrk gSA Menu ls fofHkUu Menu Items dks Attach djus ds fy, gesa fuEukuqlkj add() Method dks Call djuk gksrk gS% fileMenu.add(mOpen) fileMenu.add(mClose) editMenu.add(mUndo) editMenu.add(mRedo) optionMenu.add(mOption1) optionMenu.add(mOption2) optionMenu.add(mSeparator) optionMenu.add(mOption3)

fdlh Menu esa ;fn gesa Separator Add djuk gks] rks ge setSeparator() Method dk iz;ksx Hkh dj ldrs gSaA ;kuh ekuyks fd gesa gekjs Option Menu esa ,d Separator Add djuk gS] rks ;s dke ge fuEukuqlkj Hkh dj ldrs gSa% optionMenu.add(mOption1) optionMenu.add(mOption2) optionMenu.addSeparator() optionMenu.add(mOption3)

vc ;fn ge gekjs Program dks Compile djds Run djrs gSa] rks gesa gekjs Frame Window ds lkFk ,d Menu Bar Hkh fn[kkbZ nsrk gSA bl iwjh izfØ;k dks ge fuEukuqlkj ,d Program }kjk le> ldrs gSaA Program // File Name : ManuDemoApp.java import java.awt.*; public class ManuDemoApp { public static void main(String arts[]) { // Create a frame and a MenuBar

540 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Frame myFrame = new Frame("My Frame with Menu"); MenuBar myMenubar = new MenuBar(); // Add the MenuBar to the frame myFrame.setMenuBar(myMenubar); // Create the File and Edit Menus and Attach it with the MenuBar Menu mFile = new Menu("File"); Menu mEdit = new Menu("Edit"); myMenubar.add(mFile); myMenubar.add(mEdit); // Add New and Close options to File Menu and // Add Copy and Paste to the Edit Menu MenuItem mNew = new MenuItem("New"); MenuItem mClose = new MenuItem("Close"); mFile.add(mNew); mFile.add(mClose); MenuItem mCopy = new MenuItem("Copy"); MenuItem mPaste = new MenuItem("Paste"); mEdit.add(mCopy); mEdit.add(mPaste); // Make Close disabled mClose.setEnabled(false); // Create Print checkbox, followed by separator CheckboxMenuItem mPrint = new CheckboxMenuItem("Print"); mFile.add(mPrint); mFile.addSeparator(); // Create Font submenu Menu mFont = new Menu("Font"); mFile.add(mFont); mFont.add("Arial"); mFont.add("Times New Romans"); // Resize the frame myFrame.setSize(300, 200);

}

}

// Display the Frame on the screen myFrame.setVisible(true);

Output

541 Any Question or Suggestion, Just Discuss Here...

Java in Hindi

dbZ ckj ge gekjs Program esa Pop-up Menu Add djuk pkgrs gSaA Pop-up Menu ,d ,slk Menu gksrk gS] tks Frame Window ;k Applet esa Mouse ds Right Button dks Click djus ij Display gksrk gSA tc gesa gekjs Program esa Popup Menu Attach djuk gksrk gS] rc gesa fuEu Øe esa fofHkUu dke djus gksrs gSa% 1 lcls igys PopupMenu Class dk ,d Object Create fd;k tkrk gSA ;s dke ge fuEukuqlkj dj ldrs gSa% PopupMenu myPopup = new PopupMenu();

2 PopupMenu Class dk Object Create djus ds ckn gesa ,d Menu Create djuk gksrk gS] ftls ge Popup Menu Object esa Add djuk pkgrs gSaA ;s dke djus ds fy, gesa Menu Class dk ,d Object Create djuk gksxk vkSj ml Object dks PopupMenu Object ls Add djuk gksxkA ;s dke ge fuEukuqlkj dj ldrs gSa% Menu myPopupMenu = new Menu(“Popup”); myPopup.add(myPopupMenu);

3 PopupMenu ls Menu dks Add djus ds ckn gesa ml Menu esa Display gksus okys Menu Items Create djus gksrs gSa vkSj mu Menu Items dks Menu Object esa Add djuk gksrk gSA ;s dke ge fuEukuqlkj dj ldrs gSa% MenuItem mRefresh = new MenuItem(“Refresh”); myPopupMenu.add(mRefresh);

Dialog Boxes dbZ ckj gesa Related Controls ds ,d lewg dks Hold djus ds fy, Dialog Box dh t:jr gksrh gSA lkekU;r;k Dialog Boxes dk iz;ksx User ls Input izkIr djus ds fy, fd;k tkrk gSA mnkgj.k ds fy, “Open” Dialog Box fdlh File dks Open djus ds fy, Use gksrk gS tcfd “Save As” Dialog Box fdlh File dks Save djus ds fy, Use fd;k tkrk gSA Dialog Box ,d izdkj dk Frame Window gh gksrk gSA vUrj dsoy bruk gS fd Dialog Box gesa”kk fdlh nwljs Parent Window dk Child Window gksrk gSA 542 Any Question or Suggestion, Just Discuss Here...

Java in Hindi lkFk gh ge fdlh Dialog Box ds lkFk Menu Bar dks Attach ugha dj ldrs gSaA buds vykok ftruh Hkh ifjfLFkfr;ka gksrh gSa] muesa Dialog Box Window mlh rjg ls dke djrk gS] ftl rjg ls ,d Frame Window djrk gSA ;kuh ge fdlh Dialog Box esa Hkh mlh rjg ls fofHkUu GUI Controls Add dj ldrs gSa] ftl rjg ls fdlh Frame Window esa djrs gSaA Dialog Boxes Modal ;k Modeless gks ldrs gSaA ,d ,slk Dialog Box tks tc rd Visible jgrk gS] rc rd ge Parent Window dks fdlh izdkj ls Access ugha dj ldrs gSa] Modal Dialog Box dgykrk gSA ;kuh tc rd ,d Modal Dialog Box Active jgrk gS] rc rd ftrus Hkh Input fd, tkrs gSa] mu lHkh Inputs dks Dialog Box gh Receive djrk gSA

bldk eryc ;s gS fd ge tc rd fdlh Modal Dialog Box dks Close ugha dj nsrs gSa] rc rd ge mlds Parent Window ls fdlh izdkj dk dke ugha dj ldrs gSaA tcfd ;fn Dialog Box Modeless gks] rks ,slk ugha gksrk gSA ;kuh ,sls Dialog Box ds Open gksus ds fLFkfr esa Hkh ge Application ds vU; fgLlksa dks Access djus esa l{ke gksrs gSaA lkekU;r;k Dialog Box Create djus ds fy, gesa Dialog Class dks Use djuk gksrk gSA bl Class esa fuEukuqlkj nks Constructors gksrs gSa% Dialog(Frame parentWindow, boolean mode) Dialog(Frame parentWindow, String title, boolean mode)

bl Constructor esa parentWindow og Frame Window gksrk gS] ftlesa Dialog Box Child Window dh rjg Add fd;k tkrk gSA ;fn mode esa true gks] rks Create gksus okyk Dialog Box Modal Dialog Box gksrk gS] vU;Fkk ;s ,d Modeless Dialog Box Create djrk gSA title Argument esa ge tks String Pass djrs gSa] og String Dialog Box ds Title ds :i esa fn[kkbZ nsrh gSA lkekU;r;k ge Dialog Class dks Extend djds mldh Sub Class Create djrs gSa vkSj mlesa Application }kjk Required Functionalities dks Add dj ysrs gSaA Program // File Name : DialogBoxWithMenuBar.java import java.awt.*; import java.awt.event.*; import java.applet.*; // Create Subclass of Dialog. class SubDialog extends Dialog implements ActionListener { SubDialog(Frame parent, String title){ super(parent, title, false); setLayout(new FlowLayout()); setSize(200, 150); add(new Label("Press this button")); Button btnCancel; add(btnCancel = new Button("Cancel"));

543 Any Question or Suggestion, Just Discuss Here...

Java in Hindi }

btnCancel.addActionListener(this);

public void actionPerformed(ActionEvent actnEvnt) { dispose(); } public void paint(Graphics g) { g.drawString("This is in the dialog box", 10, 60); }

} //------------------------------------------------------------------// Create a subclass of Frame class MenuFrame extends Frame { String message = ""; CheckboxMenuItem debug, test; MenuFrame(String title) { super(title); // Create menubar and add it to frame MenuBar mBar = new MenuBar(); setMenuBar(mBar); // Create Menu Items Menu file = new Menu("File"); MenuItem mNew, mClose; file.add(mNew = new MenuItem("New")); file.add(mClose = new MenuItem("Close")); mBar.add(file); // These are checkable items of edit menu Menu edit = new Menu("Edit");

debug = new CheckboxMenuItem("Debug"); edit.add(debug); test = new CheckboxMenuItem("Testing"); edit.add(test); mBar.add(edit); // Create an Listener Object MyMenuHandler handler = new MyMenuHandler(this);

544 Any Question or Suggestion, Just Discuss Here...

Java in Hindi // Register it to receive Menu events mNew.addActionListener(handler); mClose.addActionListener(handler); debug.addItemListener(handler); test.addItemListener(handler); // Create an object to handle window events MyWindowAdapter adapter = new MyWindowAdapter(this);

}

// Register it to receive Window events addWindowListener(adapter);

public void paint(Graphics g) { g.drawString(message, 10, 150); if(debug.getState()) g.drawString("Debug is on ", 10, 220); else g.drawString("Debug is off ", 10, 220);

}

if(test.getState()) g.drawString("Test is on ", 10, 240); else g.drawString("Test is ff ", 10, 240);

} //-------------------------------------------------------------------------class MyWindowAdapter extends WindowAdapter { MenuFrame myMenuFrame; public MyWindowAdapter(MenuFrame mnuFrame) { this.myMenuFrame = mnuFrame; } public void windowClosing(WindowEvent wndEvnt) { myMenuFrame.dispose(); }

} //--------------------------------------------------------------------------

545 Any Question or Suggestion, Just Discuss Here...

Java in Hindi class MyMenuHandler implements ActionListener, ItemListener { MenuFrame myMenuFrame; public MyMenuHandler(MenuFrame myMenuFrame) { this.myMenuFrame = myMenuFrame; } // Handle action events public void actionPerformed(ActionEvent actnEvnt) { String message = "You have selected "; String argument = (String)actnEvnt.getActionCommand(); // Activate a Dialog Box when File->New Option is selected if(argument.equals("New")) { message = message + "New..."; SubDialog dialogBox = new SubDialog(myMenuFrame, "NewDialogBox"); dialogBox.setVisible(true); } // Other Menu Options else if(argument.equals("Close")) message += "Close"; else if(argument.equals("Debug")) message += "Debug";

}

else if(argument.equals("Testing")) message += "Testing...";

public void itemStateChanged(ItemEvent itmEvnt) { myMenuFrame.repaint(); }

} //-------------------------------------------------------------------------// Create Frame Window public class DialogBoxWithMenuBar extends Applet { Frame myFrame; public void init() {

546 Any Question or Suggestion, Just Discuss Here...

Java in Hindi myFrame = new MenuFrame("Accessible Menu"); int width = Integer.parseInt(getParameter("width")); int height = Integer.parseInt(getParameter("height")); setSize(width, height);

}

myFrame.setSize(width, height); myFrame.setVisible(true);

public void start() { myFrame.setVisible(true); }

}

public void stop() { myFrame.setVisible(false); }

Output

FileDialog Class tkok gesa ,d Built-In Dialog Box Class Provide djrk gS] tks gesa User }kjk Specify dh tkus okyh File dks Open djus dh lqfo/kk iznku djrk gSA bls File Dialog Box dgrs gSaA FileDialog Box Create djus ds fy, gesa FileDialog Class dk ,d Object Create djuk gksrk gSA ,slk djus ij ,d FileDialog Box Display gksus yxrk gSA lkekU;r;k ;s ,d Standard FileDialog Box gksrk gS] tks gesa Operating System }kjk izkIr gksrk gSA FileDialog Class esa fuEukuqlkj rhu Constructors gksrs gSa% FileDialog(Frame parent, String boxName) FileDialog(Frame parent, String boxName, int how) 547 Any Question or Suggestion, Just Discuss Here...

Java in Hindi FileDialog(Frame parent)

;gka parent Argument esa gesa FileDialog Box ds Parent Window dk uke nsuk gksrk gS] tcfd boxName Argument esa FileDialog Box ds Title Bar ij fn[kkbZ nsus okys uke dks Specify djuk gksrk gSA ;fn bl Argument dks NksM fn;k tk,] rks Display gksus okys Dialog Box ij dksbZ Title ugha gksrk gSA how Argument esa ;fn ge FileDialog.LOAD Specify djrs gSa] rks File Open djus okyk “Open” Dialog Box Display gksrk gS] tcfd ;fn bl Argument esa ge FileDialog.SAVE Constant Specify djsa] rks File dks Save djus ds fy, “Save As” Dialog Box Display gksus

yxrk gSA

rhljk Constructor ,d ,slk FileDialog Box Open djrk gS] ftlls ge fdlh File dks Reading Mode esa Open djus ds fy, Select dj ldrs gSaA FileDialog gesa nks Methods Provide djrk gS] ftudk iz;ksx djds ge User }kjk Select fd, x, File ds uke o Path dks izkIr dj ldrs gSaA ;s Methods fuEukuqlkj gSa% String getDirectory(); String getFile()

;s Methods File o Directory dk uke Return djrs gSaA bls le>us ds fy, ge fuEukuqlkj Program fy[k ldrs gSa% Program // File Name : FileDialogApp.java import java.awt.*; import java.awt.event.*; // Create a subclass of Frame class MyFrame extends Frame { MyFrame(String title) { super(title); // Create an Listener Object MyWindowAdapter adapter = new MyWindowAdapter(this); // Register it with Listener to receive events addWindowListener(adapter);

} } //-------------------------------------------------------------------------class MyWindowAdapter extends WindowAdapter { MyFrame myFrame; public MyWindowAdapter(MyFrame mnuFrame){ 548 Any Question or Suggestion, Just Discuss Here...

Java in Hindi }

this.myFrame = mnuFrame;

public void windowClosing(WindowEvent wndEvnt){ myFrame.dispose(); }

} //-------------------------------------------------------------------------// Create Frame window class FileDialogApp { public static void main(String a[]) { Frame f = new MyFrame(“File Dialog Demo”); f.setVisible(true); f.setSize(200,150);

}

}

FileDialog fd = new FileDialog(f, “File Dialog”); fd.setVisible(true);

bl Program ds Memory esa Load gksrs gh ,d Frame Window Display gksrk gS vkSj Screen ij Open Dialog Box fn[kkbZ nsus yxrk gSA

Explicit Event Handling ;s Events dks Handle djus dk ,d pkSFkk o vfUre Alternate rjhdk gSA bl rjhds esa fdlh Component dks ,d Sub Class esa Extend fd;k tkrk gS vkSj fQj ml Method dks Override fd;k tkrk gS] tks Events dks Receive o Dispatch djrk gSA mnkgj.k ds fy, ge Button Class dks Derive dj ldrs gSa vkSj fQj mlds processActionEvent() Method dks Override dj ldrs gSaA processActionEvent() Method dk Default dke ;s gS fd og Event dks Event Listener esa Dispatch dj nsrk gSA lkekU;r;k bl rduhd dks Use ugha fd;k tkrk gS] D;ksafd blesa dqN dfe;ka gSaA bl rduhd dks tkok 1.0 Version esa Use fd;k x;k FkkA tc ge bl rduhd dks Use djuk pkgrs gSa ;kuh tc ge AWT Package dh fdlh Class dks Extend djuk pkgrs gSa] rc gesa Component Class ds enableEvents() Method dks Use djuk t:jh gksrk gSA bl Method dk Syntax fuEukuqlkj gksrk gS% protected final void enableEvents(long eventMask)

bl Method esa eventMask ,d Bit Mask gS] tks Current Component esa vkus okys Events dks Define djrk gSA AWTEvent Class esa bu Masks dks cukus ds fy, dqN Integer Constants dks Define fd;k x;k gSA muesa ls dqN Masks fuEukuqlkj gSa%

549 Any Question or Suggestion, Just Discuss Here...

Java in Hindi ACTION_EVENT_MASK ADJUSTMENT_EVENT_MASK COMPONENT_EVENT_MASK CONTAINER_EVENT_MASK FOCUS_EVENT_MASK INPUT_METHOD_EVENT_MASK ITEM_EVENT_MASK

KEY_EVENT_MASK MOUSE_EVENT_MASK MOUSE_MOTION_EVENT_MASK MOUSE_WHEEL_EVENT_MASK TEXT_EVENT_MASK WINDOW_EVENT_MASK

blds vykok ge ftl Class dks Extend djrs gSa] gesa ml Class ds ,d Appropriate Method dks Hkh Override djuk t:jh gksrk gS] rkfd Event dks Process fd;k tk ldsA fofHkUu Components ds fy, Override fd, tkus okys Event Handling Methods fuEukuqlkj gSa% Class Button Checkbox CheckboxMenuItem Choice Component

List MenuItem Scrollbar TextComponent

Processing Method processActionEvent() processItemEvent() processItemEvent() processItemEvent() processComponentEvent(), processFocusEvent(), processKeyEvent(), processMouseEvent(), processMouseMotionEvent(), processMouseWheelEvent() processActionEvent(), processItemEvent() processActionEvent() processAdjustmentEvent() processTextEvent()

Extending Buttons bl Event Handling rduhd dks Button ds lkFk Use djus dh izfØ;k dks ge ,d mnkgj.k }kjk le>us dh dksf”k”k dj jgs gSaA vxys mnkgj.k esa geus ,d Applet Create fd;k gS] ftl ij ,d Button Object Create fd;k x;k gSA tc ge bl Button dks Click djrs gSa] rks Applet ds Status Bar esa “Action Event” String Display gksrk gSA lkFk gh Button dks dqy fdruh ckj Press fd;k x;k gS] mldh la[;k Hkh Status Bar esa Display gksrh gSA Program // File Name : ExtendingButtonApplet.java import java.awt.*; import java.awt.event.*; import java.applet.*; public class ExtendingButtonApplet extends Applet {

550 Any Question or Suggestion, Just Discuss Here...

Java in Hindi MyButton btnPress; static int i = 0; public void init() { btnPress = new MyButton("Press Me"); add(btnPress); } // Extended Button Class class MyButton extends Button { public MyButton(String label) { super(label); enableEvents(AWTEvent.ACTION_EVENT_MASK); }

}

}

protected void processActionEvent(ActionEvent actnEvtn) { showStatus("Action Event : " + i++); super.processActionEvent(actnEvtn); }

Output

bl Program esa geus MyButton Class dks ,d Inner Class ds :i esa Applet esa Define fd;k gSA bl Class dks Button Class ls Derive fd;k x;k gSA MyButton Class esa Button ij Label Display djus ds fy, geus super() Method dks Use fd;k gSA bl Method dh otg ge Button ij tks Label nsuk pkgrs gSa] og Label MyButton Sub Class ds Constructor }kjk Button Super Class esa Pass fd;k tkrk gSA fQj MyButton Class ds Object }kjk Generate gksus okys Events dks Handle fd;k tk lds] blfy, bl Class ds Constructor esa enableEvents() Method dks Use fd;k gS vkSj Argument ds :i esa ;s Hkh crk;k gS fd MyButton Class ds Object }kjk Generate gksus okys fdl rjg ds Events dks ;s Inner Class Handle dj ldsxkA ;fn ge enableEvents() Method esa Argument ds :i esa MyButton Class }kjk Generate gksus okys Events dh tkudkjh uk nsa ;k bl Method dks bl rjg ls Call uk djsa]

551 Any Question or Suggestion, Just Discuss Here...

Java in Hindi rks gekjk Button fdlh izdkj ds Event dks Response ugha djsxkA tc ge MyButton Class ds fdlh Button ij Click djrs gSa] rc ,d ActionEvent Object Generate gksrk gS vkSj tc dksbZ ActionEvent Object Generate gksrk gS] processActionEvent() Method Execute gks tkrk gSA pwafd MyButton Class Applet Class dh ,d Inner Class gS] blfy, ;s Class Applet Class ds fdlh Hkh Member dks Directly Access djus esa l{ke gSA bl rjg ls ge ,d Button Class dks Extends djds Event Handling ds fy, Use dj ldrs gSaA blh rjg ls ge vU; Classes dks Extend djds mUgsa Event Handling ds lkFk Use dj ldrs gSaA

Extending Checkbox bl Program esa geus Checkbox Class dks Bhd mlh rjg ls Use Event Handling ds fy, Use fd;k gS] ftl rjg ls geus Button Class dks Use fd;k gSA vUrj dsoy bruk gS fd bl Program esa Checkbox dks Click djus ij ItemEvent Generate gksrk gS] ftls Handle djus ds fy, processItemEvent() Method dks Override djuk gksrk gSA Program // File Name : ExtendingCheckboxApplet.java import java.awt.*; import java.awt.event.*; import java.applet.*; public class ExtendingCheckboxApplet extends Applet{ MyCheckbox check1, check2; static int i = 0; public void init(){ check1 = new MyCheckbox("Item1"); add(check1); check2 = new MyCheckbox("Item2"); add(check2); } // Extended Button Class class MyCheckbox extends Checkbox{ public MyCheckbox(String label) { super(label); enableEvents(AWTEvent.ITEM_EVENT_MASK); }

}

}

protected void processItemEvent(ItemEvent itmEvnt) { showStatus("Checkbox name/state: " + getLabel() +"/"+ getState()); super.processItemEvent(itmEvnt); }

552 Any Question or Suggestion, Just Discuss Here...

Java in Hindi Output

bl Applet esa ge tc Hkh fdlh Check Box dks Click djrs gSa] rc ,d ItemEvent Generate gksrk gS] ftlds Response esa processItemEvent() Method Execute gks tkrk gS] vkSj Status Bar ij Check Box ls lEcaf/kr ,d Message Display gksus yxrk gSA blh rjg ls ge fofHkUu izdkj ds vU; Controls dks Hkh Extend djds Event Handling ds fy, Use dj ldrs gSaA dbZ ckj dbZ Controls ,d ls T;knk mnkgj.k ds fy, ,d List Control ds ItemEvent Generate gksrk gS] tcfd ActionEvent Object Generate gksrk

izdkj ds Events Generate djus esa l{ke gksrs gSaA fdlh Option dks tc Select fd;k tkrk gS] rc ,d List ds fdlh Option dks Double Click djus ij ,d gSA

bl fLFkfr esa ;fn ge List Control dks Extend djsa] rks gesa bu nksuksa izdkj ds Events dks Handle djuk t:jh gksrk gSA List dh Extending Process o Event Handling Process dks

fuEu mnkgj.k }kjk le>k tk ldrk gS%

Program // File Name : ExtendingListApplet.java import java.awt.*; import java.awt.event.*; import java.applet.*; public class ExtendingListApplet extends Applet{ MyList list; public void init(){ list = new MyList(); list.add("Red"); list.add("Green"); list.add("Blue"); }

add(list);

// Extended Button Class class MyList extends List{ public MyList(){ enableEvents(AWTEvent.ACTION_EVENT_MASK |

553 Any Question or Suggestion, Just Discuss Here...

Java in Hindi }

AWTEvent.ITEM_EVENT_MASK );

protected void processItemEvent(ItemEvent itmEvnt) { showStatus("Item Event : " + getSelectedItem()); super.processItemEvent(itmEvnt); }

}

}

protected void processActionEvent(ActionEvent actnEvnt) { showStatus("Action Event : " + actnEvnt.getActionCommand()); super.processActionEvent(actnEvnt); }

Output

bl mnkgj.k esa ge ns[k ldrs gSa fd tc dksbZ Control ,d ls vf/kd izdkj ds Events Generate djus esa l{ke gksrk gS] rc gesa mu lHkh izdkj ds Events ds Mask dks enableEvents() Method esa Logical OR Operator }kjk Specify djuk gksrk gSA

Fonts Handling In Java tkok gesa Program ds Run Time esa Dynamically fdlh Hkh Font dks Select djus dk ,d cgqr gh Flexible rjhdk iznku djrk gSA ;kuh tkok esa ge Program ds Run Time esa Hkh fdlh Hkh Font dks Select djds vius Data dks fofHkUu Fonts esa Display dj ldrs gSaA AWT fofHkUu izdkj ds Fonts dks Support djrk gSA tkok esa gj Font fdlh Font Family dk lnL; gksrk gS] ftldk ,d Logical uke gksrk gS vkSj ,d Font Face uke gksrk gSA mnkgj.k ds fy, Courier ,d Font Family dk uke gSA Font dk tks Logical uke gksrk gS og uke fdlh uk fdlh Specific Font Category dks Specify djrk gSA

tcfd Font Face fdlh uk fdlh Specific Font tSls fd Courier Italic dks Represent djrk gSA Fonts dh fofHkUu fo”ks’krkvksa dks ,d Font uke dh Class esa Encapsulate fd;k x;k gSA bl Font Class esa fuEukuqlkj Variables Defined gSa% Variable String name float pointSize

Meaning Name of the Font Size of the Font in Points

554 Any Question or Suggestion, Just Discuss Here...

Java in Hindi int size int style

Size of the Font in Points Font Style (Bold, Italic, Normal, BoldItalic)

tc ge Fonts ds lkFk fdlh izdkj dh izfØ;k djrs gSa] rc dbZ ckj gesa ;s tkuus dh t:jr iMrh gS fd gekjs Computer esa dkSu&dkSu ls Fonts miyC/k gSaA bl Information dks izkIr djus ds fy, ge getAvailableFontFamilyNames() Method dk iz;ksx dj ldrs gSaA bl Method dks GraphicsEnvironment uke dh Class esa Define fd;k x;k gSA bl Method dk Syntax fuEukuqlkj gksrk gS% String [ ] getAvailableFontFamilyNames()

;s Method Strings dk ,d Array Return djrk gS] ftlesa Computer ij Available Fonts dh Families ds uke Stored gksrs gSaA blh rjg ls ge getAllFonts() uke ds Method dks Use djds gekjs Computer ij miyC/k fofHkUu izdkj ds Font Objects dks ,d Array ds :i esa izkIr dj ldrs gSaA ;s Method fuEukuqlkj gksrk gS% Font[ ] getAllFonts()

pwafd ;s nksuksa Methods GraphicsEnvironment Class ds Members gSa] blfy, bu Methods dks Call djus ds fy, gesa bl Class ds ,d Reference dh t:jr gksrh gSA bl Class dk Reference izkIr djus ds fy, ge getLocalGraphicsEnvironment() uke ds ,d Static Method dks Call dj ldrs gSaA bldk Syntax fuEukuqlkj gksrk gS% static GraphicsEnvironment getLocalGraphicsEnvironment()

vxys Applet Program esa geus gekjs Computer ij miyC/k fofHkUu Font Families dks izkIr fd;k gSA Program fuEukuqlkj gS% Program // File Name : AllAvailableFonts.java import java.awt.*; import java.applet.*; public class AllAvailableFonts extends Applet{ public void paint(Graphics g) { String message = ""; String FontList[]; GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment(); FontList = ge.getAvailableFontFamilyNames(); for(int i=0, j=0; ik;k gS] cfYd geus Object Oriented Programming System ds fofHkUu Theoratical Concepts dks Hkh Java Programming Language ds Programs ds ek/;e ls le>kus dh dksf”k”k dh gS fd vki fdl rjg ls OOPS Conepts dks Use djrs gq, Professional Applications Develop dj ldrs gSaA D;ksafd orZeku le; esa Use dh tkus okyh fofHkUu Programming Languages iwjh rjg ls Object Oriented Programming System Pattern ij gh vk/kkfjr gSa vkSj fcuk Object Oriented Programming System dks csgrj rjhds ls le>s gq, vki orZeku le; ds Modern Application Software Develop djus dh {kerk izkIr ugha dj ldrsA gkykafd Object Oriented Programming System ds fofHkUu Concepts vius vki esa dkQh tfVy Concepts gSa] ysfdu Java Programming Language dk iz;ksx djrs gq, bu tfVy OOPS Concepts dks Hkh bl iqLrd esa vklkuh ls le>kus dh dksf”k”k dh xbZ gSA bl iqLrd esa u dsoy Java o OOPS Concepts dks csgrj rjhds ls le>kus dh dksf”k”k dh xbZ gS] cfYd bl ckr dks Hkh le>kus dh dksf”k”k dh xbZ gS fd vki fdl rjg ls fdlh Real World Problem dks fdlh Computer Program esa Convert dj ldrs gSaA rkfd vki fdlh Hkh Real World Problem dks Solve djus ds fy, Professional Levele dk Object Oriented Applicaiotn Software Create dj ldsaA Java Language vius vki esa bruk cMk o Versatile Subject gS fd Java Language ds fodkl ds ckn ftruh Hkh Object Oriented Programming Languages dks fodflr fd;k x;k gS] os lHkh yxHkx “C/C++” Language ds Syntax o Java ds Conceepts ij gh vk/kkfjr jgh gSaA

bruk gh ugha PHP, JavaScript o orZeku le; dh lcls Modern Programming Language C# esa Hkh Java ds Concepts dks yxHkx leku rjhds ls Use fd;k x;k gSA blfy, ;fn vki Java Language dks Bhd ls le>rs gSa] rks vkr C# Programming Langauge dks Hkh cMh gh vklkuh ls lh[k o le> ldrs gSaA mEehn gS] bl iqLrd us vkids Development vkSj Programming ds Kku dks t:j c
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF