Set 10 – Java, Oracle, Unix Interview Questions


1. What is the return type of remove(Object) method of Collection interface? Choose the right option.

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

2. What is the output of the following snippet of code? Choose the right option.

List numbers1 = new ArrayList();
numbers1.add(2);     
numbers1.add(1);
numbers1.set(1, 2);
System.out.println(numbers1);  

1. [1, 2]
2. [1, 1]
3. [2, 2]
4. [2, 1]

3. What is the output of the following snippet of code? Choose the right option.

Thread t1 = new Thread(“JVM”);
System.out.println(t1.getThreadGroup());

1. JVM
2. main
3. garbage
4. does not compile as it is getGroup() and not getThreadGroup().

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

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

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

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

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

1. prints Hello
2. compiles but at runtime says InterruptedException not handled
3. start() is not a method of Thread class
4. does not compile as start() is not defined

6. What is/are the fact(s) with the unchecked exceptions of exception handling?

1. subclasses of RuntimeException are called as unchecked exceptions
2. unchecked exceptions need not be handed to compile and run the code
3. unchecked exceptions are treated as most frequently occurring general exceptions
4. all the above

7. What is the output of the following code? Choose the right option.

abstract class Hello
{
   public abstract void open() throws FileNotFoundException;
}
public class Test extends Hello
{
   public void open() throws IOException
   {
      new FileInputStream("abc.txt");
   }
   public static void main(String args[]) throws Exception
   {		
       Test t1 = new Test();
       t1.open();
       System.out.println("Sir");
    }
}  

1. File abc.txt is opened and prints Sir
2. File abc.txt is not opened and prints Sir
3. compiler says FileNotFoundException is not reported
4. does not compile

8. Choose the right option that is true.

     public void show() 
     {
          // some code here
          throw new NumberFormatException(new Exception("Unable to check formatting"));
     }  

1. In chaining, a subclass exception can be chained to a super class exception
2. A checked exception can only be chained to unchecked exception
3. no problem with the code
4. does not compile

9. nextInt(), nextDouble() and nextBoolean() are the methods of class ——————————.
Choose the right option to fill the blank.

1. DataOutputStream
2. BufferedOutputStream
3. BufferedWriter
4. Scanner

10. Which one of the following class InputStream methods does not throw IOException.
Choose the right option.

1. available()
2. reset()
3. skip(long)
4. mark(int)

11. Which opening mode will throw IllegalArgumentException?
Choose the right option.

1. RandomAccessFile raf = new RandomAccessFile(“abc.txt”, “rws”);
2. RandomAccessFile raf = new RandomAccessFile(“abc.txt”, “rwd”);
3. RandomAccessFile raf = new RandomAccessFile(“abc.txt”, “rwa”);
4. RandomAccessFile raf = new RandomAccessFile(“abc.txt”, “rw”);

12. Choose the best practices for developing JDBC code?

1. Use java.sql.PreparedStatement for repeated DML commands
2. Use cache of database connections from a connection pool
3. Use column names for accessing ResultSet instead of column index numbers to avoid invalid column index message
4. all above

13. Which interface is used to know the metadata of a database table?

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

14. What is the exception raised by the following forName() method? Choose the right option that is true.

Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);

1. ClassNotFoundException
2. SQLException
3. IllegalArgumentException
4. IllegalParameterException

15. Choose the right option about the methods of ResultSet that will not throw any exceptions?
(where res is an object of ResultSet)

1. res.absolute(-5);
2. res.relative(-5);
3 res.absolute(5);.
4. all above

16. Which HTML form method is more efficient and used often to call servlets executed in a Servlet container? Choose the right option.

1. method=”get”
2. method=”post”
3. method=”service()”
4. method=”init()”

17. Observe the code and choose the right option that is true?

import javax.servlet.*;
import java.io.*;
public class Test extends GenericServlet implements SingleThreadModel
{
   public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
   {		
      PrintWriter out = res.getWriter();
      out.println("Sir");
    }
}   

1. The code compiles successfully without any deprecation warning
2. The code compiles successfully but with deprecation warning
3. Code does not compile
4. The message Sir will not go to client as MIME type is not set and out is not closed

18. Observe the code and choose right option.

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Test extends HttpServlet
{
   public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
   {		
      PrintWriter out = res.getWriter();
      out.println("Sir");
      out.close();
    }
}   

1. Code compiles and executes successfully.
2. does not compile as ServletRequest and ServletResponse are passed as parameters instead of HttpServletRequest and HttpServletResponse.
3. compiles with exceptions
4. none of above

19. Which is not the right Cookie method?

1. getSecure()
2. getPath()
3. setPath()
4. setAge()

20. Choose the right option that is true regarding URL Encoding.

1. URLs support only ASCII character set.
2. Any unsafe character outside the ASCII is to be converted to ASCII
3. 1 and 2
4. none above

21. Observe the code and choose the right option that is true.

// all necessary imports here
public class Demo extends HttpServlet
{
   public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,  IOException
   {
        doPost(req,res);
   }
   public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, 
IOException
   {
        // HTTP Session management logic
        // create HttpSession object etc
   }
}  

1. does not compile
2. compiles but throws exception
3. no problem in the code, successfully compiles and executes
4. none above

22. To which interface, the implicit object “application” belongs? Choose the right option.

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

23. Which is not part of function JSTL tags? Choose the right option.

1. fn.excapeXML()
2. fn.lowerCase()
3. fn.upperCase()
4. 2 and 3

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

<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. Memory management, task scheduling and file management etc. are done by —————-.
Choose the right option to fill up the blank.

1. shell
2. kernel
3. hardware
4. application libraries

26. Command Interpreter is part of ——————-. Choose the right option to fill up the blank.

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

27. How to give permissions to created directories? Which command is used?
Choose the right option.

1. mkdir -m
2. mkdir -v
3. mkdir -p
4. none above

28. What is the copy command in Unix? Choose the right option.

1. copy
2. copycon
3. cp
4. none above

29. Choose the right option for the code when tried to fetch a record on a given id.

CREATE OR REPLACE PROCEDURE getName(eid IN NUMBER)
IS
   ename varchar(15);
begin
   select empname into ename from Employee where empid=eid;
   DBMS_OUTPUT.PUT_LINE(ename); 
EXCEPTION 
   WHEN TOO_MANY_ROWS OR NO_DATA_FOUND THEN 
         dbms_output.put_line('Problem'); 
    WHEN NO_DATA_FOUND THEN 
         dbms_output.put_line(' Problem'); 
end;  

1. does not compile as NO_DATA_FOUND is handled in two places.
2. compiles as the second NO_DATA_FOUND is ignored
3. TOO_MANY_ROWS and NO_DATA_FOUND are not predefined
4. none of above

30. Choose the best option that is true about the following code.

CREATE OR REPLACE PROCEDURE raise_demo AS
   menu_item INTEGER := 24;
BEGIN
   IF menu_item NOT IN (10, 20, 30) THEN
      RAISE INVALID_NUMBER;  
   END IF;
EXCEPTION
   WHEN INVALID_NUMBER THEN
      dbms_output.put_line('Menu not available'); 
END;  

1. code is with no errors and compiles successfully
2. if menu_item is not available, message ‘Menu not available’ is thrown
3. 1 and 2
4. code is erroneous and does not compile

31. In the following code, Pragma exception is declared in outer block but raised in inner block. Choose the best option that is true.

DECLARE
   small_man_exception  EXCEPTION;
   salary number;
   PRAGMA EXCEPTION_INIT(small_man_exception, -1);
BEGIN
   select empsal into salary from Employee where empid=100;
   dbms_output.put_line(salary);
   BEGIN
       if salary < 25000 then
           raise small_man_exception;
       end if;
       EXCEPTION
          WHEN small_man_exception THEN
              dbms_output.put_line('You are small man');
   END;
END;  

1. code does not compile
2. code compiles
3. Pragma error code -1 does not raise an error
4. 2 and 3

32. What could be blank for the Pragma to compile successfully? Choose the right option.

DECLARE
  age_exception  EXCEPTION;
  visitor_age  NUMBER := 9;
  ---------------------------------------------------   	-- blank
BEGIN
  IF visitor_age < 10 THEN
       RAISE age_exception;
  END IF;   
  DBMS_OUTPUT.PUT_LINE('Enjoy water games');
  EXCEPTION 
    WHEN age_exception THEN
        DBMS_OUTPUT.PUT_LINE('Not permitted for water games. Go for other');   
END;  

1. PRAGMA EXCEPTION_INIT(age_exception, SQL_ERRM);
2. PRAGMA EXCEPTION_INIT(-1000);
3. PRAGMA EXCEPTION_INIT(age_exception, -1000);
4. PRAGMA EXCEPTION_INIT(age_exception, SQL_CODE);

33. Choose the right option that is true.

1. In Composite type variables, nested tables cannot have non-consecutive subscripts.
2. In Composite type variables, records are data types which Oracle allows to be defined as a placeholder.
3. Index by Table, Nested Table are the two types of collection and there is no third one.
4. In Composite type variables, each key of an associative array need not be unique.

34. Choose the right option that compiles successfully in Oracle.

DECLARE  
   num1  POSITIVE := 10;	-- Line 1
   num2  POSITIVEN;		-- Line 2
   num3  SIGNTYPE := 10;	-- Line 3
   num4  NATURAL := 10;	-- LIne 4
BEGIN  
   dbms_output.put_line('today');
END;  

1. Line 1 and Line 4
2. Line 2
3. Line 3
4. none of above

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

DECLARE
    marks number(3) := 95;
BEGIN
CASE marks
   WHEN 90 THEN 
         dbms_output.put_line('Excellent');
   ELSE 
         dbms_output.put_line('Improve');
END CASE;
END;  

1. code does not compile
2. code compiles and output will be Improve
3. code compiles and output will be Excellent
4. none above

36. What is the output for the following associative array code. Choose the right option that is true.

DECLARE
   TYPE marks IS TABLE OF NUMBER INDEX BY VARCHAR2(20);
   student  marks;
BEGIN
  student('rao')  := 55;
  student('yadav')  := 65;
  student('reddy')  := 75;
  dbms_output.put_line(student(student.NEXT(student.FIRST)));
END;  

1. 55
2. 65
3. 75
4. none above

37. Choose the right option to fill the blank, in the following Collection record, that compiles successfully.

DECLARE
  TYPE ----------- IS RECORD(ename Employee.empname%TYPE, esal  Employee.empsal%TYPE);
  record2  record1;
BEGIN
  SELECT empname, empsal INTO record2 FROM Employee WHERE empid = 101;
  DBMS_OUTPUT.PUT_LINE(record2.ename || ',' || record2.esal);
END;  

1. record1
2. record2
3. Employee
4. Employee_Record

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

1. Closing the cursor does not mean releasing the allocated memory.
2. Fetch means accessing multiple records at a time.
3. Opening the cursor allocates the memory for the cursor and makes it ready for fetching the rows returned by the SQL statement into it.
4. A cursor is always works in local procedure only.

39. Choose the right option that is true for the following cursor code.

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; 
      EXIT WHEN persons%notfound; 
      dbms_output.put_line(person_name || ' - ' || person_address); 
   END LOOP; 
   CLOSE persons; 
END;   

1. code compiles but no output is displayed
2. code compiles and output is displayed
3. code does not compile
4. none above

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

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

1. before
2. after
3. before or after
4. none above

SOLUTIONS

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

Leave a Comment

Your email address will not be published.