Posts

Showing posts from July, 2025

Displaying Numeric Values in Applet एप्लेट में संख्यात्मक मान प्रदर्शित करना

In Java applets, numeric values are displayed using the drawString() method from the Graphics class. जावा एप्लेट्स में संख्यात्मक मानों को ग्राफ़िक्स क्लास की drawString() मेथड का उपयोग करके प्रदर्शित किया जाता है। To do this, the numeric value must first be converted into a string using the String.valueOf() method. इस कार्य को करने के लिए, संख्यात्मक मान को पहले String.valueOf() मेथड की सहायता से स्ट्रिंग में बदला जाता है। 🧪 Example: Displaying sum of two numbers   दो संख्याओं का योग दिखाना // Java File: temp.java import java.awt.*; import java.applet.*; public class temp extends Applet { public void paint(Graphics g) { int x = 10; int y = 25; int add = x + y; String s = "add: " + String.valueOf(add); g.drawString(s, 100, 100); } } 🖥️ HTML File to load applet एप्लेट लोड करने हेतु HTML फाइल: <html> <body> <applet code="temp.class" width="600" hei...

Java Applet Parameter Passing जावा एप्लेट में पैरामीटर पास करना

Java Applets allow you to interact with HTML and pass user inputs directly using the <param> tag. जावा एप्लेट HTML के साथ इंटरैक्ट कर सकता है और <param> टैग का उपयोग करके यूजर इनपुट को सीधे पास किया जा सकता है। This is useful when you need to input values from forms or user interactions in a webpage. यह तब उपयोगी होता है जब आपको वेबपेज में फॉर्म या यूजर इंटरैक्शन से इनपुट प्राप्त करना होता है। 🔷 Passing Parameters in Java Applet जावा एप्लेट में पैरामीटर पास करना The <param> tag is used within <applet> to pass values to the Java program. जावा प्रोग्राम को वैल्यू पास करने के लिए <applet> के अंदर <param> टैग का उपयोग किया जाता है। ✨ Attributes of <param> <param> टैग के ऐट्रिब्यूट्स name : The parameter name. name : वह नाम जिसे पैरामीटर के रूप में पास किया जाएगा। value : The value of the parameter. value : वह वैल्यू जो name एट्रिब्यूट के अंतर्गत पास की जाएगी। ✅ Syntax: प्रारूप: <param name="parameterName...

☕ जावा एप्लेट क्या है? What is Java Applet?

Java Applet एक छोटा Java प्रोग्राम होता है जो ब्राउज़र पर रन करता है। इसे HTML डॉक्यूमेंट में <applet> टैग द्वारा जोड़ा जाता है। Java एप्लेट का कोड .class फाइल में सेव होता है और जब यूजर HTML फाइल खोलता है, तो यह कोड क्लाइंट ब्राउज़र पर लोड होता है। 🔁 Java Applet का जीवन चक्र (Applet Life Cycle) मेथड उद्देश्य (Purpose) init() प्रारंभिक सेटअप, जैसे बैकग्राउंड कलर start() एप्लेट का सक्रिय होना stop() जब यूजर पेज छोड़ता है, एप्लेट रुक जाता है paint(Graphics g) आउटपुट को स्क्रीन पर प्रदर्शित करना destroy() ब्राउज़र बंद होने पर एप्लेट को समाप्त करना 🔧 उदाहरण (Examples) उदाहरण 1: Basic Applet Java File: photo.java import java.applet.Applet; import java.awt.*; public class photo extends Applet {     public void init() {         setBackground(Color.red);     }     public void paint(Graphics g) {         g.drawString("Applet is running", 30, 30);     } } HTML File: <!DOCTYPE html> <html...

Introduction to HTML, HTML का परिचय | What is HTML ? HTML क्या है?

HTML (HyperText Markup Language) is the standard markup language used to create web pages. It is platform-independent, tag-based, and case-insensitive. HTML (हाइपरटेक्स्ट मार्कअप लैंग्वेज) एक मानक मार्कअप भाषा है जिसका उपयोग वेब पेज बनाने के लिए किया जाता है। यह प्लेटफॉर्म-इंडिपेंडेंट, टैग-आधारित और केस-इनसेंसिटिव होती है। HTML allows us to design structured documents using tags and elements. Each tag tells the browser how to display the content. HTML हमें टैग्स और एलिमेंट्स की सहायता से संरचित डॉक्यूमेंट डिज़ाइन करने की अनुमति देता है। प्रत्येक टैग ब्राउज़र को यह बताता है कि सामग्री को कैसे प्रदर्शित किया जाए। # 🧱 Basic Structure of an HTML Document | HTML डॉक्यूमेंट की संरचना ```html <!DOCTYPE html> <html> <head>   <title>Title of Page</title> </head> <body>   <h1>Main Heading</h1>   <p>This is a paragraph.</p> </body> </html> ``` This is a simple HTML page structure that includes a header a...

Exception Handling in Java एक्सेप्शन हैंडलिंग

Exception Handling is an effective mechanism to handle runtime errors that may occur while executing a Java program. एक्सेप्शन हैंडलिंग एक प्रभावी तकनीक है जो जावा प्रोग्राम को रन करते समय उत्पन्न होने वाली रनटाइम एरर को नियंत्रित करती है। It ensures that the program flow remains normal even after unexpected errors. यह सुनिश्चित करता है कि अप्रत्याशित त्रुटियों के बावजूद प्रोग्राम का सामान्य प्रवाह बना रहे। It also helps provide user-friendly messages instead of abrupt program crashes. यह उपयोगकर्ता को अचानक क्रैश की बजाय फ्रेंडली मैसेज देता है। ✅ Why Exception Handling is Important? एक्सेप्शन हैंडलिंग क्यों ज़रूरी है? Prevents abrupt termination of programs प्रोग्राम को अचानक बंद होने से रोकता है Helps identify bugs at runtime रनटाइम पर बग की पहचान में मदद करता है Allows use of custom exception messages कस्टम एक्सेप्शन मैसेज का उपयोग संभव बनाता है Enables graceful error recovery त्रुटियों से सरल पुनर्प्राप्ति को संभव बनाता है 📌 Basic Syntax बेसिक सिंटैक्स try { ...

Types of Errors in Java (जावा में एरर के प्रकार)

Errors in Java are issues or mistakes that occur during the compilation or execution of a program. Understanding these errors is essential for debugging and writing efficient programs. जावा में एरर वे समस्याएँ होती हैं जो प्रोग्राम को कम्पाइल या रन करते समय उत्पन्न होती हैं। इन त्रुटियों को समझना प्रोग्रामिंग में सुधार और डिबगिंग के लिए आवश्यक है। 🧩 a) Syntax Errors (सिंटेक्स एरर) Syntax errors occur when the programmer does not follow the correct structure or rules of the Java language. These errors are detected during compilation time , hence also called compile-time errors . सिंटेक्स एरर तब उत्पन्न होती हैं जब प्रोग्रामर जावा की नियमबद्ध संरचना का सही पालन नहीं करता है। ये त्रुटियाँ कम्पाइल के समय पता चलती हैं, इसलिए इन्हें कम्पाइल-टाइम एरर भी कहते हैं। ✅ Example: // Missing semicolon public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!") // ← semicolon missing } } ❌ Output: HelloWorld.java:3: error...

Java Synchronization जावा में सिंक्रोनाइजेशन

Synchronization in Java is a technique used to control the access of multiple threads to a shared resource. When multiple threads try to access the same method or resource simultaneously, it may lead to inconsistency or unexpected behavior. Synchronization ensures that only one thread can access the resource at a time. जावा में सिंक्रोनाइजेशन एक ऐसी तकनीक है जिसका उपयोग तब किया जाता है जब एक से अधिक थ्रेड किसी साझा संसाधन (resource) को एक ही समय पर एक्सेस करने की कोशिश करते हैं। यह स्थिति डेटा इनकंसिस्टेंसी या प्रोग्राम एरर का कारण बन सकती है। सिंक्रोनाइजेशन के द्वारा हम सुनिश्चित करते हैं कि एक समय में केवल एक ही थ्रेड उस संसाधन को एक्सेस करे। 🧵 Why Synchronization is Needed? (सिंक्रोनाइजेशन क्यों आवश्यक है?) English: Prevents thread interference थ्रेड हस्तक्षेप को रोकने के लिए Ensures data consistency डेटा की स्थिरता बनाए रखने के लिए Useful in banking apps, inventory systems, etc. बैंकिंग या इन्वेंट्री जैसे एप्लिकेशन में आवश्यक 🛠️ Ways to Synchronize in Java (जावा...

Java Multithreading जावा में मल्टीथ्रेडिंग

Multithreading in Java is a powerful feature that allows concurrent execution of two or more parts of a program to make the best use of CPU. Java enables programs to perform multiple tasks simultaneously using threads. जब हम जावा प्रोग्राम चलाते हैं, तो CPU को कई बार इंतजार करना पड़ता है जैसे – इनपुट लेने में, नेटवर्क रिस्पॉन्स का इंतजार, या कोई अन्य प्रोसेस के कारण। इस बेकार समय का उपयोग हम दूसरे कार्यों के लिए कर सकते हैं, और यही प्रक्रिया Multithreading कहलाती है। 🧵 What is a Thread? (थ्रेड क्या होता है?) A Thread is a lightweight subprocess, the smallest unit of processing. A thread executes within a program and shares process resources with other threads. एक थ्रेड वह यूनिट है जो "execution में चल रहा प्रोग्राम" कहलाता है। जावा प्रोग्राम में default thread main() होता है। लेकिन हम और भी थ्रेड्स बना सकते हैं ताकि काम समानांतर (parallel) हो सके। 🔄 Thread Life Cycle (थ्रेड का जीवन चक्र) New – Thread is created. थ्रेड ऑब्जेक्ट बनते ही इस स्थिति में होता है। ...

Java Packages- Built-in and User Defined जावा पैकेज- इन-बिल्ट और यूजर डिफाइंड

Java पैकेज प्रोग्रामिंग के लिए एक शानदार तरीका है जिससे हम classes और interfaces को categories में बांट सकते हैं। इससे आपके कोड को manage करना, reuse करना और पढ़ना बहुत आसान हो जाता है।  Java में मुख्यतः दो प्रकार के packages होते हैं:- 1. In-built Packages (इन-बिल्ट पैकेज) Java API में पहले से ही कई useful packages शामिल होते हैं, जो अलग-अलग काम के लिए जरूरी classes और interfaces प्रोवाइड करते हैं: java.awt: इसका फुल फॉर्म “Abstract Window Toolkit” है। इस पैकेज की मदद से आप Graphical User Interface (GUI) बना सकते हैं, जैसे windows, buttons, menus आदि। java.net: Networking से जुड़े सभी operations (जैसे socket programming, HTTP connections) के लिए इस पैकेज का यूज़ किया जाता है। इसके अलावा भी कई महत्वपूर्ण पैकेज हैं जैसे java.io , java.util , javax.swing , आदि। 2. User Defined Packages (यूजर डिफाइंड पैकेज) अगर आप अपनी जरूरत के हिसाब से कोई खास functionality अलग से रखना चाहते हैं, तो आप खुद का package बना सकते हैं। आइए एक उदाहरण के साथ समझते हैं: 1. Package बनाना...

Interfaces in Java जावा में इंटरफेस

An interface in Java is a kind of blueprint or structure for a class. Just like a class, it can have methods and variables, but the methods declared in an interface are abstract by default. In other words, an interface defines a contract that other classes must follow. Interfaces are used to achieve abstraction and multiple inheritance. इंटरफेस , जावा में एक तरह की क्लास का ढांचा या ब्लूप्रिंट होता है। इसमें क्लास की तरह ही मेथड और वेरिएबल होते हैं, लेकिन इनमें घोषित मेथड डिफ़ॉल्ट रूप से एब्सट्रेक्ट होती हैं। इंटरफेस का उपयोग एब्सट्रेक्शन और मल्टीपल इनहेरिटेंस प्राप्त करने के लिए किया जाता है। 📌 Interface Features (इंटरफेस की विशेषताएं) In newer versions of Java, interfaces can also contain private , default , and static methods. Interfaces cannot be instantiated directly, but a class that implements an interface must provide implementations for all its abstract methods. जावा के नए संस्करणों में, इंटरफेस में private , default , और static मेथड्स भी हो सकती हैं। इंटरफेस का इंस्...

Java Wrapper Classes – Boxing, Unboxing, and Need जावा व्रेपर क्लासेस – बॉक्सिंग, अनबॉक्सिंग और आवश्यकता

What is a Wrapper Class? व्रेपर क्लास क्या है? A wrapper class in Java is a special type of class whose object contains a primitive data type. In simple terms, it wraps primitive values into an object form. व्रेपर क्लास जावा में एक विशेष प्रकार की क्लास होती है जिसका ऑब्जेक्ट प्रिमिटिव डेटा टाइप को अपने अंदर संग्रहीत करता है। सरल शब्दों में, यह एक प्रिमिटिव मान को ऑब्जेक्ट में लपेटता है। 🔄 a) Boxing and Autoboxing बॉक्सिंग और ऑटोबॉक्सिंग Java allows converting a primitive type into its corresponding wrapper object — this is called Boxing . When this happens automatically, it's called Autoboxing . जावा में प्रिमिटिव डेटा टाइप को उनके संबंधित व्रेपर ऑब्जेक्ट में बदलने की प्रक्रिया को  बॉक्सिंग  कहा जाता है। जब यह रूपांतरण स्वचालित रूप से होता है तो उसे  ऑटोबॉक्सिंग  कहते हैं। Examples: int → Integer double → Double long → Long 🔁 b) Unboxing and Auto-unboxing अनबॉक्सिंग और ऑटोअनबॉक्सिंग The reverse of boxing — converting a wrapper object back...

Java Vector Class – Explained with Methods and Example जावा वेक्टर क्लास – विधियों और उदाहरण सहित समझाया गया

Introduction to Vector Class वेक्टर क्लास का परिचय The Vector class in Java is like a dynamic array that grows as needed. Unlike arrays, you don't need to specify its size in advance. It is a part of the java.util package and implements the List interface. Objects in a vector can be added, removed, accessed, or searched using their index positions.  वेक्टर क्लास , जावा में एक डायनामिक ऐरे की तरह होता है, जो आवश्यकता अनुसार आकार बढ़ा सकता है। पारंपरिक ऐरे के विपरीत, इसमें साइज पहले से तय करने की जरूरत नहीं होती। यह java.util पैकेज का हिस्सा है और List इंटरफ़ेस को इम्प्लीमेंट करता है। इसमें ऑब्जेक्ट्स को इंडेक्स द्वारा जोड़ा, हटाया, खोजा और एक्सेस किया जा सकता है। 🧾 Syntax / सिंटैक्स public class Vector<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Serializable Here <E> stands for Element type. यहाँ <E> का अर्थ है एलिमेंट (Element) का प्रकार। 🔧 Commonly Used Vector Methods | सामान्यत: प्रयोग होने वाले वेक्टर म...

Java Strings – Working with Text in Java जावा स्ट्रिंग्स

In Java, a string is a sequence of characters. For example, "Java Book" is a string. Strings in Java are defined as objects so that various operations can be performed on them like concatenation, comparison, and extraction. The String class allows us to create string variables or objects and perform operations on them. जावा में, एक स्ट्रिंग अक्षरों (characters) का एक क्रम होती है। जैसे कि "जावा की किताब" एक स्ट्रिंग है। जावा में स्ट्रिंग को ऑब्जेक्ट के रूप में परिभाषित किया गया है ताकि हम उस पर विभिन्न ऑपरेशन्स जैसे जोड़ना, तुलना करना आदि कर सकें। String क्लास की मदद से हम सामान्य स्ट्रिंग वेरिएबल या ऑब्जेक्ट बना सकते हैं और उन पर ऑपरेशन कर सकते हैं। String myString = "this is a string"; // variable String myString = new String("This is a string"); // object ✨ Common Methods of Java String Class जावा स्ट्रिंग क्लास की सामान्य मेथड्स: 1. equals() – String Comparison Used to compare two strings. If they are equal, it returns true . दो ...

Array in Java – Types, Syntax & Examples जावा में ऐरे

In Java, an array is a collection of similar data types stored in contiguous memory locations . Each element in an array is accessed using an index , which starts from 0 and goes up to arraySize - 1 . The array name acts as the base address for the array. Arrays are also known as subscripted variables in programming. Java arrays are of  two main types : जावा में, ऐरे (Array) एक ही प्रकार के डेटा एलेमेंट्स का समूह होता है जिसे कंप्यूटर मेमोरी में लगातार (contiguous) बाइट्स पर स्टोर किया जाता है। प्रत्येक एलिमेंट को इंडेक्स के माध्यम से एक्सेस किया जाता है जो 0 से arraySize - 1 तक होता है। ऐरे का नाम ही उसका बेस एड्रेस होता है। इन्हें सबस्क्रिप्टेड वेरिएबल्स भी कहा जाता है। जावा ऐरे के दो मुख्य प्रकार होते हैं: 🔸 a) One-Dimensional Array (एकविमीय ऐरे – 1D) A 1D array stores elements in a single linear list format. It uses one subscript ( [] ) , hence the name 1D array. All elements are of the same type and stored in consecutive memory locations. 1D ऐरे का उपयोग डेटा...