Monday 31 January 2022

Vmou june -2019 Question 1 Opps Programming with c++ and java


1. What do you mean by applets?

An applet is a Java program that can be embedded into a web page. It runs inside the web browser and works at client side. An applet is embedded in an HTML page using the APPLET or OBJECT tag and hosted on a web server. Applets are used to make the website more dynamic and entertaining.

एप्लेट एक जावा प्रोग्राम है जिसे वेब पेज में जोडा(embed) जा सकता है। यह वेब ब्राउजर(Google Chrome etc.) के अंदर चलता है और क्लाइंट साइड(User Computer) अर्थात यूजर के सिस्‍टम पर काम करता है। APPLET या OBJECT  टैग का उपयोग करके HTML पेज में एक एप्लेट को जोडा जाता है और वेब सर्वर पर एप्लेट होस्ट किया जाता है। वेबसाइट को अधिक गतिशील और मनोरंजक बनाने के लिए एप्लेट्स का उपयोग किया जाता है।

 

2. Is c++ a platform independent language?

C++ Not a platform independent language. This is because in C++, when we compile a program, it is first translated into Assembly Language and then to Machine Language. In the machine language code, the instructions are suitable only for the machine you compiled. You can’t run the same exe file of that program in another computer because architectures of computers differ.

सी ++ ऑपरेटिंग सिस्‍टम पर dependent भाषा है। ऐसा इसलिए है क्योंकि C++ में, जब हम किसी प्रोग्राम को कंपाइल करते हैं, तो उसका पहले असेंबली लैंग्वेज और फिर मशीन लैंग्वेज में अनुवाद किया जाता है। मशीन भाषा कोड में,  निर्देश केवल आपके द्वारा संकलित मशीन के लिए उपयुक्त हैं। आप उस प्रोग्राम की वही exe फ़ाइल दूसरे कंप्यूटर/ऑपरेटिंग सिस्‍टम में नहीं चला सकते क्योंकि कंप्यूटर के आर्किटेक्चर अलग-अलग होते हैं।

 

3. What do you understand by virtual functions in c++?

A virtual function is a member function that is declared within a base class and redefined by a derived class. It is declared using the virtual keyword. It is used to tell the compiler to perform late binding on the function.

वर्चुअल फ़ंक्शन एक सदस्य फ़ंक्शन है जिसे बेस क्लास के भीतर घोषित किया जाता है और व्युत्पन्न द्वारा फिर से परिभाषित किया जाता है। इसे वर्चुअल कीवर्ड का उपयोग करके घोषित किया जाता है। इसका उपयोग लेट बाइंडिंग(डायनेमिक बाइडिंग) करने के लिए किया जाता है।

 


4. How do you declare an array to integer variable in c++?

Following ways to declare array as integer variable

1
2

3

4

int jimmy [3][5];   // is equivalent to

int jimmy [15];     // (3 * 5 = 15)

int foo [5] = { 16, 2, 77, 40, 12071 }; 
int foo [] = { 16, 2, 77, 40, 12071 };

 

5. What output following statement would print in c++?

int b;

b=6;

cout<<(b<<2);

Output:-

 

(vi) What do you mean by implicit type conversation in java?

Converting one data to another data type is called type conversion or type casting.

एक डेटा को दूसरे डेटा प्रकार में कनवर्ट करना टाइप रूपांतरण या टाइप कास्टिंग कहलाता है।

 

Two types of type conversion

1. Implicit(अंतर्निहित) :-( Automatic done by compiler, No requirement of programming or coding)

It converts small data types to big data types

(कंपाइलर द्वारा स्वचालित, प्रोग्रामिंग या कोडिंग की कोई आवश्यकता नहीं)

यह छोटे डेटा प्रकारों को बड़े डेटा प्रकारों में परिवर्तित करता है।

Example in Java: -

 

2. Explicit(प्रकट, प्रकाशित) :-( Programming Required)

It is just opposite of implicit type casting. It converts big data type to small data type.

:-( प्रोग्रामिंग आवश्यक)

यह Implicit प्रकार की कास्टिंग के ठीक विपरीत है। यह बड़े डेटा प्रकार को छोटे डेटा प्रकार में परिवर्तित करता है।


Example in Java: -

 

(Vii):- what do you understand by event listener in java?

                An event listener in Java is designed to process some kind of event — it "listens" for an event, such as a user's mouse click or a key press, and then it responds accordingly.  

                An event listener must be connected to an event object that defines the event. A listener is an object that is notified when an event occurs. Event listener receives the event object and handles it. So Event Listener interface is provided in java.util package and is responsible for handling events.

                जावा में event listener किसी प्रकार की घटना को संसाधित करने के लिए डिज़ाइन किया गया है - यह किसी घटना के लिए "सुनता है(एक्टिव होता है)", जैसे कि उपयोगकर्ता का माउस क्लिक या कुंजी प्रेस, और फिर यह तदनुसार प्रतिक्रिया करता है।

Event listener किसी ऐसे ईवेंट ऑब्जेक्ट से कनेक्टेड होना चाहिए है जो कि ईवेंट को परिभाषित करता हो। Listner एक ऐसा ओबजेक्‍ट है जिसे किसी घटना के होने पर सूचित किया जाता है। Event listener ईवेंट ऑब्जेक्ट को प्राप्त करता है और इसे संभालता है। जावा में Event listener इंटरफ़ेस java.util  पैकेज में प्रदान किया गया है और घटनाओं को संभालने के लिए ज़िम्मेदार है।

 

(viii) What is major difference between Runnable and thread in java?


A thread allows a program to operate more efficiently by doing multiple things at the same time. Threads can be used to perform complicated tasks in the background without interrupting the main program.

एक थ्रेड एक प्रोग्राम को एक ही समय में कई चीजें करते हुए अधिक कुशलता से संचालित करने की अनुमति देता है। मुख्य प्रोग्राम/सॉफ्टवेयर को बाधित किए बिना बैकग्राउण्‍ड/ पृष्ठभूमि में जटिल कार्यों को करने के लिए थ्रेड्स का उपयोग किया जा सकता है।

We have two options when we want to execute a piece of code. We can extend Thread class or implement Runnable interface and pass our runnable object to some other thread.

जब हम कोड का एक टुकड़ा निष्पादित करना चाहते हैं तो हमारे पास दो विकल्प होते हैं। हम थ्रेड क्लास का विस्तार कर सकते हैं या रननेबल इंटरफ़ेस को लागू कर सकते हैं और अपनी रननेबल ऑब्जेक्ट को किसी अन्य थ्रेड में पास कर सकते हैं।

 

Thread

·         It is a class.

·         It has multiple methods such as ‘start’ and ‘run’.

·         It requires more memory space.

·         Since multiple inheritance is not allowed in Java, hence, after a class extends the Thread class, it can’t extend to any other class.

·         Every thread creates a unique object and associates with it.

Runnable

·         It is a functional interface.

·         It has a single abstract method ‘run’.

·         It requires less memory space.

·       When a class implements the ‘runnable’ interface, the class can extend to other classes.

·         Multiple threads can share the same objects.

 

Saturday 15 January 2022

Question 7. What do you mean by function overloading? Explain with Examples. फंक्शन ओवरलोडिंग से आप क्या समझते हैं? उदाहरण सहित समझाइए।


 

Multiple functions with same name is known as function overloading or function polymorphism.

Polymorphism means one function having many forms. The overloaded function must

Be different in its argument list and with different data types. The examples of overloaded functions are given below. All the functions defined should be equivalent to their prototypes.


एक ही नाम वाले कई फंक्शन को फंक्शन ओवरलोडिंग या फंक्शन पॉलीमॉर्फिज्म के रूप में जाना जाता है। बहुरूपता का अर्थ है एक फंक्‍शन जिसको कई रूपों में प्रयोग करना हो। फंक्‍शन ओवरलोडिंग में फंक्‍शन में पास किये जाने वाले Argument व डाटा टाइप अलग प्रकार के होने चाहिए। Function Overloading का उदाहरण नीचे दिए गया हैं।ओवरलोडेड सभी फंक्‍शनों में उनके प्रोटोटाइप एक जैसे होने चाहिए।

int sqr (int);

float sqr (float);

long sqr (long);

 

Example:

Program to calculate square of an integer and float number.

Define function sqr () and use function-overloading concept.

 

# include <iostream.h>

# include <conio.h>

int sqr(int);

float sqr(float);

main ()

{

int a=15;

float D=2.5;

cout <<“Square = “<<sqr(a) <<“\n”;

cout <<“Square “<< sqr(b) <<“\n”;

return 0;

}

 

int sqr(int s)

{

return (s*s);

}

 

float sqr (float j)

{

return (j *j);

}

 

OUTPUT

Square =225

Square=6.25

Question 9. What is exception handling? What are the types of exceptions? Write a code to handle array out of bound exceptions. अपवाद हैंडलिंग क्या है? अपवाद कितने प्रकार के होते हैं? Array out of bound अपवाद को संभालने के लिए एक कोड लिखें।


Exception handling mechanism describes the behavior of program when exception occurs. Exception handling is a very powerful technique by which runtime errors are handled. There are two ways of handling exceptions: programmer defined exception handling and default exception handling.

अपवाद प्रबंधन तंत्र, अपवाद होने पर Program(Software Code) के व्यवहार का वर्णन करता है। Exception Handling एक बहुत ही शक्तिशाली तकनीक है जिसके द्वारा runtime errors को handle किया जाता है। जिससे program का normal flow बना रहता है। अपवादों को संभालने के दो तरीके हैं: प्रोग्रामर परिभाषित अपवाद हैंडलिंग और डिफ़ॉल्ट अपवाद हैंडलिंग।


Types of Exception:-

There can be two types of built-in exception classes namely, checked exceptions and unchecked exceptions. Programmer needs to explicitly mention about handling of checked exceptions in the program where as not necessarily about unchecked exceptions.

दो प्रकार के अंतर्निर्मित अपवाद Class हो सकते हैं,  अर्थात् चेक किए गए अपवाद और अनियंत्रित अपवाद। प्रोग्रामर को प्रोग्राम में चेक किए गए अपवादों को संभालने के बारे में स्पष्ट रूप से उल्लेख करने की आवश्यकता होती है। जबकि अनियंत्रित अपवादों के लिए यह आवश्‍यक नही है।

 

Checked Exception

Checked exceptions are either handled by the method that generate them using a pair of keyword try and catch or it may be explicitly declared using keyword throws. Hence, compiler checks these exceptions. Below table shows some exception conditions and their corresponding checked exception classes.

Checked Exceptions को या तो ट्राई व कैच कीवर्ड का उपयोग करके नियंत्रित किया जा सकता है या फिर स्‍पष्‍ट रूप से थ्रो कीवर्ड का उपयोग करके नियंत्रित किया जा सकता है। इसलिए,  कंपाइलर इन अपवादों की जाँच करता है। नीचे दी गई तालिका कुछ अपवाद स्थितियों और उनके संबंधित Checked Exception क्‍लास को दिखाती है।

 

S.No.

Condition

Checked Exception

1.

Class Not Found

ClassNotFoundException

2.

Clone not supported

CloneNotSupportedException

3.

Illegal access to a class

IllegalAccessException

4.

Instantiation not allowed

InstantiationException

5.

Interrupted by thread

InterruptedException

6.

Field not found

NoSuchFieldException

7.

Method does not exist

NoSuchMethodException

 

UNCHECKED Exception

Unchecked exceptions occur at run time and are not checked by compiler. Programmer is not compelled to write exception handler for them rather it is optional. Below table shows some common exception conditions and their corresponding unchecked exception classes.

अनियंत्रित अपवाद रन टाइम पर होते हैं और कंपाइलर द्वारा चेक नहीं किए जाते हैं। प्रोग्रामर उनके लिए अपवाद हैंडलर लिखने के लिए बाध्य नहीं है बल्कि यह वैकल्पिक है। नीचे दी गई तालिका कुछ सामान्य अपवाद स्थितियों और उनके संबंधित Unchecked Exception क्‍लास को दिखाती है।

S.No.

Conditions

Unchecked Exception

1

Divide by zero

ArithmeticException

2

Array index out of bounds

Array Index Out Of Bounds Exception

3

Not in a number format

NumberFormatException

4

Improper type array storage

ArrayStoreException

5

Invalid cast

ClassCastException

6

Illegal argument type

IllegalArgumentException

7

Negative array size

NegativeArraySizeException

8

Invalid use of null pointer

NullPointerException

 

 

Code to handle array out of bound exceptions

 

public class Main {
   public static void main (String args[]) {
      int array[] = {20,20,40};
      int num1 = 15, num2 = 10;
      int result = 10;
      try {
         result = num1/num2;
         System.out.println("The result is" +result);
         for(int i = 5; i >= 0; i--) {
            System.out.println("The value of array is" +array[i]);
         }
      } catch (ArrayIndexOutOfBoundsException e) {
         System.out.println("Array is out of Bounds"+e);
      } catch (ArithmeticException e) {
         System.out.println ("Can't divide by Zero"+e);
      }
   }
}
 
Output
 
The result is1
Array is out of Boundsjava.lang.ArrayIndexOutOfBoundsException : 5