Set 6 – Java, Oracle, Unix Interview Questions


1. What is the default capacity and increment rate of Vector?

1. 10 and 10
2. 10 and 11
3. 11 and 11
4. 10 and 5

2. What is the return type of add(Object) method of interface Collection?

1. void
2. boolean
3. Object
4. int

3. Choose more appropriate option.

currentThread() method of Thread class

1. returns thread group name
2. returns thread object that is running currently
3. returns the name of the thread
4. returns the thread priority

4. Choose the correct option if no properties are set to current thread.

class Demo extends Thread
{
   public void run()
   {
      Thread t1 = this.currentThread();
      System.out.println(t1.getName()+","+t1.getPriority()+","+t1.getThreadGroup());
   }
   public static void main(String args[])
   {
       Demo d1 = new Demo();
       d1.start();
  }
}

1. prints Thread-0,5,main
2. prints Thread-1,5,main
3. prints Thread-0,10,main
4. prints Thread-0,5,java

5. Choose the right option that is true regarding the following code.

public class Demo implements Runnable
{ 
    public void run()
    {
         System.out.println("Hello");
    }
    public static void main (String [] args) 
    {
         Demo d1 = new Demo();
         d1.start();
    }
}    

1. compiles but does not execute
2. compiles and prints Hello
3. Demo class does not define start() method and thereby does not compile
4. none of above

6. What is the exception thrown by the following snippet of code?

String str = "hello";
char x = str.charAt(5); 

1. IndexOutOfBoundsException
2. ArrayIndexOutOfBoundsException
3. StringIndexOutOfBoundsException
4. IllegalArgumentException

7. The job of yield() method is

1. to temporarily stop the thread from its execution
2. to permanently stop the thread from its execution
3. to get thread to dead state
4. to get the thread to runnable state

8. What are the facts of the following code? Choose the right option.

class Demo extends Thread
{
   public void start()
   {
      System.out.println("Done");
      run();
   }
   public static void main(String args[])
   {
       Demo d1 = new Demo();
       d1.start();
  }
} 

1. no output obtained as d1.start() calls predefined Thread’s start() method
2. does not compile as run() is not defined in Demo class
3. compiles, runs and prints Done
4. 1 and 2

9. What could be the second parameter (blank in the code) of the following FileOutputStream constructor?

FileOutputStream fos = FileOutputStream(String, ————-);

1. boolean
2. int
3. long
4. double

10. Fill up the blank with the best option to print 10 at command prompt?

   public static void main(String[] args)
   {
      PrintStream ps = new PrintStream(---------------);
      ps.println(10);  
   } 

1. System.out
2. System.err
3. 1 and 2
4. code does not compile as exception handling is not done

11. What is the best option from the following to merge two files?

1. SequenceInputStream sis = new SequenceInputStream(new FileInputStream(“abc.txt”), new FileInputStream(“def.txt”));

2.
Vector vect = new Vector();
vect.add(new FileInputStream(“abc.txt”));
vect.add(new FileInputStream(“def.txt”));
Enumeration e = vect.elements();
SequenceInputStream sis = new SequenceInputStream(e);

3. 1 and 2
4. code does not compile with all the errors

12. Which one of the following is not a ResultSet attribute?

1. ResultSet.TYPE_SCROLL_SENSITIVE
2. ResultSet.TYPE_SCROLL_INSENSITIVE
3. ResultSet.TYPE_FORWARD_ONLY
4. ResultSet.TYPE_BACKWARD_ONLY

13. What is the checked exception thrown by the static method forName() of class Class?

1. IllegalAccessException
2. InstantiationException
3. SecurityException
4. ClassNotFoundException

14. Which of the following statements compile successfully. Choose the best option.

1. DatabaseMetaData dsmd = con.getMetaData(); // where con is Connection object
2. ResultSetMetaData rsmd = res.getMetaData(); // where res is ResultSet object
3. Blob blob = res.getBlob(3); // where 3 is column index and res is ResultSet object
4. 1, 2 and 3

15. Which one of the following options is NOT the best practice for JDBC?

1. Use Connection Pool
2. Enable auto commit mode (to true)
3. Use PreparedStatement
4. Use JDBC Batch updates

16. For one Web application how many ServletContext objects are created by the container?

1. 0
2. 1
3. 2
4. cannot be predicted

17. If multiple clients call the same servlet, the container creates ——————- of the same servlet as servlet is multithreaded.

1. one init(), one destroy() and multiple service() methods (one for each client)
2. one init(), one destroy() and one service() methods (for all clients)
3. multiple init(),multiple destroy() and multiple service() methods (one for each client)
4. multiple init(), one destroy() and multiple service() methods

18. What is the job of SingleThreadModel interface? Choose the right option that is true?

1. To see the servlet is meant for a single client
2. To see the servlet is not meant for a single client
3. To see the servlet is for more than a single client
4. To see threads should not be created as user threads collide with server threads

19. Choose the best option to fill up the blank that is true.

Cookie is —————————————————.

1. created on server
2. stored on client
3. a class from javax.servlet.http package
4. all above

20. Which of the following options return an object of RequestDispatcher?

1. RequestDispatcher rd = ctx.getRequestDispatcher(“/myBilling”);
// where ctx is an object of ServletContext and myBilling is alias name of other servlet.
2. RequestDispatcher rd = req.getRequestDispatcher(“/myBilling”);
// where req is an object of ServletRequest and myBilling is alias name of other servlet.
3. 1 and 2
4. none of above

21. Fill up the blank by choosing correct return type option.

————— xyz = session.getId(); // where session is an object of HttpSession

1. int
2. long
3. Object
4. String

22. If “fmt” is the prefix for JSTL formatting tag library, which one of the following is a JSTL tag? Choose correct option.

1. fmt:parseNumber
2. fmt:parseInt
3. fmt:parseFloat
4. fmt:parseByte

23. Which one of the following options is of right JSP syntax?

1. <%@ page info=”project started on 01-07-2019″ import=”java.net.*” %>
<%@ page info=”base Hyderabad” language=”java” %>
2. <%@ page info=”project started on 01-07-2019″ import=”java.net.*” %>
<%@ page session=”false” language=”java” %>
3. <%@ page info=”project started on 01-07-2019″ isThreadSafe=”false” %>
<%@ page info=”base Hyderabad” language=”java” %>
4. <%@ page info=”project started on 01-07-2019″ extends=”Demo” %>
<%@ page info=”base Hyderabad” language=”java” %>

24. Which one of the following options is of right JSP syntax?

1. request.setAttribute(“userName”, “snrao”) ;
2. application.setAttribute(“userName”, “snrao”) ;
3. session.setAttribute(“userName”, “snrao”) ;
4. 1, 2 and 3

25. What are the types of OS multitasking?

1. linear and random
2. preemptive and cooperative
3. multithreading and batch processing
4. online and offline

26. Choose the right option that is true to fill up the blank.

A multiprocessing OS ——————————————————. // blank here

1. does not support a number of processors
2. supports a number of processors
3. supports time slicing
4. is not expensive in cost

27. Choose the right option that is true to fill up the blank.

In Unix, the proc directory contains —————————————-.

1. binary files
2. system binary files
3. system process specific files
4. system configuration files

28. Which command is used to rename a file in Unix? Choose the right option.

1. ren
2. rename
3. alter
4. mv

29. Choose the right option that is true for the following Oracle code.

CREATE OR REPLACE PROCEDURE calculate(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('Hello 1'); 
END; 

What input values of x and y, the output Hello 1 is obtained,

1. x = 10 and y = 0 or x = 0 and y = 0
2. x = 0 and y = 10
3. x = 10 and y = 10
4. none above

30. What predefined exception of Oracle can fill up the blank?

DECLARE
   ename varchar2(15); 
BEGIN
   SELECT empname into ename from Employee; 
   dbms_output.put_line(ename); 
EXCEPTION 
   WHEN ------------------------- THEN		-- blank here
      dbms_output.put_line('One variable cannot accommodate more data'); 
end;  

1. PROGRAM_ERROR
2. DATA_FOUND
3. VALUE_ERROR
4. TOO_MANY_ROWS

31. Choose the right option that you think true for the following code.

DECLARE
   small_man_detected  EXCEPTION;
   salary number;
   PRAGMA EXCEPTION_INIT(small_man_detected, -1422);
   PRAGMA EXCEPTION_INIT(small_man_detected, -1422);
BEGIN
   select empsal into salary from Employee where empid=101;
   dbms_output.put_line(salary);
   if salary < 1000 then
        raise small_man_detected;
   end if;
EXCEPTION
   WHEN small_man_detected THEN
      dbms_output.put_line('You are small man. Enjoy many Govt. schmes');
END;  

1. PRAGMA is declared twice for the same exception small_man_detected and is compilation error
2. PRAGMA is declared twice for the same exception small_man_detected and is not a compilation error
3. 1422 should be a predefined SQL error code.
4. Pragma need not be a negative number

32. Choose the right option that is true.

DECLARE
   number_of_employees NUMBER;
BEGIN
   select count(*) into number_of_employees from Employee;
   IF number_of_employees > 100 THEN
       raise_application_error(-20101, 'Big company');
   ELSE
      dbms_output.put_line(' Small startup company ');
   END IF;
END;  

1. without using Pragma, error code and error message are linked and compiles successfully
2. without using Pragma, error code and error message cannot be linked and does not compile
3. linking is also not possible with raise_application_error
4. none above

33. Choose the right option that is true.

1. In Composite type variables, arrays do not have a fixed upper bound.
2. Scalar variables have internal components.
3. In Composite type variables, we can access each element of a collection variable by its non-unique index.
4. In Composite type variables, data type of each key of an associative array can be of string type or PLS_INTEGER.

34. Which of the following scalar variable codes execute successfully. Choose the option that is true.

Code A:

DECLARE n4 NATURALN := 10; n5 NATURAL; n6 NATURALN := 10;
BEGIN n5 := n4*n6; dbms_output.put_line(n5); END;

Code B:

DECLARE n4 NATURALN := 10; n5 NATURALN; n6 NATURALN := 10;
BEGIN n5 := n4*n6; dbms_output.put_line(n5); END;

Code C:

DECLARE n4 real; n5 PLS_INTEGER := 10; n6 INTEGER := 10;
BEGIN n4 := n5*n6; dbms_output.put_line(n4); END;

Code D:

DECLARE n4 POSITIVE; n5 PLS_INTEGER := 10; n6 INTEGER := 10;
BEGIN n4 := n5*n6; dbms_output.put_line(n4); END;

1. A, C, D compiles successfully and B raises compilation error
2. A, B compiles successfully
3. A, B, C, D compiles successfully
4. A, B riases error

35. Choose the right option that is true of the following code.

DECLARE
  current_date1 DATE;
  current_date2 DATE;
BEGIN  
  current_date1 := current_date;
  current_date2 := sysdate;
  if current_date1 = current_date2 then
     DBMS_OUTPUT.PUT_LINE('same');
  else
     DBMS_OUTPUT.PUT_LINE('not same');
  end if;
END;  

1. code compiles and gives output, no problem with current_date and sysdate
2. code does not compile
3. code compiles but throws exception
4. problem with current_date and sysdate

36. Choose the right option that fills the blank to compile the following collection associative array successfully.

DECLARE
    TYPE house_no IS TABLE OF varchar2(20) INDEX BY PLS_INTEGER;
    house_number house_no;
BEGIN    
    ---------------------------------------------------------        -- blank here
    DBMS_output.put_line(house_number.FIRST);
END; 

1. house_number('Mahalaxmi Nilayam') := 01;
2. house_number := 'Mahalaxmi Nilayam';
3. house_number(01) := 'Mahalaxmi Nilayam';
4. house_number(01) := 2540;

37. Choose the right option to fill the blank to compile the Collection record successfully.

CREATE OR REPLACE PROCEDURE emppro123(p_empid IN Employee.empid%TYPE)
IS
    rec_emp  Employee%ROWTYPE;
    e_avgsal  Employee.empsal%TYPE;
BEGIN
    --------------------------------------------------------------------------------     -- blank here
    SELECT AVG(empsal) INTO e_avgsal FROM Employee;

    IF rec_emp.empsal > e_avgsal THEN
        DBMS_OUTPUT.PUT_LINE('Excellent');
    ELSE
        DBMS_OUTPUT.PUT_LINE('Good');
    END IF;   
END;

1. SELECT empsal INTO p_empid.empsal FROM Employee WHERE empid = p_empid;
2. SELECT empsal INTO rec_emp.empsal FROM Employee WHERE empid = p_empid;
3. SELECT empsal INTO rec_emp.empsal FROM Employee WHERE p_empid = empid;
4. SELECT empsal INTO empid FROM Employee WHERE p_empid = empid;

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

1. A cursor cannot tell how many rows are affected by the DML statement.
2. A cursor cannot tell whether any rows returned by the DML statement.
3. The set of rows the cursor holds is known as active set.
4. An implicit cursor will not be closed automatically and should be used CLOSE.

39. Choose the right option to fill the blank that returns the number of records affected in the following Cursor code.

DECLARE   
   affected_rows pls_integer;  
BEGIN  
   UPDATE Employee SET empsal = empsal + 500;  
   IF sql%notfound THEN  
      dbms_output.put_line('Sorry, no employee salary updated');  
   ELSIF sql%found THEN  
      affected_rows := -------------------;    	-- blank here
      dbms_output.put_line(affected_rows || ' employees salary is added with incentive ');  
   END IF;   
END;  

1. sql%rowfetch
2. sql%rownumber
3. sql%rowcount
4. sql%rowaffected

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 
   ---------------------------      -- blank here
BEGIN 
   SELECT empid INTO eid FROM Employee WHERE empsal = salary; 
   dbms_output.put_line(eid);
   RETURN(eid); 
 END;  

1. empsal number;
2. salary number;
3. empid number;
4. eid number;

SOLUTIONS

1. 1 2. 2 3. 2 4. 1 5. 3
6. 3 7. 1 8. 3 9. 1 10. 3
11. 3 12. 4 13. 4 14. 4 15. 2
16. 2 17. 1 18. 1 19. 4 20. 3
21. 4 22. 1 23. 2 24. 4 25. 2
26. 2 27. 3 28. 4 29. 1 30. 4
31. 2 32. 1 33. 4 34. 1 35. 1
36. 3 37. 2 38. 3 39. 3 40. 4

Leave a Comment

Your email address will not be published.