Set 19 – Advance Java, Oracle, Unix Interview Questions

1. Choose the best practice for JDBC coding?

1. Close Statement and PreparedStatement objects
2. Select the JDBC driver for the application needs
3. 1 and 2
4. none of above

2. rollback() method is defined —————– interface.
Choose the option to fill up the blank.

1. Connection
2. Statement
3. PreparedStatement
4. ResultSet

3. Choose the right option that is true about Statement interface methods.

1. execute() method returns boolean
2. executeQuery() method returns ResultSet object
3. executeUpdate() method returns int
4. all the above

4. Observe the code of a typical JDBC transaction and choose the option.

//  all the database Connection con = ......   stuff here
try
{
    con.setAutoCommit(false);
    		// some Statement's executeUpdate() statements here
    con.commit();
} 
catch(Exception e) 
{
    con.rollback();
} 
finally 
{
    con.close();
}  

1. does not compile as con.setAutoCommit(true) is not called at the end
2. does not compile as con.setAutoCommit(false) is not required
3. does not compile as con.commit() should be called from catch block only
4. no problem with the code and is the right way of writing a JDBC transaction

5. Read the following snippet of code and choose the right option to fill up the blank?

    public static void main(String args[]) throws Exception
     {
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection("jdbc:odbc:snrao", "scott","tiger");

        -------------------   //  create DatabaseMetaData object dbmd here
       
        System.out.println("Numeric Function:  " + dbmd.getNumericFunctions()); 
        System.out.println("String Functions: " + dbmd.getStringFunctions()); 
   }	
}

1. DatabaseMetaData dbmd = con.metaData();
2. DatabaseMetaData dbmd = con.retrieveMetaData();
3. DatabaseMetaData dbmd = con.getMetaData();
4. DatabaseMetaData dbmd = con.getDatabaseMetaData ();

6. What is a Servlet container? Choose the right option.

1. Container is a software that provides services to run servlets
2. Container calls callback methods at appropriate times
3. maintains servlet lifecycle
4. all above

7. Observe the snippet of code and choose right option.

RequestDispatcher rd = request.getRequestDispatcher(“/validate.jsp”);
rd.forward(request, response);

1. throws IllegalArgumentException as the method argument cannot be a JSP file
2. does not compile as the method should be include(request, response)
3. compiles and executes successfully without any problem
4. none of above

8. Observe the code and choose right option where in a single service() method both PrintWriter and ServletOutputStream are instantiated.

import javax.servlet.*;
import java.io.*;
public class Test extends GenericServlet
{
   public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
   {		
      PrintWriter out = res.getWriter();
      ServletOutputStream sos = res.getOutputStream();
    }
} 

1. code does not compile
2. code compiles but throws exception
3. compiles and runs successfully where Developer can use both the objects
4. none of above

9. getJspConfigDescriptor() is a method of —————- interface.

1. HttpServlet
2. ServletContext
3. ServletContext
4. JspContext

10. getClassLoader() is a method of —————- interface.

1. HttpServlet
2. ServletContext
3. ServletContext
4. JspContext

11. Observe the following code and choose the right answer?

public class Test extends HttpServlet
{
   public void Test()  {   }
   public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
   {     }
}  

1. does not compile as servlet cannot contain a constructor
2. compiles and executes successfully
3. throws exceptions
4. none of above

12. Observe the following snippet of code and choose the right answer.

public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{     
      PrintWriter out = res.getWriter();
      HttpSession session = req.getSession();
      String id = session.getId();	
      out.println("Know your session id:  " + id);
      out.close();	
}

1. does not compile as MIME type is not set
2. does not compile as getId() is a wrong method and should be getSessionId()
3. does not compile as getSession() is wrong method and it should be getSession(true)
4. Compiles, runs and sends session id to client

13. Choose the right option which is true to fill up the blank.

setAttribute(String, Object) is a method of ——————–.

1. HttpSession
2. ServletContext
3. 1 and 2
4. none of above

14. Choose the right URL encoding option for the following statement.

Jaya Ram&Hema

1. Jaya%20Ram%26Hema
2. Jaya%26Ram%20Hema
3. Jaya%40Ram%26Hema
4. Jaya%26Ram%40Hema

15. Choose the right URL encoding option for the following statement.

Roja+Ramani is RojaRomani

1. Roja%2BRamani%20is%20RojaRomani
2. Roja%46BRamani%20is%20RojaRomani
3. Roja%56BRamani%20is%20RojaRomani
4. Roja%66BRamani%20is%20RojaRomani

16. Choose the right option of URL Encoding of the following URL.

http://www.mytech.com/old%26new%25calculations.htm

1. Client wants “old&new%calculations htm” file from servlet
2. Client wants “old%new&calculations htm” file from servlet
3. Client wants “old&new$calculations htm” file from servlet
4. none of above

17. Which is not part of core JSTL tags? Choose the right option.

1. <c:redirect>
2. <c:set>
3. <c:remove>
4. <c:enumerate>

18. Observe the following snippet of code and choose the right option.

<body>
<%
out.println(“Product of 2 and 3 is”);
<%= 2*3 %>
%>
</body>

1. code does not compile as expression cannot be nested in scriptlet
2. compiles but throws exceptions
3. compiles, executes and response goes to client
4. none of above

19. What is the output of the following JSTL snippet of code?

<body>
<c:set var=”price” scope=”session” value=”${200}”/>
<c:remove var=”price”/>
<p> <c:out value=”${price}”/> </p>
</body>

1. nothing is printed
2. null
3. error
4. 200

20. Which one of the following options is true regarding the following scriptlet?

1. <%
2. String str1 = request.getParameter(“nameField”);
3. out.println(“Your name is ” + str1);
4. <!– some more business logic here –>
5. %>

1. The code snippet prints the name without any problem
2. error exists in line 2
3. error exists in line 3
4. error exists in line 4

21. Choose the best option that is true.

1. A printer is a daemon process.
2. A program with a lengthy processing time is worth of making it as as daemon proces.
3. Daemon process is a background process.
4. 1, 2, 3

22. Choose the best option that is true.

1. When ps –ef is executed, the daemon processes are indicated with ? in tty field.
2. Command ps displays the list the running processes.
3. 1, 2
4. none above

23. ‘wait’ command of Unix waits ——————————. Choose the best option.

1. the process to complete on the given pid
2. the process to complete on the given jobid
3. 1 and 2
4. none above

24. Which is NOT the option of ‘top’ Unix command.

1. -b
2. -c
3. -i
4. -p

25. Choose the best option that is true regarding the following grep Unix command.

grep ^hello /etc/passwd

1. displays all the lines that end with hello word
2. displays all the lines that start with hello word
3. does not display the lines that contains the word hello
4. none of above

26. Choose the best option that is true regarding the following cut Unix command.

echo ‘abc’ | cut -b 2

1. the command echoes b
2. the command echoes ac
3. the command echoes abc
4. none above

27. Choose the best option that is true regarding the following tr Unix command.

cat Demo.txt | tr -d “\n”

1. the command contains errors
2. cannot delete \n characters
3. deletes all \n characters in the file Demo.txt
4. none above

28. Choose the best option that is true regarding the following paste Unix command.

paste -d – -s Demo.txt

1. the hyphen (-) works as delimiter
2. the hyphen separates the two options -d and -s
3. 1 and 2
4. none of above

29. Choose the best option that is true regarding the following egrep command.

egrep -C 0 ‘\(h\|H\)ello’ Demo.txt

1. searches the complete string as it is of “(h|H)ello” in the file Demo.txt
2. searches the string as it is of “hello” in the file Demo.txt
3. searches the string as it is of “Hello” in the file Demo.txt
4. 2 and 3

30. Choose the option that is FALSE.

1. Number of elements in an associative array is unbounded
2. Associative array subscript can only be an integer
3. Associative array can be dense or sparse
4. Associative array is created in only in PL/SQL block

31. Choose the 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()

32. Choose the option for the blank that prints Jan in the following Varray code.

declare
    type month1 is varray(12) of VARCHAR2(20);
    month2 month1;
begin
     month2 := month1('Jan','Feb','Mar','Apr','May','Jun','Jul');
     dbms_output.put_line(---------------------);     --  blank here	
end;

1. month2.first
2. month2(month2.first)
3. month2(0)
4. month2(1)

33. Choose the option for the loop blank that prints all the records of Person.

DECLARE
   TYPE person_info IS RECORD
   (
      pname           Person.pname%TYPE,
      paddress        Person.paddress%TYPE
   );
   TYPE record_info IS TABLE OF person_info;
   name_address  record_info;
BEGIN
    SELECT pname, paddress BULK COLLECT INTO name_address FROM Person;
    for i in name_address.first .. name_address.last 
    ------------------------------              -- LOOP blank here
END;

1. LOOP dbms_output.put_line(name_address(i).pname || ‘ ‘ || name_address(i).paddress); END LOOP;
2. LOOP dbms_output.put_line(name_address(i)[1] || ‘ ‘ || name_address(i)[2]); END LOOP;
3. LOOP dbms_output.put_line(name_address(i).first || ‘ ‘ || name_address(i).last); END LOOP;
4. none above

34. Choose the right option that fills the blank to compile successfully to get total number of bulk exceptions raised.

declare
          type temp_arr is table of number;
          cust_arr    temp_arr;
          no_exceptions       number;
    begin
           select ccost bulk collect into cust_arr from Customers;
           ------------------------------          -- blank here
                update Customers set ccost = ccost+100 where ccost = cust_arr(i) ;
    exception
        when others then
             no_exceptions := sql%bulk_exceptions.count;
         dbms_output.put_line ('No. of exceptions occurred: ' || no_exceptions);
end; 

1. forall i in cust_arr.first .. cust_arr.last save errors
2. forall i in cust_arr.first .. cust_arr.last save bulk_exceptions
3. forall i in cust_arr.first .. cust_arr.last save all_exceptions
4. forall i in cust_arr.first .. cust_arr.last save exceptions

35. Choose the option that fits in the blank to iterate all through the records of Employee.

DECLARE
    type table_employee is table of Employee%rowtype;
    table_employee1  table_employee;
    cursor empcursor is select * from Employee;
BEGIN
    OPEN empcursor;
    LOOP 
        ------------------------------     -- blank here
 	EXIT WHEN table_employee1.count = 0;
 	BEGIN 
	     DBMS_OUTPUT.PUT_LINE('Rows affected:  ' || table_employee1.COUNT);
  	     FORALL i IN 1  ..  table_employee1.COUNT
   	          INSERT INTO Employee VALUES table_employee1(i);
                    END;
    END LOOP;
 EXCEPTION
     WHEN OTHERS THEN
           DBMS_OUTPUT.PUT_LINE('Errors in processing: ' || SQL%BULK_EXCEPTIONS.COUNT);
END;

1. FETCH empcursor BULK COLLECT INTO table_employee LIMIT 200;
2. FETCH table_employee BULK COLLECT INTO table_employee1 LIMIT 200;
3. FETCH table_employee BULK COLLECT INTO empcursor LIMIT 200;
4. FETCH empcursor BULK COLLECT INTO table_employee1 LIMIT 200;

36. Choose the right option that evaluates to FALSE from the following.

1. SQL provides removing s to the structure of database.
2. SQL allows users to create and drop databases and tables.
3. REVOKE takes back privileges granted from user.
4. SQL enhancements does not support usage of Regular Expression in Built-in SQL Functions.

37. Which one of the following options creates Employee12 table in Oracle.

1. create table Employee12(empsalary number(8,2) not null, primary key);
2. create table Employee12(empsalary (number(8,2) not null primary key));
3. create table Employee12(empsalary number(8,2)_not null_primary key);
4. create table Employee12(empsalary number(8,2) not null primary key);

38. Choose the right option for the following select statement in Oracle.

select * from Employee having empsal > 5000;

1. displays all the records with empsal more than 5000
2. does not display any records
3. does not compile
4. none above

39. Choose the right option that is true for the following roles and privileges.

create role manager;
create role developer;
grant all privileges on Employee to manager;
grant manager to developer;

1. syntax of granting permissions is wrong
2. developer gets all the privileges of manager
3. developer gets only select privileges of manager
4. none above

40. Create a display with dmart_employees first_name and dmart_departments dept_name. Choose the option to use with ‘equi join’.

1. select first_name, dept_name from dmart_employees and dmart_departments;
2. select dmart_employees.first_name, dmart_departments.dept_name from dmart_employees de, dmart_departments dd where de.dept_id=dd.dept_id;
3. select de.first_name, dd.dept_name from dmart_employees de, dmart_departments dd where dept_id=dept_id;
4. select de.first_name, dd.dept_name from dmart_employees de, dmart_departments dd where de.dept_id=dd.dept_id;

SOLUTIONS

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

Leave a Comment

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