Pages

Saturday 19 May 2012

Srt file reordering


You will find lots of srt files(i.e subtitles) not matching with your video sometimes if you download two files from different sources( If you download from same source you may not have this problem ). So in this case we can just reorder the time using simple programming. Just measure the time in milliseconds to reorder and you are done below i included one java code for the same . So please download it and your done just execute it .
It requires java run time to be installed in your machine. From command line go to the path where you have the jar file and execute
java -jar SrtReordering.jar
follow the instructions remember you have to enter the time in milli seconds. For any queries/suggetions please comment below.
link for the jar file is:
http://www.mediafire.com/download.php?s7sx8u3y8ozom1u

Thursday 17 May 2012

Google Plus User Count Program

I read an article about how to count the number of users on google plus. It says you can count the number of users in google plus by using its sitemap. The below is the URL for google plus sitemap .
So first you write a program which reads the url so it reads the xml file. In that xml you will find lots of sub url's those are text files so fetch all the url's into a list using any xml parser and recursively traverse all the url's and count the number of users.
The sub url file(i.e text file) will looks like the above picture. So while counting leave the entries with profile.google.com so at the end you will have the count of the number of users registered for google plus. In the xml file you will find an entry with the name modified date. So you can say you have the number of registered users on google plus up to that modified date.


Monday 12 March 2012

for Each loop

Java for each loop is a new feature from 1.5 version.It is used to iterate over arrays.
for example

String[] flowers={"rose","lilly","daisy"};
System.out.println("The flowers are");
for(String flower : flowers){
System.out.println(flower);
}

It will print

The flowers are
rose
lilly
daisy

so from the array flowers it fetches all the individual elements and assigns them to the new local variable flower.
It works for all types of arrays.We can use it for multi dimensional arrays also.

Tuesday 17 January 2012

sendRedirect vs RequestDispatcher

As you may already know that sendRedirect method in response object and RequestDispatcher object both are used to  redirect to another page in servlets,but both works in a different fashion.
RequestDispatcher forwards the request,response objects to another page/servlet this happens at the server side.
where as sendRedirect method makes a new request from client side but client is unaware of the process.

for example if you say in real time
if X is asking about some information to Y
if Y is confirming with Z and telling you the answer is RequestDispatcher mechanism.
or if Y is telling you that ask Z for that information then that is sendRedirect we can say(but client i.e X is unaware of the process since it is a automated flow of process that hapeens).

By using RequestDispatcher the url in the client browser will be the first page address(i.e Y in example),
in case of sendRedirect it changes to the second page address(i.e Z).

Monday 9 January 2012

Null Pointer Exception

The most commonly seen exception(in java) for everyone is ofcourse nullpointerexception. In this post we will see how this eception occurs and how to get rid of it.

               As you might know java is a object oriented language if we want to call any method that has to be done by using object reference. So if at all a call to a method which is refering to null will throw a null pointer exception
           for example
     ArrayList list=null;
    list.add("hai");
 will throw null pointer exception so when ever you get such kind of exception just go to the line check the object which is calling the method is not refering to null.

Saturday 7 January 2012

Java toString method


java's toString method is useful for giving string description about a  class so it's better to override tostring method for every class
for example
Class A{
public String toString(){

return "sample class written by iTfinGer";
}
public static void main(String[] s){
A a=new A();
System.out.println(a);
}


}

In the above program it will print the String returned by toString method not the hashcode of the object
So the output for the above program is

sample class written by iTfinGer

-------------------------
Class A{

public static void main(String[] s){
A a=new A();
System.out.println(a);
}

}


but the above code prints the  Hashcode.