Way2Java

Set 5 – Java, Oracle, Unix Interview Questions

1. Which method gives the index position of an element in Stack data structure?

1. indexOf()
2. search()
3. elementAt()
4. elementIndexOf()

2. The removeRange(3, 8) removes all the elements in Vector

1. from 3 to 8
2. from 3 to 7
3. from 2 to 8
4. from 2 to 7

3. What is the maximum priority that can be assigned to the threads of main group.

1. 1
2. 5
3. 8
4. 10

4. The job is join() method is

1. to see the parent thread dies later than child thread
2. to see the child thread dies later than parent thread
3. to communicate between two threads
4. 1 and 3

5. Observe the following code. Choose the correct option.

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

1. does not compile as instead of try-catch the InterruptedException is thrown in method body
2. compiles, executes and prints Hello with a late of 1000 milliseconds
3. run() is not called from main() method and thereby run() is not executed
4. compiles but throws exception

6. What the method printStackTrace() does?

1. prints the minute details of stack memory runtime problems
2. prints the major details of stack memory runtime problems
3. prints complete details of stack memory runtime problems
4. prints all the names of methods and classes involved with the problem

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

public static void main (String [] args) 
{
    String cities[][] = { {"Chennai","Delhi"}, { null }, {"Hyderabad","Bhopal"}};
    System.out.println(cities[1][1]);
}

1. compiles but throws ArrayIndexOutOfBoundsException
2. compiles but throws NullPointerException
3. compiles, executes and prints null
4. does not compile

8. Observe the following main() method code and choose the best right option that is true.

public static void main (String [] args) 
{
    List places = new ArrayList<>();
    places.add("Kochi");   places.add("Kedarnath");

    places.forEach(str ->  {
         if(str.equals("Kedarnath"))
               throw new RuntimeException("Do not go, it is winter");
         else
               System.out.println("Enjoy Kochi");
   });
}

1. code does not compile as exception cannot be thrown from Lambda expressions.
2. the code compiles, runs and prints
3. forEach loop is not supported by Java language
4. code does not compile as it is full of errors

9. If two files are opened with FileInputStream and FileOutputStream to copy a file, which order of the streams is the better way to close them?

1. first close FileInputStream and then FileOutputStream
2. first close FileOutputStream and then FileInputStream
3. streams need not be closed as they are closed automatically when copying is over
4. order is not important as both close() methods throw IOException.

10. Which method of LineNumberInputStream gives line numbers?

1. getLineNumber()
2. getLineCount()
3. getCount()
4. getNumber()

11. Fill up the blank with correct data type which can compile successfully?

FileInputStream fis = new FileInputStream ("Demo.txt");
---------- temp = 100;
fis.skip(temp); 

1. byte
2. short
3. int
4. all above

12. Which of the following statements are correct?

1. Stored procedure is used for business logic and function is used for calculations.
2. try-catch can be used with stored procedures and not with custom-defined function.
3. Stored procedure does not have a return type and function have.
4. 1, 2 and 3

13. Which interface helps us to get the name of the driver used?

1. Connection
2. ResultSetMetaData
3. DatabaseMetaData
4. MetaData

14. Choose the best option that is true.

1. execute() method is used to execute both select and update SQL statements
2. executeQuery() method is used to execute only select SQL statements and executeUpdate() is used for only update SQL statements
3. 1 and 2
4. execute() method does not exist.

15. Which one of the following statements executes successfully to set a null value with PreparedStatement without throwing exceptions?

PreparedStatement psmt = con.prepareStatement(someSqlQuery); // con is an object of Connection

1. psmt.setNull(3, java.sql.Types.VARCHAR); // 3 is the column index of a table
2. psmt.setNull(3, null);
3. psmt.setString(3, null);
4. psmt.set(3, null);

16. The service() method can have one of the parameters as

1. ServletRequest or HttpServletRequest
2. ServletConfig or HttpServletConfig
3. ServletContext or HttpServletContext
4. Response or HttpResponse

17. What is the interface used to forward request from one servlet to another?

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

18. Which is the right statement that returns an object of RequestDispatcher?

1. RequestDispatcher rd = request.getRequestDispatcher(“/roses”);
2. RequestDispatcher rd = request.getDispatcher(“/roses”);
3. RequestDispatcher rd = request.createRequestDispatcher(“/roses”);
4. RequestDispatcher rd = request.requestDispatcher(“/roses”);

(where request is an object of HttpServletRequest and roses is the alias name of the other servlet)

19. To which package Cookie class belongs?

1. javax.servlet
2. javax.servlet.http
3. javax.servlet.session
4. javax.servlet.http.session

20. Which methods return the name and value of the Cookie?

1. name() and value()
2. getCookieName() and getCookieValue()
3. cookieName() and cookieValue()
4. getName() and getValue()

21. Choose the right statement.

1. Cookie xyz[] = request.getCookies();
2. ArrayList xyz = request.getCookies();
3. HashSet xyz = request.getCookies();
4. Hashtable xyz = request.getCookies();

(where request is an object of HttpServletRequest)

22. If “c” is the prefix for JSTL core tag library, which option will iterate over a list of elements of a Java collection data structure?

1. <c:iterate>
2. <c:listIterate>
3. <c:forEach>
4. <c:tokens>

23. If “c” is the prefix for JSTL core tag library, what is the output of the following snippet of code?

<c:set var=”quantity” value=”2″/>
<c:forEach var=”quantity” begin=”0″ end=”0″ step=”3″>
<c:out value=”${ quantity }” default=”hello”/>
</c:forEach>

1. does not compile
2. 0
3. 1
4. hello

24. Which one of the following options is of correct JSP syntax to fill up the blank?

  
     ---------------------------------------------   	// fill up the blank
     <%@ page import="java.util.*" %>
     <%  Date d=new Date(); %>
     Time Particulars: 

Hours: <%= d.getHours() %>
Minutes: <%= d.getMinutes() %>
Seconds: <%= d.getSeconds() %>

1. <% response.setHeader("refresh", 5); %>
2. <% response.setHeader("5"); %>
3. <% response.setHeader("refresh", "5"); %>
4. <% response.setHeader(5); %>

25. /bin is a directory of shell which contains ——————————.

1. all error messages and log messages
2. all logical names to pysical devices
3. all system configuration files
4. all normal user executable commands

26. A multiprocessing OS

1. it not possible to execute multiple processes at the same time on a single processor
2. it is possible to execute multiple processes at the same time on a single processor
3. can support of execution of a number of processes at the same time on different processors
4. does not support of execution of a number of porcesses at the same time.

27. In Unix, the sbin directory contains

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

28. How to compare two files? Which command is used in Unix?

1. comp
2. cmp
3. compareTo
4. compare

29. Choose the right option to fill the blank that is valid for the zero input values of the client.

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

1. PROGRAM_ERROR
2. VALUE_ERROR or ZERO_DIVIDE
3. STORAGE_ERROR
4. none above

30. What predefined exception of Oracle can accommodate the blank?

DECLARE
    number varchar2(10);
BEGIN
    number:= 'ten';
    number := number * number;
    DBMS_OUTPUT.PUT_LINE(number);
EXCEPTION
   WHEN -------------------- THEN		-- blank here
        DBMS_OUTPUT.PUT_LINE('Conversion problem');
END; 

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

31. If the id 101 salary is 999, choose the right option that will be true for the following code.

DECLARE
   small_man_detected  EXCEPTION;
   salary number;
   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. schemes');
END;  

1. Both salary and exception message are printed and code compiles successfully
2. Code is with errors and does not compile
3. Only exception message is printed
4. none above

32. Choose the right option to fill the blank to get the message 'Problem'.

DECLARE
   overdraft_exception EXCEPTION;
   not_permitted_exception EXCEPTION;
   overdraft number := 10000;
   withdraw number := 20000;
BEGIN
      IF withdraw > overdraft THEN
           RAISE overdraft_exception;
      END IF;
EXCEPTION
  WHEN ------------------------ THEN 	-- blank
    DBMS_OUTPUT.PUT_LINE('Problem');
END; 

1. program_error
2. not_permitted_exception
3. value_error
4. overdraft_exception

33. Choose the right option that is true.

1. In Composite type variables, nested tables are bounded.
2. When you assign values to a record, you are not assigning values to the fields within it.
3. In Composite type variables, PL/SQL allows to define two kinds of composite data types - Collection and Record.
4. In Composite type variables, an associative array is stored in a database table.

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

Code A:

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

Code B:

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

Code C:

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

Code D:

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

1. A, D compiles successfully
2. B, C compiles successfully
3. A, B, C, D compiles successfully
4. none of above

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

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

1. if current_date1 eq current_date2 then
2. if current_date1 = current_date2 then
3. if current_date1 == current_date2 then
4. none above

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

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 first element of this associative array.

1. emp_name.FIRST
2. emp_name.1
3. emp_name.(1)
4. emp_name.getFirst()

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

DECLARE
   TYPE address IS RECORD (
    city varchar2(20),
    pincode binary_integer
  );
  TYPE customer IS RECORD(
      name  varchar2(20),
      send_to address
  );
  cust customer;
BEGIN
  cust.name := 'TCS';
  cust.send_to.city := 'Hyderabad';
  cust.send_to.pincode := 500020;

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

1. Code compiles successfully and output is displayed
2. Compiles but throws exception
3. Error in code
4. none above

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

1. %ROWCOUNT is used to know the number of records affected by the SQL statement.
2. %ISCLOSED is used to know whether the cursor is opened or not.
3. Implicit cursors are more efficient than explicit cursors.
4. A cursor variable is tied to a specific query.

39. Choose the right option to fill the blank

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

1. FOR emp IN emp1 LOOP
2. FOR emp1 IN emp LOOP
3. FOR emp1 IN Employee LOOP
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_salary(id IN NUMBER) 
   RETURN NUMBER 
   IS esal NUMBER(6,2);
BEGIN 
   SELECT empsal INTO esal FROM Employee WHERE empid = id; 
   dbms_output.put_line(esal);
   ------------------------------------       -- blank here
 END;  

1. RETURN(empsal);
2. RETURN(Employee);
3. RETURN(esal);
4. RETURN(get_salary);

SOLUTIONS

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