Set 8 – Java, Oracle, Unix Interview Questions

1. null key is not accepted by which data structure?

1. HashMap
2. Hashtable
3. List
4. Set

2. What is the output of the following snippet of code?

List myList = new ArrayList();
List yourList = new ArrayList();

myList.add(10);    
myList.add(20);
yourList.add(30);  
yourList.add(40);

myList.addAll(yourList);
System.out.println(yourList);

1. [10, 20 ]
2. [30, 40 ]
3. [10, 20, 30, 40 ]
4. [30, 40, 10, 20 ]

3. What is the output of the following snippet of code in running state?

Thread t1 = new Thread("hello");
t1.setName("world");
System.out.println(t1.getName());

1. hello
2. world
3. Thread-0
4. Thread-1

4. Choose the right option that is true regarding the following code?

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

1. The code compiles, executes and prints Hello
2. constructor cannot be used for “this” reference
3. start() cannot be called from constructor
4. compiles but executes with exceptions

5. 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();
      d1.start();
   }
}   

1. prints 0 and 1
2. prints 1 and 2
3. throws exception
4. does not compile

6. Which are not the methods of Thread class. Choose the best option.

1. wait()
2. notify()
3. notifyAll()
4. all above

7. Identify the correct option with the following snippet of code?

class Bank extends NumberFormatException { }

1. creates an unchecked custom-defined exception
2. creates a checked custom-defined exception
3. not the way of creating a custom-defined exception
4. cannot extend a predefined exception

8. With try-with-resources, the stream is automatically closed when try block exits. Even then, if the stream is closed in catch block what happens? Choose the right option.

try(FileInputStream fis = new FileInputStream("abc.txt"))
{
   System.out.println(fis.available());
}
catch(IOException  e)  
{   
   fis.close();
}  

1. code does not compile as it is not necessary to close the stream
2. code does not compile as closed stream is again closed
3. code does not compile due to fis scope problem
4. no problem with the code which compiles and runs successfully

9. Which one of the following IO classes opens the file both in read and write modes without throwing IO exception?

1. InputStreamReader
2. OutputStreamWriter
3. RandomAccessFile
4. 1 and 2

10. Choose the right option for the following statement.

BufferedReader br = new BufferedReader(Reader r1, int len1);

What could be the second parameter len1 indicates in the above statement?

1. buffer size
2. number of characters to read
3. number of bytes to read
4. number of characters to skip to read

11. What could NOT be the blank to compile the following snippet of code successfully?

 FileOutputStream fos = new FileOutputStream("def.txt");   // opening file
------------ x = 65;
fos.write(x);
fos.close();                                                             // closing file

1. byte
2. short
3. int
4. long

12. Which one of the following Connection interface methods will undo the changes made on database?
1. public abstract void cancel() throws java.sql.SQLException;
2. public abstract void rollback() throws java.sql.SQLException;
3. public abstract void undo() throws java.sql.SQLException;
4. public abstract void invalidate() throws java.sql.SQLException;

13. Which method supports to return the streams of both ASCII and Unicode characters introduced with JDBC 2.0 version?

1. getUnicodeStream()
2. getStream()
3. getByteStream()
4. getCharacterStream()

14. Which ResultSet attribute do not reflect the changes made through Java in the underlying database when it is open without throwing exceptions like SQLException or BatchUpdateException etc?

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

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

1. Minimize the size of result sets retrieved from database
2. Avoid database meta data methods to the maximum
3. 1 and 2
4. none of the above

16. Calling doPost() from doGet() and calling doGet() from doPost() makes the code ————-. Choose the right option.

1. to throw exceptions
2. not to compile
3. to terminate the servlet execution by the container
4. deadlock

17. Which object is used to send account holders photo to client by a servlet?

PrintWriter out = response.getWriter();
ServletOutputStream sos = response.getOutputStream();

(where response is an object of ServletResponse interface)

1. out
2. sos
3. anyone above
4. none above

18. Observe the following html and servlet code snippets and choose the right answer that is true.

a) HTML file:

<form method=”get”>
<input type=”hidden” name=”t1″ value=”Hello”>
<input type=”hidden” name=”t2″ value=”Sir”>
</form>

b) Servlet file service() method:

public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
 {		
      String str1 = req.getParameter("t1");
      String str2 = req.getParameter("t2");
 } 

1. does not compile as HTML hidden fields cannot be read with getParameter() method as HTTP 1.1 and HTTPS prevents.
2. compiles but throws exception
3. hidden tags do not exist in html
4. compiles and executes successfully

19. Which one is a right Cookie constructor?

1. Cookie(String itemName, String itemQuantity)
2. Cookie(String itemName, int itemQuantity)
3. Cookie(String itemName, double itemQuantity)
4. Cookie(String itemName, float itemQuantity)

20. RequestDispatcher’s include() method is capable to include the content of the following resources. Choose the right option.

1. HTML file and JSP page
2. Servlet
3. Servlet, JavaBean, HTML file
4. 1 and 2

21. What is the meaning of the following URL? Choose the right encoding option.

http://www.herohonda.com/new%20catalogue.htm

1. Client wants “new catalogue htm” file from servlet
2. Client wants “new_catalogue htm” file from servlet
3. Client wants “new/catalogue htm” file from servlet
4. none of above

22. Which is not part of sql JSTL tags?

1. sql:query
2. sql:param
3. sql:dateParam
4. sql:transactionParam

23. Which one of the following options follows JSP expression syntax. Choose the right option.

1. Today of <%= java.util.Date() %> interest is <%= p*t*r/100 %>
2. <H3> <U> No of visits: </U> </H3> <%= ++counter %>
3. Perimeter of circle with radius <%= radius %> is <%= Math.ceil(2*Math.PI*radius) %>
4. 1, 2 and 3

24. Which one of the following options is true to execute the code successfully?

<%!
         Calendar cal;
         public void jspInit()				// Line 1
          {
	  // instantiate cal
          }
          public void _jspService(request, response) 	// Line 2
          {
	  // use cal
          }
          public void jspDestroy()				// Line 3
          {
              // close cal
          }
%>

1. The JSP code translates successfully
2. error exists in Line 1
3. error exists in Line 2
4. error exists in Line 3

25. Time sharing is ————————-. Choose the right option for the blank.

1. batch processing
2. multithreading
3. cooperative
4. multitasking

26. Which OS supports parallel processing? Choose the right option that is true.

1. multiprogramming
2. multithreading
3. cooperative
4. multitasking

27. On a home directory ———————. Choose the right option that is true for the blank.

1. a user have complete control
2. a user cannot have control at all
3. control for user is optional
4. none above

28. Which command is used to display all the files of a directory including hidden files.

1. ls
2. ls -b
3. ls -a
4. none above

29. Choose the appropriate option for the blank in the Oracle procedure.

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 ---------------------- THEN 
         dbms_output.put_line(eid || ' Record does not exist'); 
end;  

1. CASE_NOT_FOUND
2. ACCESS_INTO_NULL
3. VALUE_ERROR
4. NO_DATA_FOUND

30. Choose the right option that fits exactly in the blank that prints the exception message.

DECLARE
   emp_name number;    
BEGIN
   SELECT empname into emp_name from Employee where empname='Prasad'; 
   dbms_output.put_line('The employee name is ' || emp_name); 
EXCEPTION 
   WHEN ---------------------  THEN                    -- blank here
       dbms_output.put_line('empname is varchar. Replace emp_name number to varchar2(15)'); 
END; 

1. PROGRAM_ERROR
2. NO_DATA_FOUND
3. VALUE_ERROR
4. none above

31. In the following code, VALUE_ERROR is predefined and its corresponding error code is not predefined and given user-defined. Choose the right option that is true for the following code.

DECLARE
   VALUE_ERROR  EXCEPTION;
   salary number;
   PRAGMA EXCEPTION_INIT(VALUE_ERROR, -1);
BEGIN
   select empsal into salary from Employee where empid=101;
   dbms_output.put_line(salary);
   if salary > 1000 then
       raise VALUE_ERROR;
   end if;
   EXCEPTION
   WHEN VALUE_ERROR THEN
      dbms_output.put_line('You are big man.');
END;

1. code does not compile
2. code compiles successfully
3. with Pragma, predefined exceptions cannot be used
4. with Pragma, user-defined exceptions cannot be used

32. In the following code, exception is raised in outer block and handled in inner block. Choose the right option that is true.

DECLARE
   low_stock  EXCEPTION;
   high_stock  EXCEPTION;
   stock_status number(3);
BEGIN
   stock_status := 99;
       IF stock_status < 100 THEN
           RAISE low_stock;
       ELSIF stock_status > 100 THEN
           RAISE high_stock;
       END IF;
   BEGIN
       EXCEPTION
           WHEN low_stock THEN
                DBMS_OUTPUT.PUT_LINE('Less stock. Buy more');
            WHEN high_stock THEN
                DBMS_OUTPUT.PUT_LINE('Excess stock. Dont maintain like this');
   END;
END;  

1. the code does not compile as scope problem exists
2. the code compiles successfully
3. no scope problem exists
4. none above

33. Choose the right option that is true.

1. Each scalar data type in the record holds a value.
2. Do not use %ROWTYPE when retrieving a row with the SELECT * from statement.
3. In Composite type variables, we cannot access each field of a record variable by its name.
4. Use ROWTYPE only when you are using few columns of the table.

34. Which lines of the code compile successfully, Choose the best option among all,

DECLARE  
   a char(10) := '222';		--  Line 1
   b long(4) := 'abcd';		--  Line 2
   c nchar(10) := 'klmn';		--  Line 3
   d rowid := 'pqrs';		--  Line 4
BEGIN  
   dbms_output.put_line('hello');
END; 

1. Line 1, Line 2, Line 3, Line 4
2. Line 1, Line 2
3. Line 3, Line 4
4. none above

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

DECLARE
    marks number(3);
BEGIN
   IF marks >= 90 THEN 
         dbms_output.put_line('Excellent');
   ELSE 
         dbms_output.put_line('Improve');
END;  

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

36. Choose the right option that is true.

DECLARE
    TYPE phone IS TABLE OF VARCHAR2(50) INDEX BY VARCHAR2(50);
    telephone_directory phone;
BEGIN
    telephone_directory('home') := '+91 123456789';
    DBMS_output.put_line(telephone_directory.FIRST);
END;

What is the output of the above associative array code?

1. home
2. +91 123456789
3. 1
4. home = ‘+91 123456789’

37. Choose the WRONG option to fill the blank that does NOT compile the Collection record.

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

    --------------------------------------------------------------------------------   -- blank here

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

1. SELECT AVG(empsal) INTO e_avgsal FROM Employee;
2. SELECT AVG(rec_emp.empsal) INTO e_avgsal FROM Employee;
3. SELECT AVG(p_empid.empsal) INTO e_avgsal FROM Employee;
4. SELECT AVG(p_empid) INTO e_avgsal FROM Employee;

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

1. sql%notfound returns true when records are returned by the DML statement.
2. Implicit cursors must be created when we are executing a SELECT statement that returns more than one row.
3. When the cursor is declared in a declaration section (and not in a package), Oracle Database will also automatically close it when the block in which it is declared terminates.
4. Cursor stores multiple records and capable to process all at a time.

39. What will be the SQL cursor attribute that signifies non-existence of records that fits in the blank? Choose the right option.

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

1. sql%false
2. sql%notfound
3. sql%nil
4. sql%absent

40. Choose the right option that is true for the following trigger.

CREATE or REPLACE TRIGGER my_trigger
    AFTER DELETE ON Employee
    FOR EACH ROW
BEGIN
    dbms_output.put_line('Record deleted');
END;  

1. code contains errors
2. code does not contain errors but throws exceptions
3. code does not contain errors and executes successfully
4. none above

SOLUTIONS

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

Leave a Comment

Your email address will not be published. Required fields are marked *