Saturday, January 31, 2009

Factorial Implementation in java

In mathematics, the factorial of a natural number n is the product of all positive integers less than or equal to n. This is written as n! and pronounced "n factorial", or colloquially "n shriek" or "n bang". The notation n! was introduced by Christian Kramp in 1808.

This tip shows how to implement factorial function in Java.

public class Factorial
{
public static long factorial( int n )
{
if( n <= 1 )
return 1;
else
return n * factorial( n - 1 );
}

public static void main( String [ ] args )
{
for( int i = 1; i <= 10; i++ )
System.out.println( factorial( i ) );
}
}

Tuesday, January 27, 2009

Document Retrieval Concepts

Document Retrieval Concepts:

Document: A unit of retrieval. It might be a paragraph, a section, a chapter, Web page, an article, a whole book, or images and video.
Index: A data structure built on the text to speed up searching.
Index Term( or keyword): A pre-selected term which can be used to refer to the content of a document. Usually, index terms are noun or noun groups. In the Web, however some search engines use all the words in a document as index terms.
Information Retrieval(IR): Part of computer science that studies the retrieval of information(not data) from a collection of written documents. The retrieved documents aim at satisfying a user information need usually expressed in natural language.
Logical view of documents: The representation of documents and Web pages adopted by the system. The most common form is to represent the text of the document by a set of terms or keywords.
Precision: An information retrieval performance measure that quantifies the fraction of retrieved documents which are known to be relevant.
Query: The expression of the user information need in the input language provided by the information system. The most common type of input language simply allows the specification of keywords and of a few Boolean connectives.
Recall: An information retrieval performance measure that quantifies the fraction of known relevant documents which were effectively retrieved.

Monday, January 26, 2009

Watch YouTube Videos in Gmail Chats

As if your friends linking you to YouTube videos isn’t distracting enough … now you can actually watch the videos from inside of Gmail chats.

When someone sends you a YouTube link, you’ll now get a thumbnail preview of the video. Click play and another box will open up inside of Gmail that streams it. For additional options like full screen mode, embedding, or adding the video to your favorites, you’ll still need to click over to YouTube.

Saturday, January 24, 2009

Closing your connections

Recently, we have had a spate of connection leak problems in our JMS operations in production. On analysis we found that a few of our applications are not closing the JMS connections properly. In this entry, I am going to talk about how to close your JMS connections and ways of detecting any connection leaks.

In any JMS operation, you would
a) open a connection to the JMS resource,
b) establish a session and
c) create a producer or a consumer to send or receive messages.
When you create a JMS connection, the container allocates resources on the resource provider. Therefore, the application should be responsible for ensuring that these resources are de-allocated at the end of the operation. From a programming context, this is achieved by calling connection.close().

The application should ensure that the connection.close() is being called irrespective of the outcome of the operation. i.e., it should be called even under exception scenarios. This is typically achieved by closing the connection inside the finally block.

There is generally a confusion about whether closing a connection alone is sufficient or whether the underlying session and the message producer or message consumer should also be closed. The JMS 1.1 spec clearly states that closing a connection alone is sufficient. When a connection.close() is invoked it tells the container that all the constituent objects of that connection should also be closed.

Now, once we have coded everything correctly, we should make sure that we are not leaking connections. How do we identify that? There are a couple of unix commands that I use to make sure that my code is not leaking connections. When we open a connection, a TCP communication channel is opened between your application and the resource provider. In the case of AQ, it is a connection from your JVM to the AQ database. So if we monitor the number of connections that are open between your server and the AQ database, we can find out if there is a leak or not.

One way is to use the netstat command. You can use netstat -an grep 1521 grep dbhost wc -l to get the number of connections opened from your server to the AQ database.

But there is a problem here. We have multiple oc4js running from 1 server. So we will not be able to identify whether the connections are coming from your oc4j or another oc4j. There is another command in unix called lsof which lists all the open files. In unix, a socket is again a file. If you execute the command lsof -i :1521 grep dbhost grep pid wc -l it will give the number of open connections from your oc4j to the AQ database. Here pid is the process id of your oc4j.
Give it a try and let me know your thoughts.

Wednesday, January 21, 2009

Simple e-Mail Etiquette

  • Be concise and to the point
  • Answer all questions, and pre-empt further questions
  • Use proper spelling, grammar & punctuation
  • Use templates for frequently used responses
  • Do not attach unnecessary files
  • Use proper structure & layout
  • Do not overuse the high priority option
  • Do not write in CAPITALS
  • Don't leave out the message thread
  • Read the email twice before you send it
  • Use a meaningful subject
  • Use Active Voice instead of Passive Voice
  • Avoid long sentences.

Sunday, January 18, 2009

To use Notepad as a Log File!!!

1. Open a blank Notepad file
2. Type .LOG (caps) as the first line of the file, followed by a enter. Save the file and close it.
3. Double-click the file to open it and notice that Notepad appends the current date and time to the end of the file and places the cursor on the line after.
4. Type your notes and then save and close the file.
5. Each time you open the file, Notepad repeats the process, appending the time and date to the end of the file and placing the cursor below it!

Source : Read in Chip Magazine of October 2008

Thursday, January 15, 2009

Ensure that table statistics are updated before performing a bind

The DB2 optimizer uses the table and index statistics from the DB2 catalogs to determine the optimal access path. If the table statistics do not reflect the data in the table, the optimizer may decide to perform a table scan instead of using indexes.
This can be very expensive depending on the size of the table.

A quick and easy way to look at the statistics is to query the "sysibm.systables" catalog table for the specific table you are interested in and look for the values in columns CARD, NPAGES.

A value of -1 indicates that statistics have not been collected from the table/index and runstats needs to be run on the table.

If the values differ significantly from the number of rows in the table - once again a "runstats" may be necessary to update the catalog statistics.

Once the runstats process has been run, the bind should be performed again so that the optimizer takes advantage of the new statistics.

Monday, January 12, 2009

Change the size of icons in Start menu

We can change the size of icons in Start menu by following these steps:
1. Right click on Taskbar,
2. In new open window click on Start Menu,
3. Choose Customize,
4. In General Click in Large or Small icon,
5. Click on OK,
6. Again click on OK.

Source: Read in a Magazine

Friday, January 09, 2009

Sending broadcast packets in Java

Broadcasting is defined as sending a packet to all network nodes on a subnet. An IP network subnet mask divides an IP address into two parts: the network identifier and the node identifier. A broadcast address is defined as an IP address where all bits of the node identifier are set.

So, sending a broadcast packet from a Java program (or from a program in any other language, for that matter) simply requires you to specify the broadcast address as the destination for the packet.

Source: java-tips.org

Tuesday, January 06, 2009

Disabling My Computer

Disabling My ComputerIn areas where you are trying to restrict what users can do on the computer, it might be beneficial to disable the ability to click on My Computer and have access to the drives, control panel etc.

To disable this:
1.Open RegEdit
2.Search for 20D04FE0-3AEA-1069-A2D8-08002B30309D
3.This should bring you to the HKEY_CLASSES_ROOT\CLSID section
4.Delete the entire section.

Now when you click on My Computer, nothing will happen.

You might want to export this section to a Registry file before deleting it just in case you want to enable it again. Or you can rename it to 20D0HideMyComputer4FE0-3AEA-1069-A2D8-08002B30309D. You can also hide all the Desktop Icons, see Change/Add restrictions.

Saturday, January 03, 2009

How to Change User Password at Command Prompt

How to use the net user command to change the user password at a Windows command prompt. Only administrators can change domain passwords at the Windows command prompt. To change a user's password at the command prompt, log on as an administrator and type:
"net user * /domain" (without the quotation marks)

When you are prompted to type a password for the user, type the new password, not the existing password. After you type the new password, the system prompts you to retype the password to confirm. The password is now changed.

Alternatively, you can type the following command: net user . When you do so, the password changes without prompting you again. This command also enables you to change passwords in a batch file.

Non-administrators receive a "System error 5 has occurred. Access is denied" error message when they attempt to change the password.
Computers Add to Technorati Favorites Programming Blogs - BlogCatalog Blog Directory