Set 4 – Java, Oracle, Unix Interview Questions

1. What is the index position of element 10 in the Stack?

Stack st = new Stack();
st.push(10);
st.push(20);
st.push(30);

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

2. With what you can fill up the blank so that the output is Hyderabad.

List cities = new ArrayList();
cities.add("Hyderabad"); 
------- abc = cities.get(0);
System.out.println(abc);

1. Object
2. String
3. 1 and 2
4. None of the above

3. The classes/interface required to write threads are

1. class Thread and interface Runnable
2. class Object
3. class ThreadGroup
4. 1, 2 and 3

4. To print the name of the thread “hello”, what method you will call with t1 (fill up the blank).

public class Demo
{ 
   public static void main(String[] args) 
   {
     Thread t1 = new Thread("hello");
      String str = ------------------;
      System.out.println(str);
   }
}  

1. t1.getName();
2. t1.getThreadName();
3. t1.getThread();
4. t1.name();

5. What is the output of the following program?

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

1. hello
2. does not compile
3. throws exception
4. none of the above

6. What is the alternative way of handling the checked exception with try-catch?

1. throwing the exception with throws keyword in the method signature
2. throwing the exception with throw keyword in the method signature
3. using finally
4. using user-defined exceptions

7. Fill up the blank with the option that can compile and execute the code successfully?

try
{
    FileInputStream fis = new FileInputStream("abc.txt");
}
catch( ---------------------  e)  
{   
    System.out.println(e.toString());
}

1. FileNotFoundException
2. IOException
3. Exception
4. all the above

8. What about the facts of the code? Choose the right option that is true.

class InsufficientFundsException extends Exception
{
   public InsufficientFundsException(String message)
   {
      super(message);
   }
}
public class Demo
{ 
   public static void main(String[] args) 
   {
       int balance = 5000;
       if(balance <  10000)
       {
          throw new InsufficientFundsException("No required funds");
       }
   }
}     

1. compiles, executes successfully and prints the message "No required funds"
2. does not compile as main() is not throwing InsufficientFundsException
3. does not compile as throw is used instead of throws
4. compiles but throws exception

9. What could be the blank in the following snippet of code to compile successfully?

FileInputStream fis = new FileInputStream("abc.txt");  
------------ x = fis.read();

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

10. Which is the most appropriate option to create fos1 object that compiles successfully?

1. FileOutputStream fos1 = new FileOutputStream("abc.txt");
2. FileOutputStream fos1 = new FileOutputStream("abc.txt", false);
3. FileOutputStream fos1 = new FileOutputStream(new File("abc.txt"));
4. all above

11. When the first println() prints 1000, what the second println() statement prints?

FileInputStream fis = new FileInputStream("abc.txt");      // file is opened
System.out.println(fis.available());      // prints 1000
fis.skip(500);
fis.skip(100);
System.out.println(fis.available());           // what it prints?
fis.close();				 // file is closed

1. 600
2. 500
3. 100
4. 400

12. Java Designers divided the JDBC drivers into how many types?

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

13. Which of the following are classes of java.sql package.

1. Blob
2. Clob
3. 1 and 2
4. none of the above

14. What is the super class of SQLException?

1. Exception
2. JDBCException
3. DatabaseException
4. QueryException

15. Which one of the following statements is correct about the return type of forName() method?

1. Class cls = Class.forName(String);
2. Class.forName(String) returns void
3. Connection con = Class.forName(String);
4. DatabaseConnection dc = Class.forName(String);

16. getMimeType(String) is a method of

1. ServletConfig
2. ServletContext
3. HttpServlet
4. GenericServlet

17. getServletContext() is a method of

1. ServletConfig
2. ServletContext
3. RequestDispatcher
4. HttpSession

18. Which is the correct statement that returns an object of ServletOutputStream?

1. ServletOutputStream sos = response.getServletOutputStream ();
2. ServletOutputStream sos = response.getIOStream();
3. ServletOutputStream sos = response.getOutputStream();
4. ServletOutputStream sos = response.getStream();

(where response is an object of HttpServletResponse)

19. Choose the correct option to fill the blank.

Session ----------------------------------------.

1. is a conversational state between client and server.
2. consists of multiple requests and responses between client and server.
3. comes with an unique ID
4. all above

20. addCookie(Cookie obj) method returns --------------

1. void
2. Cookie object (which added)
3. boolean (of true if cookie is added else false)
4. int (0 if added or non-zero if not added)

21. Choose the correct option.

setMaxAge(-1) of a cookie indicates

1. Cookie should not be be destroyed
2. Cookie to be destroyed when the browser is shutdown
3. throws IllegalArgumentException
4. throws NegativeIndexException

22. getParameter(String) method is defined in -------------------- implicit object.

1. session
2. out
3. request
4. response

23. Which one of the following options is correct syntax for a JSP expression.

1. <%= request.getParameter("password"); %>
2. <%= request.getParameter("password") %>
3. <=% request.getParameter("password"); %>
4. <% request.getParameter("password"); %>

24. Choose the correct option for the following code if the salary is 80000.

<%!
         public void display(double sal)
         {
                if(sal >= 75000)
	           out.println(" are great");
          }
%>        
<%
          out.println("You");  
          String str2 = request.getParameter("salaryField");
          double salary = Double.parseDouble(str2);
          display(salary);
          out.println(" man");  
%>

1. prints You are great man
2. prints You are great
3. prints are great
4. does not print anything as code contains errors

25. Interrupt and trap handling is done by -------------------.

1. shell
2. kernal
3. application layer
4. application libraries

26. In preemptive multitasking

1. CPU time is divided into slices
2. CPU time is not divided into slices
3. more than one task can be performed at the same time on a single processor
4. each program gets number of slices

27. In Unix, the home directory contains

1. binary files
2. user directories and files
3. device specific files
4. system configuration files

28. What command is used to terminate a running process in Unix?

1. kill
2. close
3. invalidate
4. cancel

29. What is the output for the following Oracle code when user enters 10 for x and 0 for y. Choose the right option.

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 VALUE_ERROR THEN
        	dbms_output.put_line('Hello 1'); 
       WHEN OTHERS THEN
        	dbms_output.put_line('Hello 2'); 
END; 

1. Hello 1 and Hello 2
2. Hello 1
3. Hello 2
4. nothing printed

30. What exception suits for the problem of the code?

DECLARE
    num number;
BEGIN
    num:= 'five';
    num := num * num;
    DBMS_OUTPUT.PUT_LINE(num);
EXCEPTION
   WHEN --------------------- THEN
        DBMS_OUTPUT.PUT_LINE('Conversion problem');
END;

1. NO_DATA_FOUND
2. TOO_MANY_ROWS
3. STORAGE_ERROR
4. VALUE_ERROR

31. Choose the right option that is true.

create or replace procedure Pragmademo(id in number) 
IS 
   manyrecords_detected  EXCEPTION;
   nodata_detected  EXCEPTION;
   salary number;
   PRAGMA EXCEPTION_INIT(manyrecords_detected, -1422);
   PRAGMA EXCEPTION_INIT(nodata_detected, -100);
BEGIN
   select empsal into salary from Employee where empid=id;
   dbms_output.put_line('Salary of ' || id || ' is ' || salary);
EXCEPTION
   WHEN manyrecords_detected THEN
      dbms_output.put_line('Many records exist on ID');
   WHEN nodata_detected THEN
      dbms_output.put_line('No data found for this ID');
END;

1. declaring two Pragma exceptions in a single procedure does not raise compilation error
2. procedure does not compile successfully
3. depending on id input value appropriate exception is not caught
4. none above

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

DECLARE
     table_already_in_use  EXCEPTION;
     PRAGMA EXCEPTION_INIT(table_already_in_use,  -955);
     new_table_status VARCHAR2(100) := 'CREATE TABLE Employee(empid number)';
BEGIN
      EXECUTE IMMEDIATE new_table_status;
      EXCEPTION 
              WHEN table_already_in_use THEN
                    DBMS_OUTPUT.PUT_LINE('Table is already existing in the database');
END;

1. statement EXECUTE IMMEDIATE causes compilation error
2. VARCHAR2(100) raises error
3. the code does not compile with other errors
4. the code does not contain errors and happily compiles

33. Choose the right option that is true.

1. In Composite type variables, nested tables cannot increase the size dynamically.
2. Composite variables does not have internal components.
3. Composite data type stores values that do not have internal components.
4. In Composite type variables, manipulation of associative array can only be carried out by collections functions and not with DML statements.

34. Choose the best right option for the following codes that executes successfully in Oracle.

Code A:

DECLARE x binary_float := 2.5; y binary_double := 2.5; z binary_float;
BEGIN z := x*y; dbms_output.put_line(z); END;

Code B:

DECLARE x real := 2.5; y binary_double := 2.5; z number;
BEGIN z := x*y; dbms_output.put_line(z); END;

Code C:

DECLARE a char(10) := '222'; b long(4) := 'abcd';
BEGIN dbms_output.put_line(a || b); END;

Code D:

DECLARE c nchar(10) := 'klmn'; d rowid := 'pqrs';
BEGIN dbms_output.put_line(c || d); END;

1. Code A, Code B, Code C, Code D
2. Code A, Code B
3. Code C, Code D
4. none above

35. Read the code and choose the right option that is true.

DECLARE
    stock_price number; 
    num_stocks number; 
BEGIN 
    stock_price := 50.5; 
    num_stocks := 50; 
DECLARE 
    total_cost number; 
BEGIN 
    total_cost := stock_price * num_stocks; 
END; 
    dbms_output.put_line('Total cost is ' || total_cost);     
END; 

1. code does not compile due to nested blocks
2. code does not compile due to scope problem of total_cost
3. code compiles fine and gives the output of total_cost
4. none above

36. Choose the right option for the blank in the following collection code.

DECLARE
   TYPE ename IS TABLE OF VARCHAR2(50) INDEX BY PLS_INTEGER ;
   emp_name ename;
BEGIN
  emp_name('01')  :=  'TCS1, Hyderabad';
  emp_name('02')  :=  'TCS2, Pune';
  emp_name('03')  := 'TCS3, Bubaneswar';
  dbms_output.put_line(---------------------------------);           -- blank here
END;

Fill up the blank of how to get the last element of this associative array.

1. emp_name.LAST
2. emp_name.1
3. emp_name.(1)
4. emp_name.getLast()

37. Choose the right option to fill the blank for the following nested record to compile successfully.

DECLARE
   TYPE address IS RECORD (
    city varchar2(20)
  );
  TYPE customer IS RECORD(
      name  varchar2(20),
      send_to address
  );
  cust customer;
BEGIN
  cust.name := 'TCS';
  ------------------------ := 'Hyderabad';          -- blank here

  dbms_output.put_line(cust.name || cust.send_to.city);
END;

1. cust(send_to(city))
2. (cust.send_to).city
3. cust.send_to.city
4. (cust.send_to) city

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

1. A cursor can hold more than one row, but can process only one row at a time.
2. Cursor does not point to context area of a SQL statement
3. When you fetch a row the current row position does not move to the next row implicitly.
4. Implicit cursors are not created automatically by the Oracle engine.

39. Choose the right option to fill the blank

DECLARE 
     -------------------------------     	-- blank here
     SELECT empid, empname from Employee;
BEGIN
    FOR  emp1 IN emp LOOP
        DBMS_OUTPUT.PUT_LINE(emp1.empid || ', ' || emp1.empname);
END LOOP;
END;

1. CURSOR emp IS
2. CURSOR emp1 IS
3. CURSOR Employee IS
4. none above

40. What could be the blank to compile the following trigger. Choose right option that is true.
Employee table contains three fields of empid, empname and empsal.

create or replace trigger emp_insert 
before INSERT
on 
------------------------            -- blank here
for each row
BEGIN  
   dbms_output.put_line('record affected successfully');  
END;

1. empid or empname or empsal
2. empid
3. Employee
4. none above

SOLUTIONS

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

Leave a Comment

Your email address will not be published.