Sunday, January 28, 2007

How can you retrieve data from the ResultSet?

Step 1.

JDBC returns results in a ResultSet object, so we need to declare an instance of the class ResultSet to hold our results. The following code demonstrates declaring the ResultSet object rs.

Eg.

ResultSet rs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");

Step2.

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.


SOURCE : www.referjava.com

How can you create JDBC statements?

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.

Eg.

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 :

Statement stmt = con.createStatement();

SOURCE : www.referjava.com

How can you make the connection?

In establishing a connection is to have the appropriate driver connect to the DBMS. The following line of code illustrates the general idea:

Eg.

String url = "jdbc:odbc:Fred";

Connection con = DriverManager.getConnection(url, "Fernanda", "J8");



SOURCE : www.referjava.com

What Class.forName will do while loading drivers?

It is used to create an instance of a driver and register it with the DriverManager.

When you have loaded a driver, it is available for making a connection with a DBMS.

SOURCE : www.referjava.com

How can you load the drivers?

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:

Eg.

Class.forName("jdbc.DriverXYZ");



SOURCE : www.referjava.com

the steps involved in establishing a connection?

This involves two steps: (1) loading the driver and (2) making the connection.


SOURCE : www.referjava.com

What are wrapper classes?

Wrapper classes are classes that allow primitive types to be accessed as objects.


SOURCE : www.referjava.com

the difference between String and StringBuffer?

String objects are constants, whereas StringBuffer objects are not.

String class supports constant strings, whereas StringBuffer class supports growable, modifiable strings.


SOURCE : www.referjava.com

uses of toLowerCase( ) and toUpperCase( ) methods?

The method toLowerCase( ) converts all the characters in a string from uppercase to

lowercase.

The method toUpperCase( ) converts all the characters in a string from lowercase to

uppercase.

SOURCE : www.referjava.com

What is Serialization and deserialization?

Serialization is the process of writing the state of an object to a byte stream.

Deserialization is the process of restoring these objects.

SOURCE : www.referjava.com

difference between the File and RandomAccessFile classes?

The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.


SOURCE : www.referjava.com

What is the purpose of the File class?

The File class is used to create objects that provide access to the files and directories of a local file system.


SOURCE : www.referjava.com

What is an I/O filter?

An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.

SOURCE : www.referjava.com

What is meant by Stream

A Stream is an abstraction that either produces or consumes information.

There are two types of Streams. They are:

Byte Streams : Byte Streams provide a convenient means for handling input and output of bytes.

Character Streams : Character Streams provide a convenient means for handling input and output of characters.

Byte Stream classes : Byte Streams are defined by using two abstract classes. They are:InputStream and OutputStream.

Character Stream classes : Character Streams are defined by using two abstract classes. They are : Reader and Writer.



SOURCE : www.referjava.com

Which class is extended by all other classes?

Object class is extended by all other classes.

SOURCE : www.referjava.com

What is the purpose of the System class?

The purpose of the System class is to provide access to system resources.

SOURCE : www.referjava.com

What is the purpose of the Runtime class?

The purpose of the Runtime class is to provide access to the Java runtime system.


SOURCE : www.referjava.com

What are the interfaces defined by java.lang?

Cloneable, Comparable and Runnable.


SOURCE : www.referjava.com

What is meant by daemon thread? In java runtime, what is it's role

Daemon thread is a low priority thread which runs intermittently in the background doing the garbage collection operation for the java runtime system.

SOURCE : www.referjava.com

What are all the methods available in the Thread class?

1.isAlive()

2.join()

3.resume()

4.suspend()

5.stop()

6.start()

7.sleep()

8.destroy().


SOURCE : www.referjava.com

What is the signature of the constructor of a thread class?

Thread(Runnable threadob,String threadName).


SOURCE : www.referjava.com

What are the two types of multitasking?

1.process-based

2.Thread-based.

SOURCE : www.referjava.com

Can we have catch block with out try block?

No. Try/Catch or Try/finally form a unit.

SOURCE : www.referjava.com

What is the ‘finally’ block?

Finally block will execute whether or not an exception is thrown. If an exception is thrown, the finally block will execute even if no catch statement match the exception. Any time a method is about to return to the caller from inside try/catch block, via an uncaught exception or an explicit return statement, the finally clause is also execute.

SOURCE : www.referjava.com

What is ‘Resource leak’?

Freeing up other resources that might have been allocated at the beginning of a method.


SOURCE : www.referjava.com

the difference between ‘Exception’ and ‘error’ in java?

Exception and Error are the subclasses of the Throwable class. Exception class is used for exceptional conditions that user program should catch. With exception class we can subclass to create our own custom exception.

Error defines exceptions that are not excepted to be caught by you program. Example is Stack Overflow.


SOURCE : www.referjava.com

the difference between ‘throw’ and ‘throws’ ?And it’s application?

Exceptions that are thrown by java runtime systems can be handled by Try and catch blocks. With throw exception we can handle the exceptions thrown by the program itself. If a method is capable of causing an exception that it does not
handle, it must specify this behavior so the callers of the method can guard
against that exception.

SOURCE : www.referjava.com