Java का आविष्कार James Gosling ने Sun Microsystems में किया था। यह काम 1991 में Green project के रूप में शुरू हुआ और 1995 में भाषा Java नाम से सामने आई। Dennis Ritchie ने Bell Labs में C भाषा बनाई थी। Larry Page और Sergey Brin ने मिलकर Google की स्थापना की थी। इन तीनों का Java के आविष्कार से कोई संबंध नहीं है, इसलिए सही उत्तर James Gosling है।
Java was invented by James Gosling at Sun Microsystems. The work began in 1991 as the Green project, and the language came out under the name Java in 1995. Dennis Ritchie created the C language at Bell Labs. Larry Page and Sergey Brin together founded Google. None of these three had a role in inventing Java, so the correct answer is James Gosling.
The main method should be static for which reason?
Aताकि class loader उसे आसानी से एक्सेस कर सकेIt can be accessed easily by the class loader
Bताकि हर मेथड या वेरिएबल बिना क्लास के उसे एक्सेस कर सकेIt can be accessed by every method or variable without class
Cताकि उसे क्लास का कोई इंस्टेंस बनाए बिना चलाया जा सकेIt can be executed without creating any instance of the class
Dउपरोक्त में से कोई नहींNone of the above
सही उत्तर / Answer: (C)
हल / Solution
program शुरू होते समय JVM के पास उस class का कोई object नहीं होता। static method class से जुड़ा होता है, इसलिए उसे object बनाए बिना सीधे ClassName.main() की तरह बुलाया जा सकता है। यही main() के static होने का असली कारण है। class loader का काम class को memory में लाना है, main को static बनाने से उसका लेना-देना नहीं। विकल्प 2 ग़लत है, क्योंकि static method भी class से ही जुड़ा रहता है।
When a program starts, the JVM has no object of the class yet. A static method belongs to the class, so it can be called directly, like ClassName.main(), without creating an object. That is the real reason main() is static. The class loader's job is only to load the class into memory; it is not the reason for static. Option 2 is wrong because a static method still belongs to its class.
Java किस प्रोग्रामिंग भाषा के आधार पर विकसित की गई है?
Java was developed on the basis of which programming language?
AB
BPascal
CC++
DD
सही उत्तर / Answer: (C)
हल / Solution
Java की syntax और object-oriented ढाँचा मुख्य रूप से C++ से लिया गया है। James Gosling चाहते थे कि C++ जानने वाले programmer इसे जल्दी सीख लें। पर pointer और multiple inheritance जैसी उलझनें इसमें से हटा दी गईं। Java की HotSpot JVM भी ज़्यादातर C++ में लिखी गई है। B एक पुरानी भाषा है जिससे आगे चलकर C बनी। Pascal का Java से सीधा संबंध नहीं है, और D तो Java के बाद आई।
Java takes its syntax and its object-oriented design mainly from C++. James Gosling wanted C++ programmers to learn it quickly. But confusing parts such as pointers and multiple inheritance of classes were removed. The HotSpot JVM that runs Java is also written mostly in C++. B is an old language that later led to C. Pascal has no direct link with Java, and D came after Java.
कंस्ट्रक्टर का निहित (implicit) रिटर्न टाइप क्या है?
The implicit return type of a constructor is?
AVoid
Bउसी क्लास का ऑब्जेक्ट जिसमें वह परिभाषित हैA class object in which it is defined
Cकोई रिटर्न टाइप नहीं होताThere is no return type
Dइनमें से कोई नहींNone of these
सही उत्तर / Answer: (B)
हल / Solution
यहाँ ख़ास शब्द implicit यानी 'निहित' है। constructor के आगे कोई return type लिखा नहीं जाता, void भी नहीं। पर new ClassName() लिखने पर constructor उसी class का नया object तैयार करता है और उसका reference हमें मिलता है। इसलिए निहित रूप से उसका return उसी class का object माना जाता है। 'कोई return type नहीं' लिखे हुए (explicit) type की बात है, निहित की नहीं। void तो constructor पर लगता ही नहीं।
The key word here is implicit. No return type is written before a constructor, not even void. But when we write new ClassName(), the constructor sets up a new object of that class and we get its reference back. So, implicitly, its return is treated as an object of the class in which it is defined. 'No return type' describes the explicit, written type, not the implicit one. Void never applies to a constructor.
निम्न में से कौन Java कोड एडिटर नहीं है? (IA 2018)
Which of the following is not a Java code editor? (IA 2018)
AMS Word
BNetBeans
CNotepad++
DEditPlus
सही उत्तर / Answer: (A)
हल / Solution
MS Word एक word processor है। इसमें चिट्ठी, रिपोर्ट जैसे formatted दस्तावेज़ बनते हैं। यह फ़ाइल में formatting की छिपी जानकारी भी जोड़ता है, इसलिए इससे Java का सादा source code लिखना ठीक नहीं। NetBeans एक पूरा IDE है, जिसमें code लिखना, compile करना और debug करना एक ही जगह होता है। Notepad++ और EditPlus सादे text editor हैं, जिनमें Java code लिखकर .java फ़ाइल बनाई जा सकती है।
MS Word is a word processor. It is used to make formatted documents such as letters and reports. It also adds hidden formatting data to the file, so it is not suitable for writing plain Java source code. NetBeans is a full IDE where you can write, compile and debug code in one place. Notepad++ and EditPlus are plain text editors, so Java code can be typed in them and saved as a .java file.
जो variable class के अंदर पर किसी method के बाहर declare होता है, उसे instance variable कहते हैं। वह हर object के साथ बनता है और उस class के सभी instance methods उसे इस्तेमाल कर सकते हैं। local variable किसी method या block के अंदर declare होता है और सिर्फ़ उसी method में चलता है, इसलिए वह सभी methods के लिए नहीं है। object ख़ुद variable नहीं, class का instance है।
A variable declared inside a class but outside every method is called an instance variable. It is created with each object, and all instance methods of that class can use it. A local variable is declared inside a method or block and works only inside that method, so it is not shared by all methods. An object is not a variable at all; it is an instance of a class. So the answer is instance variable.
James Gosling को Java का जनक कहा जाता है। उन्होंने 1991 में Sun Microsystems में Green Team के साथ इस भाषा पर काम शुरू किया। पहले इसका नाम Oak था, फिर 1995 में इसे Java नाम से जारी किया गया। Linus Torvalds ने Linux kernel बनाया था, Java नहीं। Turner Lee और James Drew का Java के विकास से कोई संबंध नहीं है, ये सिर्फ़ भटकाने वाले नाम हैं।
James Gosling is called the father of Java. In 1991 he started work on the language with the Green Team at Sun Microsystems. It was first named Oak and was released under the name Java in 1995. Linus Torvalds created the Linux kernel, not Java. Turner Lee and James Drew have no link with the making of Java; they are only distractor names added to confuse.
कंस्ट्रक्टर के साथ किस मॉडिफ़ायर का उपयोग नहीं किया जा सकता?
Which modifier cannot be used with constructors?
Apublic
Bprivate
Cstatic
Dprotected
सही उत्तर / Answer: (C)
हल / Solution
constructor का काम नया object तैयार करना है, इसलिए वह हमेशा किसी object से जुड़ा होता है। static चीज़ें class से जुड़ी होती हैं, object से नहीं। इसलिए constructor को static बनाना ग़लत है और compiler error देता है। चारों access modifier constructor पर लग सकते हैं। public से हर class object बना सकती है, private से Singleton बनता है, और protected से subclass तक पहुँच रहती है। इसलिए उत्तर static है।
A constructor sets up a new object, so it always belongs to an object. Static members belong to the class, not to any object. So a static constructor makes no sense, and the compiler gives an error. All access modifiers can be used on constructors. With public any class can create the object, private is used for Singleton, and protected gives access to subclasses. So the answer is static.
यदि कंस्ट्रक्टर के साथ रिटर्न टाइप लिख दिया जाए तो क्या होगा?
What would be the behavior if the constructor has a return type?
Aकंपाइलेशन त्रुटिCompilation error
Bरनटाइम त्रुटिRuntime error
Cप्रोग्राम कंपाइल होकर सफलतापूर्वक चलता हैCompiles and runs successfully
Dकेवल String रिटर्न टाइप की अनुमति हैOnly String return type is allowed
सही उत्तर / Answer: (C)
हल / Solution
constructor का कोई return type नहीं होता, void भी नहीं। अगर class के नाम वाले block के आगे void या int लिख दें, जैसे void Test() { }, तो Java उसे constructor नहीं मानता। वह एक साधारण method बन जाता है, जिसका नाम class जैसा है। यह नियम के अनुसार सही है, इसलिए program compile भी होता है और चलता भी है। compiler तब default constructor ख़ुद जोड़ देता है। String वाली कोई ख़ास छूट नहीं है।
A constructor has no return type, not even void. If you write void or int before a block named like the class, such as void Test() { }, Java does not treat it as a constructor. It becomes an ordinary method that happens to share the class name. This is legal, so the program compiles and runs without any error. The compiler then adds the default constructor by itself. There is no special rule for String.
निजी (private) कंस्ट्रक्टर के बारे में क्या सही है?
What is true about a private constructor?
Aprivate कंस्ट्रक्टर यह सुनिश्चित करता है कि किसी भी समय क्लास का केवल एक ही इंस्टेंस मौजूद रहेA private constructor ensures only one instance of a class exists at any point of time
Bprivate कंस्ट्रक्टर यह सुनिश्चित करता है कि किसी भी समय क्लास के कई इंस्टेंस मौजूद रहेंA private constructor ensures multiple instances of a class exist at any point of time
Cprivate कंस्ट्रक्टर दूसरी क्लासों में ऑब्जेक्ट बनाने देता हैA private constructor allows creating objects in other classes
Dउपरोक्त में से कोई नहींNone of the above
सही उत्तर / Answer: (A)
हल / Solution
constructor को private बनाने पर कोई दूसरी class new लगाकर उसका object नहीं बना सकती। object बनाने का काम class के अंदर ही रहता है। इसी का उपयोग Singleton pattern में होता है। वहाँ class एक static method से हमेशा वही एक object लौटाती है, यानी एक समय में एक ही instance रहता है। कई instance बनवाना इसका उलटा है। दूसरी class में object बनाना private होने से रुक जाता है, इसलिए विकल्प 3 भी ग़लत है।
When a constructor is private, no other class can use new to create its object. Object creation stays inside the class itself. This is used in the Singleton pattern, where a static method of the class always returns the same single object, so only one instance exists at a time. Creating many instances is the opposite of this. Creating objects from other classes is blocked by private, so option 3 is also wrong.
आगे के 10 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
कंस्ट्रक्टर वाले नीचे दिए गए जावा प्रोग्राम का आउटपुट क्या है? public class Constructor2 { int count=10; Constructor2(int count) { System.out.println("Count=" + count); }
public static void main(String[] args) { Constructor2 con = new Constructor2(); } }
What is the output of the Java program below with constructors? public class Constructor2 { int count=10; Constructor2(int count) { System.out.println("Count=" + count); }
public static void main(String[] args) { Constructor2 con = new Constructor2(); } }