1. The method that writes a string of DataOutputStream is
1. writeLine(String)
2. write(String)
3. writeString(String)
4. writeBytes(String)
2. What about the following snippet of code? Choose the right one that is true.
Hashtable ht = new Hashtable();
ht.put("marks", 40);
ht.put("marks", 50);
System.out.println(ht.get("marks"));
1. prints 40
2. prints 50
3. Compilation error
4. Throws exception
3. What is the output of the following snippet of code?
Thread t1 = new Thread(“10”);
System.out.println(t1.getPriority());
1. 0
2. 5
3. 10
4. 20
4. Observe the following code and choose the right option.
abstract class Test implements Runnable
{
public void start() { System.out.println("Demo"); }
}
public class Demo extends Test
{
public void run() { System.out.println("Hello"); }
public static void main(String args[])
{
Demo d1 = new Demo();
d1.start();
}
}
1. prints Demo
2. prints Demo and Hello
3. throws exception
4. does not compile
5. Observe the following code and choose the right option.
public class Demo extends Thread
{
int count;
public void run() { count--; }
public void start() { count++; }
public static void main(String args[]) throws InterruptedException
{
Demo d1 = new Demo();
d1.start();
Thread.sleep(1000);
System.out.println(d1.count);
}
}
1. prints 0
2. prints -1
3. prints 1
4. does not compile
6. Fill up the blank with more appropriate right option?
—————- method belongs to Throwable class.
1. getMessage()
2. printStackTrace()
3. getStackTrace()
4. all the above
7. What is the output of the following code? Choose the right option.
public class Bank
{
public static void main(String args[])
{
int x[] = { 10, 20, 30 };
try
{
System.out.println(x[3]);
}
catch(RuntimeException e) { System.out.println("Hello 1"); }
catch(ArrayIndexOutOfBoundsException e) { System.out.println("Hello 2"); }
}
1. Hello 1
2. Hello 2
3. Can’t say, depends on JVM
4. does not compile
8. Observe the code and choose the appropriate right option.
import java.io.*;
interface Hello
{
public abstract void openAndRead() throws IOException;
}
public class Demo implements Hello
{
public void openAndRead() throws Exception
{
System.out.println("Okay");
}
public static void main (String [] args)
{
new Demo().openAndRead();
}
}
1. program compiles, executes and prints Okay
2. does not compile as subclass overridden method throws Exception and not IOException
3. code contains many errors
4. compiles but does not execute
9. What is/are subclass(es) of IOException? Choose the best option.
1. InterruptedIOException
2. CharConversionException
3. 1 and 2
4. none of above
10. Which byte stream can “unread” a byte? Choose the right option.
1. LineNumberInputStream
2. PushbackInputStream
3. BufferedInputStream
4. FilterInputStream
11. To give a new line between hello and world, fill up the blank?
DataOutputStream dos = new DataOutputStream(
new FileOutputStream("def.txt")); // opening file
dos.writeBytes("hello");
dos.writeBytes(-----------------------); // blank here
dos.writeBytes("world");
1. System.getProperty(“line.separator”)
2. System.get(“line.separator”)
3. System.property(“line.separator”)
4. System.getProperty(“line.separator()”)
12. Choose the best practice for JDBC coding?
1. Close Statement and PreparedStatement objects
2. Select the right JDBC driver for the application needs
3. 1 and 2
4. none of above
13. Choose the best 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 above
14. Observe the code of a typical JDBC transaction and choose the right 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
15. 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.getData();
16. What is a Servlet container? Choose the best 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
17. 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
18. 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
19. Observe the following code and choose the right option?
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
20. Observe the following snippet of code and choose the right option.
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
3. does not compile as it should be getSession(true)
4. Compiles, runs and sends session id to client
21. 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
22. Which is not part of core JSTL tags?
1. <c:redirect>
2. <c:set>
3. <c:remove>
4. <c:enumerate>
23. 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
2. compiles but throws exceptions
3. compiles, executes and response goes to client
4. none of above
24. Which one of the following options is true?
1. <%
2. String str1 = request.getParameter(“nameField”);
3. out.println(“Your name is ” + str1);
4. <!– the name is sent to client –>
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
25. Choose the right option to fill the blank.
In multitasking —————————————————.
1. OS becomes slow if tasks are many as tasks share their own system storage slots and swapping takes more time
2. OS becomes faster as swapping of control takes small time
3. is cooperative
4. is multiprogramming
26. Choose the best option for the following statement to fill up the blank.
Preemptive multitasking means ———————————————-.
1. adapting time slices for each task
2. multithreading
3. taking control of the operating system from one task and giving it to another task
4. batch processing
27. Which command is used to change the directory to root directory in Unix. Choose the best option.
1. cd
2. cd ..
3. cd ~
4. cd /
28. What rmdir does? Choose the best option.
1. removes the directory even if it contains files
2. removes the directory even if it contains subdirectories
3. removes the directory even if it contains files and subdirectories
4. removes when the directory is empty only
29. Choose the right option for the blanks when tried to fetch a record on a given eid.
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('With ' || eid || ' Problem');
WHEN ----------------------- THEN
dbms_output.put_line('With ' || eid || ' Problem');
end;
1. VALUE_ERROR and PROGRAM_ERROR
2. TOO_MANY_ROWS and NO_DATA_FOUND
3. PROGRAM_ERROR and STORAGE_ERROR
4. none above
30. Choose the right option that can substitute the blank to compile successfully and print the exception message.
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 ------------------------------- THEN -- blank here
dbms_output.put_line('Menu not available');
END;
1. INVALID_NUMBER
2. NOT_FOUND_ERROR
3. NOT_FOUND
4. none above
31. Choose the right option that is true for the following code.
DECLARE
small_man_exception EXCEPTION;
big_man_exception EXCEPTION;
salary number;
PRAGMA EXCEPTION_INIT(small_man_exception, -1);
PRAGMA EXCEPTION_INIT(big_man_exception, -1);
BEGIN
select empsal into salary from Employee where empid=101;
dbms_output.put_line(salary);
if salary < 1000 then
raise small_man_exception;
end if;
EXCEPTION
WHEN small_man_exception THEN
dbms_output.put_line('You are small man.');
END;
1. compiles but throws exception at runtime
2. giving the same exception error code of -1 to two different user-defined exceptions is a compilation error.
3. giving the same exception error code of -1 to two different user-defined exceptions is not an error and the code compiles.
4. none of above
32. Choose the best 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;
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;
1. two user-defined exceptions are declared without Pragma and is not an error
2. exception block is handling two exceptions and is not an error
3. 1 and 2
4. handling two exceptions in a single exception block raises compilation error
33. Choose the right option that is true.
1. In Composite type variables, nested tables might have gaps in subscripts and the built-in function NEXT do not allow to iterate over subscripts.
2. Records are composite data types and is a combination of same scalar data types.
3. Use %ROWTYPE when the number and data types of the underlying database columns is unknown.
4. In Composite type variables, Associative array is not a set of key-value pairs.
34. Which lines of the code compile successfully, Choose the best right option among all.
DECLARE
name1 char(10) := 'rao'; -- Line 1
name2 varchar2(10) := 'rao'; -- Line 2
name3 nchar(10) := 'rao'; -- Line 3
name4 long; -- Line 4
name5 long raw; -- Line 5
BEGIN
dbms_output.put_line('hello');
END;
1. Line 1, Line 2, Line 3, Line 4, Line 5
2. Line 1 and Line 2
3. Line 3, Line 4 and Line 5
4. none above
35. 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;
1. code does not compile
2. code compiles and gives output is Excellent
3. code compiles and gives output is Improve
4. none above
36. Choose the right option for the blank in the following collection code to compile successfully.
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(-----------------); -- blank here
END;
Fill up the blank of how to get total number of elements of this associative array.
1. student.LENGTH()
2. student.LENGTH
3. student.SIZE
4. student.COUNT
37. Choose the right option to fill the blank to compile the Collection record successfully.
DECLARE
TYPE record1 IS RECORD(ename Employee.empname%TYPE, esal Employee.empsal%TYPE);
record2 record1;
BEGIN
SELECT empname, empsal INTO record2 FROM Employee WHERE empid = 101;
--------------------------------------------------------------------------------- -- balnk here
END;
1. DBMS_OUTPUT.PUT_LINE(record2.ename || ',' || record2.esal);
2. DBMS_OUTPUT.PUT_LINE(record1.ename || ',' || record1.esal);
3. DBMS_OUTPUT.PUT_LINE(ename || ',' || esal);
4. DBMS_OUTPUT.PUT_LINE(empname || ',' || empsal);
38. Choose the right option that is true regarding SQL cursors.
1. Explicit cursor does not have any advantages over implicit cursor.
2. A cursor is a permanent work area created in the system memory when a SQL statement is executed.
3. A cursor is basically a set of rows that we can access all at a time.
4. Whenever we execute a DML statement, the Oracle server creates an implicit cursor.
39. Choose the right option that is true for the output of the following Cursor code.
BEGIN
UPDATE Employee SET empsal = empsal + 100;
IF sql%isopen THEN
dbms_output.put_line('Cursor opened');
ELSE
dbms_output.put_line('Cursor closed');
END IF;
END;
1. Cursor opened
2. Cursor closed
3. Code does not compile
4. Code compiles but no output
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
----------------------------- -- blank here
BEGIN
SELECT empsal INTO esal FROM Employee WHERE empid = id;
dbms_output.put_line(esal);
RETURN(esal);
END;
1. IS empsal NUMBER(6,2);
2. IS esal NUMBER(6,2);
3. IS Employee NUMBER(6,2);
4. IS id NUMBER(6,2);
SOLUTIONS
1. 4 | 2. 2 | 3. 2 | 4. 1 | 5. 3 |
6. 4 | 7. 4 | 8. 2 | 9. 3 | 10. 2 |
11. 1 | 12. 3 | 13. 4 | 14. 4 | 15. 3 |
16. 4 | 17. 3 | 18. 2 | 19. 2 | 20. 4 |
21. 1 | 22. 4 | 23. 1 | 24. 4 | 25. 1 |
26. 3 | 27. 4 | 28. 4 | 29. 2 | 30. 1 |
31. 3 | 32. 3 | 33. 3 | 34. 1 | 35. 1 |
36. 4 | 37. 1 | 38. 4 | 39. 2 | 40. 2 |