Monday, June 20, 2011

Procdure Call using Java(JSP)

Database Procedure Call using Java. It requires 6 basic steps:

Step 1:Define the call to the database procedure.
As with a prepared statement, you use special syntax to define a call to a stored procedure. The procedure definition uses escape syntax, where the appropriate ? defines input and output parameters.

• Procedure with no parameters. ---- { call procedure_name }
• Procedure with input parameters.-- { call procedure_name(?, ?, ...) }
• Procedure with an output parameter.---- { ? call procedure_name }
• Procedure with input and output parameters.{ ? = call procedure_name(?, ?, ...) }




Step 2: Prepare a CallableStatement for the procedure.
You obtain a CallableStatement from a Connection by calling prepareCall.

String procedure = "{ ? = call procedure_name( ?, ? ) }";
CallableStatement statement =
connection.prepareCall(procedure);



Step 3: Register the output parameter types.
Before executing the procedure, you must declare the type of each output parameter.

statement.registerOutParameter(n, type);

Step 4: Provide values for the input parameters.
Before executing the procedure, you must supply the input parameter values.

statement.setString(2, "name");
statement.setFloat(3, 26.0F);



Step 5: Execute the stored procedure.
To execute the database stored procedure, call execute on the CallableStatement.

statement.execute();

Step 6: Access the returned output parameters. Call the corresponding getXxx method, according to the output type.

int value = statement.getInt(1);

Friday, June 17, 2011

Naming Convention

What Is a Naming Convention?

A naming convention is a rule to follow as you decide what to name your identifiers (e.g. class, package, variable, method, etc..).

Why Use Naming Conventions?

Different Java programmers can have different styles and approaches to the way they program. By using standard Java naming conventions they make their code easier to read for themselves and for other programmers. Readability of Java code is important because it means less time is spent trying to figure out what the code does, leaving more time to fix or modify it.

To illustrate the point it's worth mentioning that most software companies will have a document that outlines the naming conventions they want their programmers to follow. A new programmer who becomes familiar with those rules will be able to understand code written by a programmer who might have left the company many years before hand.

Picking a Name for Your Identifier


When choosing a name for an identifier make sure it's meaningful. For instance, if your program deals with customer accounts then choose names that make sense to dealing with customers and their accounts (e.g., customerName, accountDetails). Don't worry about the length of the name. A longer name that sums up the identifier perfectly is preferable to a shorter name that might be quick to type but ambiguous.
A Few Words About Cases

Using the right letter case is the key to following a naming convention:


*Lowercase is where all the letters in a word are written without any capitalization (e.g., while, if, mypackage).

*Uppercase is where all the letters in a word are written in capitals. When there are more than two words in the name use underscores to separate them (e.g., MAX_HOURS, FIRST_DAY_OF_WEEK).

*CamelCase (also known as Upper CamelCase) is where each new word begins with a capital letter (e.g., CamelCase, CustomerAccount, PlayingCard).


*Mixed case (also known as Lower CamelCase) is the same as CamelCase except the first letter of the name is in lowercase (e.g., hasChildren, customerFirstName, customerLastName).

Standard Java Naming Conventions


The below list outlines the standard Java naming conventions for each identifier type:

* Packages: Names should be in lowercase. With small projects that only have a few packages it's okay to just give them simple (but meaningful!) names:

package pokeranalyzer
package mycalculator

In software companies and large projects where the packages might be imported into other classes, the names will normally be subdivided. Typically this will start with the company domain before being split into layers or features:

package com.mycompany.utilities
package org.bobscompany.application.userinterface

* Classes: Names should be in CamelCase. Try to use nouns because a class is normally representing something in the real world:

class Customer
class Account

* Interfaces: Names should be in CamelCase. They tend to have a name that describes an operation that a class can do:

interface Comparable
interface Enumerable

Note that some programmers like to distinguish interfaces by beginning the name with an "I":

interface IComparable
interface IEnumerable

* Methods: Names should be in mixed case. Use verbs to describe what the method does:

void calculateTax()
string getSurname()

* Variables: Names should be in mixed case. The names should represent what the value of the variable represents:

string firstName
int orderNumber

Only use very short names when the variables are short lived, such as in for loops:

for (int i=0; i<20;i++)
{
//i only lives in here
}

* Constants: Names should be in uppercase.

static final int DEFAULT_WIDTH
static final int MAX_HEIGHT



colleted from website

Wednesday, June 15, 2011

Servlet

Servlets are modules of Java code that run in a server application (hence the name "Servlets", similar to "Applets" on the client side) to answer client requests

Java servlets are becoming increasingly popular as an alternative to CGI(Common Gateway Interface) programs. The biggest difference between the two is that a Java applet is persistent. This means that once it is started, it stays in memory and can fulfill multiple requests. In contrast, a CGI-Common Gateway Interface program disappears once it has fulfilled a request.


It acts as a middlelayer between requests coming from Web browsers or other HTTP clients and databases or applications on the HTTP server. some features are as below

• It is regular Java code. There are new APIs, but no new syntax.

• It has unfamiliar import statements. The servlet and JSP APIs are
not part of the Java 2 Platform, Standard Edition (J2SE); they are a
separate specification (and are also part of the Java 2 Platform,
Enterprise Edition—J2EE).

• It extends a standard class (HttpServlet). Servlets provide a rich
infrastructure for dealing with HTTP.

• It overrides the doGet method. Servlets have different methods to
respond to different types of HTTP commands.

Security is also an important issue related to servlet.


Quickly bookmark the link:
A complete guide to customized j2ee trainning

Tuesday, June 14, 2011

Model View Controller (MVC) design paradigm

Model-View-Controller (MVC) design paradigm, distinctly separating all three levels:

* Model: application state
* View: presentation of data
* Controller: routing of the application flow

In another way we can depicts as

The Model represents the business or database code, the View represents the page design code, and the Controller represents the navigational code.The original MVC pattern is like a closed loop: The View talks to the Controller, which talks to the Model, which talks to the View.

Struts Framwork for Netbeans





The Struts Framework is a standard for developing well-architected Web applications. It has the following features:

* Open source
* Based on the Model-View-Controller (MVC) design paradigm, distinctly separating all three levels:
o Model: application state
o View: presentation of data (JSP, HTML)
o Controller: routing of the application flow
* Implements the JSP Model 2 Architecture
* Stores application routing information and request mapping in a single core file, struts-config.xml

The Struts Framework, itself, only fills in the View and Controller layers. The Model layer is left to the developer.



Another Workflow...Collected from sruts for netbeans





Struts Components

The Controller

This receives all incoming requests. Its primary function is the mapping of a request URI to an action class selecting the proper application module. It's provided by the framework.


The struts-config.xml File

This file contains all of the routing and configuration information for the Struts application. This XML file needs to be in the WEB-INF directory of the application.


Action Classes
It's the developer's responsibility to create these classes. They act as bridges between user-invoked URIs and business services. Actions process a request and return an ActionForward object that identifies the next component to invoke. They're part of the Controller layer, not the Model layer.


View Resources
View resources consist of Java Server Pages, HTML pages, JavaScript and Stylesheet files, Resource bundles, JavaBeans, and Struts JSP tags.


ActionForms

These greatly simplify user form validation by capturing user data from the HTTP request. They act as a "firewall" between forms (Web pages) and the application (actions). These components allow the validation of user input before proceeding to an Action. If the input is invalid, a page with an error can be displayed.


Model Components

The Struts Framework has no built-in support for the Model layer. It enables you to create maintainable, extensible, and flexible web applications based on standard technologies, such as JSP pages, JavaBeans, resource bundles, and XML.

Friday, June 10, 2011

Installation of Netbeans 7 in Ubuntu

Its really easy to install................

Step 1: Copy the Netbeans 7 for Linux(netbeans-7.0-ml-linux.sh) and JDK foo Linux(java_ee_sdk-6u1-jdk-linux.sh) into the desired location.

Step 2: Open the terminal from(Application-->Accessories--> Terminal)

Step 3: Using Command, navigate to the location of two files. Its better to keep both of the files in the Home folder of you, as its the default location. To check the availabilty of the files you can use the command

ls -l

It will shows the list of the files at that location.



Step 4: Then try to install the jdk file using the command

sh jdk-6u21-linux-i586.bin

Step 5: The to install Netbeans, at first make the file executable using the command

sudo chmod +x netbeans-*

Step 6: Then use the command, to install netbeans as

sudo ./netbeans-* --javahome jdk1.6.0_21

for me, it was
sudo ./netbeans-* --javahome jdk1.6.0_21

Step 7: The above command will provide the Netbeans installer to navigate your for the further steps to follow.



After installing, to use netbeans You can use it from Applications -> Programming -> NetBeans & from ubuntu menubar. But sometimes it may occurs problem to you(i.e this may not be appeared at the menu). Then you can use it by command prompt using the command

netbeans


to do so you need to run a simple command just for once after:

ln -s /usr/local/netbeans-6.5/bin/netbeans /usr/local/bin/netbeans

Use sudo before each command if you get the access denied message. Then giving correct password, you will be able to do so.(sudo------------> Super Do)

Then the command will be as

sudo ln -s /usr/local/netbeans-7.0/bin/netbeans /usr/local/bin/netbeans


The above command will make a shortcut at bin folder(common).
After that you will get netbeans just by typing it in the terminal. You may aslo create a shortcut launcher to this link.

Now enjoy Netbeans and Ubuntu together.

Plz let me know your experience..