पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 19 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
पैकेजों के बारे में असत्य कथन ढूँढ़िए।
Find the false statement about packages.
Aपैकेज का नाम एक ही शब्द का हो सकता हैPackage can be a single name
Bsub-package का नाम dot(.) operator से अलग किया जाता हैSub package name is separated with dot(.) operators
Cpackage statement प्रोग्राम में कहीं भी लिखा जा सकता है।Package statement may be written anywhere in the program.
Dpackage statement प्रोग्राम की पहली statement हो सकता है।Package statement may be first statement of the program.
सही उत्तर / Answer: (C)
हल / Solution
package statement की जगह तय है। वह फ़ाइल की पहली statement होनी चाहिए, उससे पहले सिर्फ़ comments आ सकते हैं। उसे बीच में या class के बाद लिखने पर compile error आता है। इसलिए "कहीं भी लिखा जा सकता है" असत्य है और उत्तर विकल्प 3 है। बाक़ी सत्य हैं: पैकेज का नाम mypack जैसा एक शब्द हो सकता है, sub-package dot से अलग होता है, और package statement पहली statement हो सकती है।
The package statement has a fixed place. It must be the first statement of the file, and only comments may come before it. Writing it in the middle or after the class gives a compile error. So "may be written anywhere in the program" is false, and the answer is option 3. The rest are true: a package name can be a single word like mypack, sub-packages are separated with dots, and it can be the first statement.
प्रश्न 2उत्तर + हल
निम्नलिखित में से कौन-से पैकेज Java में वैध हैं?
Which of the following packages are valid in java?
Ajava.lang
Bjava.awt
Cjava.util
Dउपरोक्त सभीAll of the above
सही उत्तर / Answer: (D)
हल / Solution
तीनों Java की मानक library के असली पैकेज हैं। java.lang में String, Math, System जैसी मूल classes हैं और यह अपने-आप import होता है। java.awt में window, button और graphics वाली GUI classes हैं। java.util में ArrayList, HashMap, Scanner जैसी utility classes हैं। तीनों वैध हैं, इसलिए कोई एक चुनना अधूरा उत्तर होगा। सही उत्तर "उपरोक्त सभी" है।
All three are real packages of the standard Java library. java.lang has core classes like String, Math and System, and it is imported automatically. java.awt has GUI classes for windows, buttons and graphics. java.util has utility classes like ArrayList, HashMap and Scanner. All three are valid, so picking only one would be an incomplete answer. The correct answer is "All of the above".
प्रश्न 3उत्तर + हल
पैकेजों के बारे में कौन-सा कथन असत्य है?
Which statement is false about packages?
Aनामों के टकराव को सुलझाने के लिए हम पैकेज का उपयोग करते हैं।To resolve naming conflicts, we use packages.
Bयह application की modularity बढ़ाता है।It improves modularity of the application.
Cयह application की maintainability बढ़ाता है।It improves maintainability of the application.
Dयह components की सुरक्षा घटाता है।It reduces security for components.
सही उत्तर / Answer: (D)
हल / Solution
पैकेज नामों का टकराव सुलझाते हैं, code को अलग-अलग हिस्सों यानी modules में बाँटते हैं, और उसे सँभालना आसान बनाते हैं। इसलिए विकल्प 1, 2 और 3 सत्य हैं। पैकेज सुरक्षा घटाते नहीं, बढ़ाते हैं। बिना modifier वाले members और classes सिर्फ़ अपने पैकेज के अंदर दिखते हैं, बाहर का code उन्हें छू नहीं सकता। यह access protection है। इसलिए "सुरक्षा घटाता है" असत्य कथन है और उत्तर विकल्प 4 है।
Packages resolve name clashes, split code into separate parts or modules, and make it easier to maintain. So options 1, 2 and 3 are true. Packages do not reduce security; they increase it. Classes and members with no access modifier are visible only inside their own package, so outside code cannot touch them. This is access protection. So "It reduces security for components" is the false statement, and the answer is option 4.
प्रश्न 4उत्तर + हल
क्या एक ही पैकेज की classes को एक-दूसरे का उपयोग करने के लिए import की ज़रूरत होती है?
Do classes in same package need imports?
Aनहीं, import की ज़रूरत नहींNo, imports not needed
Bहाँ, सभी के लिए ज़रूरी हैYes, mandatory for all
Cइसकी अनुमति नहीं हैNot allowed
Dसिर्फ़ abstract classes के लिएOnly for abstract classes
सही उत्तर / Answer: (A)
हल / Solution
एक ही पैकेज की classes एक-दूसरे को सीधे उनके छोटे नाम से इस्तेमाल कर सकती हैं। import की ज़रूरत सिर्फ़ तब होती है जब class किसी दूसरे पैकेज की हो। जैसे com.shop की Order class उसी पैकेज की Item class को बिना import लिख सकती है। abstract class के लिए भी यही नियम है, कोई अलग नियम नहीं। इसलिए उत्तर "नहीं, import की ज़रूरत नहीं" है।
Classes in the same package can use each other directly by their simple names. An import is needed only when the class belongs to a different package. For example, an Order class in com.shop can use an Item class from the same package without any import. Abstract classes follow the same rule; there is nothing special about them. So the answer is "No, imports not needed".
प्रश्न 5उत्तर + हल
निम्नलिखित में से कौन-सा पैकेज सभी मानक (standard) Java classes को रखता है?
Which of the following package stores all the standard java classes?
Alang
Bjava
Cutil
Djava.packages
सही उत्तर / Answer: (B)
हल / Solution
Java की मानक classes सबसे ऊपर वाले java पैकेज के अंदर रखी गई हैं। lang, util, io, net जैसे पैकेज इसी के sub-packages हैं, इसलिए उनका पूरा नाम java.lang, java.util लिखा जाता है। lang और util अपने-आप में सिर्फ़ एक-एक हिस्सा हैं, पूरी मानक library नहीं। java.packages नाम का कोई पैकेज होता ही नहीं। इसलिए सही उत्तर java है।
The standard Java classes are kept under the top-level java package. Packages like lang, util, io and net are its sub-packages, which is why their full names are java.lang and java.util. On their own, lang and util are only single parts, not the whole standard library. There is no package called java.packages at all. So the correct answer is java.
प्रश्न 6उत्तर + हल
इनमें से कौन-सा किसी class और उसकी सामग्री के नामकरण और दृश्यता (visibility) नियंत्रण का तंत्र है?
Which of these is a mechanism for naming and visibility control of a class and its content?
AObject
BPackages
CInterfaces
Dइनमें से कोई नहींNone of the Mentioned
सही उत्तर / Answer: (B)
हल / Solution
पैकेज दो काम करते हैं। पहला, नामकरण: हर पैकेज एक अलग namespace देता है, इसलिए अलग पैकेजों में एक ही नाम की class रह सकती है। दूसरा, दृश्यता नियंत्रण: बिना modifier वाले members सिर्फ़ उसी पैकेज में दिखते हैं। Object सभी classes का parent है, interface यह तय करता है कि class क्या करे। दोनों नाम या दृश्यता नहीं सँभालते। इसलिए उत्तर Packages है।
Packages do two jobs. First, naming: each package gives its own namespace, so classes with the same name can live in different packages. Second, visibility control: members with no access modifier are visible only inside the same package. Object is the parent of all classes, and an interface says what a class must do. Neither of them controls names or visibility. So the answer is Packages.
प्रश्न 7उत्तर + हल
Java पैकेज में manifest फ़ाइल की क्या भूमिका है?
What is the role of a manifest file in Java packages?
Aयह पैकेजों का directory ढाँचा तय करती है।It defines the directory structure of packages.
Bइसमें पैकेज और उसकी classes के बारे में metadata होता है।It contains metadata about the package and its classes.
Cयह पैकेज की classes के लिए import statements बताती है।It specifies import statements for package classes.
Dइसका उपयोग CLASSPATH environment variable सेट करने में होता है।It is used to set the CLASSPATH environment variable.
सही उत्तर / Answer: (B)
हल / Solution
manifest फ़ाइल JAR के अंदर META-INF/MANIFEST.MF के रूप में रहती है। इसमें पैकेज की गई classes के बारे में जानकारी यानी metadata होता है, जैसे Main-Class, version, बनाने वाले का नाम और package sealing. इसलिए विकल्प 2 सही है। directory ढाँचा पैकेज के नाम से तय होता है, manifest से नहीं। import statements .java फ़ाइल में लिखे जाते हैं। और manifest system का CLASSPATH environment variable नहीं बदलती।
A manifest file sits inside a JAR as META-INF/MANIFEST.MF. It holds information, or metadata, about the packaged classes, such as Main-Class, version, vendor and package sealing. So option 2 is correct. The directory structure comes from the package name, not from the manifest. Import statements are written in the .java file. And the manifest does not change the system CLASSPATH environment variable.
प्रश्न 8उत्तर + हल
निम्नलिखित में से कौन-सा Java में पैकेज के उपयोग का लाभ नहीं है?
Which of the following is NOT a benefit of using packages in Java?
Acode को व्यवस्थित करना और सँभालनाOrganizing and managing code
Bनामों के टकराव को कम करनाReducing naming conflicts
पैकेज code को व्यवस्थित रखते हैं, नामों का टकराव कम करते हैं, और code को पढ़ना-समझना आसान बनाते हैं। ये तीनों असली फ़ायदे हैं। पर पैकेज का प्रोग्राम की speed से कोई संबंध नहीं है। class किसी भी पैकेज में हो, JVM उसे उतनी ही तेज़ी से चलाता है। पैकेज सिर्फ़ नाम और ढाँचे का मामला है। इसलिए runtime performance सुधारना पैकेज का लाभ नहीं है, और उत्तर विकल्प 3 है।
Packages keep code organised, reduce name clashes, and make code easier to read and understand. These three are real benefits. But packages have nothing to do with how fast a program runs. Whatever package a class is in, the JVM runs it at the same speed. Packages only deal with names and structure. So improving runtime performance is not a benefit of packages, and the answer is option 3.
प्रश्न 9उत्तर + हल
CLASSPATH environment variable का उद्देश्य क्या है?
What’s the purpose of the CLASSPATH environment variable?
Aयह project के लिए default पैकेज तय करता है।It sets the default package for a project.
Bयह Java compiler की जगह बताता है।It defines the location of Java compiler.
Cयह बताता है कि compiled classes और पैकेज कहाँ ढूँढ़ने हैं।It specifies where to find compiled classes and packages.
Dइसका उपयोग class documentation बनाने में होता है।It is used for creating class documentation.
सही उत्तर / Answer: (C)
हल / Solution
CLASSPATH वह सूची है जिसमें javac और java देखते हैं कि .class फ़ाइलें, पैकेज और JAR कहाँ रखे हैं। जब code किसी दूसरे पैकेज की class import करता है, तो उसे इन्हीं जगहों में ढूँढ़ा जाता है। इसलिए विकल्प 3 सही है। compiler की जगह PATH variable बताता है, CLASSPATH नहीं। default पैकेज कोई setting नहीं है, और documentation javadoc tool से बनता है।
CLASSPATH is the list of places where javac and java look for .class files, packages and JAR files. When your code imports a class from another package, it is searched for in these locations. So option 3 is correct. The location of the compiler is found through the PATH variable, not CLASSPATH. The default package is not a setting, and documentation is created with the javadoc tool.
प्रश्न 10उत्तर + हल
Java में पैकेज और directories के बारे में कौन-सा कथन सत्य है?
Which statement is true about packages and directories in Java?
Aहर पैकेज एक अलग directory से मेल खाता है।Each package corresponds to a separate directory.
Bपैकेजों का directory ढाँचे से कोई संबंध नहीं है।Packages are not related to directory structure.
Cहर class के लिए directories अपने-आप बन जाती हैं।Directories are created automatically for each class.
Dपैकेजों और directories का ढाँचा एक-दूसरे का उलटा होता है।Packages and directories have opposite structures.
सही उत्तर / Answer: (A)
हल / Solution
Java में हर पैकेज disk पर एक directory से मेल खाता है। पैकेज com.shop की classes com/shop directory में रहती हैं, और हर sub-package उसके अंदर एक और directory बनता है। इसलिए विकल्प 1 सही है। पैकेज का directory से गहरा संबंध है, इसलिए विकल्प 2 ग़लत है। directory पैकेज के लिए बनती है, हर class के लिए नहीं। और दोनों का ढाँचा एक जैसा होता है, उलटा नहीं।
In Java each package maps to a directory on disk. Classes of package com.shop live in the com/shop directory, and every sub-package becomes another directory inside it. So option 1 is correct. Packages are closely tied to directories, so option 2 is wrong. A directory is made for a package, not for each class. And the two structures match each other; they are not opposite.
आगे के 19 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
Aपैकेज में किसी ख़ास काम के लिए लिखी, तुरंत इस्तेमाल होने वाली classes होती हैं।A package contains ready-to-use classes written for a specific purpose.
Bपैकेज से code बाँटना आसान होता है। यही reusability है। नया code लिखने के बजाय पैकेज की मौजूदा classes का फ़ायदा उठाइए — बस import कीजिए और उपयोग कीजिए।Packages are easy to distribute your code. It is nothing but reusability. Instead of writing code afresh, you can take advantage of the existing classes of a package. Simply import it and use.
Cपैकेज से code को सँभालना आसान होता है। हर sub-package को किसी और ख़ास काम के लिए रखा जा सकता है। sub-packages या दूसरे पैकेजों में class के नाम बिना टकराव के दोबारा इस्तेमाल हो सकते हैं।Packages help in maintaining the code easily. Each sub-package may be maintained for more specific purposes. You can reuse the class names in sub-packages or other packages without name clash.
क्या आप पैकेज नाम लिखे बिना किसी directory के अंदर रखी Java फ़ाइल को compile कर सकते हैं? folder_1 ----- SomeFile.java . . //SomeFile.java //no package declaration //package folder_1; commented public class SomeFile {
}
Can you compile a Java file kept inside a directory without mentioning the package name? folder_1 ----- SomeFile.java . . //SomeFile.java //no package declaration //package folder_1; commented public class SomeFile {
Aपैकेज Java Class, Interface या Abstract Class वाली फ़ाइलों का संग्रह हैA Package is a collection of files of type Java Class, Interfaces, or Abstract Class
Bपैकेज बस एक Directory या Folder है जिसमें Java Classes रखी होती हैंA Package is simply a Directory or Folder with Java Classes
Cपैकेज में आम तौर पर किसी ख़ास काम या समस्या के लिए लिखी Java Classes होती हैंA Package usually contains Java Classes written for a specific purpose or problem
पैकेजों के बारे में निम्नलिखित में से कौन-सा कथन ग़लत है?
Which of the following is an incorrect statement about packages?
Aपैकेज एक namespace तय करता है जिसमें classes रखी जाती हैंPackage defines a namespace in which classes are stored
Bएक पैकेज के अंदर दूसरा पैकेज हो सकता हैA package can contain other package within it
CJava पैकेज रखने के लिए file system की directories का उपयोग करता हैJava uses file system directories to store packages
Dजिस directory में classes रखी हैं, उसका नाम बदले बिना पैकेज का नाम बदला जा सकता हैA package can be renamed without renaming the directory in which the classes are stored