View passwords under the asterisks in your browser

Have you ever used remember the password option in you browser and later forget that password. If you want to see what the password you typed there is small trick that can be used. Simply type this JavaScript in the address bar of your browser.

javascript:(function(){var s,F,j,f,i; s = ""; F = document.forms; for(j=0; j<F.length; ++j) { f = F[j]; for (i=0; i<f.length; ++i) { if (f[i].type.toLowerCase() == "password") s += f[i].value + "\n"; } } if (s) alert("Passwords in forms on this page:\n\n" + s); else alert("There are no passwords in forms on this page.");})();

You can find a full explanation at the Raymond.CC Blog.

 

Boost security by disabling 10 Windows XP services

I came across this article at TechRepublic few days back about few windows services that we can disable and boost the security of our computers. Following are the services that you can disable without any problem.

  • ISS
  • NetMeeting Remote Desktop Sharing
  • Remote Desktop Help Session Manager
  • Remote Registry
  • Routing and Remote Access
  • Simple File Sharing
  • SSDP Discovery Service
  • Telnet
  • Universal Plug and Play Device Host
  • Windows Messenger Service

Some of these services may not even installed in your machine, specially some thing like ISS. Better check the services running in you machine and disable unnecessary ones. It can help you in two ways, one is that it will boost the security and other thing is that it will save your system resources  to do some thing useful.

To see list of all the services running in you machine go to Control Panel > Administrative Tools > Services

You can find the original article here >>

Technorati Tags: ,
 

Back to the University

graduate3

 

 

 

 

 

 

 

 

Tomorrow(19th Nov) our new academic semester begins. It will be the start of my 4th year at the university. Two months of vacation seems to be vanished. Two months of vacation was very nice one. I managed to learn lots of new things during that time, and spend lot of time with my family.

Now I'm doing the IT special degree so next few months will be very busy. Road ahead will be more difficult but will be very exciting. I'm hopping to do well in this semester.

 

Reading Excel Files from Java

Microsoft Excel is one of the common was of storing data in business. There fore when we develop applications, most of the times we have to extract data from an Excel sheet. There are many methods to extract data from Excel file, both commercial and free libraries are developed for this purpose. One of such library is Apache POI HSSF.

I came across this library few weeks back when I was researching on a methods of reading data from Excel and load it to a Java application that we are developing.  The project I'm working on is a development of Retirement Planning System, which our client is going to use for consultation purposes. He wanted to give his clients an Excel template where they put their current financial information such as incomes, expenses and our software should be able to read that file and load that data for projection purposes.

Apache POI provides good API to access Excel files, not only reading but writing as well. Here I'm only using reading functionality only. When we are panning to use Excel as data input method first thing is to develop good template with all required field. This is the sample Excel file I used in my testing.

incomes 

 

 

 

When reading the data we are reading from cell by cell, so we have to know the exact cell that contains the data we need. I'm using a common interface to read data from Excel sheet.  According to our requirement we can implement that to read data in to our java objects.

public interface RowProcessor
{
public Object[] process(HSSFSheet sheet) throws Exception;
}


Here we are passing the excel sheet to our process method and get set of objects after processing it. By implementing this interface I created a class called IncomeProcessor to read the Excel sheet and get an array of Income.



public class IncomeProcessor implements RowProcessor
{
//Row columns
private static final short COLUMN_NAME = 1;
private static final short COLUMN_OWNER = 2;
private static final short COLUMN_AMOUNT = 3;
private static final short COLUMN_INCREASE_RATE = 4;
/**
* The singleton instance of this class.
*/
private static IncomeProcessor thisProcessor;

/**
* Default constructor
* Created on: Nov 8, 2007
* @Author: Sandarenu
*/
private IncomeProcessor()
{
//Private so no outside instantiation
}

/**
* Get an instance of this row processor.
* Created on: Nov 8, 2007
* @Author Sandarenu
* @return instance of this row processor.
*/
public static RowProcessor getInstance()
{
if(thisProcessor == null)
{
thisProcessor = new IncomeProcessor();
}
return thisProcessor;
}

/**
* Do required processing for the Incomes.
*/
public Object[] process(HSSFSheet sheet) throws Exception
{
if(sheet != null)
{
int first = sheet.getFirstRowNum();
int last = sheet.getLastRowNum();
HSSFRow row = null;
List<Income> incomeList = new ArrayList<Income>(5);
Income income = null;
String owner;
first += 2; //Ignore first 2 rows - they are headers
for(int i= first; i<=last; i++)
{
row = sheet.getRow(i);
if(row != null && row.getCell(COLUMN_NAME) != null)
{
income = new Income();
income.setName(row.getCell(COLUMN_NAME).getRichStringCellValue().getString());
income.setStartingValue(row.getCell(COLUMN_AMOUNT).getNumericCellValue());
income.setIncreaseRate((float)row.getCell(COLUMN_INCREASE_RATE).getNumericCellValue());
owner = row.getCell(COLUMN_OWNER).getRichStringCellValue().getString();
if(owner.startsWith("C")|| owner.startsWith("c"))
income.setClientPercentage(100);
else if(owner.startsWith("S")|| owner.startsWith("s"))
income.setSpousePercentage(100);

incomeList.add(income);
}
}

return incomeList.toArray(new Income[incomeList.size()]);
}

return null;
}

}




This is the main class I used to test my data reading. Here first I read the excel file and then get relevant Sheet for processing. Using this technique we can easily populate our java objects using the data from Excel sheet.  



public class Test {

/**
* @param args
*/
public static void main(String[] args)
{
TestListner tl = new TestListner();
ImportHandler ih = new ImportHandler();
ih.addStatusListner(tl);

try {
POIFSFileSystem fs =
new POIFSFileSystem(new FileInputStream("Book1.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs);


HSSFSheet sheet =wb.getSheet("Income");
RowProcessor ip = IncomeProcessor.getInstance();
Object [] incomes = ip.process(sheet);
for (Object object : incomes)
{
Income income = (Income)object;
System.out.println( income.getName() + " " + income.getStartingValue());
}

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

}


Output of the code.



output



 



 



 



You can download complete source code and sample Excel workbook here.




 

Windows Live Writer for Creating blog posts

I have downloaded Windows Live Writer to see whether I can use it to publish blog posts in my blog. I think it is working fine, and I'm planing to continue using this for my next blog posts. WLW is having number of plug ins to support blog editing. One of the most important plug in is Source Code Format plug in.

 

Displaying Background Image in Swing Components

This is a wonderful way to add background images to Java swing components. We can you this method to add background images for almost all of the swing components. To add image we have to override paintComponent() method.

Eg 1: Add background image to JTextArea
JTextArea textArea = new JTextArea() {
ImageIcon backImage = new ImageIcon("Resources/Background.jpg");
Image image = backImage.getImage();
{setOpaque(false);}
//Override
public void paintComponent (Graphics g) {
g.drawImage(image, 0, 0, this);
super.paintComponent(g);
}
};


Eg 2: Add background image to JDesktopPane

JDesktopPane textArea = new JDesktopPane() {
ImageIcon backImage = new ImageIcon("Resources/Background.jpg");
Image image = backImage.getImage();
{setOpaque(false);}
//Override
public void paintComponent (Graphics g) {
g.drawImage(image, 0, 0, this);
super.paintComponent(g);
}
};

We can use this method to add background images to any Swing component.
 

Multi Table Delete Error in MySQL

Today I was trying to write some SQL scripts to delete data from MYSQL database. And it uses INNER JOIN to join two tables for the delete. My query looked like follows.

DELETE fpsdb.future_changes.* FROM fpsdb.future_changes fc INNER JOIN fpsdb.income a ON a.Income_ID = fc.Dependancy_ID WHERE a.client_ID = 1;

When I try to execute, it gave the error "Unknown table 'future_changes' in MULTI DELETE"

I tried every thing to find the error without any success. Then I google for this error. Then I found out about an MySQL bug related to this issue. It states that "Cross-database deletes are supported for multiple-table deletes, but in this case, you
must refer to the tables without using aliases."

So I changed the query removing aliases and put full qualified table names everywhere.

DELETE fpsdb.future_changes.* FROM fpsdb.future_changes INNER JOIN fpsdb.income ON fpsdb.income.Income_ID = fpsdb.future_changes.Dependancy_ID WHERE fpsdb.income.client_ID = 1;

And Then it worked..... :)

 

Tribune to Heros

Tribune to Heros
We will never forget the sacrifices you made to protect our country....

Subscribe


Get Google Toolbar Button

Enter your email address:

Delivered by FeedBurner