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 बनाना:

// File: MyClass.java
package MyPack;

public class MyClass {
    public void getsetname(String s) {
        System.out.println(s);
    }
}

2. Package को Import करके यूज़ करना:

// File: AccessName.java
import MyPack.MyClass;

public class AccessName {
    public static void main(String args[]) {
        String name = "Ajay";
        MyClass obj = new MyClass();
        obj.getsetname(name);
    }
}

User Defined Package Compile करने की कमांड:

javac -d . MyClass.java

यह कमांड compiled files को सही package structure में सेव करती है (e.g., MyPack/MyClass.class).


✅ निष्कर्ष:

Java में packages का इस्तेमाल करके आप अपने कोड को modular और maintainable बना सकते हैं। In-built packages डेवलपमेंट को आसान बनाते हैं और user-defined packages आपको flexibility देते हैं।

Comments

Popular posts from this blog

Java program to implement file input stream class to read binary data from image file.

Java program to find length of given string and convert it in to upper or lower case.

Java program to read a text file and displays it's contents on screen.

Java program to check marks out of Bound exception.

Java program to calculate area and perimeter of circle using interfaces.

Java program to check greatest among three numbers where input numbers are given by user.

Java program to merge two text files in to third file.

Java Applet program to draw rectangle and right-aligned oval of orange color.

Concatenating and Buffering Files in Java जावा में फ़ाइलों को जोड़ना और बफर करना