Introduction to Java Programming language - B.Tech 5th Semester Examination, 2016

2016Semester 2Civil-CAEnd Semester
Bihar Engineering University, Patna
B.Tech 5th Semester Examination, 2016

Introduction to Java Programming language

Time: 3 hoursCode: 051529Full Marks: 70

Instructions:

  1. There are Nine Questions in this Paper.
  2. Attempt five questions in all.
  3. Question No. 1 is Compulsory.
  4. The questions are of equal value.
Q.1 Choose the correct answer of the following (any seven)[14]
  1. What is the output of this program?

    class bitwise_operator {
        public static void main (String args[]) {
            int var1 = 42;
            int var2 = ~var1;
            System.out.print(var1 + " " + var2);
        }
    }

    1. 42 42
    2. 43 43
    3. 42 -43
    4. 42 -42
  2. Which of these have highest precedence?

    1. ()
    2. ++
    3. *
    4. >>
  3. What is the output of this program?

    class operators {
        public static void main(String args[]) {
            int var1 = 5;
            int var2 = 6;
            int var3;
            var3 = ++var2 * var1 / var2 + var2;
            System.out.print(var3);
        }
    }

    1. 10
    2. 11
    3. 12
    4. 56
  4. What is the output of this program?

    class output {
        public static void main(String args[]) {
            int x, y;
            x = 10;
            x++;
            --x;
            y = x++;
            System.out.println(x + " " + y);
        }
    }

    1. 11 11
    2. 11 10
    3. 10 10
    4. 10 11
  5. What is the output of this program?

    class conversion {
        public static void main(String args[]) {
            double a = 295.04;
            int b = 300;
            byte c = (byte) a;
            byte d = (byte) b;
            System.out.println(c + " " + d);
        }
    }

    1. 38 -43
    2. 39 44
    3. 295 300
    4. 295.04 300
  6. What is the default value of Boolean variable?

    1. true
    2. false
    3. null
    4. not defined
  7. What is the output of this program?

    class array_output {
        public static void main(String args[]) {
            char array_variable[] = new char[10];
            for (int i=0; i<10; ++i) {
                array_variable[i] = '1';
                System.out.print(array_variable[i] + " ");
                i++;
            }
        }
    }

    1. 1 1 1 1 1
    2. 1 1 1 1 1 1 1 1 1 1
    3. 0 1 2 3 4
    4. None of the mentioned
  8. What is the output of this program?

    class exception_handling {
        public static void main(String args[]) {
            try {
                System.out.print("Hello" + " " + 1/0);
            } catch (ArithmeticException e) {
                System.out.print("World");
            }
        }
    }

    1. Hello
    2. World
    3. Hello world
    4. Hello world (with Exception thrown)
  9. What is the output of this program?

    class overload {
        int y;
        int x;
        void add(int a) {
            x = a + 1;
        }
        void add(int a, int b) {
            x = a + 2;
        }
    }
    class overload_methods {
        public static void main(String args[]) {
            overload obj = new overload();
            int a = 0;
            obj.add(6, 7);
            System.out.println(obj.x);
        }
    }

    1. 6
    2. 7
    3. 8
    4. 9
  10. What is the output of this program?

    class A {
        public int i;
        private int j;
    }
    class B extends A {
        void display() {
            super.j = super.i + 1;
            System.out.println(super.i + " " + super.j);
        }
    }
    class inheritance {
        public static void main(String args[]) {
            B obj = new B();
            obj.i = 1;
            obj.j = 2;
            obj.display();
        }
    }

    1. 2 2
    2. 3 3
    3. Runtime Error
    4. Compilation Error
Q.2 Solve both questions :[14]
  1. What is the difference between the C, C++ and Java?

  2. Write a program that reads an integer and check whether it is prime number or not.

Q.3 Solve both questions :[14]
  1. What do you understand by polymorphism? Explain with examples.

  2. What do you understand by precedence and Associativity? Explain with examples.

Q.4 Solve both questions :[14]
  1. What is a constructor? Give its properties. How do we declare/define it? Can they be overloaded? Explain types of constructors with example.

  2. What is exception-handling? What are the statements used for it? Show an example.

Q.5 Solve both questions :[14]
  1. Give the definition (1-2 Lines) and an example of the following: i. Thread Class, ii. AWT, iii. JDBC, iv. JVM.

  2. Difference between the following with example: i. Break and continue, ii. Abstract class and interface.

Q.6 Solve both questions :[14]
  1. What is exception-handling? What are the statements used for it? Show an example.

  2. What is inheritance in java? Explain different types of inheritance.

Q.7 Solve both questions :[14]
  1. Create an abstract class Discount Policy. It should have a single abstract method compute Discount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and itemCost.

  2. Write a program to find largest and second largest element in an array.

Q.8 Solve both questions :[14]
  1. Write a program to design a class account using the inheritance and static keyword that shows all function of bank (withdrawal, deposit).

  2. Write a program to create a thread that Implement the Runnable interface.

Q.9 Solve both questions :[14]
  1. Write a program to create a Simple class to find out the Area and perimeter of rectangle and box using super and this keyword.

  2. Write a program to find the factorial of a given number using Recursion.