Wednesday, December 6, 2006

Statements in JAVA

Statements are equivalent to sentences in natural languages. A statement forms a complete unit of execution. The following types of expressions can be made into a statement by terminating the expression with a semicolon ( :

* Assignment expressions
* Any use of ++ or --
* Method calls
* Object creation expressions

These kinds of statements are called expression statements.

In addition to these kinds of expression statements, there are two other kinds of statements. A declaration statement declares a variable. A control flow statement regulates the order in which statements get executed. The for loop and the if statement are both examples of control flow statements.

How will you pass values from HTML page to the Servlet

First we put the values to be passed inside a HTML form and then call the servlet in the form action. To catch the form fields values we simply call the getParameter method of the HttpServletRequest, supplying the parameter name as an argument. The return value is a String corresponding to the first occurrence of that parameter name. An empty String is returned if the parameter exists but has no value, and null is returned if there was no such parameter.

If the parameter could potentially have more than one value we should call getParameterValues instead of getParameter. This returns an array of strings. To get a full list of parameters we can use getParameterNames which returns an Enumeration, each entry of which can be cast to a String and used in a getParameter call.

Difference between RMI & Corba

The most significant difference between RMI and CORBA is that CORBA was made specifically for interoperability across programming languages. That is CORBA fosters the notion that programs can be built to interact in multiple languages. The server could be written in C++, the business logic in Python, and the front-end written in COBOL in theory. RMI, on the other hand is a total Java solution, the interfaces, the implementations and the clients--all are written in Java.

RMI allows dynamic loading of classes at runtime. In a multi-language CORBA environment, dynamic class loading is not possible. The important advantage to dynamic class loading is that it allows arguments to be passed in remote invocations that are subtypes of the declared types. In CORBA, all types have to be known in advance. RMI (as well as RMI/IIOP) provides support for polymorphic parameter passing, whereas strict CORBA does not. CORBA does have support for multiple languages which is good for some applications, but RMI has the advantage of being dynamic, which is good for other applications.

In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?

We can use the setTimeout method to use delay time and then the window.open method to open the new page. The script could be something like the following. We could call the doPopup() method on the click event of the button placed on our webpage.

code:


What is JDBC? How do you connect to the Database?

JDBC stands for Java Database Connectivity. Its a set of programming APIs which allow easy connection to a wide range of databases through Java programs.

To connect to the database we will need to load the database driver and then request a connection as below:

code:
Class.forName(LOCATION OF DRIVER);
Connection jdbcConnection = DriverManager.getConnection (LOCATION OF DATASOURCE)

____________________________________________________________________________________________________________________

Once ur done with it.You would have the Connection Object(
jdbcConnection )

Why Servlets

Servlets may be used at different levels on a distributed framework. The following are some examples of servlet usage:

  • To accept form input and generate HTML Web pages dynamically.
  • As part of middle tiers in enterprise networks by connecting to SQL databases via JDBC.
  • In conjunction with applets to provide a high degree of interactivity and dynamic Web content generation.
  • For collaborative applications such as online conferencing.
  • A community of servlets could act as active agents which share data with each other.
  • Servlets could be used for balancing load among servers which mirror the same content.
  • Protocol support is one of the most viable uses for servlets. For example, a file service can start with NFS and move on to as many protocols as desired; the transfer between the protocols would be made transparent by servlets. Servlets could be used for tunneling over HTTP to provide chat, newsgroup or other file server functions.
  • RMI Architecture(in brief)

    RMI uses a layered architecture, each of the layers could be enhanced or replaced without affecting the rest of the system. The details of layers can be summarised as follows:

  • Application Layer: The client and server program
  • Stub & Skeleton Layer: Intercepts method calls made by the client/redirects these calls to a remote RMI service.
  • Remote Reference Layer: Understands how to interpret and manage references made from clients to the remote service objects.
  • Transport layer: Based on TCP/IP connections between machines in a network. It provides basic connectivity, as well as some firewall penetration strategies.
  •