10/20/21

Java 2020 question

 JAVA

Sub Code: - 1618505

2020 (ODD)

Time : 3Hrs

  Semester  V(New)/CSE  

                                                                                          JAVA        

Full Marks : 70

Pass marks : 28

                                                                                                                                                     

Group A

 

Choose the most suitable answer from the following options: -   (1*20=20)


(i) Which of the following is not OOPS concept in JAVA?

(a) Inheritance

(b) Encapsulation

(c)  Polymorphism

(d)  Compilation


(ii) Which of these keywords is used to make a class?

(a) Class

(b) Struct

(c) Int

(d) None of the mentioned


(iii) What is the return type of a method that does not return any value?

(a) Int

(b) Float

(c) Void

(d) Double


(iv) Method having same name as its class name is:

(a) Struct

(b) Enum

(c) Constructor

(d) Argument


(v) Which method can be defined only once in a program?

(a) Main method

(b) Finalize method

(c) Static method

(d) Private method


(vi) Size of an integer can be:

(a) -231 to 231 - 1

(b) 0 to -2 16

(c) -28 to 28 - 1

(d) -215 to 215 -1    


(vii) Which of the following assignment operator doesn’t exist in JAVA?

(a) >>

(b) %=

(c) >>>

(d)<<


(viii) Which loop is always executed once:

(a) For

(b) For each

(c) Do … While

(d) While


(ix) Which of the following is not valid flow control statement?

(a) Break ;

(b) Continue outer;

(c) Return;

(d) Exit ()

 
(x) A top level class may have which one of the following access modifiers?

(a) Package

(b) Private

(c) Protected

(d) Public

 
(xi) A subclass is also called as:

(a) Inner class

(b) Nested class

(c) Derived class

(d) Hidden class


(xii) Which of the following is not a wrapper class?

(a) Vector

(b) Character

(c) Boolean

(d) Integer


(xiii) A default constructor has:

(a) No arguments

(b) Has no return type

(c) Has one argument but no return type

(d) Has two arguments


(xiv) Math class belongs to the package:

(a) java.,math

(b) java.lang

(c) java.util

(d) None of these

 
(xv) A package is a collection of:

(a)  Classes

(b) Interfaces

(c)  Editing tools

(d) Class and interfaces


(xvi) Primary purpose of inheritance is:

(a)  Code reuse

(b) Overloading

(c)  Overriding

(d) None of the above 


(xvii) Which method/ methods cannot be overridden?

(a)  Static

(b) Final

(c)  Only (a)

(d) Both (a) and (b)


(xviii) Which of the following does not deal with exceptions?

(a) Throws

(b) Throw

(c)  Finalize

(d) Finally


(xix) What is the default priority of a thread in java?

(a)  10

(b) 5

(c)  3

(d) 1


(xx) The class at the top the AWT hierarchy is

(a) Component

(b) Window

(c) Container

(d) Frame 

 

Group:-"B"

 

Answer all Five Questions: -                         (5*4=20) 

 

2. 

    a.          What is the difference between Java and Java script?\

    b.          What is JVM?

OR

    a.          What are primitive data types in Java?

    b.          Java is both compiled and interpreted. Explain in brief.

 

3. 

    a.          What is a class in Java? Give one example.

    b.          What do you mean by scope and lifetime of a variable?

OR

    a.          What is meant by objects in Java?

    b.          Explain the casting of variables with an example.

 

4. 

    a.          What is the difference between for loop and while loop?:

    b.          What is a ternary operator?

OR

a.          What do you mean by overloading in Java?

b.          What do you mean by constructors?

 

5.

a.          What do you mean by overloading in Java?

b.          What do you mean by constructors?

OR

a.          What is meant by polymorphism in Java?

b.          What is package in Java?      

 

6.

a.     Explain in brief the try catch blocks.

b.     What is meant by garbage collection in Java? 

OR

a.          What is meant by Exception handling in Java?

b.          What is the use of final block?

 

Group:- "C"

 

Answer all Five Questions: -                         (5*6=30) 

 

7.  What is the meaning of inheritance in Java? Describe various types of inheritance in Java.

OR

Explain in brief multithreaded programming. Also describe Alive(), joint(), suspend() and resume().

 

8. Define Applets and its life cycle. 

OR

Explain any two streams in Java. Write a short program to accept two numbers from the user and display their sum.

 

9. What is difference between an interface and abstract class?  

OR

What do you mean by a package? How is it different from an interface and how an interface and how can we import them?

 

10. Write short notes on:

a.    Wrapper class

b.    File input stream

c.     Buffered input stream

OR

What is enumeration interface? Explain in brief. What is vector in Java? Explain in brief.

 

11. Write a program to find the Fibonacci series. State differences between call by value and call by reference.

OR

Write a program to swap two numbers using call by reference. Explain call by reference with an example.   

 

 

 

 

8/8/21

Searching sorting algorithm

 DATA STRUCTURE

UNIT: - 7

Searching, Sorting and Complexity: -

 Searching

         Sequential Search

         Binary Search

Sorting

         Selection sort

         Bubble sort

         Quick sort

         Merge sort

 

Searching: -

1. Searching algorithms are designed to check for an element or retrieve an element from any data structure where it is stored.

2. Searching is the process of finding some particular element from the list.

3. The search is said to be successful or unsuccessful depending upon whether the element that is being searched is found or not.

4. In this algorithm if the element is found in the list then the process is called successful and the process returns the location of that element, otherwise the search is called unsuccessful.

5. Two popular searching methods that are widely used are: -

a. Sequential search

b. Binary search

 

Sequential Search: -

1. Sequential search is the simplest searching algorithm and also known as linear search.

2. This searching can be applied for both list of item sorted or unsorted.

3. The key which is to be searched is compared with each element of the list one by one.

4. If key is matched with the element then the search is terminated.

5. If the key is not matched with any element from the list then search is failed.

Time Complexity: -

1. The worst case performance of this algorithm is roughly proportional to n and represented as O(n).

2. The best case performance in which the first comparison returns a match it requires a single comparison and hence it is O(1).

3. The average case time depends on the probability that the key will found in the list. The average and worst case is proportional to n hence it is O(n).

Algorithm for sequential search: -

    Linear_search (Array A, value Y)

Step 1: -    for i = 1 to n; (n= number of element in array A)

Step 2: -    if A[i] = Y then go to step 4

Step 3: -    if i>n then go to step 5

Step 4: -    print element found and go to step 6

Step 5: -    print element not found

Step 6: -    Exit

Program Logic: -

        linear_Search(list, value)

             for each item in the list

                 if match item == value

                 return the item found

             end if

        end for

end function linear_search

 

Binary Search: -

1. Binary search tree technique is very fast and efficient.

2. Binary search algorithm applied only for sorted list of element.

3. In Binary search key is compared with the middle element of the given list, if key found search got stop.

4. Binary search followed divide and conquer approach in which the give item list is divide into two half after comparing middle element.

5. If key is not found then the key is searched in two halves depending upon the result produced through the match.

 

Time Complexity: -

1. The worst case performance of this algorithm is roughly proportional to lgn and represented as O(log n).

2. The best case performance in which the first comparison returns a match it requires a single comparison and hence it is O(1).

3. The average case time depends on the probability that the key will found in the list. The average and worst case is proportional to llgn hence it is O(log n).

 

Algorithm for sequential search: -

    Binary_search (Array A, value Y)

Step 1: -    Initialize i as first index and j as last index;

Step 2: -    while i <= j;

Step 3: -    (mid= (i+j)/2)

Step 4: -    if key == arr[mid] go to step 8

Step 5: -    else, compare key with mid is it greater then mid or smaller

Step 6: -    if mid < key, j= mid-1, go to step 2

Step 7: -    else, mid > key, i=mid + 1 go to step 2

Step 8: -    print element found go to step 10

Step 9: -    print element not found

Step 10: -  exit;

Program Logic: -

         binary_Search(arr, i, j, key)

             while(i<=j)

             mid = (i+j)/2;

if (key == arr[mid])

return k; //element found

if (key < arr [mid])

j = k-1;

else

i= k+1;

end while

return -1 //element not found

    end function binary_search

         

 

 Next update will available soon..!!

THANK YOU
Regards,

Diploma students

 

 

 

 

Latest Update

Java 2020 question

Popular Posts