INTRODUCTION TO JAVA PROGRAMMING LANGUAGE - B.Tech 5th Semester Exam., 2018

2018Semester 3Civil-CAEnd Semester
Bihar Engineering University, Patna
B.Tech 5th Semester Exam., 2018

INTRODUCTION TO JAVA PROGRAMMING LANGUAGE

Time: 3 hoursCode: 051529Full Marks: 70

Instructions:

  1. The marks are indicated in the right-hand margin.
  2. There are NINE questions in this paper.
  3. Attempt FIVE questions in all.
  4. Question No. 1 is compulsory.
Q.1 Answer/Fill in the blank/Choose the correct option (any seven):[2x7=14]
  1. Java is an example of ________ language.

    1. compiled
    2. interpreted
    3. hybrid
    4. script
  2. The mother tongue of a computer is:

    1. assembly language
    2. machine language
    3. BASIC language
    4. None of the above
  3. You have the following code in a file called Test.java:

    class Base{
        public static void main(String[] args){
            System.out.println("Hello");
        }
    }
    public class Test extends Base{}
    What will happen if you try to compile and run this?

    1. It will fail to compile
    2. Runtime error
    3. Compiles and runs with no output
    4. Compiles and runs printing "Hello"
  4. Which of the following are valid declarations? (Note: None of the literals used here contain the character O, they are all zeroes.)

    1. int i = 0XCAFE;
    2. boolean b = 0;
    3. byte b = 128;
    4. char c = 'A';
  5. What is the result of trying to compile and run this program?

    public class Test{
        public static void main(String[] args){
            int[] a = {1};
            Test t = new Test();
            t.increment(a);
            System.out.println(a[a.length-1]);
        }
        void increment(int[] i){
            i[i.length - 1]++;
        }
    }

    1. Compiler error
    2. Compiles and runs printing out 2
    3. Compiles and runs printing out 1
    4. An ArrayIndexOutOfBoundsException at runtime
  6. Is this legal?

    long longArr[];
    int intArr[] = {7, 8, 9};
    longArr = intArr;

    1. Yes
    2. No
  7. What is the result of attempting to compile and run this?

    interface A{
        void aMethod();
    }
    public class Test implements A{
        void aMethod(){
            System.out.println("hello");
        }
        public static void main(String[] args){
            Test t = new Test();
            t.aMethod();
        }
    }

    1. The code will not compile
    2. Runtime exception
    3. Compiles and runs printing out "hello"
  8. What are the class variables?

  9. Explain the following code sample:
    result = someCondition ? value1 : value2;

  10. Character strings are represented by the class java.lang.String.

Q.2 Solve both questions :[14]
  1. Why is Java called machine independent language? Explain the functionality of JVM.

  2. What is the main difference between an application and applet?

Q.3 Solve both questions :[14]
  1. What are the wrapper classes? Explain their uses.

  2. What does a dynamic Billboard Applet do? What are the three main classes that the applet contain?

Q.4 Solve both questions :[14]
  1. What is the difference between process-based and thread-based multitasking? Give the two ways by which a thread can be created using Java.

  2. What is RMI? What is the difference between Naming.bind and Naming.rebind methods? Write a short code to invoke a remote method using Java RMI.

Q.5 Solve this question :[14]
  1. Write an Applet (Use swings) to display the outputs:

    Question Diagram Question Diagram
Q.6 Solve both questions :[14]
  1. What are the characteristics of JDBC? What are the various steps for using JDBC? Write a program to demonstrate these steps.

  2. What is the main purpose of a container component in swing?

Q.7 Solve this question :[14]
  1. Design a class named Fan to represent a fan. The class contains:
    • Three constants named SLOW, MEDIUM and FAST with values 1, 2 and 3 to denote the fan speed.
    • A private int data field named speed that specifies the speed of the fan (default SLOW).
    • A private boolean data field named on that specifies whether the fan is on (default false).
    • A private double data field named radius that specifies the radius of the fan (default 5).
    • A string data field named colour that specifies the colour of the fan (default blue).
    • The accessor and mutator methods for all four data fields.
    • A no-arg constructor that creates a default fan.
    • A method named toString() that returns a string description for the fan. If the fan is on, the method returns the fan speed, colour, and radius in one combined string. If the fan is not on, the method returns fan colour and radius along with the string "fan is off" in one combined string.

    Implement the class. Write a test program that creates two Fan objects. Assign maximum speed, radius 10, colour yellow, and turn it onto the first object. Assign medium speed, radius 5, colour blue, and turn it off to the second object. Display the objects by invoking their toString method.

Q.8 Solve this question :[14]
  1. Write a program in Java to demonstrate communication using TCP/IP i.e., using sockets. Write a separate code for a server and client program. The program should display the contents of the file specified in a server onto the client.

Q.9 Write short notes on the following:[14]
    1. Interface
    2. String builder class
    3. Object passing
    4. Types of JDBC drivers
    5. Listener method
    6. Java exceptions
    7. Polymorphism