Tuesday, December 22, 2009

New Releases - GlassFish v3 and Java EE 6



Wednesday, December 16, 2009

What is JAX-RS (Java API for RESTful Web Services)?


(JAX-RS) - RESTful Web Services

Lightweight RESTful approaches have emerged as a popular alternative to SOAP-based technologies for deployment of services on the Internet. However, development of such services with the Java platform is significantly more complex than development of SOAP-based services, due to the low-level nature of the current platform APIs.

The goal of the Java API for RESTful Web Services (JAX-RS) is to provide a high-level declarative programming model for such services that is easy to use and encourages development according to REST tenets. Services built with this API are deployable with a variety of Web container technologies and benefit from built-in support for best-practice HTTP usage patterns and conventions.
For more details see the link below :


Overview of JSTL SQL Tags (JSTL Tags part - 3)


SQL Tags:
The tags are used to achieve common database related tasks such as selection, insertion, deletion, updation from within the jsp pages, without using any java code.

1). <sql:query>
This tag is used to query databases.
Syntax:
<sql:query sql="sqlQuery"
var="varName" [scope="{page|request|session|application}"]
[dataSource="dataSource"]
[maxRows="maxRows"]
[startRow="startRow"] />

2). <sql:update>
This tag is used to execute SQL INSERT, UPDATE or DELETE statement. It is also used to execute Data Definition Language statements.
Syntax:
<sql:update sql="sqlUpdate"
[dataSource="dataSource"]
[var="varName"]
[scope={page|request|session|application}" ] />

3). <sql:setDataSource>
This tag is used to export a data source either as a scoped variable or as the data source configuration variable.
<sql: setDataSource
{dataSource="dataSource" | url = "jdbcUrl"
[driver="driverClassName"]
[user="userName"]
[password="password"]}
[var="varName"]
[scope="{page|request|session|application}"] />

4). <sql:param>
This tag is used to set the values of parameter.
Syntax:
<sql:param value="value"/>
5). <sql:dateParam>
Sets the values of parameter markers in a SQL statement for values of type java.util.Date. It also works as a subtag of <sql:query> and <sql:update> tags.
Syntax:
<sql:dateParam value = "value" [type="{timestamp|time|date}"] />
6). <sql:transaction>
This tag is used to set a transaction context for <sql:query> and <sql:update> subtags.
Syntax:
<sql:transaction [dataSource="dataSource"]
[isolation=isolationLevel]>
<sql:query> and <sql:update> statements
</sql:transaction>

isolationLevel ::= "read_committed"
| "read_uncommitted"
| "repeated_read"
| "serializable"


Monday, December 14, 2009

Overview of JSTL Formatting Tags (JSTL Tags part - 2)


Formatting Tags

The formatting tags are used for internationalization and localization of the jsp pages. Internationalization provides support for various languages and data formats. By localization web applications becomes capable of supporting specific regions or locale.



1). <fmt:message>
This tag is used to output locale sensitive strings. The param subtag along with message provides an argument to the compound message in parent message tag. One param tag must be specified for each variable in the compound message or pattern. Replacement takes place in order of the param tags.
Syntax: <fmt:message key = "messageKey"
[bundle="resourceBundle"]
[var="varName"]
[scope="{page|request|session|application}"] />

2). <fmt:setLocale>
This tag is used to set the default locale within a specific JSP scope.
<fmt:setLocale value = "en_US" />
3). <fmt:bundle>
This tag is used to create an i18n localization context to be used by its body content.
Syntax: <fmt:bundle basename = "basename="basename"
[prefix="prefix"]>
body content
</fmt:bundle>

It creates an i18n localization context and loads its resource bundle into that context. The name of the resource bundle is specified with the basename attribute.
4). <fmt:setBundle>
This tag creates an i18n localization context and loads its resource bundle into that context. The name of the resource bundle is specified with the basename attribute.
Syntax: <fmt:setBundle basename = "basename"
[var="varname"]
[scope="{page|request|session|application}"]/>

5). <fmt:param>

This tag is used for parametric replacement to <fmt:message> tag.
Syntax: <fmt:param value="messageParameter"/>

6). <fmt:requestEncoding>

This tag is used to set the request's character encoding
Syntax: <fmt:requestEncoding [value="charsetName"]/>

7). <fmt:timeZone>

This tag is used to specify the time zone in which time information is to be formatted or parsed in its body content.
Syntax: <fmt:timeZone value="timeZone">
body content
</fmt:timeZone>

8). <fmt:setTimeZone>

This tag is used to store specified time zone in a scoped variable or the time zone configuration variable.
Syntax: <fmt:setTimeZone value="timeZone"
[var="varName"]
[scope="{page|request|session|application}"] />

9). <fmt:formatNumber>

This tag is used to format a numeric value in a locale-sensitive or customized manner as a number, currency etc.
Syntax: <fmt:formatNumber value = "numericValue"
[type="{number|currency|percent}"]
[pattern="customPattern"]
[currencyCode="currencyCode"]
[currencySymbol="currencySymbol"]
[goupingUsed="{true|false}"]
[scope="{page|request|session|application}"] />

10). <fmt:parseNumber>
This tag is used to parse the string representation of numbers, currencies, and percentages that were formatted in a locale-sensitive or customized manner.
Syntax: <fmt:parseNumber value="numericValue"
[type="{number|currency|percent}"]
[pattern="customPattern"]
[parseLocale="parseLocale"]
[integerOnly="{true|false}"]
[var="varName"]
[scope="{page|request|session|application}"]/>

11). <fmt:formatDate>
This tag is used to format date and time according to the locale.
Syntax: <fmt:formatDate value="date"
[type="{time|date|both}"]
[dateStyle="{default|short|medium|long|full}"]
[timeStyle="{default|short|medium|long|full}"]
[pattern="customPattern"]
[timeZone="timeZone"]
[var="varName"]
[scope={page|request|session|application}"] />

12). <fmt:parseDate>
Parses the string representation of dates and time that were formatted for a specific locale.
Syntax: <fmt:parseDate value = "dateString"
[type="{time|date|both}"]
[dateStyle="{default|short|medium|long|full}"]
[timeStyle="{default|short|medium|long|full}"]
[pattern="customPattern"]
[timeZone="timeZone"]
[parseLocale="parseLocale"]
[var="varName"]
[scope={page|request|session|application}"] />


Overview of JSP Initialization Parameters


Here is the procedure to specify the initialization parameters for JSP
Web.xml - is used to specify the initialization parameters.
init.jsp - is used to retrieve and show the initialized parameters



Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<servlet>
<servlet-name>InitJSP</servlet-name>
<jsp-file>/init.jsp</jsp-file>
<init-param>
<param-name>testParam</param-name>
<param-value>hello from web.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>InitJSP</servlet-name>
<url-pattern>/Init</url-pattern>
</servlet-mapping>
</web-app>

The HTML that is used to access the above parameters…


init.jsp
<html>
<head>
<title>Initialization Parameters in JSP</title>
</head>
<body>
Initialization parameter retrieved from the web.xml is:
<br>
<%= pageContext.getServletConfig().getInitParameter("testParam") %>
</body>
</html>


Sunday, December 13, 2009

How to Integrating P4 (Perforce) to IntelliJ Idea


We can reduce our development time, by integrating Perforce to IntelliJ Idea

Things that we can achieve with this are…

-We can open the file for edit form the Idea (don’t need to go to p4 client..)
-Without going to the P4 revision history, from the Idea itself we can see the changelist details and the diff reports
-We can add the new changlist, move the file between the changelists.
-more or less everything .. what we are doing with the p4 client


I have given a try.. I did not see any major/performance issues..

Here is the process..

1) Add a file “P4CONFIG.cfg” in each of the client specs by mentioning the following details..
a. P4CLIENT=<P4 client spec name>
b. P4USER=<username>
2) Set “P4CONFIG=P4CONFIG.cfg”, in the environment variables..
3) In Idea, go to settings click “Version Control”, which will open a “Version Control” configuration window..
4) In the “Default Module Version Control” tab, select Perforce and click the button “Configure”, which will open a “Version Control Configurations” window.
5) Select the option “Perforce Enabled”
6) Select the option ”Use P4CONFIG or default connection ”
7) Specify the “p4.exe” path
8) If you want select “Show branching history..” and click OK button
9) Also click OK button in the “Version Control” window
10) Close “Settings” window and restart the IntelliJ Idea.


Friday, December 11, 2009

Overview of JavaScript Performance Tuning Tool (How to use Firebug)


Most server-side programming languages have tools to do performance tuning on applications written in them. With the popularity of AJAX based applications and other rich-client HTML applications on the rise, more and more code is being written in JavaScript. So, how the heck do you go about troubleshooting performance issues for these type of client-side heavy applications written in JavaScript?

Firebug is an extension for Firefox that can be used to do the performance tuning. The way this works is,
a) install Firebug (and restart the Firefox browser)
b) enable Firebug if not currently enabled
c) load the page that needs performance tuning
d) open up Firebug and in the console, click on Profile
e) start using the UI controls in the page that have performance problem
f) Click on the profile and see a table of all the function calls ordered by the amount of time spent


This gives you an idea of the functions that are slow. The granularity of this report is only by function (thought it would have been good if there is a way to have line level granularity for some hot-spot functions to pin-point the line number). From this, it’s possible to figure out what’s going on and go about optimizing.


JavaScript Optimization Tips


Always use the "var" deceleration for local variables.
Why? It tells JavaScript that the variable is local, i.e. JavaScript won't look for the variable in the outside scope.

Always use local decelerations for lookups that you use multiple times.
Why? JavaScript code isn't optimized, so lookups wont be cached.


Wednesday, December 9, 2009

Good code snippets for Java Script, HTML, PHP, CSS, Ruby and Objective C


we can find some good code snippets here.. for Java Script, HTML, PHP, CSS, Ruby and Objective C!

http://snipplr.com/popular/.. 


Tuesday, December 8, 2009

What is XHTML - (Overview of XHTML)


Introduction to XHTML 

XHTML is really the future of the internet. It is the newest generation of HTML (comming after HTML 4) but has many new features which mean that it is, in some ways, like XML. In this tutorial I will explain how XHTML differs from HTML and how you can update your pages to support it.

Note: It is necessary to already have a basic understanding of HTML before reading this tutorial as it deals with the differences between XHTML and HTML.


What is XHTML

XHTML stands for eXtensable HyperText Markup Language and is a cross between HTML and XML. XHTML was created for two main reasons: 


  1. To create a stricter standard for making web pages, reducing incompatibilities between browsers 
  1. To create a standard that can be used on a variety of different devices without changes
The great thing about XHTML, though, is that it is almost the same as HTML, although it is much more important that you create your code correctly. You cannot make badly formed code to be XHTML compatible. Unlike with HTML (where simple errors (like missing out a closing tag) are ignored by the browser), XHTML code must be exactly how it is specified to be. This is due to the fact that browsers in handheld devices etc. don't have the power to show badly formatted pages so XHTML makes sure that the code is correct so that it can be used on any type of browser.

XHTML is a web standard which has been agreed by the W3C and, as it is backwards compatible, you can start using it in your WebPages now. Also, even if you don't think it’s really necessary to update to XHTML yet, there are three very good reasons to do so:

  1. It will help you to create better formatted code on your site 
  1. It will make your site more accessible (both in the future and now due to the fact that it will also mean you have correct HTML and most browsers will show your page better) 
  1. XHTML is planned to replace HTML 4 in the future
There is really no excuse not to start writing your web pages using XHTML as it is so easy to pick up and will bring many benefits to your site.

Changes in XHTML from HTML

There are several main changes in XHTML from HTML: 

  • All tags must be in lower case 
  • All documents must have a doctype 
  • All documents must be properly formed 
  • All tags must be closed 
  • All attributes must be added properly 
  • The name attribute has changed 
  • Attributes cannot be shortened 
  • All tags must be properly nested
At a glance, this seems like a huge amount of changes but once you start checking though the list you will find that very little on your site actually needs to be changed. In this tutorial I will go though each of these changes explaining exactly what is different.

The Doctype

The first change which will appear on your page is the Doctype. When using HTML it is considered good practice to add a Doctype to the beginning of the page like this.

Although this was optional in HTML, XHTML requires you to add a Doctype. There are three available for use.

Strict - This is used mainly when the markup is very clean and there is no 'extra' markup to aid the presentation of the document. This is best used if you are using Cascading Style Sheets for presentation.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Transitional - This should be used if you want to use presentational features of HTML in your page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w
3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

Frameset - This should be used if you want to have frames on your page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

The doctype should be the very first line of your document and should be the only thing on that line. You don't need to worry about these confusing older browsers because the Doctype is actually a comment tag. It is used to find out the code which the page is written in, but only by browsers/validators which support it, so this will cause no problems.

Document Formation

After the Doctype line, the actual XHTML content can be placed. As with HTML, XHTML has <html> <head> <title> and <body> tags but, unlike with HTML, they must all be included in a valid XHTML document. The correct setup of your file is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Page Title</title>
OTHER HEAD DATA
</head>
<body>
CONTENT
</body>
</html>

It is important that your document follows this basic pattern. This example uses the transitional Doctype but you can use either of the others (although frames pages are not structured in the same way).


Introduction to XML Schema (What is xml schema)


XML schema describes what XML document contains and content of the XML document what fields and sub elements it can contain.
Standards for Describing XML Document
DTD : was the First formulized standard.
XDR: Much comprehensive standard than DTD.
XSD: Currently de facto standard for describing the XML documents. There are two versions in use 1.0 and 1.1. An XSD schema itself is a XML document.

XSD Elements
Elements are building blocks for any XML document, element defines the structure of the XML document. The following is the syntax to define the element in XSD Schema.
Example:
<xs: element name=”abc” type=”xyz” />
1. An Element must have the name property, the same will appear in the XML document.
2. Type property describes about what can be contained in the element when it appears in XML document. eg: xs:string, xs:integer, xs:boolean or xs:date
Example:
Sample XSD
<xs:element name="Employee_dob"
type="xs:date"/>
Sample XML
<Employee_dob>
2000-01-12T12:13:14Z
</Employee_dob>
Fixed and Default Properties
The XSD element can contain the Fixed or Default properties.
Default means that if no value specified in the XML document then application uses the default value specified in the XSD document.

Example:
<xs:element name="Employee_name" type="xs:string" default="unknown"/>
Fixed means the value in the XML document can only have the value specified in the XSD.
Example:
<xs:element name="Customer_location" type="xs:string" fixed="UK"/>
Cardinality
Specifies how many times an element can appear can be called Cardinality. it is specified using the attributes minOccurs and maxOccurs. Both attributes can assigned a non-negative value.
The default value for minOccurs and maxOccurs is 1.
Example:
<xs:element name="Employee_hobbies"
type="xs:string"
minOccurs="2"
maxOccurs="10"/>

Employee_hobbies element must appear at least twice and not more than 10 times in the XML document.

Simple Types
We can define our own types by modifying the existing types.
example: Define a code, that may be an integer with a max limit.
<xs:element name="Employee" type="xs:string"/>
Complex Types: is a container for other elements which specifies child
elements an element can contain.
Example:
<xs:element name="Employee">
<xs:complexType>
<xs:sequence>
<xs:element name="Dob" type="xs:date" />
<xs:element name="Address" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
1. Created a definition for element Employee
2. <xs:complexType> is a container for other <xs:elements>
3. Complex type do not have the type attribute and contains the <xs:sequence> element.
4. The sequence element specifies that XML document must appear in the same order they are declared in the XSD Schema.
<Employee>
<Dob> 2000-01-12T12:13:14Z </Dob>
<Address> 39 spring field road London </Address>
</Employee>