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.

Wednesday, December 31, 2008

Debugging ColdFusion

ColdFusion provides detailed debugging information to help you resolve problems with your application. Debugging can be done in two ways:

1.By specifying the DEBUG attribute in tag.
2.By enabling server side debugging in ColdFusion Administrator panel.

For instance,

SELECT Distributor.Distributor_ID,
Distributor.Distributor_Name FROM Distributor ORDER BY Distributor.Distributor_ID
Returns, q_GetDist (Records=9, Time=421ms) SQL= SELECT Distributor.Distributor_ID, Distributor.Distributor_Name FROM Distributor ORDER BY Distributor.Distributor_ID

Tuesday, December 30, 2008

Hide Quick Navigation Bar

Customization of SharePoint pages, that is hiding the quick navigation, recycle bin, view all the site content from the left navigation. Here is a real quick way to achieve it.



Copy the above code lines and add a content editor webpart to any of the webpart Zone and past the copied above lines, you also make visible false of the webpart.

Monday, December 29, 2008

C# Brainteasers

Here's some code using the anonymous method feature of C# .
What does it do?

using System;
using System.Collections.Generic;
class Test{

delegate void Printer();
static void Main() {
List printers = new List();
for (int i=0; i <>
{
printers.Add(delegate { Console.WriteLine(i); } );
}
foreach (Printer printer in printers)
{
printer();
}
}
}

Saturday, December 27, 2008

Cellphone Hazards

Fact: Malignant brain tumors are the second leading cause of death in children and young adults in the United States, and this epidemic is largely caused by radiation from a cellphones which penetrate the heads of users. If you always use your cellphones for calls and has experienced ear pain, headaches, dizziness, insomnia, irritability, stress, memory loss, high blood pressure and ringing in the ears, you better start limiting yourself from using that mobile phone, or at least pave way to a number of safety options.Studies show that there is a correlation between cell phone emissions and a slightly higher incidence of human brain tumors, cell growth in human blood micronuclei, and DNA breakages. Other studies show that electromagnetic signals from cellular phones reduce the ability to concentrate, calculate and coordinate complicated activities such as driving a car. Using a cell phone is also responsible for impairing of memory and reaction times. Even the so called hands-free mobile speaker-phones do more as they emit 10-times more brainwave interference than handheld units. Sixty percent of the radiation emitted by a typical cell phone is absorbed by the user’s head, and the radiation that is coming out from the ear piece is four times out of the antenna, and a similar amount of radiation comes from the keypad and mouthpiece as well. It should be noted also that different brands and models of cellphones have widely different levels of emissions.

Four times the radiation is leaked into the side of the head than is actually being used to transmit a signal. Highest emission comes from the antenna region. The reason for the leakage is that manufacturers tend to lower down the production cost, in exchange of lessening down the radiation that would escape into the user’s head and lowering down possible risks, thus the source of leakage: poorly matched transmitters, feeds and antennas. It must also be blamed to the lack of shielding in the phone case.

It is important that mobile phone manufacturers should be alarmed with this scenario and start designing cell phones that will not endanger the health of users. Make sure that all cellphones are sold with head sets or earphones. In this way, the user will have the option of not using the cellphone close to his head. The truth is, the essential key to safety lies to the manufacturers themselves, by designing safety features that will help protect and reassure their customers.

This information is from Sciencetips.com

Tuesday, December 23, 2008

Resolving the newfolder.exe virus

Two days back my PC got affected by this virus very badly as it eat up all my empty hard disk space of around 700 MB.

This virus is know popularly as regsvr.exe virus, or as new folder.exe virus and most people identify this one by seeing autorun.inf file on their pen drives. It is spreading mostly using pen drives as the medium.

So I will tell you that how to remove this virus manually.

I prefer manual process simply because it gives me option to learn new things in the process.
  • Search for autorun.inf file. It is a read only file so you will have to change it to normal by right clicking the file , selecting the properties and un-check the read only option.
  • Open the file in notepad and delete everything and save the file.
  • Now change the file status back to read only mode so that the virus could not get access again.
  • Click start->run and type msconfig and click ok
  • Go to startup tab look for regsvr and uncheck the option click OK.
  • Click on Exit without Restart.
  • Now go to control panel -> scheduled tasks, and delete the At1 task.
  • Click on start -> run and type gpedit.msc and click Ok.
  • Go to users configuration->Administrative templates->system Find “prevent access to registry editing tools” and change the option to disable.
  • Once you do this you have registry access back.
  • Click on start->run and type regedit and click ok
  • Go to edit->find and start the search for regsvr.exe,
  • Delete all the occurrence of regsvr.exe; remember to take a backup before deleting.
  • Don't delete the regsvr32.exe.
  • Delete regsvr.exe occurrences only.
  • At one or two places you will find it after explorer.exe in theses cases only delete the regsvr.exe part and not the whole part. E.g. Shell = “Explorer.exe regsvr.exe” the just delete the regsvr.exe and leave the explorer.exe
  • Click on start->search->for files and folders. Their click all files and folders Type “*.exe” as filename to search for
  • Click on ‘when was it modified ‘ option and select the specify date option Type from date as 10/16/2008 and also type To date as 10/16/2008
  • Now hit search and wait for all the exe’s to show up.
  • Once search is over select all the exe files and shift+delete the files, caution must be taken so that you don’t delete the legitimate exe file.
  • Also find and delete regsvr.exe, svchost .exe
Now reboot your PC.


Source for this post:
http://amiworks.co.in/talk/how-to-remove-new-folderexe-or-regsvrexr-or-autoruninf-virus/

Saturday, December 20, 2008

Search a User By name & get his ID on Unix

#! /usr/bin/sh
echo "Enter User Name to be Searched"
read USERNAME
NAMES=`who awk {'print $1'} sort -u`

for NAME in $NAMES
do
USER=`finger $NAMEgrep $USERNAME awk {'print $7,$8'}`
if [ "$USER" != "" ]
then
echo $USER ——- $NAME
fi
done

Wednesday, December 17, 2008

Searching lines before & After in Unix

#! /usr/bin/sh
#———————————————–
#Program used to search a seed in a program
#———————————————–

SEED=$1
LINE=$2
FILE1=$3


for X in `awk '/'"$SEED"'/{ print NR }' $FILE1 `
do
echo ———————– $SEED ————————————–
NOB=`expr $X - $LINE`
NOA=`expr $X + $LINE`

if [ $NOB -lt 1 ]; then NOB=1
fi
for J in `awk 'NR == '"$NOB"',NR == '"$NOA"'
{
if(NF!=0) print; else print "\n"
}' $FILE1 `

do
echo $J
done
echo ——————————————————————-
done

Monday, December 15, 2008

Deploying J2EE applications on JBOSS Application Server

Step 1: Go /server//log
Step2 : Bring down the JBOSS Application server, Copy J2EE files like WAR/JAR/EAR/SAR/ZIP/RAR/JSE or xxx-ds.xml (data source) under the deploy directory
Step3:
Bring up the JBOSS Application service after deployment, follow the steps in 6.1.2
Go to /server//log

Open console.log and check whether J2EE files are deployed successfully

Note: Application stop/start is not required if it is a Hot deployment.

Saturday, December 13, 2008

ROUND() function in sql

Syntax:
ROUND ( numeric_expression , length [ ,function ] )

numeric_expression Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.
length Is the precision to which numeric_expression is to be rounded. length must be an expression of type tinyint, smallint, or int. When length is a positive number, numeric_expression is rounded to the number of decimal positions specified by length. When length is a negative number, numeric_expression is rounded on the left side of the decimal point, as specified by length.
function Is the type of operation to perform. function must be tinyint, smallint, or int. When function is omitted or has a value of 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.

SELECT ROUND(column_name,decimals) FROM table_name

Parameter Description column_name Required. The field to round. decimals Required. Specifies the number of decimals to be returned.
1. SELECT ROUND(10.09 ,1) = 10.1
2. SELECT ROUND(10.09 ,-1) = 10
Computers Add to Technorati Favorites Programming Blogs - BlogCatalog Blog Directory