Set 1 – Java, Oracle, Unix Interview Questions


1.  

compareTo(Object) belongs to which class?

1.  Collections

2.  Comparator

3.  Comparable

4.  Arrays

2.

singletonList(Object) method is defined in?

1.  class ArrayList

2.  interface List

3.  interface Collection

4. class Collections

3.  

When a thread is started with start() method, in which state it exists?

1.  born state

2.  runnable state

3.  blocked state

4.  dead state

4.

Following is the code. 

class Demo extends Thread

{

   public static void main(String args[])

   {

       Demo d1 = new Demo();

       d1.start();

       d1.start();

  }

}

In the above code, thread d1 is started twice.

1.  It is compilation error

2.  It throws exception

3.  It compiles and runs without a problem

4.  Thread’s life cycle does not start

5. 

class Demo

{

    public void run()

    {

       System.out.println(“Hello”);

    }

    public static void main(String args[])

    {

       Demo d1 = new Demo();

       Thread t1 = new Thread(d1);

       t1.start();

    }       

}

The above code

1.  Compiles, executes and prints Hello

2.  Compiles, executes and does not print Hello

3.  Compiler raises error

4.  Compiles but at runtime throws exception

6. 

What is the need for exception handling?

1.  Designers did not promise exception handling in JDK 1.0

2.  Introduced in JDK 1.1

3.  To see the code looks smarter with try-catch-finally blocks

4. To see that code executes in spite of problem occurs created by user

7. 

class Demo

{

    public static void main(String args[])

    {

        int a = 10, b = 0, c;

        c = a/b;

        System.out.println(c);

    }       

}

The above code

1. Does not compile as ArithmeticException is not handled

2. The code compiles but does not execute.

3. The code prints 0

4. The code prints Infinity.

8. 

Observe, the following snippet of code.

    public static void main(String args[])

    {

        try { System.out.println(10/0);  }

        catch(Exception e) { System.out.println(“Hello 1”);  }

        catch(ArithmeticException e) { System.out.println(“Hello 2”);  }    }       

    }

The output of the above code is

1.  Hello 1

2.  Hello 2

3.  Compiles but does not execute

4.  Does not compile

9. 

EOFException is a subclass of

1.  IOException

2.  RuntimeException

3.  FileMarkerException

4.  FileException

10.  

To copy an image file which stream class can be used?

1.  FileInputStream

2.  FileReader

3.  File

4.  ImageInputStream

11. 

import java.io.*;

class Demo

{

   public static void main(String args[])

   {

      FileInputStream fis;

      try

      {

         fis = new FileInputStream(“abc.txt”);       

      }

      catch(Exception e) {  }

      finally { try { fis.close();  } catch(Exception e) { } }       

   }

}

The above code

1.  Does not compile

2.  Compiles but does not execute

3.  compiles and executes

4.  fis should not be closed in finally block

12.  

JdbcOdbcDriver is

1.  Bridge driver

2.  Thin driver

3.  Remote driver

4.  Native API drive

13.  

Which method returns an object of PreparedStatement?

1.  preparedStatement()

2.  prepareStatement()

3.  preparedCall()

4.  prepareCall()

14.  

Which exception is thrown by Class.forName() method?

1.  SQLException

2.  JdbcOdbcException                          

3.  DatabaseConnectionException

4.  ClassNotFoundException

15.

Which is the best practice for executing different multiple SQL statements on the database with JDBC?

1.  Partially compiled with PreparedStatement

2.  Executing stored procedures with CallableStatement

3.  addBatch() method of Statement

4.  execute() method of Statement

16.

Servlet lifecycle methods are

1.  init(), start(), destroy()

2.  init(), start(), atop()

3.  init(), service(), destroy()

4.  start(), doService(), destroy()

17. 

The parameter of init() method is an object of

1.  ServletConfig

2.  ServletContext

3.  initFilter

4.  FilterListener

18.  

What is the return type of getOutputStream()?

1.  OutputStream

2.  ServletOutputStream

3.  PrintStream

4.  ServletStream

19.

The method getSession() is defined in

1.  HttpServlet

2.  HttpServletRequest

3.  HttpSession

4.  ServletConfig

20.  

getRequestDispatcher() method is defined in

1.  ServletRequest

2.  ServletContext

3.  ServletRequest and ServletContext

4.  RequestDispatcher

21.

Cookie c1 = new Cookie(“Lux”, 2);

To send c1 to client and to retrieve Lux and 2, what methods can be used?

1.  sendCookie(), getCookieName(), getCookieValue()

2.  sendCookie(), getName(), getValue()

3.  addCookie(), getCookieName(), getCookieValue()

4.  addCookie(), getName(), getValue()

22. 

Which JSP lifecycle method cannot be overridden by Developer?

1.  init()

2.  _init()

3.  jspService()

4.  _jspService()

23.  

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

<body>

<c:set var=”salary” value=”5000″/>

<c:if test=”${salary < 5000}”>

<c:out value=”Big Man”/>

</c:if>

</body>

The above JSTL snippet of output

1.  compilation error as the syntax of if tag is incorrect.

2.  false

3.  Big Man

4.  No output

24.

Observe the following snippet of code?  Choose the right option that is true.

<body>

<%!

          public void calculate(int x, int y)

          {

              out.println(x*y);

          }

%>

<%

       calculate(10, 20);

%>

</body>

1.  Client gets the response of 200

2.  Code has errors and thereby not compiled by container

3.  void return type cannot send JSP response to client

4.  We cannot pass parameters from scriptlet to declaration without throwing exceptions

25.  Command Interpreter is —————-

1.  shell

2.  kernal

3.  hardware

4.  application libraries

26.  In preemptive multitasking

1.  slice is not the concept on which multitasking works

2.  time slices do not exist

3.  when one time slice is over control goes to another slice of another program

4.  none above

27.  In Unix file system, the top-level directory is known as

1.  exception

2.  root (denoted by just /, slash)

3.  main

4.  heir

28.  In Unix, unshareable files can be accessed by

1. local systems and remote hosts

2. local systems only

3. remote systems only

4. none above

29.  Which type of exceptions are called Oracle named exceptions?

1. user-defined exception

2. external exception

3. predefined exception

4. internal exception

30.  What is the problem in the following Oracle code?  Choose the right option that is true.

CREATE OR REPLACE PROCEDURE ZERODIVISION(x IN NUMBER, y IN NUMBER)

IS

z NUMBER;

begin

    z := x/y;

    dbms_output.put_line(‘Value is ‘ || z);

EXCEPTION

      WHEN ZERO_DIVIDE THEN

                dbms_output.put_line(‘Take care of zero input values.’);

END;

/

1.  z NUMBER is not in DECLARE statement

2.  problem in dbms_output statement

3.  ZERO_DIVIDE is undefined

4.  no problem in the code and executes fine

31.  Choose the right option to fill the blank.

create or replace procedure division_calculate(x in number, y in number)

IS

   zerodivide_detected  EXCEPTION;

   ———————————————                — blank

   z number;

BEGIN

   z := x/y;

   dbms_output.put_line(‘Value is ‘ || z);

EXCEPTION

   WHEN zerodivide_detected THEN

      dbms_output.put_line(‘Avoid zero by division’);

END;

1.  PRAGMA EXCEPTION_INIT(zerodivide_detected, -1476);

2.  PRAGMA EXCEPTION_INIT(zerodivide_detected, 1476);

3.  EXCEPTION_INIT(zerodivide_detected, -1476);

4.  PRAGMA_INIT(zerodivide_detected, -1476);

32.  Choose the right option that is FALSE for the following code.

DECLARE

  age_exception  EXCEPTION;

  visitor_age  NUMBER := 9;

  PRAGMA EXCEPTION_INIT(age_exception, -1000);

BEGIN

  IF visitor_age < 10 THEN

       RAISE age_exception;

  END IF;  

  DBMS_OUTPUT.PUT_LINE(‘Enjoy water games’);

  EXCEPTION

    WHEN  OTHERS THEN  

        DBMS_OUTPUT.PUT_LINE(‘Not permitted for water games. Go for other’);  

END;

1.  code compiles even the Pragma statement is not the first one in DECLARE block

2.  code compiles even age_exception is not handled in EXCEPTION block

3.  code compiles as OTHERS is written without using age_exception before

4.  code does not compile as Pragma syntax is wrong

33.  Choose the right option that is FALSE.

1.  In Composite type variables, we can delete elements from a nested table using the built-in procedure DELETE

2.  We can access each element of a collection variable by its unique index.

3.  Collection and Records are two types of composite data types.

4.  In Composite type variables, indexes in associative array are stored in addition order and not in sorted order.

34.  Choose the option that is true for the following code in Oracle.

DECLARE 

   num1 number(3) := 123.5432;

BEGIN 

   dbms_output.put_line(num1);

END;

What is the output for the above put_line statement.

1.  123.5432

2.  123

3.  124

4.  none above

35.  Choose the right option that fits in the blank to compile and execute successfully.

DECLARE

    grade varchar(10);

BEGIN

   grade := ‘A’;

CASE grade

   ————————-          — blank here

        dbms_output.put_line(‘Excellent’);

   ELSE

        dbms_output.put_line(‘No such grade’);

END CASE;

END;

1.  WHEN grade = ‘A’ THEN

2.  WHEN grade := ‘A’ THEN

3.  WHEN ‘A’ THEN

4.  none above

36.  Choose the right option for the blank in the following associative array to compile successfully.

DECLARE

   TYPE marks IS TABLE OF NUMBER INDEX BY VARCHAR2(20);

   student  marks;             

BEGIN

  student(‘Rao’)  := 55;

  student(‘Yadav’)  := 65;

  student(‘Reddy’)  := 75;

  ———————————————         — blank here

END;

Which option prints Rao ?

1.   dbms_output.put_line(student.FIRST);  

2.   dbms_output.put_line(student(‘rao’));  

3.   dbms_output.put_line(student(student.FIRST));

4.   dbms_output.put_line(student(student.FIRST));

37.  Choose the right option that is true for the following Collection record.

DECLARE

     e_record Employee%ROWTYPE;                         — Line 1

BEGIN

  e_record.empid := 106;

  e_record.empname := ‘ION’;

  e_record.empsal  := 456.50;

  INSERT INTO Employee VALUES e_record;         — Line 2

  dbms_output.put_line(‘record inserted’);

END;

1.  Code does not compile due to error at Line 1

2.  Code does not compile due to error at Line 2

3.  Code does not compile due to error at Line 1 and Line 2

4.  Code compiles successfully and output will be displayed

38.  Choose the right option that is true regarding SQL cursors.

1.  Implicit cursor is not created by the Oracle engine automatically,

2. %ISCLOSE is a cursor attribute.

3.  Cursor does not refer to a context area of a DML statement.

4.  Declaring the cursor defines cursor with a name and the associated SELECT statement.

39.   Choose the right option to fill the blank in the following explicit cursor code to terminate the loop.

DECLARE

   person_name Person.pname%type;

   person_address Person.paddress%type;

   CURSOR persons is

      SELECT pname, paddress FROM Person;

BEGIN

   OPEN persons;

   LOOP

   FETCH persons into person_name, person_address;

      ——————————————–                                      — blank here to terminate the loop

      dbms_output.put_line(person_name || ‘ – ‘ || person_address);

   END LOOP;

   CLOSE persons;

END;

1.  EXIT WHEN persons%notfound;

2.  EXIT WHEN persons sql%notfound;

3.  CLOSE WHEN persons%notfound;

4.  none above

40. Choose the right option for the blank, that compiles successfully, in the following user-defined function.

CREATE OR REPLACE FUNCTION get_id(salary number)

   RETURN number

   IS

   eid number;

BEGIN

   ——————————————————————————–    — blank here

   dbms_output.put_line(eid);

   RETURN(eid);

 END;

1.  SELECT empid INTO empsal FROM Employee WHERE empsal = salary;

2.  SELECT empid INTO salary FROM Employee WHERE empsal = salary;

3.  SELECT eid INTO empid FROM Employee WHERE empsal = salary;

4.  SELECT empid INTO eid FROM Employee WHERE empsal = salary;

SOLUTIONS

1.  3                        2.  4                        3.  2                        4.  2

5.  3                        6.  4                        7.  2                        8.  4

9.  1                        10.  1                      11.  1                      12.  1

13.  2                      14.  4                      15.  3                      16.  3

17.  1                      18.  2                      19.  2                      20.  3

21.  4                      22.  4                      23.  4                      24.  2

25.  1                      26.  3                      27.  2                      28.  2

29.  1                      30.  4                      31.  1                      32.  4

33.  4                      34.  3                      35.  3                      36.  1

37.  4                      38.  4                      39.  1                      40.  4

Leave a Comment

Your email address will not be published.