Saturday, July 30, 2005

What is a Transaction?

To illustrate the concept, let us assume that you want to transfer money from a savings account into a current account. In this scenario, it is critical that both the accounts are changed from a successful transaction and neither is affected from an unsuccessful one. You just cannot afford to have your money vaporize if crediting your current account fails for any reason after the debit on your savings account! Therefore, the most important concept that one has to be aware of when dealing with enterprise applications is the concept of a transaction. To a user, a transaction is a single change event that either happens or doesn't happen. Although this may sound like a fairly straightforward and simple requirement, it is hard to make this work in a distributed system without deploying some form of transaction control - computers can fail and messages can be easily lost.
Transactions provide a way to bundle a set of operations into an atomic execution unit. This atomic "all-or-nothing" property is not new; in short, within any transaction, several independent entities must agree before the deal is done. If any party disagrees, the deal is off and the independent entities are reverted back to their original state by invoking a rollover operation.Transactions are essential for distributed applications. Further, transactions provide modular execution, which complements a component technology’s modular programming.

The ACID properties

All transactions subscribe to the following "ACID" properties:
Atomicity - A transaction either commits or rollbacks. If a transaction commits, all of its effects remain. If it rollbacks, then all of its effects are undone. For example, in money transfer example above, the money is deducted from Saving account, and the same amount is added to current account (commit) or nothing changes (rollback).
Consistency - A transaction always leads to a correct transformation of the system state by preserving the state invariance. For example, a transaction adding an element to a doubly linked list, all forward and backward pointers are updated.
Isolation - Concurrent transactions are isolated from the updates of other incomplete transactions. This property is also often called serializability. For example, a second transaction traversing a doubly linked list already undergoing modification by a first transaction will see only completed changes, and be isolated from any non-committed changes of the first transaction.
Durability - If a transaction commits, its effects will be permanent after the transaction commits. In fact, the effects remain even in the face of system failures. It is up to the application to decide what consistency is and to bracket its computation to delimit these consistent transformations. It is the job of the transactional resource managers to provide consistent, isolated and durable transformations of the objects they manage. If the transactions are distributed among multiple computers, the two-phase commit protocol is used to make these transactions atomic and durable.

Friday, July 29, 2005

Do you have BRAIN?

Who Said English is easy?

Fill in the following blank with Yes or No -

______ I don't have a BRAIN.

;)

GNU utilities for Win32

I have been using a W2K machine for the devlopment activities. However, sometime back I came acroos this set of tools that port some of the GNU Utilities to Win32 platform. Since then, I have been using them for various activities. Just check it out at http://unxutils.sourceforge.net/.

Wednesday, July 27, 2005

What is P3P?

P3P is the Platform for Privacy Preferences Project. It was developed by the W3C, (World Wide Web Consortium) as a protocol for providing automated privacy information to the end user, giving them more control over their own personal information at the web sites they visit.

P3P websites offer privacy information in a machine-readable format and P3P enabled browsers can read this and compare it to their own privacy standards. This protocol provides a standardization of privacy statements and presents it in a format that allows surfers to act on the information they are provided with.

The two main goals of implemented P3P policies are:

* To enable Web sites to present their data-collection practices in a standardized, computer-readable, easy-to-locate manner
* To enable Web users to understand what data will be collected by sites, how that data will be used, and what data and uses they may "opt-out" of or "opt-in" to.

How is it useful?

Web Applications usually uses cookies to track any kind of user information. Internet Explorer (IE) 6.0's default privacy setting "interprets" framed sites as third party cookies. IE 6.0 does not accept third party cookies. Users setting their privacy settings on high on IE 6.0 disable access to such sites. Users have to customize the privacy setting to gain access to these sites. This really can annoy the users to change their privacy settings.

To avoid such kind of issues sites having cookies can implement P3P Policies and publish them on site. The policy will provide information of the site accepting the kind of cookies and the data collected by the user. After the implementation when user access the site user's privacy is matched with the policy deployed on the site. A handshake is done and if the users privacy settings matches the policy hosted on the site user is allowed to login to the site. Else the site is shown as blocked. P3P is being usually employed by Ad Servers to serve Ads.

How do I implement P3P on my site?

First, you need a privacy statement for your site that surfers can read, or you can use the HTML privacy statement that is generated with the IBM P3P editor. Policies can also be created from P3PDeveloper

The P3P Editor will create four files, a policy file, written in XML, a reference file, written in XML, a compact policy and an HTML version of the privacy statement that you can use on your site as your privacy statement if you don't wish to reference your site's current privacy statement, or if your site doesn't have one. Further compact policies setting can be set on IIS on custom header tab.

Along with the policy file a legal document page will also be created with the information about the legal implications of a site. The generated policy file can then be deployed along with the legal document on the web site. User can view the policy by viewing the privacy report on IE for the page with the posted policy information.

I, myself, have used P3P in one of my recent Projects where we built a 3rd Party Ad Server (I would be willing to discuss 3rd party AdServer in one of my later posts). Have you used P3P in your web applications? Your comments are welcome.

Tuesday, July 26, 2005

Common UNIX Commands

I just decied to look for a few commonly used UNIX command. A quick Google produces a lot more, but here are a list of more useful commands.

  1. cd - Change Directory. (Just like in dos)
  2. mkdir - Make Directory.
  3. rmdir - Removes a Directory that is empty!
  4. ls - List directory. (Like dir in Windows)
  5. cat – Short for concatenate. It was used to concatenate two filestogether via cat file1 file2 >file3 Didn‘t know that did you. Theechoing out to standard out gave cat a whole new meaning to the users.
  6. more - Just like less. It pages output to the screen.
  7. mv - Move. For moving files and directories around
  8. rm Remove a file. Also rm rf for removing a folder and it‘scontent.
  9. grep - Used to search for text within a stream or files. (man regex)
  10. vi – A text based editor. You‘ll find that it‘s really a symboliclink to vim now a days.
  11. rlogin - Remote login. I hope your admins disabled this!
  12. passwd - Used to change your password.
  13. ps - Used to processes.
  14. nice - Run a program with lower priority so you don't hog CPU.
  15. kill – Terminates a program. You can select what signal you want tokill a program with also. -9
  16. gzip - Compresses files.
  17. gunzip - Uncompresses files.
  18. tee – Pipe your output to standard out and to a file. Nice forwatching a process and logging.
  19. sort - A sort program
  20. sed – Stream Editor. Excellent program to modify files or streams!(man regex)
  21. uniq - Unique program.
  22. awk – An excellent program to parse up streams or files into tokens.It supports a hellva lot of cool things and you can complete writeprograms with it. (man nawk also)
  23. chgrp - Change Group
  24. chown - Change owner
  25. pwd - Current working directory.
  26. find – Used to find programs and you can also execute commands oneach match found.
  27. wc - Word, line, letter count program. For you line counting whores.
  28. which - Finds a location of a program that's in your path.
  29. last - See who last logged in.
  30. du - Disk usage.
  31. df - Disk Free
  32. top – Running processes with CPU and other information thatrefreshes.
  33. watch – Repeats a command and updates the screen with only thechanges
  34. login - Logging in
  35. telnet - Connect to another machine
  36. logout - Logging out
  37. emacs - Using the emacs text editor
  38. cp - Making a copy of a file
  39. chmod - Controlling access to your files
  40. cmp - Comparing two files
  41. compress - Compress a file
  42. pine Using Pine to send and receive email
  43. mush - The mush electronic mail system
  44. talk - Talk to another user
  45. write - Write messages to another user
  46. ftp - Transferring files with ftp
  47. man - Manual pages
  48. quota v Finding out your available disk space quota
  49. ical - Using the Ical personal organizer
  50. finger - Getting information about a user
  51. who - Finding out who's logged on
  52. lpr - Printing
  53. lprm - Removing a print job
  54. lpq - Checking the print queues
  55. ps - Finding your processes
  56. kill - Killing a process
  57. nohup - Continuing a job after logout
  58. nice - Changing the priority of a job
  59. & - What is a background process?
  60. Cntrl-z - Suspending a process
  61. fg - Resuming a suspended process

Monday, July 25, 2005

What are the different type of JDBC drivers?

There are four types of JDBC database driver:

The JDBC/ODBC bridge driver (Type 1) A piece of native C-code that translates a JDBC call to an ODBC call. Use this driver for development, not for industrial-strength application environments. Note that you have to have an ODBC database driver manager + an ODBC database driver installed on the server in addition to the JDBC/ODBC bridge. Though useful for learning JDBC and quick testing, bridging solutions are rarely appropriate for production environments.

Native API partly java driver (Type 2) A piece of native C-code that translates a java JDBC call to a native database call level API. Use this driver for development and deployment. Due to its native code, this driver can only be used by Java Applications with full computer access (i.e. not Applets). Type 2 drivers generally provide the best performance, but they require the installation of native libraries on clients that need to access the database. Applications using Type 2 drivers have a limited degree of portability.

JDBC-Net pure Java driver (Type 3) A piece of pure java code that translates an incoming JDBC call to an outgoing database Net protocol call (such as SQL*Net). Use this driverfor development and deployment. Flexible and powerful, this driver can be used by any Java component and requires only connect access to work. The Type 3 architecture is actually more of a benefit to driver vendors than application architects since it enables the vendor to write a single implementation and claim support for any database that has a JDBC driver. Though this driver type is quite powerful but, unfortunately, it has weak performance and unpredictable stability.

Native protocol pure Java driver (Type 4) A piece of pure java code that translates an incoming JDBC call to an outgoing database native protocol call (such as Oracle CLI). Use this driver for development and deployment. This driver type is the recommended one for server-side java development unless a type 2 driver has considerable performance advantages.

Practically speaking, Type 2 and Type 4 drivers are the only viable choices for a production application. At an abstract level, the choice between Type 2 and Type 4 comes down to a single issue: is platform independence critical? By platform independence, I mean that the application can be bundled up into a single jar and run on any platform. Type 2 drivers have a hard time with platform independence since you need to package platform-specific libraries with the application. If the database access API has not been ported to a client platform, your application will not run on the platform. On the other hand, Type 2 drivers tend to perform better than Type 4 drivers.

Always remember, knowing the driver type provides only a starting point for making a decision about which JDBC driver to use in your application. The decision really comes down to knowing the drivers that exist for your database of choice and how they compare to each other.

Useful Links : List of JDBC Drivers

Saturday, July 23, 2005

What’s the difference between Primary Key and Unique Key?

Both Primary & Unique keys are Indexes.

Index - An index is a structure in a table that orders the data. It allows the database to access data quickly (In MySQL its implemented using B-tree algorithms).

Primary Key - This is an index that cannot be NULL, Primary Keys are used in building relationships between tables in a database. (an index is automatically created on the primary key). The difference between primary and ordinary keys is that there can be multiple keys, but only one primary key.

Unique Key - Unique and Index are same, the difference is, in Unique, duplicate are not allowed in any circumstances and that is enforced by database server. Primary key(s) qualify to be Unique on basis of their uniqueness.
In case, your table has 2 primary keys means that the 2 fields together form one unique key. Each field by itself may have repeating values, but both primary keys combined together must be unique.

Wednesday, July 20, 2005

EMail Validation using Regular Expressions

Using Regular Expressions in Java, we can validate where the given email-id string is of the valid format. Here is a sample.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public static boolean validateEmailId(String astrEmailId) {
//Set the email pattern string
Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
//Match the given string with the pattern
Matcher m = p.matcher(astrEmailId);
//check whether match is found
return m.matches();
}

RegExp can also be used in JavaScriptto validate EMail ID

function isEmail(str) {
// are regular expressions supported?
var supported = 0;
if (window.RegExp) {
var tempStr = "a";
var tempReg = new RegExp(tempStr);
if (tempReg.test(tempStr)) {
supported = 1;
}
}
if (!supported) {
return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
var r1 = new RegExp("(@.*@)(\\.\\.)(@\\.)(^\\.)");
var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.
([a-zA-Z]{2,3}[0-9]{1,3})(\\]?)$");
return (!r1.test(str) && r2.test(str));
}

Monday, July 18, 2005

Sunday, July 17, 2005

How old are the daughters?

Two MIT math graduates bump into each other at Fairway on the upper west side. They hadn't seen each other in over 20 years.
The first grad says to the second: "how have you been?"
Second: "Great! I got married and I have three daughters now"
First: "Really? how old are they?"
Second: "Well, the product of their ages is 72, and the sum of their ages is the same as the number on that building over there.."
First: "Right, ok.. oh wait.. hmmmm.., I still don't know"
second: "Oh sorry, the oldest one just started to play the piano"
First: "Wonderful! my oldest is the same age!"

Problem: How old are the daughters?

Monday, July 11, 2005

Improve the quality of your JMeter scripts

Javaworld.com has published an article on improving the quality of a JMeter Test Script.
 
Just in case you are unaware, JMeter is an Open Source Load-Testing Tool from Apache. It has an excellent UI and various parameters and elements can be drag-and-dropped. [http://jakarta.apache.org/jmeter/index.html]
 

Wednesday, July 6, 2005

Patterns: Inversion of Control

I consider the following links to be a good introduction into IoC (Inversion of Control) pattern and would like to share them:

How do I make Tomcat startup faster?

These are a few of the options u can try to make your Tomcat Server startup faster:
  • Get a faster computer (:D)
  • Make sure your code is not doing slow things. (Use a profiler like JProbe)
  • Remove any jar files you don't need. When searching for classes every JAR file needs to be examined to find the needed class. Also during webapp startup, jar files are searched for TLD files. If the jar file is not there - there is nothing to search.
  • Remove any webapps you don't need. (So remove the all the webapps installed with tomcat)
  • Tweak memory parameters - Google is your friend.
  • Trim the config files as much as possible. XML parsing is not cheap. The less there is to parse - the faster things will go.

Monday, July 4, 2005

How can I prevent my public JSP page from appearing within the search engine

There are two ways of achieving it:
  • You can add a meta tag to the generated HTML content indicating that the page must not be indexed by the search engine's spider.
<head>
<meta name="robots" content="noindex">
...
</head>
  • put a file robots.txt at the root of your site, that is /robots.txt. In that file you can configure certain sections of your site to be skipped by crawling bots:
# All robots will spider the domain
User-agent: *
Disallow: /path/of/files/or/documents/to/deny

How does session management work internally within the servlet en gine?

This very much depends on the servlet engine. Sometimes sessions are stored only in memory, in a HashSet of session IDs and the HttpSession. Some servlet engines support serializing session information to a file system or database, which allows the servlet engine to restart without losing session information, and to allow a cluster of web servers to use the same pool of sessions. Each servlet engine should provide details of the features of their session management. If you want to look at actual implementations, there are numerous open source projects including Tomcat (http://jakarta.apache.org/), and others.

Java SE 5.0: What's the difference between a StringBuffer and StringBuilder?

What's the difference between a StringBuffer and StringBuilder?

The StringBuilder class was introduced with JDK 5.0. Essentially, a StringBuffer is a thread-safe version of StringBuilder. If you are only adding/removing characters from a single-thread, the StringBuilder implementation will be faster. If you are using multiple threads to add and remove characters, use StringBuffer.

Friday, July 1, 2005

A Few IT definitions :-)

  • Project Manager is a Person who thinks Nine women can deliver a baby in One month.
  • Developer is a Person who thinks a single woman cannot deliver a baby in nine months.
  • Onsite Coordinator is one who thinks single woman can deliver nine babies in one month.
  • Client is one who knows that it takes a man, a woman & nine months to deliver a baby.
  • Marketing manager is a person who thinks I can deliver a child whether a man and woman is available or not.
  • Resource optimisation team thinks I dont want man or woman, i'll still produce a child with zero resources.
  • Documentation team will think I dont care how a child is delivered, i'll just document 9 months.
  • QA Auditor is the only person who is never happy with the PROCESS to produce baby.

Total Pageviews

Diving into the Controversial World of IPL with Lalit Modi

Lalit Modi, the mastermind behind the Indian Premier League (IPL), recently had a candid interview with Raj Shamani. The interview delved d...