0% found this document useful (0 votes)
2 views

oracle++practice+questions+part1+

Uploaded by

mirrpython
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

oracle++practice+questions+part1+

Uploaded by

mirrpython
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Oracle question answers part1

01. Which one of these concepts provides access restriction to


public methods only?
a) Platform independence
b) Object orientation
c) Encapsulation
d) Inheritance

Answer: c

02. This is not applied “implicitly” to all interface variables.


a) final
b) abstract
c) static
d) public

Answer: b

03. Which three are advantages of the Java exception mechanism?


a) Provides standard exceptions bunch that covers all possible errors
b) Allows the creation of new exceptions that are customizable to
the particular program
c) Improves the program structure because exceptions must be
handled in the method in which they occur
d) Improves the program structure because the programmer can
choose where to handle exceptions
e) Improves the program structure because the error handling code
is separated from the normal program function

Answer: b, d, e

04. Select A valid JavaBean method signature


a) public void getArrow()
b) public void setBow()
c) public void setRange(int range)
d) public String addTarget(String target)

Answer: c

05. "You have a list orders of PurchaseOrder objects, each with a


date, a Customer and a state. You want filter list in various ways"
Which of the following in built functional interface you are going to
use for above?
a) UnaryOperator<T>
b) Consumer<T>
c) Supplier<T>
d) Predicate<T>

Answer : D

06. What is the value of Number “no” after this code will be
executed?
long no = 5 >= 5 ? 1+2 : 1*1;
if(++no < 4)
no += 1;
a) 3
b) 4
c) 5
d) The answer cannot be determined until runtime.

Answer: b

07. Valid way of compiling java source file named "Animal"?


a) javac Animal.java
b) java Animal.class
c) java Animal.java
d) javac Animal
e) java Animal

Answer: a

08. Which of the following statement exactly explains


encapsulation?
a) Encapsulation ensures that classes can be designed so that if a
method has an argument of Type x, any subclass of Type can be
passed to that method.

b) Encapsulation ensures that classes can be designed so that only


certain fields and methods of an object are accessible from other
objects.

c) Encapsulation ensures that classes can be designed so that their


methods are inheritable.

d) Encapsulation ensures that classes can be designed with some


fields and methods declared as abstract.

Answer: b

09. You are writing a method that is returning nothing. Then what
is allowed from following?
a) omission of the return statement
b) return null;
c) return void;
d) return;

Answer: a, d
10.
If a try statement has catch blocks for both Exception and
IOException, then which of the following statements is correct?
a) The catch block for Exception must appear before the catch block
for IOException.
b) The catch block for IOException must appear before the catch
block for Exception.
c) The catch blocks for these two exception types can be declared in
any order.
d) A try statement cannot be declared with these two catch block
types because they are incompatible.

Answer: b

11.Given the code fragment:


public class CheckString {
public static void main(String[] args) {
String mystr=null;
switch(mystr) {
case "":
System.out.println("blank"); break;
case "null":
System.out.println("NULL"); break;
default:
System.out.println("invalid"); break;
What is the result?

 A. Compilation fails
 B. Blank
 C. NULL
 D. An exception is thrown at runtime
 E. Invalid
Answer : D

Explanation: A java.lang.NullPointerException will be thrown at


runtime at line: switch(str) {
Ensure that the expression in any switch statement is not null to
prevent a
NullPointerException from being thrown.

12.Given the code fragment:


try {
String query = "SELECT * FROM Student WHERE ID=120";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query); // Line 13
System.out.println("Student ID: " + rs.getInt("ID")); // Line 14
} catch (Exception se) {
System.out.println("Error");
Assume that the SQL query matches one record. What is the result of
compiling and executing this code?

 A. The code prints error.


 B. The code prints the Student ID.
 C. Compilation fails due to an error at line 13.
 D. Compilation fails due to an error at line 14.

Answer : B

Explanation: Assuming that the connection conn has been set up


fine, the code will compile and run fine.
Note #1: The GetInt method retrieves the value of the designated
column in the current row of this ResultSet object as an int in the
Java programming language.
Note 2: A table of data representing a database result set, which is
usually generated by executing a statement that queries the
database.
A ResultSet object maintains a cursor pointing to its current row of
data. Initially the cursor is positioned before the first row. The next
method moves the cursor to the next row, and because it returns
false when there are no more rows in the ResultSet object, it can be
used in a while loop to iterate through the result set.
A default ResultSet object is not updatable and has a cursor that
moves forward only.
Thus, you can iterate through it only once and only from the first row
to the last row. It is possible to produce ResultSet objects that are
scrollable and/or updatable.

13.Which two descriptions are benefits of using PreparedStatement


objects over static SQL in JDBC?

 A. Conversion to native SQL


 B. Supports BLOB types on every type of database
 C. Prevention of SQL injection attacks
 D. Improved performance from frequently run SQL queries
 E. Built in support for multi database transaction semantics

Answer : A,D

Explanation: Sometimes it is more convenient to use a


PreparedStatement object for sending SQL statements to the
database.

This special type of statement is derived from the more general class,
Statement, that you already know.

If you want to execute a Statement object many times, it usually


reduces execution time to use a PreparedStatement object instead.
The main feature of a PreparedStatement object is that, unlike a
Statement object, it is given a SQL statement when it is created. The
advantage to this is that in most cases, this
SQL statement is sent to the DBMS right away, where it is compiled.
As a result, the PreparedStatement object contains not just a SQL
statement, but a SQL statement that has been precompiled. This
means that when the PreparedStatement is executed, the
DBMS can just run the PreparedStatement SQL statement without
having to compile it first.
Although PreparedStatement objects can be used for SQL statements
with no parameters, you probably use them most often for SQL
statements that take parameters. The advantage of using SQL
statements that take parameters is that you can use the same
statement and supply it with different values each time you execute
it.
Reference: The Java Tutorials, Using Prepared Statements

14.Which is a key aspect of composition?

 A. Using inheritance
 B. Method delegation
 C. Creating abstract classes
 D. Implementing the composite interface

Answer : B
Explanation: In an object-oriented design of a Java program,
the way in which you model objects that contain other objects
is with composition, the act of composing a class out of
references to other objects. With composition, references to
the constituent objects become fields of the containing object.
To use composition in Java, you use instance variables of one
object to hold references to other objects.
The relationship modeled by composition is often referred to as
the "has-a" relationship.
Delegation involves re-exporting methods; in a composition
relationship, the inner objects methods may be used only
privately and not re-exposed.

Reference : ITExams.com

15.Given the code fragment:


/* method declaration */ {
try {
String className = "java.lang.String";
String fieldname = "somefield";
Class c = Class.forName(className);
Field f = c.getField(fieldname);
} catch(Exception e) {
e.printStackTrace();
throw e;
Which two method declarations are valid options to replace /*
method declaration */?

 A. public void getMetadata ()


 B. public void getMetadat ()
 C. public void getMetadata () throws Exception
 D. public void getMetadata () throws NoSuchFieldException
 E. public void getMetadata () throws classNotFoundException
 F. public void getMetadata () throws ClassNotFoundException,
NoSuchFieldException.

Answer : C,F
Explanation: We must specify that the getMetaData method
can throw both
ClassNotFoundException (line Class c =
Class.forName(className);) and a
NoSuchFieldException (line Field f = c.getField(fieldname);).
We can do this by either declare that all exception can be
thrown or that these two specific exceptions can be thrown
Note: Valid Java programming language code must honor the
Catch or Specify
Requirement. This means that code that might throw certain
exceptions must be enclosed by either of the following:
* A try statement that catches the exception. The try must
provide a handler for the exception.
* A method that specifies that it can throw the exception. The
method must provide a throws clause that lists the exception.
Code that fails to honor the Catch or Specify Requirement will
not compile.
Reference: The Java Tutorials, The Catch or Specify
Requirement

You might also like