Anda di halaman 1dari 7

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

Answer
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 java.io 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 java.io package is intended for a different purpose.

How Files and Streams Work: Java uses streams to handle I/O operations through which the data is flowed from one location to another. For example, 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. When we work with a text file, we use a character stream where one character is treated as per byte on disk. When we work with a binary file, we use a binary stream. The working process of the I/O streams can be shown in the given diagram.

2. 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.applet.*; import java.awt.*; public class ChangeColor extends Applet { Button switch = new Button ("click"); boolean light = true; public void init () { add (switch); } public void paint (Graphics g) { if (light) setBackground (Color.lightGray); else setBackground (Color.darkGray); } public boolean action (Event e, Object o) { if (e.target == switch) { light = !light; repaint(); return true; } return false; } }

3. What are the uses of ODBC, JDBC and Driver Manager? Answer
ODBC: In computing, ODBC (Open Database Connectivity) is a standard C programming language interface for accessing database management systems (DBMS). The designers of ODBC aimed to make it independent of database systems and operating systems. An application can use ODBC to query data from a DBMS, regardless of the operating system or DBMS it uses.ODBC accomplishes DBMS independence by using an ODBC driver as a translation layer between the application and the DBMS. The application uses ODBC functions through an ODBC driver manager with which it is linked, and the driver passes the query to the DBMS. JDBC: Is a Java-based data access technology (Java Standard Edition platform) from Sun Microsystems, Inc.. It is an acronym as it is unofficially referred to as Java Database Connectivity, with DB being universally recognized as the abbreviation for database. This technology is an API for the Java programming language that defines how a client may access a database. It provides methods for querying and updating data in a database. JDBC is oriented towards relational databases. A JDBC-to-ODBC bridge enables connections to any ODBC-accessible data source in the JVM host environment. JDBC allows multiple implementations to exist and be used by the same application. The API provides a mechanism for dynamically loading the correct Java packages and registering them with the JDBC Driver Manager. The Driver Manager is used as a connection factory for creating JDBC connections. JDBC connections support creating and executing statements. These may be update statements such as SQL's CREATE, INSERT, UPDATE and DELETE, or they may be query statements such as SELECT. Additionally, stored procedures may be invoked through a JDBC connection. JDBC represents statements using one of the following classes:

Statement the statement is sent to the database server each and every time. 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. CallableStatement used for executing stored procedures on the database.

Update statements such as INSERT, UPDATE and DELETE return an update count that indicates how many rows were affected in the database. These statements do not return any other information. Query statements return a JDBC row result set. The row result set is used to walk over the result set. Individual columns in a row are retrieved either by name or by column number. There may be any number of rows in the result set. The row result set has metadata that describes the names of the columns and their types. DRIVER MANAGER: The Driver Manager (DM) is the software that loads a particular driver based on the connection information. An application is actually linked to the DM. When the application calls the ODBC function to connect to the DBMS, the DM parses the connection string and loads the appropriate driver. The JDBC DriverManager class defines objects which can connect Java applications to a JDBC driver. DriverManager has traditionally been the backbone of the JDBC architecture. It is quite small and simple. This is a very important class. Its main purpose is to provide a means of managing the different types of JDBC database driver. On running an application, it is the DriverManager's responsibility to load all the drivers found in the system property jdbc. drivers. For example, this is where the driver for the Oracle database may be defined. This is not to say that a new driver cannot be explicitly stated in a program at runtime which is not included in jdbc.drivers. 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 API defines the Java interfaces and classes that programmers use to connect to databases and send queries. A JDBC driver implements these interfaces and classes for a particular DBMS vendor. A Java program that uses the JDBC API loads the specified driver for a particular DBMS before it actually connects to a database. The JDBC DriverManager class then sends all JDBC API calls to the loaded driver. JDBC Driver

This topic defines the Java(TM) Database Connectivity (JDBC) driver types. Driver types are used to categorize the technology used to connect to the database. A JDBC driver vendor uses these types to describe how their product operates. Some JDBC driver types are better suited for some applications than others. Types of JDBC drivers This topic defines the Java(TM) Database Connectivity (JDBC) driver types. Driver types are used to categorize the technology used to connect to the database. A JDBC driver vendor uses these types to describe how their product operates. Some JDBC driver types are better suited for some applications than others. There are four types of JDBC drivers known as:

JDBC-ODBC Bridge plus ODBC driver, also called Type 1. Native-API, partly Java driver, also called Type 2. JDBC-Net, pure Java driver, also called Type 3. Native-protocol, pure Java driver, also called Type 4.

4. Write short notes on (i) RMI and (ii) CORBA. Answer


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

5. Write an essay on history of web application. Answer


In earlier computing models, e.g. in client-server, the load for the application was shared between code on the server and code installed on each client locally. In other words, 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. 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, adding to the support cost and decreasing productivity. In contrast, web applications use web documents written in a standard format such as HTML and JavaScript, which are supported by a variety of web browsers. 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, using standard procedures such as HTTP. Client web software update may happen each time the web page is visited. During the session, the web browser interprets and displays the pages, and acts as the universal client for any web application. In the early days of the Web each individual web page was delivered to the client as a static document, but the sequence of pages could provide an interactive experience, as user input is returned through web form elements embedded in the page mark-up. 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. So instead of sending data to the server in order to generate an entire web page, the embedded scripts of the downloaded page can perform various tasks such as input validation or showing/hiding parts of the page. In 1996, Macromedia introduced Flash, a vector animation player that could be added to browsers as a plugin to embed animations on the web pages. It allowed the use of a scripting language to program interactions on the client side with no need to communicate with the server. In 1999, the "web application" concept was introduced in the Java language in the Servlet Specification version 2.2.At that time both JavaScript and XML had already been developed, 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. In 2005, the term Ajax was coined, and applications like Gmail started to make their client sides more and more interactive. A web page script is able to contact the server for storing/retrieving data without downloading an entire web page. In 2011, HTML5 was created, which provides graphic and multimedia capabilities without the need of client side plugins. HTML5 also enriched the semantic content of documents. The APIs and document object model (DOM) are no longer afterthoughts, but are fundamental parts of the HTML5 specification. WebGL API paved the way for advanced 3D graphics based on HTML5 canvas and JavaScript language. These have significant importance in creating truly platform and browser independent rich web applications.

Anda mungkin juga menyukai