You are on page 1of 5

Ques 1. What are the uses of random access file over sequential access file?

Ans: 1 Random Access Files


The term random access means that data can be read from or written to random locations within a file.In all the above mentioned streams, data is read and written as a continuous stream of information.Java provides the RandomAccessFile class to perform I/O operations a t specified locations within a file.The RandomAccessFile class implements the DataInput and DataOutput interfaces for performing I/O using the primitive data types. The RandomAccessFile class also supports permissions like read and write, and allows files to be accessed in read-only and read-write Creating a Random Access File There are two ways to create a random access file- using the pathname as a string or using an object of the File class. RandomAccessFile (String pathname, String mode); RandomAccessFile (File name, String mode); Example randomFile = new RandomAccessFile (iotets.txt,rw); or File file1 = new File (iotest.txt); RandomAccessFile randomFile = new RandomAccessFile (file1, rw); The second argument is the mode argument that determines whether you have read-only or read/write (rw) access to the file.The RandomAccessFile class has several methods that allow random access to the content within the file. Creating a Random Access File The second argument is the mode argument that determines whether you have read-only or read/write (rw) access to the file. The RandomAccessFile class has several methods that allow random access to the content within the file Method Explanation void seek (long Sets the file pointer to a particular location inside pos ) the file. long Return the current location of the file pointer. getFilePointer () long length () Returns the length of the file, in bytes.

Ques2 What do you mean by the term CORBA? Ans CORBA


CORBA stands for Common Object Request Broker Architecture. CORBA is a distributed computing technology where the participating objects need not only be written in Java. What is Java IDL? Java IDL is a technology for distributed objects-that is, objects interacting on different platforms across a network.

Java IDL is similar to RMI (Remote Method Invocation), which supports distributed objects written entirely in the Java programming language. However. Java IDL enables objects to interact regardless of whether theyre written in the Java programming language or another language such as C, C++, COBOL, or others. Java IDL is based on the Common Object Request Brokerage Architecture (CORBA), an industry-standard distributed object model. A key feature of CORBA is IDL, a language-neutral Interface Definition Language. Each language that supports CORBA has its own IDL mapping and as its name implies, Java IDL supports the mapping for Java. CORBA and the IDL mappings are the work of an industry consortium known as the OMG, or Object Management Group. To support interaction between objects in separate programs, Java IDL provides an Object Request Broker, or ORB. The ORB is a class library that enables low-level communication between Java IDL applications and other CORBA-compliant applications

Ques3 Explain the different methods used in Input Stream class and Output Stream class? Ans3 Stream Classes
The FileInputStream and FileOutputStream Classes These streams are classified as mode streams as they read and write data from disk files. The classes associated with these streams have constructors that allows you to specify the path of the file to which they are connected.The FileInputStream class allows you to read input from a file in the form of a stream.The FileOutputStream class allows you to write output to a file stream. Example FileInputStream inputfile = new FileInputStream (Employee.dat); FileOutputStream outputfile = new FileOutputStream (binus.dat); The BufferedInputStream and BufferedOutputStream Classes The BufferedInputStream class creates and maintains a buffer for an input stream. This class is used to increase the efficiency of input operations. This is done by reading data from the stream one byte at a time. The BufferedOutputStream class creates and maintains a buffer for the output stream. Both the classes represents filter streams. The DataInputStream and DataOutputStream Classes The DataInputStream and DataOutputStream classes are filter streams that allow the reading and writing of Java primitive data types. The DataInputStream class provides the capability to read primitive data types from an input stream. It implements the methods presents in the Data Input interface. Methods of the DataInputStream class
Method Explanation boolean readBoolean Reads one byte and returns true if that byte is nonzero, false if it is () zero. byte readByte () Reads a byte as an 8-bit signed value. char readChar () int readInt () Reads a Unicode character. Reads an integer value.

The DataInputStream class provides methods that are complementary to the methods of DataInputStream classes. It keeps track of the number of bytes written to the output stream. Methods of the DataOutputStream Class
Method void writeChar (int v ) void writeLong (long v) void writeInt (int v ) Explanation Writes a character to the output stream. Writes a long integer to the output stream. Writes an integer to the output stream.

The ByteArrayInputStream and ByteArrayOutputStream Classes These classes allow you to read and write to an array of bytes.
Method ByteArrayInputStream (byte [] b) int size () Explanation Creates an input stream of the array of byes Returns the total number of bytes written to the stream.

Ques4 Explain the procedure for connecting to the database? Ans ODBC is an abbreviation of Open Database Connectivity, a standard database
access method developed by Microsoft Corporation.The goal of ODBC is to make it possible to access any data from any application, regardless of which database management system (DBMS) is handling the data.ODBC manages this by inserting a middle layer, called a driver, between an application and the DBMS. The purpose of this layer is to translate the queries of the application into commands that the DBMS understands JDBC JDBC provides a database-programming interface for Java programs. Since the ODBC is written in C language, a Java program cannot directly communicate with an ODBC driver.JavaSoft created the JDBC-ODBC Bridge driver that translates the JDBC API to the ODBC API. It is used with ODBC drivers. JDBC Driver Manager The JDBC driver manager is the backbone of the JDBC architecture.The function of the JDBC driver manager is to connect a Java application to the appropriate driver. JDBC-ODBC Bridge The JDBC-ODBC Bridge allows you to use the ODBC driver as JDBC drivers

JDBC Application Architecture

Connection to a Database The java.sql package contains classes that help in connecting to a database, sending SQL statements to the database, and processing query results. The Connection Objects The Connection object represents a connection with a database Loading the JDBC-ODBC Bridge and Establishing Connection To establish a connection with a database,you need to register the ODBC-JDBC Driver by calling the forName () method from the Class class and then calling the getConnection () method from the DriverManager class. The getConnection () method of the DrverManager class attempts to locate the driver that can connect to the database represented by the JDBC URL passed to the getConnection () method. The JDBC URL The JDBC URL is a string that provides a way of identifying a database. A JDBC URL is divided into three parts: <protocol>:<subprotocol>:<subname> <protocol> in a JDBC URL is always jdbc. <subprotocol> is the name of the database connectivity mechanism. If the mechanism of retrieving the data is ODBC-JDBC Bridge, the subprotocol must be odbc. <subname> is used to identify the database

Ques5 What are the different components of an event. Ans 5 Event Handling
Event-handling is essential to GUI programming. The program waits for a user to perform some action. The user controls the sequence of operations that the application executes through a GUI. This approach is called event-driven programming .

Components of an Event An event comprises of three components: Event Object Event Source Event-handler Event Classes The Event Object class is at the top of the event class hierarchy. It belongs to the java.util package. Most other event classes are present in the java.awt.event package.The hierarchy of the event classes is show below. The java.util.EventObject and the

java.awt.AWTEvent classes do not belong to the java.awt.event package. The hierarchy of the JDK 1.2 event classes is given below

The get Source () method of the Event Object class returns the object that initiated the event. The get ID () method returns the event ID that represents the nature of the event. Event Listener An object delegates the task of handling an event to an event listener. When an event occurs, an event object of the appropriate type (as given above) is created. This object is passed to the listener. A listener must implement the interface that has the method for event-handling

You might also like