• Enter Slide 1 Title Here

    This is slide 1 description. Go to Edit HTML of your blogger blog. Find these sentences. You can replace these sentences with your own words.

  • Enter Slide 2 Title Here

    This is slide 2 description. Go to Edit HTML of your blogger blog. Find these sentences. You can replace these sentences with your own words.

  • Enter Slide 3 Title Here

    This is slide 3 description. Go to Edit HTML of your blogger blog. Find these sentences. You can replace these sentences with your own words.

Friday, April 27, 2007

Google Adsense gets nice look and feel with Google Account

Seems Google has started integrating Google Adsense with Google Account. We believe this as a good step since it makes life easier, login to only one account but have many services working. Previously Google did this with Blogger as well. New login page is very nice and colorful. New login page looks as below.


Currently the two old and new login pages can be accessed using two different URLs, but this will be changed very soon.
Old login page: www.google.com/adsense/login3
New login page: www.google.com/adsense/login/

Wednesday, April 25, 2007

Sri Lanka through to World cup finals playing against 11 or 13?

Today is a special day for Sri Lankans as SL made their way to finals in World Cup 2007 after the semi final victory over New Zealand yesterday. That was a fantastic match even though it was hard to judge whether SL were playing against 13, not just 11 players. SL was playing against 11 friendly and claim NZ players (and 2 slightly unfair professional umpires).

Interesting point was both the 2 umpires, RE Koertzen (South Africa) and SJA Taufel (Australia) made poor LBW decisions against SL. One LBW was given for a thick edge and the other for a ball going far away from the leg stump. When NZs were batting, umpire RE Koertzen warned Dilhara twice putting him under huge pressure. Another a tough LBW decision was given against Rose Tailer for a ball slightly missing the stumps. We can not guess why such experienced umpires give that much bad decisions in crucial matches like semi finals.

Even with that type of a situation, SL team came up brilliantly in batting, balling as well as fielding. NZ got the wicket of SL inform batsman Sanath Jayasuriya pretty early putting SL under pressure. But SL came back strongly with Upul Tharanga's 70 followed by the superb captains knock of 115* by Mahela Jayawardana. SL scored over 100 runs in the last 10 overs. In the NZ innings, it was just a series of perfect bowling to get them all out for 208 runs. My deepest sympathies to all the New Zealanders.

We were discussing about the match here (before the match). Congratulations Sri Lanka and all the very best wishes for the coming finals to bring the World Cup here again.

Sunday, April 22, 2007

World Cup Semi final on 24th: Sri Lanka vs New Zealands

Tomorrow (2007-04-24) is going to be a big big day for both Sri Lanka and New Zealand. Two teams meet each other in a crucial match, semi finals. In recent past, SL have done well against New Zealand. They once met in the super eight matches and Sri Lanka won comprehensively by 6 wickets.

According to news, the pitch at Sabina Park in Jamaica will have some bounce. This is said to be favoring NZs because SLs have much experiences on subcontinent wickets. But having the best balling department, SLs will be able to get the benefit of the bounce as well.

A quick comparison over the two teams

1. Captaincy:
Stephen Fleming, the New Zealand captain has more experience and is a good leading captain. But Mahela Jayawardane is one of the best positive captains in the world who has shown much colors in a lesser number of matches. So I weight SL has a good captaincy.

2. Balling attack:
NZ comes with one of the best ballers in the world, Shane Bond. But SL goes with 4 high class ballers: Vaas, Murali, Sanath and impressive Malinga. So SL has a huge advantage.

3. Batting:
NZ has a good batting line up starting with their captain, Fleming and following with Oram, Styris, McMillan and McCullum. SL comes with Sanath Jayasuriya (World's best batsman who frightens the opposite), following Sangakkara, Mahela, Chamara and Dilshan. So seems both have good batting attack. But it's a matter of getting some of them to show their class.

4. Fielding:
NZ is doing well of fielding, but they are not up to the level as much as SL. SL are putting huge pressure on the opposition by a showing a good team effort at the ground.

These are some comparisons, but the team that play as one unit and perform best will defeat the other. This is the first time NZ plays for a semi final in a world cup. So it will be a huge game for them.

But still I believe SL will beat NZ and go for the big final on 28th.

All the best wishes for SL from me and all the SL lovers. (Hope you are also joining with me to wish SL).

Tuesday, April 17, 2007

Open and read any file in a .war file of a web application with Java

Question: How can I open and read a file inside a war file of a web application?



Answer: InputStream can be used for this with a ClassLoader.




A code snippet for opening a file from Java for reading a file inside a web application is listed below. Commented line (InputStream inputStream = new FileInputStream(filePath);) shows the common approach used in non-web applications. Common approach is not usable with web applications (.war file) since it fails to find the files. Even though the correct relative path is provided, programs will face issues depending on the web server versions.





For web applications, the InputStream will be created using a ClassLoader. Following code snippet can be used for this requirement. But this approach has one limitation. This can read only the files inside WEB-INF/classes folder.
import java.io.InputStream;

public class WebAppFileReader {

public static void main(String[] args) throws Exception {

// full path: "C://projects//myWeb//WebRoot//WEB-INF//classes//testFile.txt";

String filePath = "testFile.txt";



// InputStream inputStream = new FileInputStream(filePath);

InputStream inputStream = WebAppFileReader.class.getClassLoader()

.getResourceAsStream(filePath);


int size = 10;

byte chars[] = new byte[size];

inputStream.read(chars);

String str = "";

for (int i = 0; i < size; i++) {

str += (char) chars[i];

}

System.out.println(str);

....

}

}


Note that only one change has to be made to make it read the files inside a web application. This is highlighted below.

1. InputStream inputStream = new FileInputStream(filePath);

2. InputStream inputStream = WebAppFileReader.class.getClassLoader()

.getResourceAsStream(filePath);



By replacing line #1 with #2, a class to read files of a web application is created. One important point to note is: WebAppFileReader is the name of the class in which these codes will be written. So if a different class is used with these code snippet, keep in mind to alter this line and add the class name of that.



Hope this will help you.

Friday, April 6, 2007

Cricket: Sri Lanka won by two runs over England in World Cup 2007


Sri Lanka vs England super 8 match was on 2007-04-04. They played an amazing match, it was the best game so far in this World Cup. Even that was one of the greatest matches I ever had watched.

Sri Lankans were all out for just 235 runs causing many discussions to calculate how many runs should have been added to make it a winnable score. Then England started batting, but they were 12/2 after 6 overs.

Over 20: Englands were in a comfortable situation, 100/2 with a RRR(required run rate) of 5.4. But this was easily reachable as Pietersen was batting impressively putting Sri Lankans under pressure.

Over 34: Pressure on Englands. They were 134/6, with a RRR of 6.4. And Sri Lankans needed only one wicket two celebrate the tail enders' fun. And England fans were dead silent.

Over 46: But that required wicket didn't fell and England batsman were rotating the strike well and they were 217/6 with a RRR of 9.5. But this was easily reachable as both the batsman were well established. It was just 19 runs from 12 balls.

Sri Lankans were under huge pressure, two more overs to go. Who should ball the late two overs?

Over 49: Lasith Malinga called for the 49th over. Big task for young Malinga.
1 1 0 1 W 4
This is a fantastic over. Malinga got the needed break through, but the last ball went for a four.

Over 50: Last over, 6 balls more to go, needs 12 runs. Who should ball the last 6 balls? Chaminda Vaas had two more overs, Sanath Jayasuriya had two more... No no it was Dilhara Fernando to ball the last over.
49.1 - 1 run
49.2 - 4 runs
49.3 - 2
49.4 - 1
49.5 - 1

Just 3 runs from the last ball, the well set batsman Bopara was facing. Dilhara came to ball the last ball, but stopped at the last second. Crowd get confused!!! He came back again, and balled him!
Oh! Dilhara balled him! Can you believe it? Sri Lanka won the match just by 2 runs.

What a fantastic game? You should have watched it.

Congratulations Sri Lanka.