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 c
dbZ vU; Languages tSls fd Visual Basic vkfn esa Program “kq: ls vUr rd dksbZ Error ugha nsrk ysfdu fdlh uk fdlh txg ij ,slh Error Generate djrk gS] ftldk Solution djus esa gesa mruk le; yx tkrk gS ftruk ml Program dks Create djus esa ugha yxrkA
14 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Java dk fodkl Sun Microsystems ds ,d Developer James Gosling us fd;k FkkA mUgsa bldk fodkl djus dh t:jr blfy, iMh D;ksafd os “C++” Language dk iz;ksx djds ,d Project cuk jgs Fks ysfdu mUgsa og ifj.kke izkIr ugha gks ik jgk Fkk tks os pkgrs FksA blfy, mUgksaus Lo;a ,d Language Develop dh ftlls mudh Requirement iwjh gks ldsA blh Language dk uke “Java” gSA Java dks lh[kuk fdlh Hkh vU; Language dks lh[kus dh rqyuk esa vf/kd ljy gSA T;knkrj Languages ,d nwljs ds yxHkx leku gh gSaA blfy, ;fn ,d Language esa Mastery dj yh tk, rks ckdh dh vU; Languages esa fdlh Programmer dks T;knk ijs”kkuh ugha vkrh gSA og vklkuh ls fdlh Hkh Language esa idM cuk ysrk gSA ysfdu blds fy, t:jh gS fd mls de ls de ,d Language esa dkQh tkudkjh gksA
tks yksx igys “C” ;k “C++” ;k nksuksa lh[k pqds gSa mUgsa Java dks lh[kus esa dksbZ ijs”kkuh ugha vkrh gS cfYd os mu yksxksa dh rqyuk esa T;knk tYnh ls Java dks lh[k ysrs gSa vkSj Java ij idM cuk ysrs gSa] ftUgksaus “C” ;k “C++” ugha lh[kh gSA vxj ge ,slk dgsa fd Java “C” o “C++” dk feyktqyk :i gS vkSj Java esa ls mu phtksa dks gVk fn;k x;k gS] ftudks “C” o “C++” Language esa lh[kus esa ijs”kkuh vkrh Fkh] rks xyr ugha gksxkA ysfdu bldk eryc ;s ugha gS fd Java dks lh[kus ls igys “C” o “C++” dks lh[kuk t:jh gSA gkykafd ;fn igys “C” o “C++” lh[kk tk, rks Java dks le>uk 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 c
blfy, ,d ckj fQj Programmers dks ;s eglwl gksus yxk fd mUgsa dqN vkSj vf/kd ljy rjhds dh t:jr gS] ftlls os cMs o tfVy Programs dks Handle dj ldsaA ;s u;k rjhdk Hkh t:jr ds vuqlkj Develop fd;k x;k vkSj bl rjhds dks Object Oriented Concept dgk x;kA bl Object Oriented Concept dks /;ku esa j[k dj Programming language “C” esa
15 Any Question or Suggestion, Just Discuss Here...
Java in Hindi fQj fodkl fd;k x;k vkSj bl fodkl dk ifj.kke “C++” Programming Language ds :i esa izkIr gqvkA gkykafd vkt Java dk ftl mn~ns”; ds fy, T;knkrj iz;ksx fd;k tk jgk gS vkSj tkok ftl izdkj dh Programming ds fy, tkuh tkrh gS] okLro esa Java dk fodkl blds fy, ugha fd;k x;k FkkA tkok dk fodkl General Electronic Equipments dks vf/kd le>nkj 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 c
s 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 c
;s ,sls Programs gksrs gSa ftUgsa Run gksus ds fy, Browser dh t:jr gksrh gSA ;s Programs Web Pages ij Run gksrs gSaA ,d Applet Program dHkh Hkh fdlh Local Machine ds Resources dks Access ugha djrk gSA
Servlet ;s Programs Web Servers dh Functionality dks c
;kuh lHkh Objects viuh lwpukvksa dk ,d nwljs ds chp Transaction dj ldrs gSaA OOPS esa nqfu;k dh gj pht dks Object ekuk tkrk gSA ekuyks fd ,d Worker Object Money Object dks CompanyFunds Object ls ysrk gS vkSj vius Lo;a ds BankAccount Object esa tek djokrk gSA ;fn nwljk dksbZ Worker Object DoublecheckFund Object dks Use djrk gS rks Polish Object dks cqyk;k tkrk gSA Java Program dh lcls cMh ;fn dksbZ fo”ks’krk gS] rks og ;s gS fd Java ds Program dks World Wide Web Pages ij Execute fd;k tk ldrk gSA bu Programs dks Applets dgrs gSaA Java ls igys HTML Format esa gh fofHkUu Web Pages dks fy[kk tkrk FkkA ;s Web Pages ,sls gksrs Fks] ftlesa ftl Page dks ns[kuk gks mlds Hyperlink ij Click djks vkSj nwljk Page ns[kuk gS rks mlds Hyperlink ij Click djks vkSj vkxs ls vkxs c
Java in Hindi tcfd Java Applet tks fd Web Pages ij Run gksrs gSa] vf/kd vPNk vuqHko iznku djrk gSA blesa User ds Response ds vuqlkj Web Page Dynamically Update gksrk gSA tSls vkt ge dbZ TV Channel ij ns[krs gSa tgka dksbZ loky iwNk tkrk gS vkSj yksx SMS Hkst dj viuk i{k crkrs gSaA tSls&tSls yksx SMS Hkstrs jgrs gSa] SMS dh la[;k Hkh cnyrh jgrh gSA ;s dke Dynamically gksrk gS tks fd Java ds dkj.k gh lEHko gqvk gSA vkt User Internet ij miyC/k fofHkUu izdkj ds Web Pages ls Java ds dkj.k gh Interact dj ldrk gSA ;fn bldk mnkgj.k ysuk pkgsa] rks Share Market dk lkjk dke Online gksrk gSA User tc pkgs vius Account dh Information dks izkIr dj ldrk gSA ;fn og fdlh Company dk Share [kjhnuk pkgrk gS] rks og Online [kjhn ldrk gSA tSls gh og Share [kjhnrk gS] ml Company ds Buyers dh la[;k c< tkrh gSA blh rjg ls ;fn Share dks cspk tkrk gS] rks Company ds Sellers dh la[;k c< tkrh gSA ;s tks ifjorZu Web Pages ds Data esa gksrk gS] og Dynamic ifjorZu dgykrk gSA ;kuh Web Page Dynamically ;k Run Time esa User ds Interaction ls Update gksrk gSA bl izdkj dh Secure Dynamic o Online lqfo/kk gesa Java ds dkj.k gh izkIr gks ik jgh gSA gkykafd Web Based Programs dh otg ls Java vf/kd egRoiw.kZ yxrh gS ysfdu ;s ,d General Purpose Language Hkh gS ftldk iz;ksx lHkh rjg ds Programs dks Develop djus esa gksrk gSA vkt ge Mobile ds ftrus Hkh Software ns[krs gSa muesa ls T;knkrj Java Based gSaA Mobile esa tks Games Run gksrs gSa os T;knkrj Java esa Develop fd, tkrs gSaA
Java – Working
tc Java ds fdlh Program dks Compile fd;k tkrk gS rc Java dk Program iwjh rjg ls Machine Language esa Convert ugha gksrk gS cfYd ,d Intermediate Language esa Convert gksrk gS] ftls Java Bytecodes dgk tkrk gSA ;s Codes Platform Independent gksrs gSa] blfy, bUgsa fdlh Hkh Operating System o fdlh Hkh Processor ij pyk;k tk ldrk gSA Java ds Program dh Compilation dsoy ,d gh ckj gksrh gS ysfdu ftruh ckj Hkh Java ds Program dks pyk;k tkrk gS] gj ckj ml Program dk Interpretation gksrk gSA bls ge fuEu fp= }kjk le> ldrs gSa&
Java Bytecodes dks ge Java Virtual Machine (Java VM) ds fy, Machine Codes eku ldrs gSaA gj Java Interpreter pkgs og Java Development Tool gks ;k dksbZ Browser tks fd Java Applets dks Run djrk gks] Java Virtual Machine dk gh Implementation gSA Java Virtual Machine dks Hardware esa Hkh Implement fd;k tk ldrk gS] ftldk ifj.kke vkt ds Mobile System Software gSaA
22 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Java Bytecodes gesa ;s lqfo/kk nsrs gSa fd ge Java ds Program dks ,d ckj Compile djsa vkSj dgha Hkh Run djsaA ge fdlh Java Program dks fdlh Hkh ml Computer ij Compile dj ldrs gSa ftl ij Java Compiler gksA fQj ml Java Program ds Bytecodes dks fdlh Hkh ml Computer ij Run fd;k tk ldrk gS ftl ij Java VM gksA
mnkgj.k ds fy, ,d gh Java Program Windows, OS/2 MacOS NT, Macintosh vkfn fofHkUu Platform ij Execute gks ldrs gSaA
Java Platform
Platform ,d ,d ,slk Software ;k Hardware Environment gksrk gS ftlesa dksbZ Program Run gksrk gSA Java Platform dbZ vU; Platforms ls vyx gSA Java Platform ,d Software Platform gS] tks lHkh vU; Hardware Based Platform ds Top ij ;kuh Åij Run gksrk gSA T;knkrj vU; Platforms Hardware o Operating System dk Combination
gksrs gSaA
Java Platform ds nks Components gSaA igyk gS Java Virtual Machine (Java VM) ftlds ckjs esa ge tku pqds gSaA ;s Java Platform dk Base ;k vk/kkj gS vkSj fofHkUu Hardware Base Platform ds Åij jgrk gSA nwljk gksrk gS Java Application Programming Interface (Java API) ftlds ckjs essa ge vc tkusaxsA Java API Ready Made Software Components dk ,d cgqr cMk Collection gS tks fd Programmer dks GUI (Graphical User Interface) tSlh dbZ mi;ksxh {kerk,a iznku djrk gSA Java API dks Related Components dh Libraries ds :i esa Group dj fn;k x;k gSA bu fofHkUu Related Components ds Group dks gh Packages dgrs gSaA ,d Java Program
dks ge fuEu fp=kuqlkj n”kkZ ldrs gSa%
tc ,d Java Program dks fdlh Computer ij Execute fd;k tkrk gS rks Java Program o Hardware Based Platform ds chp Java API o Java Virtual Machine dh Layer gksrh gSa tks Java ds Program dks Hardware Dependencies ls vyx djrh gSaA
23 Any Question or Suggestion, Just Discuss Here...
Java in Hindi ;kuh bu nksuksa dh otg ls Java dk dksbZ Program fdlh Hkh Computer ds Hardware ij fuHkZj ugha gksrk gSA ,d Platform Independent Environment ds :i esa Java dk Program vU; Native Codes Programs dh rqyuk esa dqN /khek gksrk gSA ysfdu fQj Hkh vPNs Compilers, Java ds lkFk vPNh rjg ls Tune gksus okys Interpreters vkSj Bytecodes Compilers dh otg ls Java dh Performance dks Native Code dh Performance ds vkl&ikl yk;k tk ldrk gS vkSj oks Hkh tkok dh lHkh fo”ks’krkvksa ds lkFkA Java Programs dk lcls vf/kd tkuk igpkuk ;fn dksbZ :i gS rks og Java Applets dk gSA ,d Applet Hkh ,d Java Program gh gksrk gS ysfdu bldh fo”ks’krk ;s gS fd ;s fdlh Java Enabled Browser tSls fd Internet Explorer, Google Chrome, Firefox, Safari, Opera vkfn esa Run gksrk gS] Lora= :i ls ;s Run ugha gks ldrkA tcfd Java Application Standalone Run gks ldrs gSaA Applets Application ds leku gh gksrs gSaA ,slk Hkh ugha gS fd Java dk iz;ksx dsoy Web Pages Applications fy[kus ds fy, gh fd;k tk ldrk gSA cfYd Java ,d Powerful Software Platform vkSj General Purpose High Level Programming Language Hkh gSA Java ds lcls Common Application Programs ds mnkgj.k Servers gSa tks fdlh Network ds fofHkUu Clients dks Service iznku djus dk dke djrs gSaA Web Servers, Proxy Servers, Mail Servers, Print Servers o Boot Servers Java Applications ds fofHkUu mnkgj.k gSaA Servlets Applets ds leku gh gksrs gS]a ysfdu fdlh Browser esa Run gksus ds ctk; ;s Java Servers esa Run gksrs gSa vkSj Java Server dh Configuring ;k Tailoring djrs gSaA
,d loky iSnk gks ldrk gS fd Java API bu lHkh izdkj ds Programs dks fdl izdkj ls Support djrk gSA bldk tokc ;s gS fd ;s bu lHkh izdkj ds Programs dks ,d Software Components ds Package ds ek/;e ls Support djrk gS ftlesa fofHkUu izdkj dh Functionalities gksrh gSaA Core API ,d ,slk API gS tks gj Java Platform esa iwjh rjg ls Implemented gksrk gSA Core API gesa fuEu Features iznku djrk gS& The Essentials:
Objects, strings, threads, numbers, input and output, data structures, system properties, date and time tSlh dbZ phtksa dks Handle djus dh lqfo/kk iznku djrk gSA
Applets:
Java applets cukus ds fy, fofHkUu Components iznku djrk gSA
Networking: Networking dh lqfo/kk izkIr djus ds fy, URLs, TCP o UDP sockets rFkk IP addresses iznku djrk gSA Internationalization: ;s gesa ,slh lqfo/kk iznku djrk gS fd ge ,sls Programs fy[k ldrs gSa tks lkjh nqfu;k esa leku :i ls py ldrk gSA 24 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Security: ;s gesa Low-level vkSj high-level nksuksa izdkj dh lqj{kk iznku djrk gSA lkFk gh electronic signatures, public/private key management, access control vkSj certificates dh Hkh lqfo/kk iznku djrk gSA Software components: ;s gesa JavaBeans tSls Components iznku djrk gS tks fdlh igys ls cus gq, Component Architecture esa tSls fd Microsoft's OLE/COM/Active-X architecture, OpenDoc vkSj Netscape's Live Connect esa Plug in gks ldrk gSA Object serialization: ;s gesa Remote Method Invocation (RMI) }kjk nwljs ljy midj.kksa ls Communication djus dh lqfo/kk iznku djrk gS] ftldk iz;ksx vkt Mobile Technology esa Hkh gks jgk gSA Java Database Connectivity (JDBC): ;s gesa Relational databases ls Connect gksus o mUgsa Access djus dh lqfo/kk iznku djrk gSA Java esa dsoy Core API gh ugha gSa cfYd dqN Standard Extensions Hkh gSaA ;s Standard Extensions 3D, Servers, Collaboration, Telephony, Speech, Animation o dbZ vU; phtksa ds fy, Hkh APIs Define djrs gSaA
Program
Computer Program ,d rjhdk gS tks Computer dks ;s crkrk gS fd mls dc, D;k djuk gSA Computer ds Boot gksus ls ysdj Shut Down gksus rd tks Hkh dqN gksrk gS] fdlh uk fdlh Program dh otg ls gksrk gSA MS-Word ,d Program gS] Norton Antivirus ,d Program gS] DOS Prompt ij fy[kk tkus okyk gj Command ,d Program gS] ;gka rd fd fofHkUu izdkj ds Computer Viruses Hkh ,d Program gSaA
vkt Artificial Intelligence dk ,d mnkgj.k Robots gSaA bu Robots dks vehj yksx vius ?kjksa esa j[krs gSaA ;s Robots ,sls gksrs gSa fd bUgsa tks dke djus ds fy, dg fn;k tkrk gS ;k fdlh rjhds ls crk fn;k tkrk gS] ;s Robots os lHkh dke cMh gh vPNh rjg ls dj ysrs gSaA tSls ;fn vki bu [kksyuk gSA rks ;s ftlesa vki fdlh ckr ekurk gS vkSj
Robots dks dgsa fd tc vkids ?kj dh Bell Ring gks rks bUgsa ?kj dk njoktk oSlk gh djrs gSaA ;s Computer Program dk ,d lk/kkj.k lk mnkgj.k gS futhZo Robot dks dqN Instruction nsrs gSa] vkSj og futhZo Robot vkidh
vkids }kjk crk;k x;k dke dj nsrk gSA
blh rjg ls Computer dks Hkh fofHkUu izdkj ds Instructions iznku fd, tkrs gSa] ftuds vuqlkj Computer dke djrk gSA tSls fd Microsoft Company us Windows ds Program
25 Any Question or Suggestion, Just Discuss Here...
Java in Hindi }kjk Computer dks ;s Instruction fn;k gS fd ;fn dksbZ Mouse dks Move djrk gS] rks Monitor dh Screen ij fLFkr Cursor ;k Pointer Hkh mlh rjg ls Move gksuk pkfg,A ;fn dksbZ Start Button ij Click djrk gS rks Start Menu Popup gksuk pkfg,] vkfn&vkfnA ;kuh Computer ij ge tks dksbZ Action djrs gSa] mls Response djus ds fy, igys ls gh Program fy[kk x;k gSA tc dksbZ Event gksrk gS] Computer ml Event ls lEcaf/kr Program ds vuqlkj dke djus yxrk gS vkSj gesa gekjk Required Result iznku djrk gSA Computer esa tks Hkh dqN gksrk gS mls Event dgrs gSaA tSls ;fn ge Mouse dks Move djrs gSa rks MouseMove Event Generate gksrk gS] ;fn ge Mouse ls Click djrs gSa rks MouseClick] Event Generate gksrk gSA blh rjg ls ;fn ge Keyboard ij dksbZ Key Press djrs gSa rks Keypress Event Generate gksrk gSA
;s rks Hardware Events ds mnkgj.k gSaA Computer esa Software Events Hkh Generate gksrs gSa ftUgsa Response djus ds fy, Hkh fofHkUu izdkj ds Programs fy[ks x, gSaA mnkgj.k ds fy, fdlh Window dks Minimize djuk] Restore djuk] fdlh Window dks Close djuk vkfn Software Events ds mnkgj.k gSaA fuEu Program nsf[k,& #include main() { printf("Hello Gopala"); }
bl Program }kjk ge gekjs Computer dks dsoy ,d Message Screen ij Print djus ds fy, ,d Instruction iznku dj jgs gSaA ;s Program Computer Screen ij “Hello Gopala” Print djrk gSA ge fdlh Computer Program esa ftruh Hkh Coding Lines fy[krs gSa] ;s lHkh Lines Program Statements dgykrh gSaA Computer mu lHkh Statements dks ,d fuf”pr Øe esa Handle djrk gS] Bhd mlh rjg ls ftl rjg ls ,d jlksbZ;k fdlh fo”ks’k izdkj ds idoku dks cukus ds fy, ,d fo”ks’k Øe dk ikyu djrk gSA pwafd Computer mlh Øe esa fofHkUu Statements ds vuqlkj dke djrk gS ftl Øe esa ,d Programmer fdlh Program dks fy[krk gSA blfy, ;fn dksbZ Program oSlk Result iznku ugha djrk] tSlk ,d Programmer pkgrk gS] rks ;s Computer dh xyrh ugha gS cfYd ml Program dh Mistake gSA T;knkrj Program mlh rjg ls fy[ks tkrs gSa] ftl rjg ls ge dksbZ Letter fy[krs gSa] ftlesa fdlh Word Processor esa ge gj Word dks Type djrs gSaA dqN Programming Languages ds Compilers ds lkFk muds [kqn ds Word Processors vkrs gSa] tSls fd Turbo C++ dk Program Creation dk iwjk IDE vkrk gS tcfd dqN Compilers ds lkFk dksbZ Word Processor ugha vkrkA ftu Compilers ds lkFk dksbZ Word Processor ugha vkrk ftlesa Program dh Coding dh tk lds] rks ,sls Program ds Source Code fy[kus ds fy, fdlh Hkh vU; Word Processor
26 Any Question or Suggestion, Just Discuss Here...
Java in Hindi dk iz;ksx fd;k tk ldrk gSA ge Java Developer Kit ds lHkh Components dk iz;ksx fdlh Hkh Word Processor tSls fd Notepad ;k WordPad ds lkFk dj ldrs gSaA tc ,d Program ds Source Codes fy[k fy, tkrs gSa] rks mlds ckn ml Source File dks ml Language ds Extension ds lkFk Save djuk gksrk gSA tSls ;fn ge Notepad dk iz;ksx djds “C” Language dk Program fy[krs gSa rks File dks Save djrs le; gesa File ds uke ds ckn .C Extension nsuk gksrk gSA mlh rjg ls ;fn ge Java ds Program dks Save djrs gSa] rks gesa File ds uke ds ckn .java Extension dk iz;ksx djuk gksrk gSA tSls Program.java, Application.java vkfnA ge tks Program fy[krs gSa os English ds dqN lkekU; Words gksrs gSaA ysfdu Computer dsoy Binary Language dks gh le>rk gSA blfy, gesa ,d ,sls Program dh t:jr gksrh gS tks gekjs Source Codes dks Computer ds le>us ;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
fd [kkuk [kkus okys esgekuksa dh la[;k lhfer gksA ysfdu ;fn esgekuksa dh la[;k vf/kd gks rks ;s rjhdk Bhd ugha dgk tk ldrk gSA
D;ksafd tc esgeku vf/kd gksaxs rks Table Hkh cMk gksxk vkSj [kkus ds fofHkUu lkeku iwjs Table ij dkQh nwj&nwj gksaxsA ,sls esa ;fn dksbZ esgeku fdlh nwj j[ks O;atu rd igqapus dh dksf”k”k djrk gS] rks gks ldrk gS fd dksf”k”k djrs le; mlds Shirt dh Sleeves fdlh nwljs esgeku ds [kkus esa pyh tk, ;k ,slk Hkh gks ldrk gS fd dbZ esgeku ,d lkFk fdlh ,d gh O;atu ij gkFk c
30 Any Question or Suggestion, Just Discuss Here...
Java in Hindi bl leL;k ds lek/kku ds :i esa ;fn dbZ NksVs&NksVs Tables gksa vkSj mu ij ,d lhfer ek=k esa esgeku gksa vkSj lcds ikl mudk viuk Hkkstu gks] rks ;s ,d vPNh O;oLFkk gks ldrh gSA bl NksVs Table ij lHkh esgeku fdlh Hkh O;atu ij vklkuh ls igqap ldrs gSaA ;fn dksbZ esgeku fdlh vU; Table ij j[ks fdlh O;atu dks ysuk pkgrk gS rks lEHkor;k og fdlh vU; esgeku ls ml O;atu dks ykus ds fy;s dg ldrk gSA ;s rjhdk Object Oriented Programming dk gS ftlesa gjsd NksVh Table dks ,d Object dgk tk ldrk gSA gjsd Object esa mldk Lo;a dk Data vkSj Data ij Perform gksus okyk Operation ;k Function gksrk gSA Data o Operations ds chp gksus okys fofHkUu ysu&nsu vf/kdrj Object ds vUnj gh gksrs gSa ysfdu vko”;drkuqlkj ;s Hkh lEHko gS fd fdlh vU; Object ds Data dks Hkh Use fd;k tk ldsA pwafd ,d Object ds Data dks dsoy ogh Object Access dj ldrk gS] blfy, ;fn fdlh Object A ds Data dks dksbZ nwljk Object B Access djuk pkgrk gS] rks og Object B Object A ls Data dks Access djus ds fy, dgrk gSA bl izfØ;k dks Message Passing djuk dgrs gSaA Object A Object B dh Request dks iwjk djrk gS vkSj vius Data dks Access djds djus ds fy, ml nwljs Object B dks ns nsrk gSA
Difference Between C++ and Java
okLro esa Java “C” o “C++” dk gh Modified :i gSA pwafd vkt Hkh T;knkrj Professional yksx cMs Projects ds fy, “C++” dks gh pqurs gSa] blfy, ;s tkuuk t:jh gS fd Java esa “C++” dh fdu fo”ks’krkvksa dks fy;k x;k gS vkSj fdu phtksa dks NksMk x;k gS tks lkekU; Programmer dks ijs”kku djrh gSaA Preprocessor “C” o “C++” esa Program ds Compilation dks Control djus ds fy, Preprocessors dk iz;ksx fd;k tkrk gSA “C++” dk Compiler fdlh Hkh Source Program dks Compile djus ls igys lHkh Preprocessor Directives dks Expand djus dk dke djrk gSA lHkh “C” o “C++” ds Programmers tkurs gSa fd Preprocessors dk iz;ksx djus ij Program dh tfVyrk c< tkrh gSA “C++” ds Programmer Preprocessors dk iz;ksx djds yxHkx Lo;a dh Language cukuk “kq: dj nsrs gSaA T;knkrj Statement ds fy, o Constant ekuksa ds fy, os Preprocessors dk iz;ksx djrs gSaA blls Program dh tfVyrk bruh c< tkrh gS fd dksbZ Hkh u;k Programmer ;fn ml Program dks le>uk pkgs rks mls dkQh ijs”kkuh vkrh gSA lkFk gh bu Program Codes dks Reuse Hkh ugha fd;k tk ldrk gSA Preprocessor Directives dh ,d deh ;s Hkh gS fd budh Type Checking dHkh Hkh fuf”pr ugha gksrhA ;kuh ;s gesa”kk ,d String Format dks Follow djrs gSaA ;fn ge #define MAX 10 Statement fy[krs gSa] rks ;gka eku 10 Integer ugha cfYd ,d String gksrk gSA Java esa Preprocessors dks gVk fn;k x;k gSA gkykafd Java Preprocessor Directives ds leku gh Functionality iznku djrk gS ysfdu vf/kd Control ds lkFkA Java esa #define ds LFkku ij Constant Data Members dk iz;ksx fd;k tkrk gSA
31 Any Question or Suggestion, Just Discuss Here...
Java in Hindi bldk ifj.kke ;s gS fd Java ds Codes dks iuk “C++” ds Codes dks ius dh rqyuk esa vf/kd ljy gks tkrk gSA lkFk gh Java ds Programs esa Header Files dk iz;ksx ugha gksrk gS cfYd Java dk Compiler Source Code File ls lh/ks gh Class Definitions cuk ysrk gS ftlesa Class Definitions o Methods nksuksa gksrs gSaA Pointers ftrus Hkh “C” ;k “C++” ds Programmers gSa] os lHkh ekurs gSa fd ;fn Pointers dks iwjh lko/kkuh ls iz;ksx uk fd;k tk, rks ,sls Errors Generate gksrs gSa] ftUgsa Debug djus esa fnekx dk ilhuk fudy tkrk gSA lkFk gh Pointers ds iz;ksx ls Program gesa”kk le>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
Software Programming Computer dks dke djus yk;d voLFkk esa ykus ds fy, ftl Software dks cuk;k tkrk gS] mls Operating System Software dgk tkrk gSA BIOS Chip dk dke iwjk gksus ds ckn Computer dk iwjk Control Operating System Software ds ikl vk tkrk gSA Computer ds ikl BIOS ls Controlling vkus ds ckn lcls igys Memory esa Load gksus okyk Software Operating System Software gh gksrk gSA bls Master Software ;k Operating System Software Hkh dgrs gSaA vkt fofHkUu izdkj ds Operating System Software cu pqds gSa tSls DOS, Windows, OS/2, WRAP, Unix, Linux vkfnA bu lHkh Software dk eq[; dke Computer dks Boot djds User ds dke djus ;ksX; voLFkk esa ykuk gksrk gSA nwljh Programming og Programming gksrh gS] ftlls Computer gekjh ckr dks le>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 i
Main Method Class tkok ds gj Application Program esa gesa ,d Main() Method dh t:jr gksrh gS] ftldks tkok Compiler lcls igys Execute djrk gSA ;s fdlh Hkh tkok Application Program dk ,d cgqr gh t:jh fgLlk gSA fdlh Simple tkok Program esa dsoy ;s ,d Method Hkh gks ldrk gSA Main Method fofHkUu izdkj dh Classes ds Objects Create djrk gS vkSj muds chp esa Communication dks Establish djrk gSA Main Method ds vUr esa igqapus ij Program Terminate gks tkrk gS vkSj Program Control iqu% Operating System dks Transfer gks tkrk
gSA
Definition – The Applet and Application
tkok esa ge nks rjg ds Programs Develop dj ldrs gSaA igys Program os Program gksrs gSa tks fdlh ,d Computer ij Execute gksrs gSa vkSj fdlh leL;k dk lek/kku iznku djrs gSaA ;s Programs ftl Computer ij Store gksrs gSa mlh Computer ij Run gksrs gSa vkSj ml Computer ds Resources dks Use djrs gSaA
44 Any Question or Suggestion, Just Discuss Here...
Java in Hindi bl izdkj ds Programs dks Application Programs dgrs gSaA tcfd tkok esa ftl nwljs izdkj ds Program dks Develop fd;k tk ldrk gS] mu Programs dks Run gksus ds fy, tkok Platform Enabled Web Browser dh t:jr gksrh gSA ;kuh ;s os Programs gksrs gSa tks fdlh uk fdlh Web Page esa Run gksrs gSa vkSj bUgsa mi;ksx esa ysus ds fy, gesa Web Browser dh t:jr gksrh gSA tkok esa Develop fd, tkus okys bl nwljs izdkj ds Programs dks Java Applets dgrs gSaA
Java - Applications tkok bruk l{ke gS fd ge blesa Professional Applications Develop dj ldrs gSaA ge blesa fofHkUu izdkj ds Window Based Applications cuk ldrs gSa vkSj mUgsa lQyrk iwoZd mi;ksx esa ys ldrs gSaA ysfdu pwafd tkok ,d Interpreted Language gS] blfy, blds Programs dh Speed “C” o “C++” Languages esa Develop fd, x, Applications dh rqyuk esa de gksrh gSA blfy, lkekU;r;k tkok Based Applications rHkh cuk, tkrs gSa] tc Application Distributed gks o Network ij Execute gksrk gksA D;ksafd tkok Internet ds fy, ,d cgqr gh vPNh o Powerful Programming Language blfy, blesa Desktop Applications ugha cuk, tkrs gSaA D;ksafd Desktop Applications fy, Visual Basic, “C” o “C++” Programming Languages dkQh vPNh Languages blfy, tkok dk iz;ksx lkekU;r;k Web Pages ds Applets cukus ds fy, fd;k tkrk ftlds ckjs esa ge vkxs foLrkj ls le>saxsA
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
;s Line Computer dks dgrh gS fd | | “Program dk Main Part ;gka ls “kq: gks jgk gSA”
||
Java dk Program dbZ Sections esa Organized jgrk gS] blfy, gesa ,d ,sls rjhds dh t:jr gksrh gS ftlls ;s irk py lds fd Program dk dkSulk fgLlk igys Handle gksxk vkSj
49 Any Question or Suggestion, Just Discuss Here...
Java in Hindi dkSulk ckn esaA ;gka ls vkxs ge ftrus Hkh Application Programs Create djsaxs] mu lHkh esa main Part gh Starting Point gksxkA Bracket Mark
ge ns[k ldrs gSa fd gekjs Program esa Brackets dk Hkh iz;ksx gqvk gSA ;s Bracket fdlh Hkh Java Program dk cgqr gh egRoiw.kZ fgLlk gSaA Java esa ;s Bracket Program ds fofHkUu fgLlksa dks Group djus dk rjhdk gSA Bracket dh rjg gh Parenthesis dk Hkh iz;ksx fd;k tkrk gSA Opening Bracket o Closing Bracket ds chp tks dqN Hkh fy[kk tkrk gS] og lcdqN ml Group dk fgLlk gksrk gSA Opening o Closing Bracket ds chp fy[ks Statements dks Block dgk tkrk gSA
ge gesa”kk gekjs Program ds fofHkUu fgLlksa dh “kq:vkr dks n”kkZus ds fy, Opening Bracket “{“ dk iz;ksx djrs gSa vkSj fdlh fo”ks’k fgLls dk vUr n”kkZus ds fy, Closing Bracket “}” dk iz;ksx djrs gSaA ,d Block ds vUnj nwljs Block dks Use fd;k tk ldrk gS] tSlkfd gekjs Program esa HelloWorld Class ds Block esa Main() Method ds Block Use fd;k x;k gSA main() Method Block ds vUnj tks Hkh Statement fy[ks tkrs gSa] os lHkh Statements Computer ds fy, Instructions ;k Commands gksrs gSa ftUgsa Computer Execute djrk gSA geus main() Method esa fuEukuqlkj dsoy ,d gh Statement fy[kk gS& System.out.println(“Hello World”);
//Display this String
;s Statement Screen ij ml Data ;k Information dks Print dj nsrk gS] ftls bl Statement ds Parenthesis esa fy[kk tkrk gSA tSls ;fn ge “Hello World” ds LFkku ij “Java Is a Web Language” fy[k nsa] rks Hello World ds LFkku ij ;gh Statement Screen ij Print gksxkA tc fdlh Characters ds ,d lewg dks Double Quote ds chp fy[kk tkrk gS] rks bl Characters ds lewg dks String dgk tkrk gSA ;kuh “Hello World” o “Java Is A Web Language” nksuksa Strings gSa] D;ksafd ;s Characters dk ,d lewg gSa ftUgsa Double Quote ds chp fy[kk x;k gSA bl rjg ls geus Java dk ,d lk/kkj.k lk Program cuk;kA gesa blh rjg ls tkok esa fofHkUu Programs Develop djus gksrs gSaA ge pkgs tks Hkh Program cukuk pkgsa] gesa fuEu Statements rks gesa”kk fy[kus gh gksrs gSa tks Compiler dks crkrk gS fd Program dh “kq:vkr o vUr dgka ij gks jgk gSA public class ClassName //Name of the Class of the Java Program { //Starting of Program Level Class Block //Other program specific statements } //End of the Program Level Class Block Javac Compiler ls ge fdlh Hkh Java Class dks Compile dj ldrs gSa] ysfdu java Interpreter ls ogh Class Command Prompt ij Run gksrh gS] ftlesa main() Method gksrk
50 Any Question or Suggestion, Just Discuss Here...
Java in Hindi gSA blfy, ftl Class esa main() Method gksrk gS] ml Class dk uke gh ml Class dh Source File dk uke Hkh gksuk t:jh gksrk gSA pwafd tkok ,d Highly Case Sensitive Language gS] blfy, ftl izdkj dk uke ge Class dk fy[krs gSa] mlh rjhds dk uke gesa Source File dk Hkh j[kuk gksrk gSA lkFk gh Source File dk uke gesa”kk .java Extension ds lkFk fy[kk tkrk gS] rHkh javac Compiler mls Compile dj ldrk gSA gesa gekjs Program ds ftrus Hkh Codes fy[kus gksrs gSa] os lHkh Codes ;k Statements gesa Class Block ds vUnj gh fy[kus gksrs gSaA
Java – Applet
tkok Applet Internet Computing esa Use fd, tkus okys NksVs&NksVs Programs gksrs gSaA bu Programs dks ,d Computer ls nwljs Computer esa Internet ij Transport fd;k tk ldrk gS vkSj Applet Viewer ;k fdlh Java Enabled Web Browser }kjk Run fd;k tk ldrk gSA fdlh Hkh vU; Application Program dh rjg gh ,d Applet Hkh gekjs fy, dbZ t:jh dke dj ldrs gSaA mnkgj.k ds fy, Applet fofHkUu izdkj ds Arithmetical Operations Perform dj ldrs gSa] Applet esa fofHkUu izdkj ds Graphics Display gks ldrs gSa tks fd Web Page ij fn[kkbZ nsrs gSa] ;s Applets fofHkUu izdkj ds Sounds Play dj ldrs gSa vkSj Browser esa fofHkUu izdkj ds Animations Display dj ldrs gSaA ;kuh ,d Web Browser esa Java Applets dks Use djds ge fdlh Web Site esa Multimedia dks Use djds Web Page dks vf/kd mi;ksxh] Informative, ljy] Interactive o Dynamic cuk ldrs gSaA tkok ds dkj.k gh ge Internet ds vkt ds Lo:i dks ns[k ldrs gSa ftlesa
Applet – Local and Remote fdlh Applet dks ge Web Page esa nks rjhdksa ls Embed dj ldrs gSaA igys rjhds esa ge gekjk Lo;a dk Web Page cukrs gSa vkSj mlesa Applet dks Embed dj nsrs gSaA nwljs rjhds esa ge fdlh Applet dks fdlh Remote Computer System ls Download djrs gSa vkSj fQj mls vius Web Page esa Embed dj ysrs gSaA
51 Any Question or Suggestion, Just Discuss Here...
Java in Hindi ,d ,slk Applet ftls Local Computer ij Develop fd;k x;k gks vkSj mlh Local System ij ml Applet dks Store fd;k x;k gks] rks bl izdkj ds Applet dks Local Applet dgrs gSaA tc ,d Local Web Page fdlh Local Applet dks [kkstrk gS] rc mldk Internet ls Connected jguk t:jh ugha gksrk gSA ,slk Web Page lkekU;r;k Local Computer dh fofHkUu Directories dks Search djds Applet dks [kkstrk gS vkSj Web Page esa Load dj nsrk gSA Remote Applet ,slk Applet gksrk gS ftls fdlh vU; Developer us Develop fd;k gksrk gS vkSj fdlh ,sls Computer System ij Store fd;k gksrk gS tks fd Internet ls Connected gksrk gSA ;fn gekjk Computer Internet ls Connected gks rks ge ml Remote Applet dks Internet }kjk Download djds vius Local Computer System ij Run dj ldrs gSaA
fdlh Remote Computer ij j[ks Remote Applet dks [kkstus o vius Computer System ds Web Browser esa Load djus ds fy, gesa ml Applet ds Web Address dh tkudkjh gksuk t:jh gksrk gSA fdlh Applet ds bl Web Address dks Uniform Resource Locator (URL) dgrs gSa vkSj bl Address dks gesa gekjh HTML File esa APPLET Tag ds CODEBASE Attribute ds ,d eku ds :i esa Specify djuk gksrk gSA ge fdlh Remote Applet dks viuh HTML File esa fuEu Code Statement }kjk Specify dj ldrs gSa% CODEBASE = http:// www.achyut.com/applets
ysfdu tc ge Local System ij fdlh Applet dks Locate djuk pkgrs gSa] rc bl CODEBASE Tag esa gesa gekjs Applet ds Local Address ;kuh Applet dk Directory Path nsuk gksrk gSA Clients and Servers ;fn fdlh User dks fdlh Applet dh t:jr gS vkSj og Applet mlds Computer ij miyC/k ugha gS] rks og User ml Applet dks fdlh Remote Computer ls izkIr djds Use dj ldrk gSA mls ;s tkuus dh t:jr ugha gksrh gS fd og Applet fdl Remote Computer ij fLFkr gS ;k fdl rjg ls cuk gSA ,d rjg ls ns[kk tk, rks ,d User Internet }kjk iwjh nqfu;ka ds Computers ls tqM tkrk gS vkSj ftl izdkj dh lwpuk pkgs ml rjg dh lwpuk dks Internet ls Applet ds :i esa izkIr dj ldrk gSA Information Technology (I.T.) dh Hkk’kk esa dgsa rks ftl Computer ls User dks lwpuk,a Applet ;k Web Pages ds :i esa izkIr gksrh gSa] ml Remote Computer dks Server dgrs gSa vkSj User dk Local Computer tks fd Applet ;k Web Pages }kjk fdlh izdkj dh Information dks Server ls izkIr djuk pkgrk gS] mls Client dgrs gSaA
bl rjg ls ,d Local Computer ds Browser o ,d Remote Computer ls vkus okys Applet dh Information ds chp esa Client/Server dh Relationship cu tkrh gSA bl fLFkfr esa Client og gksrk gS] tks Web Page ds HTML Documents dks vius Local Computer ij Download djrk gS] tcfd Server og gksrk gS] tks Web Pages dks Client ds Computer ij Upload djrk gSA User dk Computer gesa”kk Client ugha gksrk gS vkSj Remote Computer gesa”kk Server ugha gksrk gSA dc dkSulk Computer Client gksxk vkSj dc dkSulk Computer Server gksxk] ;s bl ckr ij fuHkZj gksrk gS fd fdlh le; dkSulk Computer fdl rjg dk dke dj jgk gSA
52 Any Question or Suggestion, Just Discuss Here...
Java in Hindi mnkgj.k ds fy, tc ,d User fdlh Web Site dk Address vius Browser esa Fill djds Internet ls ml Web Page dks ns[kuk pkgrk gS] ml le; og Web Page ftl Computer ij gksrk gS] og Remote Computer Server gksrk gS vkSj User dk Local Computer Client gksrk gSA ysfdu tSls gh Web Page User ds Computer esa Download gks tkrk gS vkSj User fdlh vU; Web Page dks Search djus ds fy, fdlh Search Engine esa dqN Texts Input djrk gS] oSls gh User dk Computer Server cu tkrk gS vkSj File dks Search djus okyk Program Client cu tkrk gSA
Difference – Applet and Application
Applications o Applets nksuksa gh tkok Programs gksrs gSa] ysfdu nksuksa gh izdkj ds Programs esa dqN vUrj gksrk gSA Applets dHkh Hkh Full Featured Application Programs
ugha gksrs gSaA lkekU;r;k bUgsa fdlh NksVs ls dke dks iwjk djus ds fy, fy[kk tkrk gSA pwafd bUgsa Internet ij Run djus ds fy, Design fd;k x;k gS] blfy, budh Design dh dqN lhek,a gSaA Applets esa Codes ds Initialization ds fy, main() Method ugha gksrk gSA tc Applets Web Browser esa Load gksrs gSa] rc Applet ds Codes Automatically Applet Class ds dqN Methods dks Call djds Applet dks Start o Execute djrs gSaA Applications dh rjg Applets Lora= :i ls Run ugha gks ldrs gSaA bUgsa Run gksus ds fy, Web Page dh t:jr gksrh gS] ftlesa dqN Codes fy[k dj Applets dks HTML Web Page esa Embed fd;k tkrk gSA Applets dHkh Hkh Local Computer ds Resources dks iwjh rjg ls Access ugha dj ldrs gSaA ;kuh Applets }kjk ge fdlh Local Computer dh fdlh File esa Data dks Write ugha dj ldrs gSa vkSj uk gh Local Computer ij miyC/k fdlh File ds Data dks Read dj ldrs gSaA Applets, Network ij miyC/k fdlh vU; Server ls fdlh izdkj dk dksbZ Communication
ugha dj ldrs gSaA
Applets fdlh Local Computer ds fdlh Program dks Run ugha dj ldrs gSaA
Preparation – The Applet Writing tkok Applet Programs fy[kus ls igys gesa blds fy, dqN rS;kfj;ka dj ysuh pkfg,A lcls igys rks gesa ;s r; djuk gksrk gS fd fdlh Program esa tkok Applet dks dc Use djuk pkfg,A bldk tokc fuEukuqlkj gS% 1 tc gesa gekjs Web Page esa dqN Multimedia Operations dks Perform djuk gks o vius Web Page dks Dynamic o Interactive cukuk gks] rc gesa vius Web Page esa Java Applet dks Use djuk pkfg,A
53 Any Question or Suggestion, Just Discuss Here...
Java in Hindi mnkgj.k ds fy, Share–Market dks gh ysrs gSaA tc Trading gks jgh gksrh gS] rc gj {k.k fofHkUu Shares dh dherksa esa Change gksrk jgrk gSA bu dherksa ds vk/kkj ij fofHkUu izdkj ds Dynamic Graph cuk, tkrs gSaA bu fofHkUu izdkj ds Graphs dks Computer esa Web Page ij Dynamically rHkh n”kkZ;k tk ldrk gS] tc ge Web Page esa Multimedia dks Use djsa vkSj Web Page ij Multimedia Use djus dh lqfo/kk gesa tkok Applet }kjk izkIr gksrh gSA 2 tc gesa gekjs Web Page esa dqN Flash Outputs iznku djus gksrs gSa] rc Hkh gesa Java Applets dks Use djuk t:jh gks tkrk gSA tSls ekuyks fd gekjs Web Page dks ;fn dksbZ Hacker Hack djus dh dksf”k”k djs] rks Web Page ls ,d fo”ks’k izdkj dh Sound Play gksuh pkfg,] vkSj Web Page ds dqN Matters Blink gksus pkfg, ;fn ge gekjs Web Page esa bl izdkj dh lqfo/kk pkgrs gSa] rks gesa gekjs Web Page esa Java Applet dks Use djuk pkfg,A 3 tc ge fdlh Program dks Develop djrs gSa vkSj mls vU; Users ds mi;ksx ds fy, Internet ij miyC/k djokuk pkgrs gSa] rc gesa tkok Applet dk mi;ksx djuk pkfg,A
System Package – Predefined (Built-In) Library of Java Classes Reusability Object Oriented Programming System (OOPS) dk ,d egRoiw.kZ Concept gSA bl Concept ds vUrxZr ge fdlh dke dks djus ds fy, ftl Coding dks ,d ckj fy[k nsrs gSa] ml Coding dk iz;ksx ckj&ckj dj ldrs gSaA tkok ,d iw.kZ Object Oriented Programming Language gS] blfy, tkok esa ge OOPS ds bl Concept dks iwjh rjg ls Apply dj ldrs gSa vkSj fofHkUu izdkj ds Common Program Codes dks bl rjg ls fy[k dj Store dj ldrs gSa] ftUgsa fcuk nqckjk fy[ks ;k Modify fd, T;ksa dk T;ksa fQj ls Use dj ldsA tkok esa bl dke dks ftl Concept ds vk/kkj ij Perform fd;k tkrk gS] mls Package dgrs gSaA Package dks ge ,slh Classes dh Library Hkh dg ldrs gSa] ftUgsa ckj&ckj Use fd;k tk ldrk gSA ;fn nwljs “kCnksa esa dgsa rks dg ldrs gSa fd Particular fdlh ,d dke dks djus ls lEcaf/kr lHkh Classes dks ;fn ,d Group ds :i esa ifjHkkf’kr djds Store dj fn;k tk,] rks tkok esa bl Classes ds bl Group dks Package dgrs gSaA ;kuh ,d Package ,d gh dke ls lEcaf/kr fofHkUu izdkj dh Classes dk ,d Container gksrk gSA Java API (Application Programming Interface) Programmer dks Application Development ls lEcaf/kr fofHkUu izdkj ds Predefined Components iznku djrk gSA bu fofHkUu izdkj ds Predefined Components (Program Codes) dks muds dke ds vk/kkj ij fofHkUu izdkj ds Group esa foHkkftr fd;k x;k gS] ftUgsa Package dgrs gSaA
tkok esa ge tks Hkh Program cukrs gSa] muesa fofHkUu izdkj dh Predefined Classes dks Use djrs gSa] tks fd fdlh uk fdlh Package dk fgLlk gksrs gSa vkSj ;s lHkh Packages Java API
54 Any Question or Suggestion, Just Discuss Here...
Java in Hindi ds fgLls gSaA blfy, ge Directly ;k Indirectly Java API dks Use djds gh viuk Program cukrs gSaA ;fn ge lkjka”k esa dgsa rks dg ldrs gSa fd Java gesa dqN Built-In ;k Predefined Classes iznku djrk gS] ftUgsa ge fcuk fdlh izdkj dk Modification fd, T;ksa dk R;ksa vius Program esa Reuse dj ldrs gSaA bu Predefined Classes dks mudh Functionality ds vk/kkj ij Group esa Store fd, x, gSa] ftUgsa Packages dgrs gSa vkSj ;s fofHkUu izdkj ds Packages Java API ds fgLls gSaA blfy, ;fn ge fdlh Java Package dks vius Program esa Use djuk pkgsa] rks gesa ml Package dks vius Program esa Use djuk t:jh gksrk gSA
Using – The System Packages tkok esa fofHkUu izdkj ds Packages dks Hierarchical Structure esa Organize fd;k x;k gSA fofHkUu izdkj dh Classes fofHkUu izdkj ds Packages esa Stored jgrs gSa vkSj fofHkUu izdkj ds Packages Java API uke ds Java Platform ds fgLls gSaA bl fuEukuqlkj fp= }kjk ljyrk ls le> ldrs gSa%
fofHkUu izdkj dh Required Classes dks muds Package ls vius Program esa Reuse djds Access djus ds nks rjhds gSaA igyk rjhdk ;s gS fd vius Program esa ftl Class dh t:jr gS mlh Class dks vius Program esa Include fd;k tk,A dsoy Required Class dks gh vius Program esa Include djus ds fy, gesa ml Class dk iwjk Qualified uke fy[kuk t:jh gksrk gSA mnkgj.k ds fy, eku yks fd gesa gekjs Program esa awt Package ds dsoy Color Class o Font Class dh t:jr gS] rks dsoy bu nksuksa Class dks vius Program esa Reuse djus ds fy, gesa fuEu fuEukuqlkj Statement fy[kuk gksxk% import import
java.awt.Color ; java.awt.Font ;
ge tkurs gSa fd lHkh izdkj ds Packages Java API dk fgLlk gSa] blfy, gesa ftl fdlh Hkh Package dh Class dks Use djuk gks] Java ds lkFk ml Package ds uke dks Dot Operator ds lkFk fy[kuk gksxkA
55 Any Question or Suggestion, Just Discuss Here...
Java in Hindi gkykafd awt Package esa dbZ Classes o Subclasses gSa] ysfdu gesa dsoy Color Class ds Codes o Font Class ds Codes dks gh vius Source Program esa Reuse djuk gS] blfy, geus Package ds uke ds lkFk ml Required Class ds uke dks Dot Operator }kjk Specify dj fn;k gSA gekjs Source Program esa fdlh Predefined Class ds Codes dks Include djus dk dke import uke dk “kCn djrk gS] tks fd Java dk ,d Keyword ;k Reserve Word gSA Keyword / Reserve Word Keyword ;k Reserve Word dqN ,sls “kCn gksrs gSa] ftudk tkok Compiler ds fy, fo”ks’k vFkZ gksrk gSA tc Hkh ge gekjs Program esa fdlh Keyword dks Use djrs gSa] tkok Compiler ml Keyword ds fy, fu/kkZfjr dke djus ds fy, ck/; gks tkrk gSA mnkgj.k ds fy, ;fn ge import Statement dks gh ysa] rks tkok Compiler dks tSls gh import Keyword izkIr gksrk gS] og ml Predefined Program Code dks Source Program esa Reuse dj ysrk gS] ftldk uke bl Keyword ds ckn fy[kk x;k gksrk gSA ;fn gesa gekjs Program esa Particular fdlh ,d gh Class dks Use djuk gks] rks mijksDr rjhds ls ml Class dks vius Source Program esa Reuse fd;k tk ldrk gSA ysfdu ;fn gesa Particular fdlh ,d Class dh ugha cfYd fdlh Package dh lHkh Classes dh vius Source Program esa t:jr gks] rks gesa * Operator dk fuEukuqlkj iz;ksx djuk t:jh gksrk gS% import import
java.awt.* ; java.applet.*.
tc ge bl rjg dk Statement fy[krs gSa] rks bldk eryc gksrk gS] fd ge awt Package dh lHkh Predefined Classes dks vius Source Program esa Reuse djus ds fy, Import dj jgs gSa] tks fd Lo;a java uke ds Package esa miyC/k gSA blh rjg ls nwljs Statement }kjk ge applet Package dh lHkh Classes dks vius Program esa fcuk fQj ls fy[ks gq, Use dj jgs gSa] tks fd Lo;a java uke ds Package esa miyC/k gSA bl rjg ls ge nks rjhdksa ls fdlh igys ls cuh Class dks mldh Class Library }kjk Access djds vius Program esa Use dj ldrs gSaA ;fn ge pkgsa rks fcuk import Keyword dk Use fd, gq, Hkh fdlh Predefined Package ds fdlh Class dks Directly Access dj ldrs gSaA blds fy, gesa Class dks Access djrs gh mldk Object Create djuk t:jh gksrk gSA ;kuh
java.awt.Button OKBtn;
bl rjg ls ge gekjs Program esa fcuk import Statement dk iz;ksx fd, gq, Hkh Predefined Button Class dks Use dj ldrs gSa] ysfdu ;s Class dsoy OKBtn Object ds fy, gh mi;ksxh gksxhA ;s Button Create djds gekjs Program ls fQj ls Invisible gks tk,xhA blfy, import Statement dk iz;ksx djds bls vius Program esa Use djuk Bhd jgrk gS] vU;Fkk gesa gj Class dk iwjk Path /;ku j[kuk t:jh gks tkrk gSA
56 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Building – The Applet Code Applets dks dHkh Hkh Console Mode esa Run ugha fd;k tk ldrk gSA ;s gesa”kk fdlh uk fdlh Browser Window esa ;k fQj ,d Special Program ftls Applet Viewer dgrs gSa] esa gh Run gksrs gSaA pwafd lHkh Java Applets Graphical gksrs gSa] blfy, bUgsa GUI Mode esa gh Run fd;k tk ldrk gSA tkok esa Graphical User Interface cukus ds fy, AWT (Abstract Windowing Toolkit) uke dh ,d Class Library ;k Package gS] ftlesa Applet ij Graphics Display djus ls lEcaf/kr fofHkUu izdkj dh Classes dks ifjHkkf’kr fd;k x;k gSA pwafd gj Applet ,d Window esa Run gksrk gS] blfy, gj Applet ds fy, gesa Window Support dks izkIr djuk t:jh gksrk gS vkSj Window Creation o Management ls lEcaf/kr tkok dh ftruh Hkh Classes gSa] os lHkh Classes AWT uke ds Package esa miyC/k gSa] blfy, gesa bl Package dks vius gj Applet Program esa Include djuk t:jh gksrk gSA pwafd fdlh Applet dks gesa”kk GUI Form esa gh Display fd;k tk ldrk gS] blfy, fdlh Applet dks GUI Form esa Display djus ds fy, ftu Functionality dh t:jr gksrh gS] mUgsa applet uke ds ,d Package esa Predefine dj fn;k x;k gS] ftUgsa ge fcuk Extra Coding fd, gq, T;ksa dk R;ksa Reuse dj ldrs gSaA vr% ;fn ge Applet Development dj jgs gSa] rks gesa bl Package dks Hkh vius Source Program esa Import djuk t:jh gksrk gS rkfd ge Applet ls lEcaf/kr lkekU; Functionality dks izkIr dj ldsaA bl izdkj ge le> 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
leL;k ls lEcaf/kr egRoiw.kZ Objects igpkuus ds ckn gesa mu Objects ds mu Attributes dks izkIr djuk gksrk gS] tks leL;k ls lEcaf/kr gksaA pwafd ,d Bank Account o ,d Customer nksuksa ds gh fofHkUu izdkj ds Attributes gks ldrs gSa vkSj ;s t:jh ugha gS fd lHkh Attributes leL;k dks Represent djus ds fy, mi;ksxh gksaA blfy, gesa fdlh Object ds leL;k ls lEcaf/kr t:jh Attributes izkIr djus ds fy, leL;k dk Abstraction djuk gksxkA fdlh leL;k ls lEcaf/kr lcls egRoiw.kZ Object ds leL;k ls lEcaf/kr lcls egRoiw.kZ Attributes izkIr djus dk ;kuh Abstraction djus dk lcls vPNk rjhdk ;s gS fd ge ;s irk djsa fd gekjh leL;k esa Object D;k Operation Perform djsxkA ;kuh Object dke D;k djsxk\ ge tkurs gSa fd dksbZ Object tc Hkh dksbZ dke djrk gS ;k Operation Perform djrk gS] rks fdlh uk fdlh rjhds ls og vius gh fdlh Attribute ds eku esa ifjorZu djrk gSA blfy, ;fn gesa ;s irk py tk, fd gekjh leL;k esa gekjk Object vius fdu Attributes ds ekuksa esa ifjorZu djsxk] rks ge mu ifjofrZr gksus okys ekuksa dks Store djus okys Attributes dks Object 65 Any Question or Suggestion, Just Discuss Here...
Java in Hindi ds t:jh Abstract Attributes ds :i esa ifjHkkf’kr dj ldrs gSa] ;kuh Object ds t:jh Data Members dk irk yxk ldrs gSaA ;fn dksbZ Object dksbZ ,slk Operation Perform djrk gS] ftlls Object ds fdlh Hkh Attribute ds eku esa dksbZ ifjorZu ugha gksrk gS] rks le> 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 << 4 )
=
( 0000000000000001 << 0000000000010000 ) =
16
ge ns[k ldrs gSa Left Shift Operator Bit 1 dks pkj Bit Left esa Shift dj jgk gS] ftlls eku 1 dk eku cny dj eku 16 gks tkrk gSA blh rjg ls 16 ij ge Right Shift Operator dk fuEukuqlkj iz;ksx dj ldrs gSa& ( 16 >> 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
tc tkok ds fdlh Program dks Command Prompt ls Run fd;k tkrk gS] rc ml Program ds main() Method dks ;fn ge fdlh izdkj dk Argument nsuk pkgsa] rks Command Prompt ls ns ldrs gSaA Command Prompt ij fn, tkus okys Arguments args uke ds String izdkj ds Array esa Store gksrs gSa] ftUgsa main() Method esa Use djds dksbZ dke fd;k tk ldrk gSA main() Method dks [kkstus ds ckn Compiler main() Method ds Statement Block esa izos”k djrk gS] tgka mls System.out.println() Method izkIr gksrk gSA Compiler bl Method dks Compile djrk gS vkSj vkxs c
vkxs okil mls nwljk System.out.println() Method izkIr gksrk gSA Compiler bl Statement ds String dks Hkh Output esa Print djrk gSA fQj rhljs Statement dks Execute djrk gS vkSj rhljs Statement dks Output esa Print djrk gSA fQj mls main() Method dk Closing Curly Brace izkIr gksrk gS] tgka ls Compiler dk Program Control ckgj fudy tkrk gS vkSj Terminate gks tkrk gSA Example
,d ,slk Program cukvks ftlesa lHkh Arithmetical Operators dk iz;ksx fd;k x;k gksA Name of File = AllArithmetic.java public class AllArithmetic { public static void main(String args []) { int firstValue = 100; int secondValue; int addResult, subResult, mulResult, divResult, remResult; secondValue = 50; addResult = firstValue + secondValue; subResult = firstValue - secondValue; mulResult = firstValue * secondValue; divResult = firstValue / secondValue; System.out.println(firstValue + "+" +secondValue+ "="+addResult); System.out.println(firstValue + "-" +secondValue+ "="+subResult); System.out.println(firstValue + "*" +secondValue+ "="+mulResult); System.out.println(firstValue + "/" +secondValue+ "="+divResult); secondValue = 60; remResult = firstValue % secondValue; System.out.println(firstValue + "%" +secondValue+ "="+remResult);
113 Any Question or Suggestion, Just Discuss Here...
Java in Hindi }
}
Output 100 + 50 = 150 100 - 50 = 50 100 * 50 = 5000 100 / 50 = 2 100 % 60 = 40
bl Program esa geus main() Method esa lcls igys ,d Integer izdkj dk fuEukuqkj Variable Create fd;k gS% int firstValue = 100;
;s Statement Memory esa Integer izdkj ds eku dks Store djus ds fy, pkj Bytes dh Space Reserve djrk gS] vkSj ml Space dk uke firstValue j[k nsrk gSA lkFk gh Variable ds fy, Memory Reserve djrs le; ;kuh Variable Create djrs le; gh ml Variable esa eku 100 iznku dj fn;k x;k gSA tc fdlh Variable dks Create djrs le; gh mls eku iznku dj fn;k tkrk gS rks bl izfØ;k dks Value Initialization dgk tkrk gSA fuEukuqlkj nwljs Statement esa geus ,d vkSj Variable Create fd;k gS] ysfdu bls Value Initialize ugha fd;k gSA int secondValue;
bu nksuksa Statements esa geus ,d le; esa dsoy ,d gh Variable Create fd;k gS tcfd rhljs Statement esa geus ,d lkFk Integer izdkj ds ikap Variables Create fd, gSaA tc gesa ,d gh Data Type ds dbZ Variables Create djus gksrs gSa] rc ge bl rjhds ls Variables dk Declaration dj ldrs gSaA Bhd mlh rjg ls ftl rjg ls geus bl Program esa fuEukuqlkj Statement }kjk ,d gh le; esa Integer izdkj ds ikap Variables Create fd, gSa& int addResult, subResult, mulResult, divResult, remResult; main() Method ds pkSFks Statement esa geus secondValue Variable dks fuEukuqlkj Statement }kjk eku iznku fd;k gS& secondValue = 50;
tc fdlh Variable dks Declare djrs le; eku iznku uk djds ckn esa eku iznku fd;k tkrk gS] rks eku iznku djus ds fy, Equal To Operator dk iz;ksx fd;k tkrk gSA bl Operator dks Assignment Operator Hkh dgrs gSa] blfy, bl izdkj ls eku iznku fd, tkus ds rjhds dks Variable Assignment ;k eku Assign djuk dgrs gSaA geus gekjs Program esa fuEukuqlkj pkj Statement }kjk ikap izdkj dh izfØ;k,a dh gSa tks firstValue o secondValue Variables ds ekuksa ds vk/kkj ij fofHkUu Arithmetical Operators ds iz;ksx }kjk Result Generate djrs gSa% addResult = firstValue + secondValue;
114 Any Question or Suggestion, Just Discuss Here...
Java in Hindi subResult = firstValue - secondValue; mulResult = firstValue * secondValue; divResult = firstValue / secondValue;
nksuksa Variables ds ekuksa dk ;ksx gks dj addResult uke ds Variable esa ifj.kke Store gks tkrk gSA blh rjg ls firstValue Variable esa eku esa ls secondValue Variable dk eku ?kVkus ds ckn tks ifj.kke izkIr gksrk gS] og ifj.kke subResult uke ds Variable esa Store gks tkrk gSA rhljk Statement nksuksa Variables ds ekuksa dk xq.kk djrk gS vkSj ifj.kke dks mulResult uke ds Variable esa Store dj nsrk gSA pkSFks Statement esa firstValue Variable ds eku esa secondValue Variable ds eku dk Hkkx fn;k tkrk gS vkSj ifj.kke ds :i esa tks eku izkIr gksrk gS] mls divResult uke ds Variable esa Store dj fn;k tkrk gSA vc bu pkjksa ekuksa dks Output esa fuEukuqlkj Statutes }kjk Print dj fn;k tkrk gSA System.out.println(firstValue + "+" +secondValue+ "="+addResult); System.out.println(firstValue + "-" +secondValue+ "="+subResult); System.out.println(firstValue + "*" +secondValue+ "="+mulResult); System.out.println(firstValue + "/" +secondValue+ "="+divResult);
bu Statements esa println() Method dks vyx rjhds ls Use fd;k x;k gSA tc gesa ,d gh Line esa Numerical o Non-Numerical nksuksa rjg ds ekuksa dks Screen ij Print djuk gksrk gS] rc ge + Operator dk iz;ksx dj ldrs gSa] tSlkfd bu Statements esa fd;k x;k gSA pwafd Variables ds eku os uke gSa ftUgsa Compiler Directly igpkurk gS] blfy, bu ukeksa dks Double Quote esa cUn djus dh t:jr ugh gSA tcfd fofHkUu izdkj ds Operators ds fpUgksa dks ge String ds :i esa Output esa Print djuk pkgrs gSa] blfy, bUgsa Double Quote esa cUn fd;k x;k gSA String o Variables esa Stored eku dks ,d lkFk ,d gh println() Method ls Print fd;k tk lds] blds fy, t:jh gS fd buds chp + Operator dk iz;ksx mlh rjg ls fd;k tk,] ftl rjg ls mijksDr pkjksa Statements esa fd;k x;k gSA pwafd geus bl Program esa ftrus Hkh Variables Create fd, gSa] mu lHkh ds ekuksa dks Program esa dgha Hkh Change fd;k tk ldrk gS] ;s n”kkZus ds fy, geus fuEukuqlkj Statement }kjk secondValue Variable ds eku dks Change fd;k gS& secondValue = 60;
vxys Statement esa geus firstValue ls secondValue dk Reminder fudkyus ds fy, fuEukuqlkj Statement dk iz;ksx fd;k gS& remResult = firstValue % secondValue; main() Method ds vfUre Statement esa remResult Variable ds eku dks Output esa Print fd;k x;k gS] tks fd Output esa 40 Print djrk gSA ;fn ge secondValue Variable dk eku 60 Assign uk djrs] rks bl Statement }kjk izkIr gksus okyk ifj.kke 0 gksrkA D;ksafd firstValue ds eku 100 esa secondValue ds eku 50 dk Hkkx iwjk&iwjk pyk tkrk vkSj Reminder 0 cprkA
115 Any Question or Suggestion, Just Discuss Here...
Java in Hindi blfy, geusa secondValue Variable dk eku Change djds 60 dj fn;kA blfy, gesa Output esa 40 izkIr gksrk gSA D;ksafd 100 esa 60 dk iwjk&iwjk Hkkx dsoy ,d gh ckj tkrk gS vkSj “ks’kQy 40 cprk gSA blh Program dks ;fn gesa ,d Applet }kjk Solve djuk gks] rks Applet ds fy, gesa fuEukuqlkj Coding djuh iMsxh% Name of File = AllArithmeticApplet.java import java.awt.*; import java.applet.*; public class AllArithmeticApplet extends Applet { int firstValue, secondValue; int addResult, subResult, mulResult, divResult, remResult; public void init() { firstValue = 100; secondValue = 50; addResult = firstValue + secondValue; subResult = firstValue - secondValue; mulResult = firstValue * secondValue; divResult = firstValue / secondValue; } public void paint(Graphics g) { g.drawString(firstValue+"+"+secondValue + " = " + addResult, 10, 20); g.drawString(firstValue+"-"+secondValue + " = " + subResult, 10, 40); g.drawString(firstValue+"*"+secondValue + " = " + mulResult, 10, 60); g.drawString(firstValue+"/"+secondValue + " = " + divResult, 10, 80); secondValue = 60; remResult = firstValue % secondValue;
}
}
g.drawString(firstValue+"%"+secondValue+ " = " + remResult, 10, 100);
Output
116 Any Question or Suggestion, Just Discuss Here...
Java in Hindi
Example
,d ,slk Program cukvks ftlesa ,d lky esa lw;Z dh jks”kuh }kjk r; dh tkus okyh dqy nwjh Miles esa Output esa izkIr gksA pwafd lw;Z ds izdk”k dh xfr ,d Second esa 186000 gksrh gS] blfy, lw;Z ds izdk”k }kjk ,d lky esa r; dh tkus okyh xfr dk Formula fuEukuqlkj gksxk% Total Length = 186000 * 365 * 24 * 60 * 60 Program class LightDistance { public static void main( String args []) { int lightSpeed; long days; long seconds; long distance; //Approximate speed of light in miles per second lightSpeed = 186000;
}
}
days = 365; seconds = days * 24 * 60 * 60; //Convert to Seconds distance = lightSpeed * seconds; //Total Distance System.out.print("In " + days ); System.out.print(" days light will travel about "); System.out.println(distance + " miles");
Output In 365 days light will travel about 5865696000000 miles
bl Program esa geus System Class ds out Object ds fy, ,d u, Method print() dk iz;ksx fd;k gSA ;s method Bhd mlh izdkj ls dke djrk gS] ftl izdkj ls println() Method djrk gSA vUrj dsoy bruk gS fd println() Method Automatically New Line Provide djrk
117 Any Question or Suggestion, Just Discuss Here...
Java in Hindi gS tcfd ;s Method New Line Provide ugha djrk gSA blhfy, geus rhu ckj System.out Object ds fy, Method dks Call fd;k gS] ysfdu ifj.kke gesa ,d gh Line esa izkIr gks jgk gSA bl Program esa geus long Data Type dk Variable Declare fd;k gSA geus ,slk blfy, fd;k gS D;ksafd 365 Days esa izdk”k ftruh nwjh r; djrk gS] og nwjh int izdkj ds Variable esa Store ugha fd;k tk ldrk gSA D;ksafd ;s nwjh int izdkj ds Data Type ds Variable dh Range ls T;knk gSA int izdkj dk Variable brus cMs eku dks Store ugha dj ldrk gSA blh rjg ls ge fofHkUu izdkj dh t:jrksa ds fy, fofHkUu izdkj ds Data Type ds Variables Declare dj ldrs gSa vkSj mUgsa Use dj ldrs gSaA
Variable Scope
tc ge tkok esa dksbZ Program fy[ks gSa rc ge Program esa fdlh Hkh LFkku ij dksbZ Variable Declare ugha dj ldrs gSaA lcls igys gesa ;s r; djuk gksrk gS fd gesa fdlh Variable dh t:jr dgka ij gSA ;s r; djuk blfy, t:jh gksrk gS D;ksafd gj Variable dk ,d Scope gksrk gS] tks ;s r; djrk gS fd fdlh Variable dks Program esa dc rd o dgka ls dgka rd Access fd;k tk ldrk gSA tkok esa fdlh Variable ds Scope dks mlds Block ls Identify fd;k tkrk gSA tks Variable ftl Block esa Declare fd;k tkrk gS] og Variable mlh Block rd mi;ksx fd;k tk ldrk gSA ml Block ls ckgj Variable dks Use ugha fd;k tk ldrk gSA ftl Variable dks tgka ij Declare fd;k tkrk gS] og Variable ogha ls Block ds vUr rd Visible jgrk gSA Variable uk rks Create ;k Declare gksus ls igys Visible jgrk gS vkSj uk gh Program Control ds Block ls ckgj fudyus ds ckn Visible jgrk gSA tSls gh Program Control fdlh Block ls ckgj fudyrk gS] ml Block ds lHkh Variables Destroy gks tkrs gSaA bl izfØ;k dks Programming esa Variable dk “Out Of Scope” gksuk dgrs gSaA
Code Block
Program Codes ds Statements dk og lewg ftls ,d Opening o Closing Curly Braces ( { } ) ds chp fy[kk tkrk gS] Statement Block ;k Code Block dgykrk gS vkSj lkekU;r;k bls dsoy Block dgrs gSaA Blocks dk iz;ksx lkekU;r;k Functions, Class, Loops vkfn esa fd;k tkrk gS] ftuds ckjs esa ge vkxs lh[ksaxsA
Type Casting
tkok dk Compiler bl fu;e ij dke djrk gS fd rHkh nks Operands ds chp fdlh izdkj dh Calculation gks ldrh gS] tc nksuksa Operands leku Data Type ds gksaA fofHkUu izdkj ds Binary Operators nks Operands ij izfØ;k djrs gSa vkSj ifj.kke Generate djrs gSaA ;fn Binary Operator ds nksuksa vksj leku Data Type ds Variables uk gksa] rks Compiler Lo;a gh Lower Data Type ds Variable ds eku dks nwljs Operand ds vuqlkj Higher Data Type ds eku esa Convert djrk gSA bl rjg dh Type Casting dks Automatic Type Casting dgrs gSaA mnkgj.k ds fy, fiNys Program ds fuEu Statement dks nsf[k,& distance = lightSpeed * seconds;
//Total Distance
118 Any Question or Suggestion, Just Discuss Here...
Java in Hindi ge ns[k ldrs gSa fd lightSpeed Variable Integer izdkj dk Variable gS tcfd seconds long izdkj dk Variable gSA ;gka Integer izdkj ds Variable ds eku dk xq.kk long izdkj ds Variable ds eku ls gks jgk gS vkSj ifj.kke long izdkj ds Variable distance dks Assign gks jgk gSA bls Automatic Type Casting dgrs gSa] D;ksafd blesa Compiler Lo;a gh Integer izdkj ds Variable lightSpeed ds eku dks long izdkj ds eku esa Convert djus ds ckn nwljs long izdkj ds Variable seconds ds eku ls xq.kk djrk gS vkSj ifj.kke dks long izdkj ds Variable esa Store djrk gSA ;fn distance tks fd long izdkj dk Variable gS] float izdkj dk gksrk] rks Calculation ls izkIr gksus okyk ifj.kke float izdkj dk Return gksrk vkSj distance esa Float izdkj dk eku Store gksrk vkSj ;fn distance double izdkj dk Variable gksrk rks izkIr Resultant eku double izdkj esa Store gksrkA pwafd bl Statement esa Integer ls long esa ;kuh Lower Data Type ds eku dks Higher Data Type ds eku esa Convert djuk gS] blfy, ;s dke Compiler Automatically dj ysrk gSA ysfdu tc fdlh Higher Data Type ds eku dks Lower Data Type ds eku esa Convert djds Calculation djokuh gksrh gS] rc ge Automatic Type Casting dk iz;ksx ugha dj ldrs gSA
,slk djus ij ifj.kke xyr izkIr gksrk gSA bl fLFkfr esa gesa Manual Type Casting djuh iMrh gSA ;fn ge pkgsa fd blh Statement esa lightSpeed dk eku Long Data Type esa Convert gksus ds ctk;] seconds dk eku Integer izdkj esa Convert gks vkSj mlds ckn nksuksa Variables ds ekuksa dk xq.kk gks] rks gesa blh Statement dks fuEukuqlkj fy[kuk iMsxk& distance = lightSpeed * (int) seconds; //Total Distance
ge ns[k ldrs gSa fd seconds Variable ds igys ,d dks’Bd esa geus int Keyword dk iz;ksx fd;k gSA ;s Keyword seconds ds eku dks Integer izdkj ds eku esa Convert dj nsrk gSA pwafd dks’Bd dh Priority lHkh Operators o fofHkUu Language Symbols ls T;knk gksrh gS] blfy, lcls igys seconds dk eku long ls int esa Convert gksrk gSA mlds ckn lightSpeed o seconds ds ekuksa dk xq.kk gksrk gS] ftldk ifj.kke gesa Integer izdkj ds eku ds :i esa izkIr gksrk gSA ;s eku distance uke ds Variable esa Store gks tkrk gSA tgka rd gks lds gesa Higher Type ls Lower Type esa Data ds eku dks Convert ugha djuk pkfg,A ,slk djus ij Data dk Loss gks tkrk gSA tSls ;fn ge fdlh Integer izdkj ds eku 1234 dks char izdkj ds ;k byte izdkj ds eku esa Convert djsaxs] rks Data dk Loss gks tk,xkA D;ksafd byte izdkj dk Variable vf/kdre 256 rd dk eku gh Store dj ldrk gSA ;fn blls vf/kd eku dks bl izdkj ds Variable esa Store fd;k tkrk gS] rks izkIr gksus okyk ifj.kke viw.kZ ;k xyr gks tkrk gSA pfy,] Manual Type Casting dks le>us ds fy, ,d Example Program ns[krs gSaA Program public class ManualTypeCasting { public static void main(String args[]) { byte b;
119 Any Question or Suggestion, Just Discuss Here...
Java in Hindi int i = 257; double d = 345.678; System.out.println("\n Conversion of int to byte. "); b = (byte) i; System.out.println("i and b " + i + " " + b); System.out.println("\n Conversion of double to int. "); i = (int) d; System.out.println("d and i " + d + " " + i);
}
}
System.out.println("\n Conversion of double to byte. "); b = (byte) d; System.out.println("d and b " + d + " " + b);
Output Conversion of int to byte. i and b 257 1 Conversion of double to int. d and i 345.678 345 Conversion of double to byte. d and b 345.678 89
tc Integer izdkj ds eku 257 dks byte izdkj esa Convert fd;k tkrk gS] rc gesa byte izdkj ds Variable dk eku 1 izkIr gksrk gSA ,slk blfy, gksrk gS D;ksafd Byte izdkj ds Variable esa dsoy 256 rd dk gh eku Store gks ldrk gS vkSj 256 rd dk eku Store djus ds fy, dsoy 8-Bits dh t:jr gksrh gSA tcfd 257 eku dks Store djus ds fy, gesa de ls de 9Bits dh t:jr gksrh gS vkSj 257 dh Binary 100000001 gksrh gSA vc pwafd Byte izdkj ds Variable esa dsoy 8 Bits gh Store gks ldrs gSa] blfy, Byte izdkj ds Variable esa 00000001 Bits gh Stored gks ikrs gSa 9 osa LFkku dk Bit Lost gks tkrk gSA bl fLFkfr esa ;s Bits eku 1 dks Represent djrs gSaA tc double izdkj ds eku dks int izdkj ds eku esa Convert fd;k tkrk gS] dk Variable nleyo ds ckn ds eku dks Store ugha dj ldrk gS] blfy, ds eku dks int izdkj esa Convert fd;k tkrk gS] rc double izdkj ds nleyo okys Hkkx dks Compiler }kjk NksM fn;k tkrk gS vkSj int izdkj ds 345 gh Store gks ikrk gSA
rc pwafd int izdkj tc double izdkj eku 345.678 ds Variable esa dsoy
tc double izdkj ds eku dks byte izdkj ds Variable esa Store djus ds fy, Convert fd;k tkrk gS] rc double izdkj ds Variable ds nleyo okyk fgLlk Compiler }kjk NksM fn;k tkrk gSA fQj pwafd byte izdkj dk Variable dsoy 256 rd ds eku dks gh Store dj ldrk gS] blfy, double izdkj ds eku 345 esa ls 256 Less gks tkrk gS vkSj 89 cprk gSA ;s 89 eku byte izdkj ds Variable esa Store gks tkrk gSA
120 Any Question or Suggestion, Just Discuss Here...
Java in Hindi tkok Type Checking ds ekeys esa cgqr gh Strict gSA ge fdlh byte izdkj ds Variable esa int izdkj ds eku dks Store djuk pkgrs gSa] rks tkok gesa ,slk ugha djus nsrk gSA ;fn gesa byte izdkj ds Variable es int izdkj ds Variable dk eku Assign djuk gks] rks gesa int izdkj ds Variable dh Type Casting djuh gh iMrh gSA tSls% int i; byte b; b = (int) i;
Arrays
;s ,d Secondary Data Type gSA tc gesa Computer esa dsoy ,d eku dks Store djuk gksrk gS] rc ge ml eku ds Data Type ds vuqlkj ,d Variable Create dj ysrs gSaA ysfdu tc gesa ,d gh izdkj Data Type ds ,d ls vf/kd ekuksa dks ,d gh Variable ds :i esa Computer esa Store o Manage djuk gksrk gS] rc ge Array dk iz;ksx djrs gSaA mnkgj.k ds fy, ekuyks fd gesa dsoy ,d Student dk Roll Number Computer esa Store djuk gS] rks ge fuEukuqlkj ,d Variable Declare dj ldrs gSa& int rollNumber;
ysfdu ;fn gesa 100 Students ds Roll Number dks Computer esa Store djuk gks vkSj ge blh lkekU; rjhds dk iz;ksx djsa] rks gesa fuEukuqlkj 100 Variables Create djus gksaxs& int rollNumber1; int rollNumber2; int rollNumber3; int rollNumber4; int rollNumber5; . . . . . .
int rollNumber99; int rollNumber100; Array ,d ,slh O;oLFkk gS tks blh dke dks ,d gh Statement }kjk dj nsrk gSA blds fy, gesa Bracket Symbol ( [ ] ) dk fuEukuqlkj iz;ksx djuk gksrk gS& int rollNumber[];
ge bl Bracket Symbol dks Variable ds uke ds igys Hkh fy[k ldrs gSaA ;kuh int []rollNumber;
;fn gesa nks Array Create djus gksa vkSj ge Bracket Symbol dks Variable ds uke ds ckn esa fy[ksa] rks gesa Array dk Declaration fuEukuqlkj djuk gksxk&
121 Any Question or Suggestion, Just Discuss Here...
Java in Hindi int rollNumber[], serialNumber[];
tcfd ;fn ge bl Bracket Symbol dks Data Type ds Just ckn esa fy[krs gSa] rks gesa gj Variable ds uke ds ckn Bracket Symbol dk iz;ksx djus dh t:jr ugha gksrh gSA ;kuh ge blh dke dks fuEukuqlkj Hkh dj ldrs gSa& int [ ] rollNumber, serialNumber;
;fn ge pkgsa fd dqN Variable dsoy lkekU; Variables gksa vkSj dqN Array gksa rks ge fuEukuqlkj Statement fy[k ldrs gSa& int contactNumber, [] rollNumber, serialNumber;
bl Statement esa contactNumber ,d gh Variable gksxk tcfd rollNumber o serialNumber nks Array gSaA Array Memory Allocation lHkh Primary Type ds Variables Declare djrs gh mUgsa Java dk Compiler Memory Allocate dj nsrk gS] ysfdu tc ge dksbZ Array Create djrs gSa] rc gesa ,d vyx Statement }kjk Array ds fy, Memory Allocate djuh iMrh gS vkSj ;s crkuk iMrk gS fd ge fdrus eku Store djuk pkgrs gSaA ;gka ge ;fn 100 Students ds fy, Memory Allocate djuk pkgsa rks gesa fuEukuqlkj new Operator dk iz;kssx djrs gq, Statements fy[kus gksaxs& int rollNumber[] = new int[100];
;fn ge “C” ;k “C++” dh rjg Java esa Array dk Declaration djsa] rks Java Error nsrk gSA ;kuh int rollNumber[100];
;s Statement “C” o “C++” esa dke djrk gS ysfdu Java esa Error nsrk gSA
Array Initialization ge tc fdlh Variable dks Create djrs gSa] rks Variable Create djrs le; gh mls igyk izkjfEHkd eku iznku dj ldrs gSaA bl izfØ;k dks Initialization dgrs gSaA tSls int serialNumber = 131200;
blh rjg ls ge tkok esa fdlh Array dks Hkh Initialize dj ldrs gSaA Java esa fdlh Array dks fuEukuqlkj Initialize fd;k tk ldrk gS& int intArray[] = {1,2,3,4,5}; char [] charArray = {'a', 'b', 'c'}; 122 Any Question or Suggestion, Just Discuss Here...
Java in Hindi string [] stringArray = {"A", "Four", "Element", "Array"};
tc ge bl izdkj ls fdlh Array dks Declare djrs gSa rc Array dh Size Lo;a gh Initialize fd, x, ekuksa dh la[;k ds vk/kkj ij r; gks tkrh gSA mnkgj.k ds fy, igys Statement ds Array intArray dh Size 5 gksxh] nwljs Array charArray dh Size 3 vkSj rhljs Statement stringArray dh Size 4 gksxhA lHkh vU; Hkk’kkvksa dh rjg gh Java esa Hkh ge 2-Dimesional o Multi-Dimensional Array Create dj ldrs gSaA ,slk djus ds fy, gesa dsoy Brackets dh la[;k dks c
ge Java esa nks rjhdksa ls ;s dke dj ldrs gSaA bu nksuksa rjhdksa dks mijksDr Statements esa crk;k x;k gSA ;fn ge Multidimensional Array Create djuk pkgsa] rks fuEukuqlkj dj ldrs gSa% float floatArray[][][]; floatArray = new float[10][5][10]; double [][][] doubleArray = new double[10][10][10];
fdlh 2-D ;k Multi-D Array ds Brackets esa fn, tkus okys lHkh ekuksa dks ;fn vkil esa xq.kk dj fn;k tk,] rks feyus okyh la[;k ml Array esa dqy Store gks ldus okys ekuksa dh la[;k dks Represent djrk gSA tSls doubleArray Memory esa 10 * 10 * 10 = 1000 Double Data Type ds ekuksa dks Store dj ldrk gSA ekuyks fd geus fuEukuqlkj ,d Statement }kjk nl ukeksa dks Store djus ds fy, Array Create fd;k% String name = new String[6];
;s Statement okLro esa ,d gh le; esa 6 Variables Create djrk gS vkSj lHkh Variables dk uke leku gksrk gSA bu fofHkUu Variables dks ge Variable ds Index Number ls igpkurs gSaA tkok esa Index Number ,d ,slk Number gksrk gS] tks ,d gh izdkj ds ukeksa esa fofHkUurk ykus ds fy, Use fd;k tkrk gSA pwafd ge ,d gh Program ds leku Scope esa ,d gh uke ds dbZ Variables Create ugha dj ldrs gSaA blfy, Compiler Lo;a gh ,d lkFk ,d gh uke ls Create gksus okys fofHkUu Variables dh igpku ds fy, muds lkFk ,d Number tksM nsrk gSA bl Number dks Index Number dgrs gSa vkSj bldh “kq:vkr gesa”kk 0 ls gksrh gSA gekjs Statement esa geus 6 ukeksa dks Store djus ds fy, Memory Reserve dh gSA bl Statement }kjk fuEukuqlkj name uke ds 6 Variables Create gksrs gSa%
123 Any Question or Suggestion, Just Discuss Here...
Java in Hindi name[0] name[1] name[2] name[3] name[4] name[5]
vc ;fn ge bu Variables esa uke Assign djuk pkgsa rks fuEukuqlkj dj ldrs gSa& name[0] = “Balaji” ; name[1] = “Madhav” ; name[2] = “BalGopal” ; name[3] = “Nandlal” ; name[4] = “BalKishan” ; name[5] = “ManMohan” ;
vc ;fn ge bl Array ds fofHkUu Index Number ij Stored ukeksa dks Output esa Print djuk pkgsa] rks fuEukuqlkj Statements }kjk dj ldrs gSa% System.out.println("Name in Array at Index Number [0] = " + name[0]); System.out.println("Name in Array at Index Number [1] = " + name[1]); System.out.println("Name in Array at Index Number [2] = " + name[2]); System.out.println("Name in Array at Index Number [3] = " + name[3]); System.out.println("Name in Array at Index Number [4] = " + name[4]); System.out.println("Name in Array at Index Number [5] = " + name[5]);
bl iwjs Program dks ge fuEukuqlkj fy[k ldrs gSa& Program public class Array { public static void main(String args[]) { String name[] = new String[6]; name[0] = "Balaji" ; name[1] = "Madhav" ; name[2] = "BalGopal" ; name[3] = "Nandlal" ; name[4] = "BalKishan" ; name[5] = "ManMohan" ; System.out.println("Name in Array at Index Number [0] = " + name[0]); System.out.println("Name in Array at Index Number [1] = " + name[1]); System.out.println("Name in Array at Index Number [2] = " + name[2]); System.out.println("Name in Array at Index Number [3] = " + name[3]); System.out.println("Name in Array at Index Number [4] = " + name[4]); System.out.println("Name in Array at Index Number [5] = " + name[5]); } }
124 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Output Name in Array at Index Number [0] = Balaji Name in Array at Index Number [1] = Madhav Name in Array at Index Number [2] = BalGopal Name in Array at Index Number [3] = Nandlal Name in Array at Index Number [4] = BalKishan Name in Array at Index Number [5] = ManMohan
;fn ge blh Program dks Applet ds :i esa cukuk pkgsa rks bl dke dks djus ds fy, gesa fuEukuqlkj Applet Program fy[kuk gksxk% Program File Name : ArrayApplet.java import java.awt.*; import java.applet.*; public class ArrayApplet extends Applet { String name[] = new String[6]; public void init() { name[0] = "Balaji" ; name[1] = "Madhav" ; name[2] = "BalGopal" ; name[3] = "Nandlal" ; name[4] = "BalKishan" ; name[5] = "ManMohan" ; }
}
public void paint(Graphics g) { g.drawString("Name in Array at Index Number[0]="+name[0],30,20); g.drawString("Name in Array at Index Number[1]="+name[1],30,40); g.drawString("Name in Array at Index Number[2]="+name[2],30,60); g.drawString("Name in Array at Index Number[3]="+ name[3],30,80); g.drawString("Name in Array at Index Number[4]="+name[4],30,100); g.drawString("Name in Array at Index Number[5]="+ name[5],30,120); }
Output
125 Any Question or Suggestion, Just Discuss Here...
Java in Hindi
blh rjg ls ge ,d 2-D o Multi-D Array dks Hkh Use dj ldrs gSaA ekuyks fd gesa ,d 2-D Array esa fuEu Table ds ekuksa dks Store djuk gS& 10 50 2 93
20 46 12 39
30 20 30 3
ge ns[k ldrs gSa fd bl Table esa pkj Row o rhu Columns gSa] blfy, gesa fuEukuqlkj [4][3] dk Array Create djuk gksxk% int Table = new int[4][3];
;fn ge bl Table ds fofHkUu ekuksa dks Initialize djuk pkgsa rks igys gesa ;s le>uk gksxk fd bl Array dks Memory esa fdl izdkj ls Represent fd;k tk ldrk gSA ftl rjg ls Table fn[kkbZ ns jgh gS] mlh rjg ls fofHkUu Index Numbers Hkh Set gksrs gSaA ;fn ge mijksDr Tables ds fofHkUu ekuksa ds Index Numbers dks Represent djuk pkgsa] rks fuEukuqlkj dj ldrs gSa& [0][0] [1][0] [2][0] [3][0]
[0][1] [1][1] [2][1] [3][1]
[0][2] [1][2] [2][2] [3][2]
ge le> 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
Output Balgopal Kanhaiya Krishna Madhav Nandlal
bl Program esa for() Loop dk iz;ksx fd;k x;k gSA Looping ,d Control Statement gS] ftlds ckjs esa ge vxys v/;k; esa i
StringBuffer Class
StringBuffer String Class dh ,d Peer Class gSA ;kuh String Class Fixed_Length dh String Object Create djrk gS] tcfd StringBuffer Flexible Length dk String Object Create djrk gS] ftlds Contents o Length nksuksa dks Modify fd;k tk ldrk gSA
bl Object dh String ds chp esa ge ubZ String Insert dj ldrs gSa lkFk gh fdlh ubZ String dks bl String Object dh String ds End esa Append Hkh dj ldrs gSaA blds Object ds lkFk ge fuEu String Methods dks Use dj ldrs gSa tks fd lokZf/kd Use fd, tkrs gSa& string1.setChartAt(n, ‘p’) ;s Statement string1 ds nth Character dks Modify djds ‘p’ dj nsrk gSA string1.append(string2)
136 Any Question or Suggestion, Just Discuss Here...
Java in Hindi ;s Statement string2 ds vUr esa string1 dks Append dj nsrk gSA string1.insert(n, string2) ;s Statement string1 ds nth Character ij string2 dks Insert dj nsrk gSA string1.setLength(n) ;s Statement string1 dh length dks n ds cjkcj Set dj nsrk gSA ;fn nString 1.length gks rks string1 esa zeros Add gks tkrs gSaA
bUgsa Use djrs gq, ge fuEukuqlkj ,d Program cuk ldrs gSa& Program class StringManipulation { public static void main(String args[]) { StringBuffer string1 = new StringBuffer("OOPS with JAVA"); System.out.println("Original String : " + string1); //Obtaining string length System.out.println("Length of String : " + string1.length()); //Accessing characters of string for(int i=0; i
}
}
//Appending a string at the end string1.append(" Programming"); System.out.println("Appended string : " + string1);
Output 137 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Original String : OOPS with JAVA Length of String : 14 Character at position : 1 is O Character at position : 2 is O Character at position : 3 is P Character at position : 4 is S Character at position : 5 is Character at position : 6 is w Character at position : 7 is i Character at position : 8 is t Character at position : 9 is h Character at position : 10 is Character at position : 11 is J Character at position : 12 is A Character at position : 13 is V Character at position : 14 is A Modified string : OOPS Concepts with JAVA String now : OOPS C_ncepts with JAVA Appended string : OOPS C_ncepts with JAVA Programming
Command Line Arguments
dbZ ckj ,slh ifjfLFkfr;ka gksrh gSa fd tc ge pkgrs gSa fd gekjk Program Command Prompt ij gekjs }kjk fn, x, Input ds vk/kkj ij fofHkUu izdkj ds Operations Perform djsA fdlh izksxzke ls ;s fof”k’Vrk izkIr djus ds fy, gesa ,d ,sls tkok Concept dks Use djuk gksrk gS] ftls Command Line Arguments dgrs gSaA Command Line Arguments os eku gksrs gSa] tks fdlh Program dks Command Prompt ij Run djrs le; Parameters ds :i esa Program dks iznku fd, tkrs gSaA mnkgj.k ds fy, tc ge fuEukuqlkj Hello World Program dks Run djrs gSa % C:jdk\bin\> java HelloWorld
rc ;gka ge HelloWorld Program dks fdlh izdkj dk dksbZ Argument Pass ugha dj jgs gSaA ge ;gka ;fn Arguments Pass Hkh djrs gSa] rks Hkh HelloWorld Program dks ;s irk ugha gksrk gS] fd Supply fd, tkus okys Command Line Arguments ds lkFk D;k izfØ;k djuh gSA ge ,sls tkok Programs fy[k ldrs gSa tks Command Line ij iznku fd, x, Arguments dks Use dj ldrk gS vkSj Arguments ds vk/kkj ij fofHkUu izdkj ds Output iznku dj ldrk gSA bls le>us ds fy, main() Method ds Structure dks nsf[k, % public static void main(String args[])
138 Any Question or Suggestion, Just Discuss Here...
Java in Hindi ge ns[k ldrs gSa fd main() Method esa args dks ,d Strings ds Array izdkj dk Declare fd;k x;k gS] tks fd String Objects dks Store dj ldrk gSA Program ds Execution ds nkSjku ;fn Command Prompt ij dksbZ Hkh Argument iznku fd;k tkrk gS] rks Command Line ij fn, tkus okys lHkh Argument dk eku args uke ds bl Object esa String Object ds :i esa Store gks tkrk gSA main() Method esa ge args Array ds fofHkUu Objects dks Array Elements ds :i esa Access dj ldrs gSa vkSj fofHkUu izdkj ds Manipulations dj ldrs gSaA mnkgj.k ds fy, eku yks fd ge Command Prompt ij HelloWorld Program dks fuEukuqlkj Interpret djrs gSa% C:jdk\bin\> 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( i
bl Program dks Compile djds tc ge fuEukuqlkj Command Line Arguments ds lkFk Run djrs gSa] rc gesa vxzkuqlkj ifj.kke izkIr gksrk gS % C:jdk\bin\>java 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
bls Practically le>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 i
161 Any Question or Suggestion, Just Discuss Here...
Java in Hindi
dk;Ziz.kkyh & bl lajpuk esa value1, value2........value n expression ;k Variable gSa] ftUgs case label dgk tkrk gSA buds ckn Colon yxkuk t:jh gksrk gSA ;s lHkh eku vyx&vyx gksus t:jh gksrs gSaA Statement or Statement Block 1, Statement or Statement Block 2, ......... Statement or Statement Block n Statements dk lewg gSA bu Statements ds lewgksa esa ,d ls vf/kd Statements gksus ij Hkh ea>ys 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 c
blls izFke ckj x dk eku 0 + 1 = 1 gks tk,xk D;ksafd x dk izkjafHkd eku geus 0 fn;k gSA tc nqckjk ;gh Statement execute gksxk rc x ds eku 1 esa 1 vkSj tqMsxk ;kuh x = 1 + 1 blfy;s vc x dk eku nks gks tk,xk D;ksafd igys Execution esa x dk eku c< dj ,d gks x;k FkkA vc ;fn rhljh ckj ;gh Statement Execute gks rks x = 2 + 1 gksus ls x dk eku 3 gks tk,xk vkSj ;g eku Øe ls rc rd c
Decrement blds foijhr tc fdlh Variable ds eku esa ls Øe ls dksbZ la[;k ?kVk dj izkIr eku okil mlh Variable esa Store dj nsrs gSa] rks ml Variable dk eku ml ?kVkbZ xbZ la[;k ds vuqlkj Øe ls ?kVrk tkrk gS] bl izfØ;k dks Variable dk Decrement gksuk dgrs gSaA mijksDr mnkgj.k dks gh ge Decrement ds fy;s Hkh Use dj jgs gSaA ekuk x = 10 gS o ge Øe ls x dk eku 1 de djuk pkgrs gSa] rks gesa fuEu Statement dks rc rd Use djuk gksxk tc rd fd Condition lR; jgrh gSA x=x–1
;gka x dk izkjafHkd eku geus 10 fn;k gSA tc igyh ckj ;s Statement Execute gksxk] rc x = 10 - 1 ;kuh x = 9 gks tk,xkA nwljh ckj esa x = 9 - 1 ;kuh x = 8 gks tk,xkA rhljh ckj esa x = 8 - 1 ;kuh x = 7 gks tk,xk vkSj ;g Øe Hkh rc rd pyrk jgsxk tc rd fd fdlh Condition }kjk bl izfØ;k dks jksd uk fn;k tk,A bls Variable dk Decrement gksuk dgrs gSa vkSj “C” Hkk’kk esa bls ,d vU; izdkj X-- ls Hkh fy[k ldrs gSaA 164 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Increment o Decrement Hkh nks izdkj ds gksrs gSaA Pre - Increment o Post - Increment rFkk Pre - Decrement o Post Decrement. tc fdlh Variable ds igys Increment ++ dk fpUg yxk;k tkrk gS] rc ml Variable dk eku igys Increase gksrk gS] mlds ckn og Statement ;k Expression Execute gksrk gS] ftlesa ml Variable dks Use fd;k x;k gSSA
tSls ekuk
a = 10 , b = 15 c = a + ++b c = 10 + (1 +15) c = 10 + 16 c = 26
gS djus ij igys b esa ,d tqMsxk ftlls b dk eku 16 gks tk,xk b dk eku 16 gksus ds ckn b esa a dk eku 10 tqMsxk bl rjg ls c dk eku 25 uk gks dj 26 izkIr gksxk D;ksafd b dk Pre Increment gqvk gSA bl izdkj vc a = 10 o b = 16 gksxkA
tc fdlh Variable ds ckn esa Increment fpUg yxk;k tkrk gS] rks ml Variable dk eku mlh Statement ;k expression esa Increase ugha gksrk] cfYd igys og Statement ;k Expression Execute gksrk gS] mlds ckn ml Variable dk eku Increase gksrk gSA tSls ekuk a = 10 , b = 15 c = a + b++ c = (10 + 15 ) + 1 c = 25
gS djus ij igys a esa b tqMsxk a esa b tqMus ds ckn b dk eku Increase gks dj 16 gks tk,xk vkSj c dk eku 25 gh izkIr gksxk
;gh izfØ;k Variable ds Pre-Decrement o Post-Decrement esa Hkh gksrh gSA tSls fuEu mnkgj.k Pre-Decrement dk gS& a = 10 , b = 15 c = a + --b c = 10 + (-1 +15) c = 10 + 14 c = 24 Because b have been Pre Decremented Now The Values of Variables are a = 10 but b = 14 because b is Decremented
;g mnkgj.k Post Decrement dk gSA a = 10 , b = 15 c = a + b-c = (10 + 15) - 1 c = 10 + 15 c = 25 Because b have been Post Decremented Now The Values of Variables are a = 10 but b = 14 because b is Decremented
bl izdkj tc fdlh Variable ds ckn esa Increment ;k Decrement dk fpUg yxk;k tkrk gS] rks ml Variable dk eku izfØ;k ds ckn esa c
Java in Hindi Decrement dk fpUg yxk;k tkrk gS] rks ml Variable dk eku izfØ;k ls igys c
tSls c = a + b++ blesa Compiler dks ++ fpUg ls igys Variable b izkIr gksrk gS vkSj c dk eku 25 gh izkIr gksrk gSA tcfd ;fn Compiler dks igys] Variable ds lkFk Use fd;k x;k $$ ;k -- fpUg feyrk gS] rks Compiler igys ml Variable ds eku dk Increment ;k Decrement djrk gS] mlds ckn ml Variable dks expression esa Use djrk gSA tSls c = a + ++b blesa Compiler dks Variable b ds igys Increment Operator ++ izkIr gksrk gSA blfy;s a ds eku 10 esa b dk eku 15 tqMus ls igys c dk eku Incremented gks dj 16 gks tkrk gS vkSj fQj a + b dk eku c dks ;kuh 10 + 16 = 26 c dks fey tkrk gSA ++ Increment Operator gS vkSj -- Decrement Operator vkSj budk iz;ksx vf/kdrj Looping ds vUrxZr gh fd;k tkrk gS D;ksafd Loop dks gesa”kk ,d Øe esa gh c
,slh t:jrksa dks iwjk djus ds fy;s ge Looping Condition ds vUnj ;k vko”;drk ds vuqlkj dgha vkSj]] fdlh vU; Variable ds eku dks ,d ds Øe esa ?kVkus ;k c
Loops
;s rhljs izdkj ds Control Statements gksrs gSaA tc izksxzke esa gesa fdlh izfØ;k dks ckj&ckj nksgjkuk gksrk gS] rc ge Looping Control Statements dk iz;ksx djrs gSaA fdlh Hkh Loop esa gesa”kk rhu ckrsa fuf”pr djuh gksrh gSa& 1. bls Loop dk Initial Part dgk tkrk gSA blesa Loop dks Iterate djus okys Variable dks izkjafHkd eku fn;k tkrk gS] tks ;s r; djrk gS fd Loop dh “kq:vkr dc ls gksxhA ;gka gesa”kk Assignment Operator = dk iz;ksx fd;k tkrk gSA 2. bls Test Condition dgk tkrk gSA fdlh Hkh Loop esa ;g Part ;s r; djrk gS fd Loop fdl Condition esa execute gksxkA tc rd Test Condition lR; gksrh gS] rHkh rd Loop dk Iteration pyrk gSA blfy;s Loop ds bl Hkkx dks Define djuk cgqr gh t:jh gksrk gSA ;gh Hkkx fdlh Loop dks crkrk gS fd Loop dks dgka rd pyuk gSA bl Hkkx esa Conditional o Logical Operators dk iz;ksx fd;k tkrk gSA ;gka ,d Valid Condition nsuk cgqr gh t:jh gksrk gS] D;ksasfd ;fn ;gka ij ,d Valid Condition define ugha djrs gSa rks dbZ ckj Loop Infinite gks tkrk gSA 3. Loop ds bl esa Step Size crkuk gksrk gSA ;kuh ;gka Loop dks ;s crkuk gksrk gS fd Loop fdl Øe esa vkxs c
166 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Decrement Operator dk iz;ksx fd;k tkrk gSA ;fn gesa Loop dks ,d ds Øe esa uk c
vUrxZr crk;k x;k gSA
Loop eq[;r% rhu izdkj ds gksrs gSaA budh viuh&viuh] vyx&vyx fo”ks’krk o mi;ksx gSA bUgsa fuEukuqlkj crk;k x;k gS&
for Loop ;g lokZf/kd iz;ksx gksus okyk Loop gSA bl Loop esa “C” ds for Key Word dk iz;ksx gksrk gSA bl Loop esa Åij crk, x, rhuksa gh Hkkx ,d gh dks’Bd esa fy[kus gksrs gSaA bl Loop dh fo”ks’krk ;g gS] fd blds ftrus Hkh Statement gksrs gSa] mUgs for Loop fy[kus ds ckn mlds uhps ea>ys dks’Bd ds ,d Block eas fy[kk tkrk gS vkSj ;s Statements Block rHkh Execute gksrk gS] tc for Condition lR; gksrh gSA for Loop dk Syntax fuEukuqlkj gksrk gS& for( Initial Part; Conditional Part; Step Size Part) { Statements Block; }
Flow of For Loop
tc for Loop dk Execution gksrk gS] rks loZ izFke Loop dk Variable Initialize gksrk gS vkSj fQj Condition Check gksrh gSA ;fn Condition lR; gksrh gS] rks Program Control for Loop ds Statement Block esa tkrk gS vkSj ogka ds Statements dk Execution djrk gSA tc For Loop Statement Block ds lHkh Statements dk Execution dj nsrk gS rks Block ls ckgj vkus ls igys Loop ds Step Size Part dk Execution djrk gS vkSj crkbZ xbZ Size ds vuqlkj Variable dk eku Increment ;k Decrement djrk gSA fQj okil Condition Check djrk gS ;fn Condition lR; gksrh gS rks okil Statement Block esa tkrk gS vkSj lHkh Statements dk Execution djus ds ckn okil Step Size Part dk Execution djrk gSA ;s Øe rc rd pyrk jgrk gS tc rd fd for Loop dh Condition lR; jgrh gSA Loop dk Initialization dsoy ,d ckj gh gksrk gS tc igyh ckj Program Control For Loop esa izos”k djrk gSA for Loop dk Execution gesa”kk blh Øe esa gksrk gSA Example : bl Loop }kjk ge ,d izksxzke cukrs gSa ftlesa 1 ls 7 rd dh fxurh dks Output esa fuEukuqlkj Print djokuk gSaA 1 2 3 4
167 Any Question or Suggestion, Just Discuss Here...
Java in Hindi 5 6 7
bl izksxzke dks ge igys xf.krh; :i esa fy[krs gSaA ge int izdkj dk ,d Variable i ysrs gSaA bl izksxzke esa fxurh dk izkjafHkd eku 1 gS vr% i dk izkjafHkd eku i = 1 dj ldrs gSaA ;g bl izksxzke ds Initial Part dk Declaration gSA Print gksus okyh fxurh dk vf/kdre eku 7 gS] blfy;s Condition ds :i esa ge ;s dg ldrs gSa fd Loop rc rd pyuk pkfg;s tc rd fd i dk eku 7 ugha gks tkrkA blfy;s ge bls xf.krh; :i esa i <= 7 fy[k ldrs gSaA ;g Expression izksxzke dks crkrk gS fd Condition rc rd lR; jgsxh tc rd fd i dk eku 7 ls de ;k 7 ds cjkcj ugha gks tkrkA ;g bl izksxzke ds Conditional Part dk Declaration gSA
bl izksxzke esa gj igyh la[;k gj nwljh la[;k ls cMh gSA blfy;s Loop ds Step Size Part esa gesa Increment Operator dk iz;ksx djuk gksxk vkSj lkFk gh gj la[;k ,d ds Øe esa c< jgh gS blfy;s gesa Variable ds eku dks gj Iteration esa ,d ds Øe esa c
bu rhuksa dks for Loop esa j[k nsrs gSa rks fuEu izdkj ls for Loop dk dks’Bd cu tkrk gSA /;ku nsa fd ;s rhuksa Expression vyx&vyx gSaA blfy;s bUgs ; ( Semicolon ) ls vyx djds fy[kk x;k gS& for(i = 1; i <= 7; i = i + 1)
or
for(i = 1; i <= 7; i++)
vc for Loop dk Statement Block fy[kuk gSA i dk eku Øe ls ,d&,d c< jgk gSA blfy;s Statement Block esa ;fn i dk eku Print dj fn;k tk,] rks gesa gekjk Output izkIr gks tk,xkA bls ge fuEukuqlkj fy[k ldrs gSa& { }
printf(“%d ”, i );
vc ;fn ge bu lHkh Statement dks ,d main() Method esa fuEukuqlkj fy[k dj Program dks Compile djsa] rks gesa gekjk Required ifj.kke izkIr gks tk,xkA Example Program fuEukuqlkj gS& Program public class ForLoop { public static void main(String args[]) { int i;
168 Any Question or Suggestion, Just Discuss Here...
Java in Hindi
}
}
for(i=1; i<=7; i++) { System.out.println(i); }
bl Program esa geus for Loop esa <= Relational Operator dk iz;ksx fd;k gSA lcls igys ,d Integer izdkj ds Variable dk eku 1 gksrk gSA pwafd i dk eku 7 ls de gS] blfy, for Loop true Return djrk gSA true Return gksus dh fLFkfr esa Program Control Loop ds Block esa izos”k djrk gS vkSj i ds eku dks Print djrk gSA fQj Program Control i ds eku dk Increment djds 2 dj nsrk gSA Program Control fQj ls for Loop ds Parenthesis esa ;s Check djus ds fy, tkrk gS fd i dk eku Increment gksus ds ckn Hkh 7 ls de ;k cjkcj gS ;k ughaA pwafd i dk eku vHkh Hkh 7 ls de gS] blfy, Program Control fQj ls for Loop ds Block esa vkrk gS vkSj i ds eku dks fQj ls Print djrk gS] tks fd bl ckj 2 gksrk gSA Program Program eku 7 ls Control i
Control fQj ls i ds eku dks Increment djrk gSA vc i dk eku 3 gks tkrk gSA Control fQj ls for Loop ds Parenthesis esa tkrk gS vkSj Check djrk gS fd i dk de ;k cjkcj gS ;k ughaA ,d ckj fQj Condition true gksrh gS vkSj Program ds eku dks Print dj nsrk gSA
bl rjg ls i dk eku 7 ckj Increment gksrk gSA tc i dk eku Increment gksdj 8 gks tkrk gS vkSj Compiler fQj ls for Loop ds Parenthesis esa ;s Check djus ds fy, tkrk gS fd i dk eku 7 ls de ;k cjkcj gS ;k ughaA rc false Return gksrk gSA D;ksafd bl ckj i dk eku 8 gS tks fd 7 ls cMk gSA bl fLFkfr esa Program Control for Loop ds Statement Block esa izos”k ugha djrk vkSj lh/ks gh ckgj fudy tkrk gSA ge pkgsa rks tks Variable geus for Loop ds igys Declare fd;k gS mls for Loop ds Parenthesis esa Hkh Declare dj ldrs gSaA tks Variable dsoy Loop dks pykus ds fy, Declare fd;k tkrk gS] og Variable dsoy rHkh rd mi;ksxh gksrk gS tc rd Loop Run gksrk gSA blfy, ;fn ge pkgsa rks for Loop ds Statement dks fuEukuqlkj Hkh fy[k ldrs gSa& Program public class ForLoop { public static void main(String args[]) { for(int i=1; i<=7; i++) { System.out.println(i); } } }
169 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Assignment Operators tSls gesa 1 ls 20 rd dh dsoy le la[;k,a gh Screen ij Print djokuh gks vkSj ge Loop dks ,d ds Øe esa pyk,a rks gesa if condition dks Use djds ;s dke djuk gksxk fd ;fn Print gksus okyk eku 2 ls iwjh rjg HkkT; gS] rks ogh la[;k Print gks “ks’k ughaA bl izdkj dk izksxzke cukus ls izksxzke dk Loop iwjs 20 ckj pysxkA tcfd ;gh dke ge Looping Statement ds varxZr Assignment Operator dk iz;ksx djds dj ldrs gSa] ftlesa Loop dk izkjfEHkd eku 0 dj nsuk gksxk vkSj Loop dks ,d ds Øe esa uk c es vk tk,xh fd fdl izdkj ls Increment ;k Decrement Operator ds LFkku ij izksxzke dh t:jr dks le>rs gq, Assignment Operators dk iz;ksx fd;k tk ldrk gSA ;fn gesa fdlh Variable ds eku esa Øe ls dksbZ vU; la[;k tksMuh ;k ?kVkuh gks rks] ge bls fuEukuqlkj Hkh fy[k ldrs gSaA ekuk x = 10
gS rks
Mathematical Expression x=x%3 x=x+2 x=x+6 x=x–3 x=x*2 x=x/5
“C” Expression x %= 3 x += 2 x += 6 x -= 3 x *= 2 x /= 5
Output x=1 x=4 x=8 x=7 x = 20 x=2
izFke Expression esa x ds eku 10 es 3 dk Hkkx fn;k x;k gS vkSj izkIr “ks’kQy dks okil x esa store dj fn;k x;k gSA x %=3 dk ;gh eryc gS fd x ds eku es 3 dk Hkkx nsdj og eku okil x dks iznku dj nksA nwljs Expression esa x dk eku nks c
Java in Hindi ikapos Expression es ;s crk;k x;k gS fd x ds eku dks 2 ls xq.kk djds izkIr gksus okys eku dks iqu% x dks ns fn;k tk,A bl Expression dks Hkh ge Looping esa Use dj ldrs gSaA NBs Expression dk ;s vFkZ gS fd x ds eku esa 5 dk Hkkx fn;k tk, o tks HkkxQy izkIr gksrk gS] mls iqu% x esa Hkst fn;k tk,A x /= 5 blh Statement dk laf{kIr :i gSA Expression ds :i esa “C” izksxzke esa mij crk, x, nksuksa gh rjg ds Expression lgh gSa vkSj izksxzke nksuksa dks ekU;rk nsrk gSA ge gekjs izksxzke esa bu nksuksa esa ls fdlh Hkh rjg ds Expression
dk mi;ksx dj ldrs gSaA
Nesting of Loop ftl rjg geus if Conditionals Statements dh Nesting dh Fkh mlh rjg ls ge Loops Hkh Nesting dj ldrs gSaA ;kuh dbZ ckj izksxzke esa ,slh t:jrsa gksrh gSa] fd ml [kkl dke Loop dh lk/kkj.k izfØ;k }kjk ugha dj ldrsA rc gesa ,d Loop ds vanj ,d vU; Loop Use djuk iMrk gSA tc fdlh Loop esa okil Loop dk iz;ksx fd;k tkrk gS rks bls Loop Nesting djuk dgrs gSaA
dh dks dks dh
Nesting of for Loop For Loop dh tc Nesting dh tkrh gS rc geas”kk Outer Loop, Inner Loop dks Control djrk gSA Outer Loop Row ds fy;s o Inner Loop Column ds fy;s fy[kk tkrk gSA bldk Syntax fuEukuqlkj gksrk gS&
Definition of Nesting of for Loop tc Program Control, Outer for Loop ij vkrk gS rc check djrk gS fd Outer For Loop dh Condition lR; gS ;k ughaA ;fn Outer For Loop dh Condition lR; gksrh gS] rks Program Control Inner Loop esa izos”k djrk gSA ;gka Program Control dks ,d vkSj for Loop feyrk gS vkSj izksxzke Control bl for dh Condition dks check djrk gSA ;fn Inner for Loop dh Condition lR; gksrh gS rks Inner for Loop Iterate gksrk gS vkSj ;s Inner Loop rc rd Iterate gksrk jgrk gS tc rd fd Inner Loop dh Condition lR; gksrh gSA
171 Any Question or Suggestion, Just Discuss Here...
Java in Hindi tSls gh inner Loop dh Condition vlR; gksrh gS] izksxzke Control okil Outer Loop dks check djrk gSA ;fn okil Outer Loop dh Condition lR; gks tkrh gS rks Program Control iqu% inner Loop esa izos”k djrk gS vkSj iqu% Inner Loop dk rc rd Iteration gksrk gS tc rd fd Inner Loop dh condition vlR; ugha gks tkrhA Program Control bUgha nksuksa Loops ds chp rc rd Iterate gksrk jgrk gS tc rd fd nksuksa Loops dh Condition vlR; uk gks tk,A ;fn Outer Loop dh Condition igyh ckj esa gh vlR; gks tk, Execution gh ugha gksrk gSA Inner Loop dk Execution rHkh gksrk gS Condition lR; gksA Loop dh Nesting dks le>us ds fy;s vkxs ,d blls for Loop dh nesting o mlds dke djus rjhds dks vPNh rjg ls
rks Inner Loop dk tc Outer Loop dh izksxzke cuk;k x;k gSA le>k;k x;k gSA
Example :
,d ,slk izksxzke cukvks tks fuEu Format dks print djsA * ** *** **** *****
bl izksxzke esa nks for Loop pyk, x, gSa vkSj Condition bl izdkj dh j[kh xbZ gS fd Inner Loop mruh gh ckj pys ftruk ckgj dk Loop pykus okys Variable dk eku gksA izksxzke fuEukulkj gS% Program public class ForLoopNested { public static void main(String args[]) { for(int i=1; i<=5; i++) { for(int j=1; j<=i; j++) { System.out.print(" * "); } System.out.println(); } } } Output
* * * * *
* * * *
* * *
* *
*
172 Any Question or Suggestion, Just Discuss Here...
Java in Hindi tc fdlh Statement dh Nesting dh tkrh gS rc Inner Most Control Statement igys Execute gksrk gS vkSj fQj Øe ls Outer Control Statements Execute gksrs gSaA tc ;s Program Run fd;k tkrk gS] rc lcls igys Program Control Outer Loop esa igqaprk gSA Outer Loop dh Condition true gksrh gS D;ksafd i dk eku 1 ls de gSA blfy, Program Control Outer Loop ds Statement Block esa izos”k djrk gSA Statement Block esa fQj ls ,d Loop izkIr gksrk gSA ;s Loop Hkh True Return djrk gS] D;ksafd Inner Loop ds Variable j dk eku i ds eku 1 ds cjkcj gSA bl fLFkfr es Program Control Inner Loop ds Statement Block esa izos”k djrk gS vkSj ,d * Print djrk gSA pwafd ge pkgrs gSa fd * Print gksus ds ckn Hkh gesa New Line izkIr uk gks] blfy, geus bl Block esa out Object ds print() Method dk iz;ksx fd;k gSA Inner Loop ds Statement Block dk Execution gksus ds ckn j dk eku Increment gks dj 2 gks tkrk gSA pwafd i dk eku 1 gS vkSj j dk eku 2 gS] blfy, j dk eku i ds eku ls NksVk ;k
cjkcj ugha gSA
bl fLFkfr esa Inner Loop false Return djrk gSA tc Inner Loop False gks tkrk gS] rc Program Control Outer Loop ds Variable i dk eku Increment djds 2 dj nsrk gSA pwafd i dk eku vHkh Hkh 5 ls de gS blfy, Outer Loop dh Condition true gksrh gS vkSj Program Control Outer Loop ds Statement Block esa igqaprk gS] tgka mls fQj ls Inner Loop izkIr gksrk gSA pwafd Inner Loop ds Looping Variable dks geus Inner Loop ds Parenthesis esa gh Declare fd;k gS] blfy, tc Program Control bl Inner Loop esa izos”k djrk gS rc Inner Loop ds Variable dks Create djrk gS vkSj tc Program Control Inner Loop ls ckgj fudyrk gS] rc Inner Loop ds Variable dks Destroy dj nsrk gSA blfy, ftruh ckj Hkh Program Control Outer Loop ds Statement Block esa vkrk gS] os Inner Loop ds Variable dks fQj ls Create djrk gSA ,slk djus ds dkj.k Inner Loop ds Variable dk eku okil ,d gks tkrk gS D;ksafd Inner Loop dk Variable Create gksus ds ckn fQj ls Initialize gksrk gSA pwafd Inner Loop ds Variable j dk eku fQj ls 1 gks x;k gS vkSj ;s eku Outer Loop ds Variable i ds eku ls de gS] blfy, Loop Execute gksrk gS vkSj ubZ Line esa ,d * Print djrk gSA fQj j dk eku Increment gksdj 2 gks tkrk gSA ;s eku 2 i ds eku ds cjkcj gS] blfy, Inner Loop fQj ls Execute gksrk gS vkSj ,d vkSj * Print djrk gSA tc rhljh ckj Inner Loop ds Variable j dk Increment gksrk gS] rc j dk eku i ds eku ls T;knk gks tkrk gS vkSj Program Control Inner Loop ls ckgj fudyrk gSA ogka mls ,d println() Method feyrk gSA ;s Method dsoy ,d New Line iznku djrk gSA blds ckn i ds eku dk Increment gksdj i dk eku 3 gks tkrk gSA pwafd i dk ;s eku Hkh 5 ls NksVk gS] blfy, Outer Loop fQj ls Execute gksrk gSA Inner Loop ds Variable dk eku okil 1 gks tkrk gSA bl fLFkfr esa vc Inner Loop rhu ckj Execute gksrk gS vkSj rhu * Print djrk gSA
173 Any Question or Suggestion, Just Discuss Here...
Java in Hindi ;s izfØ;k rc rd pyrh jgrh gS] tc rd fd Outer Loop ds Variable i dk eku 6 ugha gks tkrkA tSls gh i dk eku 6 gks tkrk gS] Outer Loop false Return djrk gSA ftlls Program Control Outer Loop ds Statement Block esa izos”k gh ugha djrk vkSj lh/ks gh Program ds vUr ij igqap tkrk gSA bl rjg ls bl Program esa ge ns[k ldrs gSa] fd Inner Loop dk Execution mlds Outer Loop dh Condition ij fuHkZj djrk gSA ;fn Outer Loop Execute gksrk gS rks gh Inner Loop Execute gksrk gSA for Loop dk T;knkrj iz;ksx fdlh Array ds fofHkUu Index Number ij fLFkr ekuksa dks izkIr djus ds fy, fd;k tkrk gSA fiNys v/;k; esa geus ,d Array esa Stored ekuksa dks dbZ Statements }kjk Screen ij Print fd;k FkkA mlh Program ds Array ds fofHkUu ekuksa dks ge fuEukuqlkj Loop ds iz;ksx ds }kjk Hkh Access dj ldrs gSaA Program public class ArrayWithLoop { public static void main(String args[]) { String name[] = new String[6]; name[0] = "Balaji" ; name[1] = "Madhav" ; name[2] = "BalGopal" ; name[3] = "Nandlal" ; name[4] = "BalKishan" ; name[5] = "ManMohan" ;
}
}
for(int i=0; i<=5; i++) { System.out.println("Name in Array at Index Number ["+i+"] = " + name[i]); }
Output Name in Array at Index Number [0] = Balaji Name in Array at Index Number [1] = Madhav Name in Array at Index Number [2] = BalGopal Name in Array at Index Number [3] = Nandlal Name in Array at Index Number [4] = BalKishan Name in Array at Index Number [5] = ManMohan
tSlkfd geus igys gS] blfy, gesa tks Program esa tc Screen ij Print
Hkh dgk fd fdlh Hkh Array ds igys Index Number dk eku gesa”kk 0 gksrk Loop Array ds fy, Use djuk gksrk gS] mls gesa”kk 0 ls “kq: djrs gSaA bl i dk eku 0 gksrk gS rc Array ds Index Number 0 ij fLFkr String gksrh gSA tc i dk eku 1 gksrk gS] rc Array ds Index Number 1 ij fLFkr
174 Any Question or Suggestion, Just Discuss Here...
Java in Hindi String Screen ij Print gksrh gSA blh rjg ls Array dh fofHkUu Strings Output esa Print
gksrh gSA
tc ge fdlh 2-D Array ds fofHkUu Data Elements dks Loop }kjk Access djuk pkgrs gSa] rks gesa nks Inner Loops dk iz;ksx djuk iMrk gSA blh rjg ls ;fn gesa 5-D Array ds fofHkUu Data Elements dks Access djuk gks] rks gesa ikap Inner Loop pykus gksrs gSaA geus fiNys v/;k; esa ftl 2-D Array dks lkekU; Statement }kjk Access fd;k Fkk ;fn ge mlh Array dks Loop }kjk Access djuk pkgsa] rks ;s dke ge fuEukuqlkj dj ldrs gSa& Program public class TableWithArray { 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 ;
}
}
for(int i=0; i<4; i++) { for(int j=0; j<3; j++) { System.out.println("Value in Array at Index Number [“ +i+ “][“ +j+ “] = " + table[i][j]); } }
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 Value in Array at Index Number [2][0] = 2 Value in Array at Index Number [2][1] = 12
175 Any Question or Suggestion, Just Discuss Here...
Java in Hindi 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
fdlh 2-D Array esa Outer Loop gesa”kk ROW dks Represent djrk gS vkSj Inner Loop COLUMNS dks Represent djrk gSA pwafd gekjh Table esa ROWS dh la[;k 4 gS blfy, Outer Loop dks pkj ckj pykuk t:jh gS vkSj COLUMNS dh la[;k 3 gS blfy, Inner Loop dks rhu ckj pyk;k gSA lkFk gh Array ds Index Numbers dh “kq:vkr gesa”kk 0 ls gksrh gS] blfy, Loop ds izkjfEHkd eku dks 0 Initialize fd;k gSA while Loop For Loop dh rjg ;g Hkh fdlh Statement ds nksgjkus dk dke djrk gS] ysfdu fQj Hkh ;g for Loop ls dkQh vyx gSA bl Loop esa Java ds Keyword while dk iz;ksx fd;k tkrk gSA while Loop esa while dks’Bd esa dsoy Condition nh tkrh gSA Variable dk izkjafHkd eku o Step Size while ds dks’Bd dk fgLlk ugha gksrs gSa] cfYd Variable dk izkjafHkd eku while Loop dks “kq: djus ls igys gh Declare o Initialize dj fn;k tkrk gS vkSj Loop dh Step Size while Condition ds Statement Block dk fgLlk gksrh gSA while Loop dk syntax fuEukuqlkj gksrk gS% Variable Declaration; Value Initialization; while(Condition ) { Statement Block; Step Size; } Statement 1; while Statement ds dks’Bd ds ckn dHkh Hkh ; (Semi Colon) dk iz;ksx ugha fd;k tkrk gSA tc while ds ckn dsoy ,d gh Statement dk Execution djuk gksrk gS] rc gesa ea>ys
dks’Bd dk iz;ksx djus dh t:jr ugha jgrh gSA fQj Hkh ;fn ea>ys dks’Bd dk iz;ksx dj fy;k tk, rks dksbZ QdZ ugha iMrk gSA
Control Flow in while Loop LkoZizFke gesa Loop pykus okys Variable dks izkjafHkd eku nsuk gksrk gSA ;g dke while Loop ds ckgj gh dj fy;k tkrk gSA tc Program Control, while Loop esa izos”k djrk gS rks Program Control, Condition Check djrk gSA ;fn Condition lR; gksrh gS rks Program Control while Loop ds Statement Block esa izos”k djrk gS vkSj Statement Block dk Execution djrk gSA Execution ds ckn Statement Size r; djrk gS] ;kuh Loop ds Variable dk eku t:jr ds vuqlkj Increment ;k Decrement djrk gSA
;g Øe rc rd pyrk jgrk gS tc rd fd while Condition vlR; ugha gks tkrh gSA ;fn Condition lR; ugha gksrh gS rks Program Control while Loop ds Statement Block esa izos”k ugha djrk] cfYd lh/ks gh Statement 1 ij pyk tkrk gSA
176 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Example : While Loop dk iz;ksx djrs gq, ,d ,slk izksxzke cukvks ftlesa 1 ls 100 ds chp og la[;k Print gks ftlesa 2 o 3 dk iwjk&iwjk Hkkx tkrk gSA Program Definition & fdlh Hkh Loop dks pykus ds fy;s Loop dh vko”;d rhuksa ckrsa gesa irk gksuh pkfg,A igyh ckr ;s fd Loop dk izkjaHk dgka ls gksxk] nwljk ;s fd Loop dk var dgka gksuk gS vkSj rhljk ;s fd Loop dks fdl Øe esa Increase ;k Decrease djuk gSA fdlh Hkh Loop esa fdlh Variable }kjk ;s rhuksa ckrsa r; dh tkrh gSaA
bl izksxzke esa Hkh ,d Variable x fy;k x;k gS rkfd ;s rhuksa eku izkIr fd;s tk ldsaA bl izksxzke esa gesa 1 ls 100 ds chp dh la[;kvksa ij izfØ;k djuh gS blfy;s Loop ds Variable dk izkjafHkd eku 1 o vafre eku 100 Define fd;k x;k gS vkSj Step Size dks ,d ds Øe esa gh c
iwjk&iwjk Hkkx tkrk gSA bl “krZ dks ;fn ge /;ku ls le>sa rks ;s dg ldrs gSa fd bl ,d “krZ esa nks “krZ gSA igyh ;s fd fdlh la[;k esa 2 dk Hkkx iwjk&iwjk tkuk pkfg;s vkSj nwljh ;s fd mlh la[;k esa 3 dk Hkkx Hkh iwjk&iwjk tkuk pkfg;s rHkh og Condition iw.kZ :i ls lR; gksxhA bl “krZ dks ;fn ge nwljs “kCnksa esa dgsa rks dg ldrs gSa fd fdlh la[;k esa ;fn 2 dk Hkkx nsus ij “ks’k Qy “kqU; izkIr gksrk gS rks Condition lR; gksrh gSA ;fn bls xf.krh; :i esa fy[ksa rks x%2 == 0 fy[k ldrs gSaA lkFk gh mlh la[;k esa 3 dk Hkkx Hkh iwjk&iwjk tkuk pkfg;s ;kuh mlh la[;k esa 3 dk Hkkx nsus ij Hkh “ks’kQy “kwU; vkuk pkfg;s bls Hkh xf.krh; :i esa x%3 = = 0 fy[k ldrs gSaA bl izdkj nksuksa Condition lR; gksus ij gh Statement Block dk Execution gksuk pkfg;sA vr% bu nksuks Condition dks Logical Operator AND ( && ) }kjk tksM dj if dks’Bd esa fy[kuk gksxkA bl izdkj bl Loop dh okLrfod Condition x % 2 = = 0 && x % 3 = = 0 gksxhA bl izdkj gesa bl izksxzke dh lHkh vk/kkjHkwr phtsa izkIr gks tkrh gSa tks fuEukuqlkj gSa& 1 2
3
Loop ds Variable dk izkjafHkd eku ftlls Loop dk Iteration “kq: gksxk ;kuh 1 Loop ds Variable dk vafre eku ftlds ckn Loop dk Iteration :d tk,xk] ;kuh 100 Loop ds Variable dh Step Size ftl Øe esa Loop ds Variable dk increment
gksxkA
177 Any Question or Suggestion, Just Discuss Here...
Java in Hindi 4 ,d if Condition ftlesa ;s check gksxk fd 1 ls 100 ds chp dkSulh la[;k,a gSa ftuesa 2 o 3 nksuksa dk Hkkx iwjk&iwjk tkrk gSA bl Discussion ds vk/kkj ij ge fuEukuqlkj while Loop dk iz;ksx djds bl leL;k dks gy dj ldrs gS:a Program public class DivisionWithReminder { public static void main(String args[]) { int x = 1; while(x<=100) { if(x%2 == 0 && x%3 == 0) { System.out.print(“\t” + x); } x++; } } } Output 6 12 18 24 30 36 42 48 54 60 66 72 78 84 90 96
lkekU;r;k bl Loop dk iz;ksx ge rc djrs gSa] tc gesa ;s irk ugha gksrk gS fd Loop ds Statement Block dks fdruh ckj Execute djuk gSA tcfd for Loop dk iz;ksx ge rc djrs gSa tc gesa irk gksrk gS fdlh for Loop ds Statement Block dk iz;ksx fdruh ckj djuk gSA
do while Loop ;g Java esa iz;ksx gksus okyk rhljk o vafre Loop gSA blesa Hkh vU; Loop dh rjg gh rhuksa vk/kkjHkwr Statements dh t:jr gksrh gS ;kuh Loop ds Variable dk izkjafHkd eku] vafre eku o Step Size. bl Loop dh fo”ks’krk ;s gS fd bl esa check gksus okyh Condition Loop ds var esa check gksrh gSA ;kuh tc gesa ,slh t:jr gks fd izksxzke esa Loop ds Statement ;k Statement Block dk Execution de ls de ,d ckj rks djuk gh gks] rc ge bl Loop dk iz;ksx djrs gSaA bl Loop dk syntax fuEukuqlkj gS& Variable Declaration; Value Initialization; do {
Statement Block; Step Size; }while(Condition); 178 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Statement 1;
bl Loop dh “kq:vkr do key word ls gksrh gS vkSj Statement Block ds ckn ea>yk dks’Bd can djus ds ckn while Condition nh tkrh gSA lkFk gh ;gh ,d Loop gS] ftlesa while ds Condition dks’Bd ds ckn ; (Semi Colon ) dk iz;ksx fd;k tkrk gSA do ds ckn dksbZ Hkh Colon ;k Semi Colon iz;kssx ugha fd;k tkrk gSA bl Loop esa izksxzke Control dks tSls gh do Key word feyrk gS rks Program Control lh/ks gh do ds Statement Block esa pyk tkrk gS vkSj mlesa fy[ks Statements dks Execute dj nsrk gSA faQj Loop pykus okys Variable dk Step Size Increase ;k Decrease izksxzke ds vuqlkj djrk gSA Program Control tc bl Block ls ckgj vkrk gS rc mls while Condition izkIr gksrh gSA ;gka ;fn Condition lR; gksrh gS rks Program Control do ls okil Statements dk Execution djrk gS vkSj ;fn Condition vlR; gksrh gS] rks Program Control Loop dks okil Iterate ugha djrk cfYd lh/ks gh Statement 1 ij pyk tkrk gSA for Loop dks ge while Loop dh rjg Hkh Use dj ldrs gSaA ;fn ge fiNys Program dks for Loop ls gh gy djuk pkgsa vkSj lkFk gh ;s Hkh pkgsa fd for Loop dks while Loop dh rjg gh Use djsa] rks ge ;s dke djus ds fy, for Loop dks fuEukuqlkj Use djrs gq, mijksDr Program fy[k ldrs gSa& Program public class DivisionWithReminder { public static void main(String args[]) { int x = 1; for( ; x<=100 ; ) { if(x%2 == 0 && x%3 == 0) { System.out.print(“\t” + x); } x++; } } }
ge fofHkUu izdkj ds Loops dh Hkh mlh izdkj ls Nesting dj ldrs gSa] ftl rjg ls for Loop dh dj ldrs gSaA ;kuh ge fdlh leL;k ds lek/kku ds fy, fdlh Hkh Loop dk iz;ksx dj ldrs gSaA
;s gekjh lqfo/kk ij fuHkZj djrk gS fd ge fdlh leL;k ds lek/kku ds fy, fdl Loop dk iz;ksx djrs gSaA fofHkUu Loops dks ,d nwljs ds izfrLFkkiu ds :i esa Use fd;k tk ldrk gS vkSj ge fdlh Hkh dke dks rhuksa gh Loops }kjk leku izdkj ls lEiUu dj ldrs gSaA
179 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Jump Statements
tkok esa rhu rjg ds Jump Statements gSa ftudk iz;ksx djds ge gekjs Program esa fdlh Hkh Statement ij Jump dj ldrs gSaA break Statement bl Statement dk iz;ksx ge nks LFkkuksa ij dj ldrs gSaA igyk iz;ksx geus switch Statement esa ns[k fy;k gSA ge fiNys Programs esa ns[k ldrs gSa Loop ds Iteration ds le; Loop ds Block Statements dk nksgjku rc rd gksrk jgrk gS] tc rd fd Loop dh Condition lR; gksrh gSA ysfdu dbZ ckj gekjs lkeus ,slh ifjfLFkfr vk tkrh gS fd fdlh [kkl dke ds fy;s gesa Loop ds dqN Statements ds Execution dks NksM dj Loop ds chp esa ls gh ckgj vkuk gksrk gS] ml le; ge break Statement dk iz;ksx djrs gSaA ;s bl Statement dk nwljk iz;ksx gSA ge fdlh Loop esa tgka Hkh bl Statement dks fy[k nsrs gSa] Program Control lh/ks gh bl Statement ds feyrs gh Loop ls ckgj fudy tkrk gSA bls ,d Program }kjk le>us dh dksf”k”k djrs gSa& Program public class BreakStatement { public static void main(String args[]) { for(int i=0; i<10; i++) { if(i==5) { break; } System.out.print(“\t” + i); } System.out.println(“\nLoop is Terminated”); } } Output 0 1 2 3 4 Loop is Terminated
bl Program esa gkykafd geus Loop dks 10 ckj pyk;k gS] ysfdu tSls gh i dk eku 5 gksrk gS] Loop ds Statement Block esa fy[kk x;k if Statement true gks tkrk gS vkSj Program Control bl Statement Block esa izos”k djrk gS] tgka mls break Statement izkIr gSA ;s Statement izkIr gksrs gh Program Control Loop ls ckgj fudy tkrk gS vkSj Sequential Statement dks Print dj nsrk gSA
180 Any Question or Suggestion, Just Discuss Here...
Java in Hindi bl Statement dk iz;ksx djds ge fdlh Hkh Statement ij Jump dj ldrs gSaA bls le>us ds fy, fuEu Program nsf[k,% Program public class BreakStatementJump { public static void main(String args[]) { boolean x = true; first: { second: { third: { System.out.println("Before the break statement."); if( x )
}
}
break second;
System.out.println("This statement will not Execute."); } System.out.println("This statement will not Execute."); } System.out.println("This Statement will Execute after second Block."); }
Output Before the break statement. This Statement will Execute after second Block.
bl Program esa geus rhu Statement Blocks cuk, gSaA ;s Statement Blocks fdlh Loop ds Hkh gks ldrs gSa vkSj lkekU; Block Hkh gks ldrs gSaA rhuksa Blocks esa geus ,d Label fn;k gSA Outer Most Block ls igys geus first Label fn;k gSA fQj Middle Block dk Label geus second fn;k gS vkSj Inner Most Block ls igys geus third Label fn;k gSA ,d ckr /;ku j[ksa fd Label ds ckn gesa”kk Colon dk iz;ksx gksrk gS uk fd Semi Colon dkA tc Program Control Inner Most Block esa igqaprk gS] rc mls fuEukuqlkj ,d Break Statement feyrk gS& if(x)
break second;
;kuh Program Control dks bl Statement ls ;s tkudkjh feyrh gS fd ;fn x dk eku true gS rks ml Block ls ckgj fudy tkuk gS] ftlesa second Label dks Define fd;k x;k gSA
181 Any Question or Suggestion, Just Discuss Here...
Java in Hindi pwafd second Label nwljs Block dks Represent dj jgk gS] blfy, Program Control nwljs Block ls ckgj fudy tkrk gS vkSj rhljs Block ds Statement dk Execution dj nsrk gSA ifj.kke Lo:i gesa Output esa dsoy nks gh Statements izkIr gksrs gSaA tkok esa bl Statement dks “C” o “C++” ds goto Statement ds LFkku ij iz;ksx fd;k x;k gSA D;ksafd Java esa goto Statement dks Include ugha fd;k x;k gSA ;s Statement tkok esa os lHkh dke dj ldrk gS ftu dkeksa dks “C” o “C++” esa goto Statement ds iz;ksx }kjk fd;k tk ldrk FkkA continue Statement bl Statement dk iz;ksx rc fd;k tkrk gS] tc ge fdlh [kkl ifjfLFkfr esa Loop ds fdlh nksgjku esa Block ds Statements dks Execute djuk ugha pkgrs gSA /;ku nsa fd tgka break dk iz;ksx Program Control dks Loop ls gh ckgj fudky nsrk gS] ogka continue dk iz;ksx gesa Loop ls ckgj ugha fudkyrk cfYd dsoy ek= gesa Loop ds ml Iteration ls ckgj fudkyrk gSA uhps break o continue Statement ds iz;ksx ls izksxzke cuk;k x;k gS ftlls bUgs vklkuh ls le>k tk ldrk gSA Program public class BreakAndContinueStatement { public static void main(String args[]) { for(int i=0; i<10; i++) { if(i==5) { break; } System.out.print(“\t” + i); } System.out.println(“\nBreak Loop is Terminated”);
}
}
Output 0 1
for(int i=0; i<10; i++) { if(i==5) { continue; } System.out.print(“\t” + i); } System.out.println(“\nContinue Loop is Terminated”);
2
3
4
182 Any Question or Suggestion, Just Discuss Here...
Java in Hindi Break Loop is Terminated 0 1 2 3 4 6 7 8 Continue Loop is Terminated
9
bl Program esa ge nksuksa Statements ds vUrj dks le> ldrs gSa] tgka Break Statement gesa ml le; Loop ls ckgj fudky nsrk gS] tc Loop ds Variable i dk eku 5 gksrk gSA ogha Continue Statement gesa dsoy Loop ds ml Iteration ls vxys Iteration esa Move dj nsrk gS] ftl Iteration esa Variable i dk eku 5 gksrk gSA return Statement ;s Statement fdlh Method ls Program Control dks Return djus ds fy, iz;ksx fd;k tkrk gSA main() Method dh rjg gh vkxs ge Lo;a ds User Defined Methods cukuk Hkh lh[ksaxsA ;s Methods Class ds Member Function ds :i esa Define fd, tkrs gSaA fdlh Method ls fdlh fo”ks’k fLFkfr esa dqN Statements dks fcuk Execute fd, gq,] tc Program Control dks Return gksuk gksrk gS] rc bl Statement dk iz;ksx fd;k tkrk gSA lkFk gh bl Statement dk iz;ksx fdlh Method ls fdlh eku dks return djokus ds fy, Hkh fd;k tk ldrk gSA bl Statement ds ckjs esa ge Methods dks le>rs le; Use djsaxsA
Drawing Graphics
gesa yxHkx lHkh Applets esa FkksMk cgqr Graphics Programming rks djuk gh iMrk gS] fQj pkgs ge Texts dh ,d Line Applet ij Display djus ds fy, Graphics Programming dk iz;ksx djsa ;k fQj pkgs Animation ds :i esa Graphics dh ,d Sequence Display djsaA D;ksafd Windows ,d GUI System gS] blfy, gesa Screen ij tks dqN Hkh fn[kkbZ nsrk gS] og lcdqN Graphically gh fn[kkbZ nsrk gSA ;gh ckr Texts ds lEca/k esa Hkh Apply gksrh gSA ;kuh Windows ;k GUI Mode esa gesa Screen ij tks Texts Hkh fn[kkbZ nsrs gSa] os Texts Hkh okLro esa Graphics gh gksrs gSaA
Applet Canvas fdlh Applet dk tks fgLlk gesa Screen ij fn[kkbZ nsrk gS] Applet ds ml fgLls dks Canvas dgrs gSa] ftlesa Applet fofHkUu izdkj dh Information ;kuh Texts o Graphics dks Display djrk gSA Applet ds Canvas dh Size Applet dh Size ij fuHkZj gksrh gSA ;kuh Applet ftruk cMk gksxk] Applet dk Canvas Hkh mruk gh cMk gksxkA Applet dh Size HTML Document ds