Feeds:
Posts
Comments

Archive for the ‘J2EE’ Category

The two-tier application programming model was developed to enhance the file server application programming model. As compared with the file server application programming model, the two-tier application programming model provides you with improved usability, scalability, and flexibility of applications.

In Two-Tier model, you will have two seperate layers namely Client & Server.

can-support-only-a-few-users.JPG

The applications developed using the two-tier application
programming model have a user-friendly interface.
These applications can support only a few users and
allow data to be shared within a homogeneous environment.


Example of the Model

two-tier-application-model-example.JPG
The various tiers in a two-tier architecture are separated from each other by physical boundaries.
These physical boundaries can be machine boundaries, process boundaries, or corporate boundaries.

(more…)

Read Full Post »

   1. What is the servlet?

      Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet may be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.

   2. What’s the difference between servlets and applets?

      Servlets are to servers; applets are to browsers. Unlike applets, however, servlets have no graphical user interface.

   3. What’s the advantages using servlets than using CGI?

      Servlets provide a way to generate dynamic documents that is both easier to write and faster to run. It is efficient, convenient, powerful, portable, secure and inexpensive. Servlets also address the problem of doing server-side programming with platform-specific APIs: they are developed with Java Servlet API, a standard Java extension.

   4. What are the uses of Servlets?

      A servlet can handle multiple requests concurrently, and can synchronize requests. This allows servlets to support systems such as on-line conferencing. Servlets can forward requests to other servers and servlets. Thus servlets can be used to balance load among several servers that mirror the same content, and to partition a single logical service over several servers, according to task type or organizational boundaries.

   5. What’s the Servlet Interface?

      The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or, more commonly, by extending a class that implements it such as HttpServlet. Servlets–>Generic Servlet–>HttpServlet–>MyServlet. The Servlet interface declares, but does not implement, methods that manage the servlet and its communications with clients. Servlet writers provide some or all of these methods when developing a servlet.

   6. When a servlet accepts a call from a client, it receives two objects. What are they?

      ServeltRequest: which encapsulates the communication from the client to the server.
      ServletResponse: which encapsulates the communication from the servlet back to the client.
      ServletRequest and ServletResponse are interfaces defined by the javax.servlet package.

Read Full Post »

JSP

   1. What is JSP technology?

      Java Server Page is a standard Java extension that is defined on top of the servlet Extensions. The goal of JSP is the simplified creation and management of dynamic Web pages. JSPs are secure, platform-independent, and best of all, make use of Java as a server-side scripting language.

   2. What is JSP page?

      A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format such as HTML, SVG, WML, and XML, and JSP elements, which construct dynamic content.

   3. What are the implicit objects?

      Implicit objects are created by the web container and contain information related to a particular request, page, or application. They are request, response, pageContext, session, application, out, config, page and exception.

   4. How many JSP scripting elements and what are they?

      There are three scripting language elements: declarations, scriptlets, and expressions.

   5. Why are JSP pages the preferred API for creating a web-based client program?

      Because no plug-ins or security policy files are needed on the client systems(applet does). Also, JSP pages enable cleaner and more module application design because they provide a way to separate applications programming from web page design. This means personnel involved in web page design do not need to understand Java programming language syntax to do their jobs.

   6. Is JSP technology extensible?

      YES. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.

Read Full Post »

JDBC

   1. What is JDBC?

      JDBC is a layer of abstraction that allows users to choose between databases. It allows you to change to a different database engine and to write to a single API. JDBC allows you to write database applications in Java without having to concern yourself with the underlying details of a particular database.

   2. What are the two major components of JDBC?

      One implementation interface for database manufacturers, the other implementation interface for application and applet writers.

   3. What is JDBC Driver interface?

      The JDBC Driver interface provides vendor-specific implementations of the abstract classes provided by the JDBC API. Each vendors driver must provide implementations of the java.sql.Connection,Statement,PreparedStatement, CallableStatement, ResultSet and Driver.

   4. What are the common tasks of JDBC?

1.Create an instance of a JDBC driver or load JDBC drivers through jdbc.drivers;
2. Register a driver;
3. Specify a database;
4. Open a database connection;
5. Submit a query;
6. Receive results.

   5. What packages are used by JDBC?

      There are 8 packages: java.sql.Driver, Connection,Statement, PreparedStatement, CallableStatement, ResultSet, ResultSetMetaData, DatabaseMetaData.

   6. What are the flow statements of JDBC?

      A URL string –>getConnection–>DriverManager–>Driver–>Connection–>Statement–>executeQuery–>ResultSet.

   7. What are the steps involved in establishing a connection?

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

   8. 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:

E.g.
Class.forName(“jdbc.DriverXYZ”);

   9. 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.

  10. 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:

E.g.
String url = “jdbc:odbc:Fred”;
Connection con = DriverManager.getConnection(url, “Fernanda”, “J8″);

  11. 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. E.g. 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();

  12. How can you retrieve data from the ResultSet?

      First 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.

E.g.
ResultSet rs = stmt.executeQuery(“SELECT COF_NAME, PRICE FROM COFFEES”);

Second:
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

  13. What are the different types of Statements?

1.Statement (use createStatement method)
2. Prepared Statement (Use prepareStatement method) and
3. Callable Statement (Use prepareCall)

  14. How can you use PreparedStatement?

      This special type of statement is derived from the more general class, Statement. If you want to execute a Statement object many times, it will normally reduce execution time to use a PreparedStatement object instead. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement ‘s SQL statement without having to compile it first.

E.g.
PreparedStatement updateSales = con.prepareStatement(“UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?”);

  15. How to call a Stored Procedure from JDBC?

      The first step is to create a CallableStatement object. As with Statement an and PreparedStatement objects, this is done with an open Connection object. A CallableStatement object contains a call to a stored procedure;

E.g.
CallableStatement cs = con.prepareCall(“{call SHOW_SUPPLIERS}”);
ResultSet rs = cs.executeQuery();

  16. How to Retrieve Warnings?

      SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object

E.g.
SQLWarning warning = stmt.getWarnings();
    if (warning != null) {

        while (warning != null) {
          System.out.println(“Message: ” + warning.getMessage());
          System.out.println(“SQLState: ” + warning.getSQLState());
          System.out.print(“Vendor error code: “);
          System.out.println(warning.getErrorCode());
          warning = warning.getNextWarning();
        }
    }

  17. How to Make Updates to Updatable Result Sets?

      Another new feature in the JDBC 2.0 API is the ability to update rows in a result set using methods in the Java programming language rather than having to send an SQL command. But before you can take advantage of this capability, you need to create a ResultSet object that is updatable. In order to do this, you supply the ResultSet constant CONCUR_UPDATABLE to the createStatement method.

E.g.
Connection con = DriverManager.getConnection(“jdbc:mySubprotocol:mySubName”);
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet uprs = (“SELECT COF_NAME, PRICE FROM COFFEES”);

Read Full Post »

Prerequisites:
Knowledge about Struts Validator Plugin & Message Resources.

Problem:

Most of the project tend to group the resources into more than one resource bundles.
And specify all the message resources with ‘key’ attribute in <message-resources> tag.

<message-resources key=”en” parameter=”resources”/>
<message-resources parameter=”ValidationErrors” null=”false” key=”err”/>

In ValidationErrors.properties I have the following messages,

errors.required={0} is required.
errors.missing.Name=Name

If I intend to use Validator with ‘required’ type for ‘Name’, and use <html:errors bundle=”err” />
I get the following message displayed in screen..

???en_US.errors.missing.Name??? is required.

The reason being “errors.required” is extracted correctly from bundle ‘err’ as it is specified in <html:errors/> tag.
Whereas the argument of the message ‘errors.missing.Name’ is taken from the default bundle of struts, and
sicne Validator cannot find the key…it returns the above message.

Solution:

Configure your <field> tag validation.xml like the following…

<field property=”activeApplicationId” depends=”required“>
       <msg name=”required” bundle=”err” key=”errors.required”/>
        <arg0 key=”missing.applicationId” bundle=”err”/>
</field>

Specify bundle in <msg> tag with name = “validation type”
and key = “your message resources key for that validation type”

I know that this actually sucks, but this is the only workaround for the problem.

Read Full Post »

Follow

Get every new post delivered to your Inbox.

Join 174 other followers