Professional Documents
Culture Documents
Ans: Object oriented programming languages directly represent the real life
objects. The features of OOPL as inhreitance, polymorphism, encapsulation makes
it powerful.
Ans: Polymorhisum: is a feature of OOPl that at run time depending upon the type
of object the appropriate method is called.
Inheritance: is a feature of OOPL that represents the "is a" relationship between
different objects(classes). Say in real life a manager is a employee. So in OOPL
manger class is inherited from the employee class.
Encapsulation: is a feature of OOPL that is used to hide the information.
Ans: By using the static method there is no need creating an object of that class to
use that method. We can directly call that method on that class. For example, say
class A has static function f(), then we can call f() function as A.f(). There is no
need of creating an object of class A.
Ans: virtual methods are used to use the polymorphism feature in C++. Say class A
is inherited from class B. If we declare say function f() as virtual in class B and
override the same function in class A then at runtime appropriate method of the
class will be called depending upon the type of the object.
Q5: Given two tables Student(SID, Name, Course) and Level(SID, level) write
the SQL statement to get the name and SID of the student who are taking
course = 3 and at freshman level.
Ans: DeadLock.
Q1: Write the Java code to declare any constant (say gravitational constant)
and to get its value
Ans: Multiple inheritance is a feature in C++ by which one class can be of different
types. Say class teachingAssistant is inherited from two classes say teacher and
Student.
Q3: Can you write Java code for declaration of multiple inheritance in Java ?
The Object class is the highest-level class in the Java class hierarchy. The
Class class is used to represent the classes and interfaces that are loaded
by a Java program.
3. How is it possible for two String objects with identical values not to be equal
under the == operator?
The == operator compares two objects to determine if they are the same
object in memory. It is possible for two String objects to have the same
value, but located indifferent areas of memory.
Two methods may not have the same name and argument list but different
return types.
Overridden methods must have the same name, argument list, and return
type. The overriding method may not limit the access of the method it
overrides. The overriding method may not throw any exceptions that may
not be thrown by the overridden method.
1. What happens when a thread cannot acquire a lock on an object?
2. What is the difference between the Reader/Writer class hierarchy and the
InputStream/OutputStream class hierarchy?
A catch clause can catch any exception that may be assigned to the
Throwable type. This includes the Error and Exception types.
JDBC Questions
1. What is JDBC?
This involves two steps: (1) loading the driver and (2) making the
connection.
Loading the driver or drivers you want to use is very simple and involves
just one line of code. If, for example, you want to use the JDBC-ODBC
Bridge driver, the following code will load it:
Eg.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Your driver documentation will give you the class name to use. For instance,
if the class name is jdbc.DriverXYZ , you would load the driver with the
following line of code:
E.g.
Class.forName("jdbc.DriverXYZ");
E.g.
String url = "jdbc:odbc:Fred";
Connection con = DriverManager.getConnection(url, "Fernanda", "J8");
A Statement object is what sends your SQL statement to the DBMS. You
simply create a Statement object and then execute it, supplying the
appropriate execute method with the SQL statement you want to send. For
a SELECT statement, the method to use is executeQuery. For statements
that create or modify tables, the method to use is executeUpdate. E.g. It
takes an instance of an active connection to create a Statement object. In
the following example, we use our Connection object con to create the
Statement object stmt :
E.g.
ResultSet rs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM
COFFEES");
Second:
String s = rs.getString("COF_NAME");
The method getString is invoked on the ResultSet object rs , so getString
will retrieve (get) the value stored in the column COF_NAME in the
current row of rs
This special type of statement is derived from the more general class,
Statement. If you want to execute a Statement object many times, it will
normally reduce execution time to use a PreparedStatement object
instead. The advantage to this is that in most cases, this SQL statement
will be sent to the DBMS right away, where it will be compiled. As a result,
the PreparedStatement object contains not just an SQL statement, but an
SQL statement that has been precompiled. This means that when the
PreparedStatement is executed, the DBMS can just run the
PreparedStatement 's SQL statement without having to compile it first.
E.g.
PreparedStatement updateSales = con.prepareStatement("UPDATE
COFFEES SET SALES = ? WHERE COF_NAME LIKE ?");
E.g.
CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
ResultSet rs = cs.executeQuery();
E.g.
SQLWarning warning = stmt.getWarnings();
if (warning != null) {
Another new feature in the JDBC 2.0 API is the ability to update rows in a
result set using methods in the Java programming language rather than
having to send an SQL command. But before you can take advantage of this
capability, you need to create a ResultSet object that is updatable. In
order to do this, you supply the ResultSet constant CONCUR_UPDATABLE
to the createStatement method.
E.g.
Connection con =
DriverManager.getConnection("jdbc:mySubprotocol:mySubName");
Statement stmt =
con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet uprs = ("SELECT COF_NAME, PRICE FROM COFFEES");
Strings HANDLING
Constructing a String
If you are constructing a string with several appends, it may be more efficient to
construct it using a StringBuffer and then convert it to an immutable String
object.
// Modify
int index = 1;
buf.insert(index, "abc");
buf.append("def");
// Convert to string
String s = buf.toString();
Getting a Substring from a String
int start = 1;
int end = 4;
String substr = "aString".substring(start, end); // Str
Searching a String
// First occurrence.
int index = string.indexOf('S'); // 1
// Last occurrence.
index = string.lastIndexOf('i'); // 4
// Not found.
index = string.lastIndexOf('z'); // -1
JSP /Servlets
The central abstraction in the Servlet API is the Servlet interface. All
servlets implement this interface, either directly or, more commonly, by
extending a class that implements it such as HttpServlet.
Servlets-->Generic Servlet-->HttpServlet-->MyServlet.
The Servlet interface declares, but does not implement, methods that
manage the servlet and its communications with clients. Servlet writers
provide some or all of these methods when developing a servlet.
6. When a servlet accepts a call from a client, it receives two objects. What
are they?
9. If you want a servlet to take the same action for both GET and POST
request, what should you do?
An HTTP Servlet handles client requests through its service method. The
service method supports standard HTTP client requests by dispatching
each request to a method designed to handle that request.