Tuesday, March 25, 2025
What is Java ?

Java क्या है?

Java एक popular programming language है, जिसे 1995 में बनाया गया था।

यह Oracle के स्वामित्व में है, और 3 बिलियन से अधिक डिवाइस Java चलाते हैं।

It is used for : 

  • Mobile Apps (especially Android Apps)
  • Desktop application
  • Web Applications
  • Web server and application server
  • sport
  • Database connection
    etc.

Why use Java?

  1.  Java विभिन्न platforms (Windows, Mac, Linux, Raspberry Pi, etc.) पर काम करता है |
  2.  यह दुनिया में सबसे popular programming languages में से एक है |
  3. यह सीखना easy है और उपयोग में सरल है |
  4.  यह open-source और free है |
  5.  यह safe, fast और powerful है |
  6.  इसका एक विशाल community support है (tens of millions of developers) .
  7. Java एक object-oriented language है जो programs को एक स्पष्ट संरचना देता है, और code को reused करने की Permission देता है, जिससे विकास लागत कम होती है|

जैसा कि java, C ++ और C # के करीब है, यह programmer के लिए java या इसके विपरीत switch करना easy बनाता है |

Java variable :

Variable data values को Store करने के लिए Container हैं।

Types of variable :
Java के लिए Variables के तीन type होते है |

  1.  Local Variable
  2. Instance Variable
  3. Static Variable

        Local Variable :

  •  Local Variables block, methods और constructor के अन्दर होते है |
  •  Local Variable का scope  local होता है | ये सिर्फ methods और constructor के अन्दर visible होते है |
  •  जब Local Variables; methods और constructor के बाहर जाते है, तब destroyed हो जाते है |

        Instance Variable :

  • Instance Variables; class के अन्दर होते है और methods और constructor के बाहर होते है |
  • Instance Variables non-static variables होते है |

       Static Variable :

  • Static Variables को Class Variables भी कहते है |
  • ये Instance Variable के तरह class के अन्दर और methods और constructor के बाहर होते है |
  • ‘static’ keyword के साथ इनका इस्तेमाल किया जाता है |

Java में, विभिन्न प्रकार के variable हैं, उदाहरण के लिए :

  1. String – Text stores, such as “Hello”। String value double quotes से घिरा हुआ है|
  2. int – stores integers (पूर्ण संख्या) को, Decimal के बिना, जैसे कि 123 या -123 store करता है|
  3. Float – floating point numbers को, decimals के साथ, जैसे 19.99 या -19.99 store करता है|
  4. char – single characters, जैसे ‘a’ या ‘B’ को store करता है।four values are surrounded by single quotes.
  5. Boolean – two states के साथ values को store करता है True or False.

Java identifier:

  • सभी Java variables को specific names से पहचाना जाना चाहिए।
  • इन distinct names को identifiers कहा जाता है।
  • identifiers संक्षिप्त नाम (जैसे x और y) या अधिक descriptive names (age, sum, total volume) हो सकते हैं।
  • Common rules for creating names for variables (unique identifiers) are:
  • Names may contain letters, digits, underscores, and dollar के संकेत हो सकते हैं|
  • Names must begin with a letter.
  • Names को lowercase letter से शुरू करना चाहिए और इसमें Whatsapp नहीं हो सकता है|
  • Name भी $ और _ से शुरू हो सकते हैं (but we will not use them in this tutorial)
  • Names sensitive हैं (“myVar” और “myvar” अलग-अलग Variable हैं)
  • Reserved words (such as Java keywords, such as int or boolean) को name के रूप में उपयोग नहीं किया जा सकता है|

Java Operator:

  • Operators का उपयोग mathematical comparison और logical operation करने के लिए किया जाता है operators हमारे प्रोग्राम में data और variable का हेर फेर करते है।
  • Operators ऐसे sign होते हैं, जो Java interpreter को विशिष्ट Mathematical या Logical process करने के लिए सूचना देते हैं।
  • इन Symbols का Use variables को operate करने हेतु किया जाता हैं, इसलिए इन्हें operator कहा जाता हैं।
  • Java में operators का Use आप variables पर operations perform करने के लिए करते है। हर data type पर अलग अलग operations perform किये जाते है।

Operators unary और binary प्रकार के होते है।Java में 6 type के operators होते है|

  1. Arithmetic Operator
  2.  Relational Operator
  3. Logical Operator
  4. Bitwise Operator
  5. Assignment Operator
  6. Conditional Operator           

1. Arithmetic Operator

  • Arithmetic Operator का इस्तेमाल Operands(Variables, जिनपर Operation किया जाना हैं उन्हें operands कहा जाता हैं) पर आसान अंक-mathematical process करने हेतु किया जाता हैं।
  • Operator Use Explanation
  • + Addition Addition operator 2 values को add करने के लिए यूज़ किया जाता है।
  • – Minus Subtraction operator एक value में से दूसरी value को subtract करने के लिए यूज़ किया जाता है।
  • * Multiplication Multiplication operators 2 variables की values को multiply करने के लिए यूज़ किया जाता है।
  • / division किसी एक variable की संख्या का भाग दूसरे variable की संख्या में देने के लिए division operator यूज़ किया जाता है।
  • % Modulus भाग देने के बाद यदि आप शेष बची हुई संख्या प्राप्त करना चाहते है तो modulus operator यूज़ करते है।

2.Logical Operators :

  • Logical Operators का इस्तेमाल, logical AND और logical OR इन Operation को करने के लिए किया जाता हैं जोकि Digital Electronics के AND गेट और OR Gate से सम्बंधित हैं।
  • Operator Explanation Example
    Logical AND (&&) इस तरह के operators के साथ जब दोनों variables की value true होती है तो ही result true होता है नहीं तो false होता है। a&&b
  • Logical OR (||) इस तरह के operator के साथ यदि दोनों variables में से किसी एक भी value true होगी तो result true ही होगा। a||b
  • Logical NOT (!) ये एक unary operator है। जिस भी variable के साथ ये Use किया जाता है उस variable की value को उल्टा कर देता है। !a

3. Bitwise Operators :

  • Bitwise operators bit by bit operations perform करने के लिए Use किये जाते है। ये operators variables की values को bits में convert करके उन पर operations perform करते है।
  • Bitwise operators 4 types के होते है।
  1. Bitwise AND (&) इस operator को जिन 2 variables के साथ use किया जाता है ये उनकी common bits को result variable में copy कर देता है। a&b
  2. Bitwise OR (|) इस operator को जिन 2 variables के साथ Use किया जाता है ये उनकी uncommon bits को result variable में copy कर देता है। a|b
  3. Left shift (<<) इस operator के द्वारा आप किसी variable की value को bits में convert करने के बाद उसकी bits को left में shift करते है। कितनी bits को Shift करना है ये वो variable बताता है जो इसके right में होता है। a<<b
  4. Right shift (>>) इस variable के द्वारा आप किसी variable की value को bits में convert करने के बाद उसकी values को right में shift करते है। कितनी bits को shift करना है ये वो variable बताता है जो इसके right में होता है। a>>b

4.Relational Operators :

  • Relational Operators का इस्तेमाल दो या अधिक Variables के बीच Relations को जांचने के लिए किया जाता हैं, जैसे की- से बड़ा, से कम, समान इत्यादी। Relation Operators का इस्तेमाल अधिकतर Loop Statement या If-Else Control Structure में किया जाता हैं।
  • Operator Explanation Example
  • Equal to (==) यदि दोनों variables equal होते है तो result true होता है। a==b
  • Not equal to (!=) यदि दोनों variables एक दूसरे के equal नहीं होते है तो result true return होता है। a!=b
  • Greater than (>) यदि left side का variable right side के variable से बड़ा है तो result true होता है। a>b
  • Less than (<) यदि left side का variable right side के variable से छोटा है तो result true होता है। a<b
  • Greater than equal to (>=) यदि left side का variable right side के variable से बड़ा है या उसके बराबर है तो result true होगा। a>=b
  • Less than equal to (<=) यदि left side का variable right side के variable से छोटा है या उसके बराबर है तो result true होता है a<=b

5.Assignment Operators :

  • Assignment Operator का इस्तेमाल Variables को Value Assign करने के लिए किया जाता हैं। आम तौर पर Variable के दाईं ओर लिखी Value, बाईं तरफ लिखे Variables में स्टोर की जाती हैं।
  • Assignment Operator(=) के साथ किसी भी Arithmatic Operator का इस्तेमाल किया जा सकता हैं। जैसे की,+=, -=, *=, /= इत्यादि.

6.Conditional Operator :

  • Conditional operator java का special operator होता है जो if statement की तरह काम करता है। इसे ternary operator भी कहते है।
  • ये variables में conditions के according values store करने के लिए Use किया जाता है।

Control Statement :

  • Java में programme को control करने के लिए control statements का use करते हैं जो programme के statements को condition के द्वारा बांध देते है अगर condition true होगी तो statement execute होगा नहीं तो condition false होने पर कोई और statement execute हो जायेगा या फिर programme exit हो जायेगा |
  • यह 6 Types के होते हैं |
  1. if statement :
    if Statement में अगर Condition true होती है तब Statement Execute होता है |
  2. If-else statement :
    if else Statement में अगर Condition true हो तो वो if का statement Execute करता है | अगर Condition false होती है तो else का Condition करता है |
  3. Else-if statement :
    else if Statement में अगर if की Condition true होती है तो if का statement execute होता है | अगर if का condition false होता है तो वो अगले condition पर जाकर check करता है | अगर वो condition true होता है तो वो उसका statement execute करता है | अगर कोई भी condition true नहीं होती तो वो else का statement execute करता है |
  4. Switch case statement :
    Switch case statement में expression होता है और उससे related कुछ cases होते है | जो case उस expression या declare किये हुए variable से match होती है तब वो output में print होता है | अगर कोई भी case expression से match नहीं होती तो वो default का statement output में print करेगा | आपको हर statement के बाद break लगाना पड़ता है, इसका मतलब वो उसके पहले का statement ही print करेगा | अगर आप break नहीं लगाते तो वो पहला और दूसरा ये दोनों statement को print करेगा | default case के बाद break नहीं लगाते |
  5. Break statement :
    Break Statement Program के loops और switch case के execution का काम किसी condition पर बंद कर देता है |
  6. Continue statement :
    Continue Statement Program के loops के condition के हिसाब से बीचवाले statements को skip कर देता है और बादवाले statement को execute करता है |

Classes in Java:

  • एक class object का एक group है। यह एक Template या blueprint है जिसमें से object बनाए जाते हैं। यह एक logical entity है। यह physical entity नहीं हो सकता।
  • Java में सब कुछ class और object के साथ-साथ इसकी विशेषताओं और method के साथ जुड़ा हुआ है। for exp- वास्तविक जीवन में, एक car एक object है। car में वजन और रंग, जैसे drive और break जैसी विशेषताएं हैं।

Object in Java:

  • Java में, Class से Object बनाया जाता है।
  • सबसे पहले हमे object बना ने के लिए जावा basic syntax लिखा उसके बाद । जब आप कोई भी object create करते है तो सबसे पहले उस class का constructor call होता है। constructor बना ने के लिए हमे brackets का यूज़ करना पड़ता

Inheritance In Java:

  • Java में Inheritance ये Object Oriented Programming का एक प्रकार है | जिसमे एक class की properties और methods किसी दुसरे class में inherit की जाती है |
  • Inheritance में मुख्यतः Parent class और child class का इस्तेमाल किया जाता है | इसमे Parent class को Base class या super class भी कहा जाता है और Child class को Derived class या sub class भी कहा जाता है | C++ ये Inheritance के प्रकार को support करता है, लेकिन Java; Multiple Inheritance को support नहीं करता मतलब Java में Parent class को कई child classes हो सकते है, लेकिन child classes को सिर्फ एक ही Parent class होता है |

Java में 3 प्रकार के Inheritance होते हैं :-

  1. Single Inheritance:
    single inheritance में 1 class किसी दूसरे class को Extend करती है , aur Is Inheritance का उपयोग basic programming मैं किया जाता है|
  2. Multilevel Inheritance:
    Multilevel inheritance मैं एक class दूसरी class से मिलती है और दूसरी class को तीसरी class से मिलती है|
  3. Hierarchical Inheritance:
    Hierarchical Inheritance में एक class को बहुत सी Classes Extend करती है, इस तरह inheritance का प्रयोग तब किया जाता है जब सुपर class के Task के कई Subtask होते हैं|

Packages & interface in Java :

Advantage of Java Package :

  • Java package को आप यूज़ करके classes और interface को आप अच्छे से maintain कर सकते हैं। package की help से अलग-अलग category की class को अलग-अलग package में maintain कर सकते है।
  • Java package आपकी class और interface को access protection प्रदान करता है।
  • Java package naming collision को हटाता है।

Creating Java Packages :
Java मे package यूज़ करने के लिए आपको package keyword का यूज़ करना होगा। और package का एक unique name होना चाहिए।

How to access package from another package?
1.import package.*;
2.import package.classname;
3.fully qualified name.
यदि आप package का उपयोग करते हैं। * तो इस package के सभी class और interface accessible होंगे, लेकिन sub-package नहीं।

Exception Handling:

Exception Handling in Java: जावा Exception एक Object होता है, जो किसी Run Time Error को Represent करता है। ये एक तरह का Exception Event Object या Abnormal Event Object है, जो तब Generate होता है, जब Program अपने Normal Flow से अचानक Disturb हो जाता है। जावा Program में जब भी कोई Run Time Error Generate होने की सम्भावना होती है, तो उस Run Time Error को Exception कहा जाता है।

Java में दो प्रकार के Errors होते है |

  1. Compile-Time Error
  2. Run-Time Error

1.Compile-Time Error : ये एक normal Errors है जो Compiler द्वारा आ जाता है | जब Program में कही syntax में, कही curly brace, semi-colon या comma नहीं दिया आता है, तो ये Compile-Time पर Error occur होता है |

2.Run-Time Error : यहाँ Program successfully run होता है | लेकिन कुछ ऐसी internal errors आ जाती है, जो interpreter द्वारा दी जाती है | इससे Program भी बंद हो जाता है |

Exception handling मे आप कुछ keyword यूज़ करते है। और ये सभी keyword से मिलकर exception handling का structure बनता है।

  • Try
    try statement आपको error के लिए test किए जाने वाले code के एक block को define करने की अनुमति देता है। try keyword आपके program का वो code है जो exception error generate करता है। try block मे आप वही कोड लिखते है। जो program आपको exception के आदि लगते है।
  • Catch
    Catch statement आपको code के एक block को execute करने की अनुमति देता है, जब try block में कोई error होती है।
  • Throw
    “Throw” keyword का उपयोग अपवाद फेंकने(Throw) के लिए किया जाता है।
  • finally
    “final” block का उपयोग program के महत्वपूर्ण code को execute करने के लिए किया जाता है। Try ब्लॉक में exception आने के बाद compiler उस कोड को execute नहीं करता है और catch ब्लॉक के बाद सीधा finally ब्लॉक को execute करता है।

Multithreading in java:

  • एक साथ एक या एक से ज्यादा threads या sub-programs को run किया जाना Multithreading कहलता है।
  • सोचिये यहाँ सब mobile पर बात करते हुए खाना खा सकते है। और साथ ही TV भी देख सकते है। हमारा दिमाग इस तरह बना हुआ है। की हम एक साथ कई काम कर सकते है। इसे हम multitasking भी कह सकते है। इसी तरह जावा का कोई भी program task complete कर सकता है। Java के इस feature को multi-threading कहते है।
  • एक multi-threading program के 2 या 2 से अधिक thread होते है। ये thread एक साथ execute किये जा सकते है। हर thread एक unique task complete करने के लिए responsible होती है। ये सभी threads main thread में होती है। आपके program की main थ्रेड main() method के साथ शुरू होती है।

Thread Life Cycle

  1. New State
  2. Runnable State
  3. Running State
  4. Waiting State
  5. Dead State

 

  1. New State : यहाँ से thread की शुरुआत होती है। यहाँ पर thread का object create किया जाता है।
  2. Ready/Runnable State : जब start() method को call किया करता है। तब thread New से Runnable State पर आ जाता है। ये execute होने के लिए Ready होता है |
  3. Running State : जब thread execution होना शुरू होता है, तब thread इस state पर होता है।
  4. Waiting State : दुसरे thread को perform करने के लिए कुछ thread को block या waiting state पर होते है, waiting state पर जो thread होता है उसे resume किया जाता है।
  5. Dead State : यहाँ पर thread का काम पूरा होकर वो बंद हो जाता है।

i/o in Java :

  • हर Programming Language में Input और Output का System होता है |Input और output के लिए stream का इस्तेमाल किया जाता है |
    अलग-अलग input और output के लिए java में एक package में ये input और output के classes define किये गए है और वो package है Java.io |
  • जब C और C++ में किसी function का इस्तेमाल किया जाता था, तब उस header file को program में include करना पड़ता था | Java में अगर कुछ input और output के classes को इस्तेमाल करना हो तो java के Java.io इस package को import करना पड़ता है |

कुछ Basic I/O Streams:

  • Basic I/O Console Streams तीन प्रकार के है |
  1. System.out : ये एक Output Stream है | इससे data को output करने के लिए इस्तेमाल किया जाता है |
  2. System.in : ये एक input Stream है | इससे data को input करने के लिए इस्तेमाल किया जाता है |
  3. System.err : ये एक error Stream है | ये System.out के तरह ही होता है | ये सिर्फ error को output करने के लिए इस्तेमाल होता है |

For more information click this link

java

My name is Yash Pogra and I am the chief blogger at Codeash and where I like to share my internet/tech experience with my online readers on this website. I have been a webmaster from 2015 which is when I had registered my first company by the name Codeash. I have ventured into different online businesses like offering SEO Services, Digital Marketing and website development services.

Related Article

No Related Article

0 Comments

Leave a Comment