You are on page 1of 7

1. What are the uses of FileInputStream and FileOutputStream? Write short notes on each.

InputStream:The InputStreamclass is used for reading the data such as a byte and array of bytes from an input source. An input source can be a file, a string, or memory that may contain the data. It is an abstract class that defines the programming interface for all input streams that are inherited from it. An input stream is automatically opened when you create it. You cans explicitly close a stream with the close( ) method, or let it be closed implicitly when the object is found as a garbage. The subclasses inherited from the InputStreamclass can be seen in a hierarchy manner shown below:

InputStream is inherited from the Object class. Each class of the InputStreams provided by the package is intended for a different purpose.

OutputStream:The OutputStream class is a sibling to InputStream that is used for writing byte and array of bytes to an output source. Similar to input sources, an output source can be anything such as a file, a string, or memory containing the data. Like an input stream, an output stream is automatically opened when you create it. You can explicitly close an output stream with the close( ) method, or let it be closed implicitly when the object is garbage collected. The classes inherited from the OutputStreamclass can be seen in a hierarchy structure shown below:

OutputStream is also inherited from the Object class. Each class of the OutputStreams provided by the package is intended for a different purpose.

The working process of the I/O streams can be shown in the given diagram. we use a binary stream. For example. we use a character stream where one character is treated as per byte on disk.How Files and Streams Work: Java uses streams to handle I/O operations through which the data is flowed from one location to another. . When we work with a binary file. When we work with a text file. an InputStream can flow the data from a disk file to the internal memory and an OutputStreamcan flow the data from the internal memory to a disk file. The disk-file may be a text file or a binary file.

public class ChangeColor extends Applet { Button switch = new Button ("click"). } return false. repaint(). return true. boolean light = true.*.*.applet.2. } public boolean action (Event e. } } . else setBackground (Color. } public void paint (Graphics g) { if (light) setBackground (Color. public void init () { add (switch). Write an applet program to change the background colour of an applet window as soon as you click on a button? Answer Source Code: // A button which changes the background colour // of the applet window when a button is clicked import java. Object o) { if ( == switch) { light = !light. import java.lightGray).darkGray).awt.

the DM parses the connection string and loads the appropriate driver. It provides methods for querying and updating data in a database.3. There may be any number of rows in the result set. This technology is an API for the Java programming language that defines how a client may access a database. An application can use ODBC to query data from a DBMS. JDBC allows multiple implementations to exist and be used by the same application. Inc. When opening a connection to a database it is the DriverManager' s role to choose the most appropriate driver from the previously loaded drivers. The JDBC DriverManager class defines objects which can connect Java applications to a JDBC driver. or they may be query statements such as SELECT. What are the uses of ODBC. It is quite small and simple. regardless of the operating system or DBMS it uses. The designers of ODBC aimed to make it independent of database systems and operating systems. The row result set has metadata that describes the names of the columns and their types. drivers. PreparedStatement – the statement is cached and then the execution path is pre determined on the database server allowing it to be executed multiple times in an efficient manner. For example. These may be update statements such as SQL's CREATE. When the application calls the ODBC function to connect to the DBMS. On running an application. DRIVER MANAGER: The Driver Manager (DM) is the software that loads a particular driver based on the connection information. INSERT. JDBC is oriented towards relational databases. This is a very important class. and the driver passes the query to the DBMS. The Driver Manager is used as a connection factory for creating JDBC connections. These statements do not return any other information. Individual columns in a row are retrieved either by name or by column number. with DB being universally recognized as the abbreviation for database. This is not to say that a new driver cannot be explicitly stated in a program at runtime which is not included in jdbc. The application uses ODBC functions through an ODBC driver manager with which it is linked. JDBC: Is a Java-based data access technology (Java Standard Edition platform) from Sun Microsystems. it is the DriverManager's responsibility to load all the drivers found in the system property jdbc. UPDATE and DELETE..drivers. Query statements return a JDBC row result set. . Its main purpose is to provide a means of managing the different types of JDBC database driver. ODBC (Open Database Connectivity) is a standard C programming language interface for accessing database management systems (DBMS). A JDBC-to-ODBC bridge enables connections to any ODBC-accessible data source in the JVM host environment. JDBC connections support creating and executing statements. JDBC represents statements using one of the following classes:    Statement – the statement is sent to the database server each and every time. The API provides a mechanism for dynamically loading the correct Java packages and registering them with the JDBC Driver Manager. CallableStatement – used for executing stored procedures on the database. An application is actually linked to the DM. DriverManager has traditionally been the backbone of the JDBC architecture. Additionally. The row result set is used to walk over the result set.ODBC accomplishes DBMS independence by using an ODBC driver as a translation layer between the application and the DBMS. this is where the driver for the Oracle database may be defined. UPDATE and DELETE return an update count that indicates how many rows were affected in the database. It is an acronym as it is unofficially referred to as Java Database Connectivity. JDBC and Driver Manager? Answer ODBC: In computing. Update statements such as INSERT. stored procedures may be invoked through a JDBC connection.

pure Java driver. Types of JDBC drivers This topic defines the Java(TM) Database Connectivity (JDBC) driver types. also called Type 3. also called Type 4. JDBC Driver This topic defines the Java(TM) Database Connectivity (JDBC) driver types. A JDBC driver vendor uses these types to describe how their product operates. Native-API. Native-protocol. . also called Type 2. Driver types are used to categorize the technology used to connect to the database. partly Java driver. A JDBC driver vendor uses these types to describe how their product operates. pure Java driver. A Java program that uses the JDBC API loads the specified driver for a particular DBMS before it actually connects to a database. There are four types of JDBC drivers known as:     JDBC-ODBC Bridge plus ODBC driver.The JDBC API defines the Java interfaces and classes that programmers use to connect to databases and send queries. The JDBC DriverManager class then sends all JDBC API calls to the loaded driver. Some JDBC driver types are better suited for some applications than others. A JDBC driver implements these interfaces and classes for a particular DBMS vendor. also called Type 1. JDBC-Net. Some JDBC driver types are better suited for some applications than others. Driver types are used to categorize the technology used to connect to the database.

Currently a formal revised submission has been posted online. Both the methods achieve the same goal. There are also non-standard mappings for Perl. which allows objects in different hosts to send and receive messages. An object exports itself by registering itself with a Remote Registry Server. Objects executing on one host system can invoke the methods of objects on remote hosts. or remote host on a network). RMI Terminology RMI is built upon the specification of how local and remote objects interoperate. before the end of April 2012 the OMG will publish a beta 1 version of this new language mapping. The remotely invoked methods can return values to the local objects.and language-specific class base for use by the user application. The registry service maintains a database of all the named remote objects. C++. However.4. The Internet and the Web are examples of distributed systems that have been developed using the Client/Server approach. Visual Basic. Java. Generated code classes are the result of compiling the user IDL code. PL/I and Python. Write short notes on (i) RMI and (ii) CORBA. Smalltalk. Remote objects are objects that execute on all the other machines. RMI allows objects in different JVMs belonging to different hosts to send and receive message. The CORBA specification dictates there shall be an ORB through which an application would interact with other objects.0 was released in October 1991. COBOL. CORBA: CORBA enables separate pieces of software written in different languages and running on different computers to work with each other like a single application or set of services. The C++ mapping is notoriously difficult. There are different approaches used for developing distributed applications. In practice. due to the nature of Java. Some IDL mappings are more difficult to use than others. . Another way to achieve the same in using Remote Method Invocation (RMI). which translates the high-level interface definition into an OS. Version 1. the application simply initializes the ORB. Objects on remote hosts are exported so that they can be invoked remotely. The Object Adapter is used to register instances of the generated code classes. Standard mappings exist for Ada. This step is necessary in order to enforce CORBA semantics and provide a clean user process for interfacing with the CORBA infrastructure. CORBA then specifies a mapping from IDL to a specific implementation language like C++ or Java. C. CORBA uses an interface definition language (IDL) to specify the interfaces which objects present to the outer world. Answer RMI:Distributed applications are applications that execute across multiple host system. object (and reference) instantiation policies. The transfer of data is one of the most important processes in distributed applications. You have learned how to cross process boundaries to transfer the data from one host to the other using sockets. Local objects are objects that execute on the local machine. the IDL-Java mapping is rather straightforward and makes usage of CORBA very simple in a Java application. and Tcl implemented by object request brokers (ORBs) written for those languages. the method calls approach used by RMI in much easier to use. Erlang. which maintains things like reference counting. For example. At the OMG March 2012 meeting the OMG recommended the new IDL to C++11 language mapping for adoption. More specifically. and object lifetime policies. This is also true of the IDL to Python mapping. Ruby. the mapping requires the programmer to learn complex and confusing datatypes that predate the C++ Standard Template Library (STL). CORBA is a mechanism in software for normalizing the method-call semantics between application objects residing either in the same address space (application) or remote address space (same host. A Remote Registry Server is a service that runs on a server and helps the objects on other hosts to remotely access its registered objects. The default implementation of the message passing method in Java transfers data from the calling object to the called object within a single Java Virtual Machine (JVM). and accesses an internal Object Adapter. Lisp.

adding to the support cost and decreasing productivity. but Ajax had still not yet been coined and the XMLHttpRequest object had only been recently introduced on Internet Explorer 5 as an ActiveX object. It allowed the use of a scripting language to program interactions on the client side with no need to communicate with the server. but are fundamental parts of the HTML5 specification. These have significant importance in creating truly platform and browser independent rich web applications. the embedded scripts of the downloaded page can perform various tasks such as input validation or showing/hiding parts of the page. as user input is returned through web form elements embedded in the page mark-up.g. HTML5 was created. So instead of sending data to the server in order to generate an entire web page. An upgrade to the server-side code of the application would typically also require an upgrade to the client-side code installed on each user workstation. A web page script is able to contact the server for storing/retrieving data without downloading an entire web page. web applications use web documents written in a standard format such as HTML and JavaScript. In the early days of the Web each individual web page was delivered to the client as a static document. the web browser interprets and displays the pages. the "web application" concept was introduced in the Java language in the Servlet Specification version 2. In 1996. the load for the application was shared between code on the server and code installed on each client locally. and applications like Gmail started to make their client sides more and more interactive. and acts as the universal client for any web application. In 2005. which are supported by a variety of web browsers. In 2011. an application had its own client program which served as its user interface and had to be separately installed on each user's personal computer. In contrast. In 1995 Netscape introduced a client-side scripting language called JavaScript allowing programmers to add some dynamic elements to the user interface that ran on the client side.2. . e. Answer In earlier computing models. using standard procedures such as HTTP. which provides graphic and multimedia capabilities without the need of client side plugins.5. WebGL API paved the way for advanced 3D graphics based on HTML5 canvas and JavaScript language. In 1999. in client-server. Macromedia introduced Flash. Client web software update may happen each time the web page is visited.At that time both JavaScript and XML had already been developed. The APIs and document object model (DOM) are no longer afterthoughts. but the sequence of pages could provide an interactive experience. During the session. Write an essay on history of web application. the term Ajax was coined. In other words. a vector animation player that could be added to browsers as a plugin to embed animations on the web pages. HTML5 also enriched the semantic content of documents. Web applications can be considered as a specific variant of client-server software where the client software is downloaded to the client machine when visiting the relevant web page.