Set 7 – Java, Oracle, Unix Interview Questions


1. What is the return type of insertElementAt(Object, int) method of Vector?

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

2. Observe the following code snippet and choose the right option.

List  fruits = new ArrayList();
fruits.add("mango");
ListIterator li1 = fruits.listIterator();
while(li1.hasNext())
{
   fruits.add("apple");
   System.out.println(li1.next());
}
 

1. Compiles and at execution throws ConcurrentModificationException
2. prints mango
3. prints mango and apple
4. Compiles and executes but no output

3. Observe the following code and choose the right option.

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

1. code prints Done
2. code does not compile as anonymous object of thread cannot be created
3. code compiles but throws exceptions without printing Done
4. no output is obtained as run() is not called anywhere in the code

4. What is the output of the following program? Choose the right option.

public class Test
{
   public void run()
   {
       System.out.println("Hello");
   }
   public static void main(String args[]) throws Exception
   {		
       Test t1 = new Test();
       t1.start();
       System.out.println("Sir");
    }
}  

1. Sir followed by Hello
2. Hello followed by Sir
3. Can’t say order
4. does not compile

5. What is the output of the following program? Choose the correct option.

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

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

6. Which block of code is more appropriate to close the IO streams?

1. try block
2. catch block
3. finally block
4. all the above

7. In the following program which threads are created? Choose correct option?

public class Demo extends Thread
{
    public static void main(String args[])
    {		
       Demo d1 = new Demo();
       d1.start();
    }
}  

1. main and Demo
2. Demo
3. main
4. none above

8. The following is snippet of code. Choose the right option.

try
{
    FileInputStream fis = new FileInputStream("abc.txt");
}
catch(IOException  e)  
{   
    System.err.println(e.printStackTrace());
}

1. compiles successfully
2. does not compile as errors exist in the code
3. compiles and catch is executed when abc.txt file does not exist
4. compiles and catch block is ignored when the file abc.txt file exist

9. What is the immediate super class of FileNotFoundException?

1. IOException
2. EOFException
3. Exception
4. Throwable

10. When to use markSupported() method? Choose the right option.

1. to know whether which socket is marked to receive input
2. to know whether which socket is marked to send output
3. to know whether an input stream supports mark() method
4. to know whether which thread is marked for animation with mark() method

11. Fill up the blank with one of the following options?

FileOutputStream fos = new FileOutputStream("def.txt"); // opening file
------------------------------------              // this is the blank 
BufferedWriter bw = new BufferedWriter(xyz);                 
bw.write("Hello 1");  

1. OutputStreamWriter xyz = new OutputStreamWriter(fos);
2. RandomAccessFile xyz = new RandomAccessFile(fos);
3. PipedWriter xyz = new PipedWriter(fos);
4. PushbackWriter xyz = new PushbackWriter(fos);

12. Which type of driver converts JDBC calls into database (like Sybase, Oracle etc.) specific calls.

1. JDBC-ODBC Bridge, plus ODBC driver (Type 1 driver known as bridge driver)
2. Native-API, partly-Java driver (Type 2 driver)
3. JDBC-Net, pure Java driver (Type 3 driver)
4. Native protocol, pure Java driver (Type 4 driver known as thin driver)

13. To provide batch updates which interface to use? Choose the right option.

1. Statement interface
2. PreparedStatement interface
3. CallableStatement interface
4. 1 and 2

14. Which method is more appropriate for executing SQL statements that are used frequently for client calls?

1. createStatement()
2. prepareStatement()
3. prepareCall()
4. all above

15. Choose the best JDBC practice(s) for JDBC coding?

1. Avoid * (asterisk) and instead write column list for select statement (means, avoid select * from ……)
2. Prefer delegate model for connecting database
3. 1 and 2
4. none of the above

16. HttpServlet is ———————–.

1. an abstract class without a single abstract method
2. non-abstract class without any abstract methods
3. interface with all abstract methods
4. none above

17. Fill up the blank with correct option where req is an object of HttpServletRequest.

req.setAttribute(“rate”, “2.25”);
————— xyz = req.getAttribute(“rate”);

1. String
2. Double
3. double
4. Object

18. Which class/interface is used to know the Servlet API version the container is supporting? Choose the right option.

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

19. What are the parameters of include() and forward() methods of RequestDispatcher used for inter-servlet communication? Note: Order is also important

1. ServletRequest, ServletResponse
2. ServletResponse, ServletRequest
3. ServletConfig, ServletContext
4. none of above

20. Calling rd.include(request, response) three times includes the response of other servlet ——– times where rd is an object of RequestDispatcher.

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

21. Which method returns the HTTP session id. Choose the right option?
(where session is an object of HttpSession)

1. String id = session.getSessionId();
2. String id = session.getId();
3. String id = session.sessionId();
4. String id = session.getSessionNumber();

22. Which implicit object cannot be used from declaration?

1. application
2. session
3. request
4. config

23. Which of the following is not a JSTL core tag? Choose correct option.

1. <c:out>
2. <c:export>
3. <c:import>
4. <c:remove>

24. Which one of the following options is of right JSP syntax to fill up the blank? Choose the best option.

<body>
————————————– // fill up the blank
News over.
</body>

1. <%@ include file=”news.html” %>
2. <jsp:include page=”Footer.jsp” />
3. <jsp:include file=”Footer.jsp” />
4. 1 and 2

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

In time sharing —————————————————————-. // blank here

1. to share the system, all Programmers should sit a single place
2. while sharing the system, all Programmers may be distributed in different locations on the globe
3. time sharing does not mean a single system
4. time sharing is done at the same time and not simultaneously

26. Which OS is more complex in execution? Choose the right option.

1. batch processing OS
2. multiuser OS
3. multiprogramming OS
4. multiprocessing OS

27. In Unix, the file extensions are

1. should not have
2. should have
3. optional
4. none above

28. Which command is used to print the path of the working directory, starting from the root.

1. print
2. pwd
3. printDirectory
4. none above

29. Choose the right option that is appropriate for the following Oracle procedure.

CREATE OR REPLACE PROCEDURE calculate(x IN NUMBER, y IN NUMBER)
IS
z NUMBER;
SET SERVEROUTPUT ON;
begin
    z := x/y; 
    dbms_output.put_line('Value is ' || z); 
EXCEPTION
      WHEN VALUE_ERROR OR ZERO_DIVIDE THEN
        	dbms_output.put_line('Hello 1'); 
       WHEN OTHERS THEN
        	dbms_output.put_line('Hello 2'); 
END; 

1. inclusion of statement SET SERVEROUTPUT ON raises compilation error
2. no problem with the statement SET SERVEROUTPUT ON
3. code is fine and compiles successfully
4. none above

30. Choose the best option that replaces the blanks for select statement.

DECLARE
    esal number(6,2);
BEGIN
    SELECT empsal INTO esal FROM Employee WHERE empid = 101;
    DBMS_OUTPUT.PUT_LINE('Salary is' || esal);
EXCEPTION
    WHEN ----------------------- THEN
         DBMS_OUTPUT.PUT_LINE ('The student is not enrolled');
     WHEN ----------------------- THEN
         DBMS_OUTPUT.PUT_LINE ('The student is enrolled in too many courses');
END;  

1. TOO_MANY_ROWS
2. TOO_MANY_ROWS, NO_DATA_FOUND
3. STORAGE_ERROR
4. CASE_NOT_FOUND

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

DECLARE
   small_man_detected  EXCEPTION;
   salary number;
   PRAGMA EXCEPTION_INIT(small_man_detected, -1);
BEGIN
   select empsal into salary from Employee where empid=101;
   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. SQL error code -1 is not predefined
2. With SQL error code -1, the code compiles
3. Pragma should always be a negative number
4. 1, 2, 3

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

create or replace procedure company(id in number) 
IS 
   salary number;
BEGIN
   select empsal into salary from Employee where empid=id;
   dbms_output.put_line('Salary of ' || id || ' is ' || salary);
   raise TOO_MANY_ROWS;
EXCEPTION
   WHEN TOO_MANY_ROWS THEN
      dbms_output.put_line('Many records exist on this ID');
END;  

1. without using Pragma, the exception is raised and compilation is successful
2. without using Pragma, the exception is raised and is a compilation error
3. when many records found on the input id number, the runtime problem is handled
4. when many records found, the message 'Many records exist on this ID' is displayed

33. Choose the best option that is true.

1. A record can be visualized as a row of data. It can contain all the contents of a row.
2. In Composite type variables, the internal components of a collection must be of same data type.
3. In Composite type variables, the internal components of a record can have different data types.
4. 1, 2, 3

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

Code A:

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

Code B:

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

Code C:

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

Code D:

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

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

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

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; 
    dbms_output.put_line('Total cost is ' || total_cost);
END; 
END;   

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

36. Choose best option among all that can fill the blank to compile the code successfully.

DECLARE
    TYPE phone IS TABLE OF ------------------- INDEX BY BINARY_INTEGER;
    telephone_directory phone;
BEGIN
    telephone_directory(01) := 123456789;
    DBMS_output.put_line(telephone_directory.COUNT);
END;  

1. PLS_INTEGER, BINARY_INTEGER, INTEGER, NUMBER
2. BINARY_INTEGER
3. INTEGER, NUMBER
4. none above

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;
BEGIN
    SELECT empid, empname, empsal INTO ----------------------------------- FROM Employee WHERE empid = p_empid;
    DBMS_OUTPUT.PUT_LINE(rec_emp.empid);
    DBMS_OUTPUT.PUT_LINE(rec_emp.empname);
    DBMS_OUTPUT.PUT_LINE(rec_emp.empsal);
END;  

1. Employee.empid, Employee.empname, Employee.empsal
2. p_empid.empid, p_empid.empname, p_empid.empsal
3. rec_emp.empid, rec_emp.empname, rec_emp.empsal
4. empid, empname, empsal

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

1. With a cursor FOR loop, the body of the loop is executed for each row returned by the query.
2. SQL does not support dynamic queries with EXECUTE IMMEDIATE.
3. A cursor variable does not point to a cursor or a result set.
4. Cursor variables cannot be used with dynamic SQL.

39. What will be the SQL cursor attribute that signifies the existence of records that fits in the blank?

DECLARE   
BEGIN  
   DELETE FROM Employee WHERE empsal < 1000;
   IF ---------------------- THEN  
        dbms_output.put_line('Records exist which satisfies the delete command');
   END IF;   
END;  

1. sql%exist
2. sql%found
3. sql%true
4. sql%false

40. What could be the blank to compile the following trigger. Choose the best option that is true.

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

1. insert or update or delete
2. insert or update
3. update or delete
4. none above

SOLUTIONS

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

Leave a Comment

Your email address will not be published.