Friday, May 20, 2011

Overriding the Overloaded

Most of the java programmers would have faced this problem, like i did.

I was reading about Collections and there was a line in double quotes in that web page..

"If you want to use equals() method for your class, you have to write hashCode() also".....

An any developer would do, i started writing a program to try this and i wrote following code

public class Emp{
private String Name;
private int code;

public int hashCode(){
return code;
}

public equals equals(Emp that){
return that.code == this.code;
}

}

COMPARISON NEVER WORKED ....

Can somebody explain me the reason ???????????????

Monday, March 14, 2011

Making of "Ringtone" .........

All of us want new ringtones and we waste lot of time searching for them on the WWW. Do you know we can create ringtones without installing any additional software on our machine !!!.

Let us explore the making of "Ringtone" ....

System requirements:
==> Windows XP or above


STEP 1:
Open windows movie maker Start -> Programs -> Windows Movie Maker

STEP 2:
On the left side you will see options to import Video, Pictures , Audio files etc.

STEP 3:
Click on import Audio and select the file you want to cut / use for creating ring tone.
Now you should be able to see the selected file in the Collection: Movie window.
Drag and drop the file on the Time-line at the bottom.

STEP 4:
Now you can cut the audio file by clicking and dragging the mouse on the Time-line as shown below.




And this is how we cut the unwanted parts form the Audio file.

STEP 5:
Now save the file using File -> Save Movie File. Enter the File Name and select the output directory.

The Ringtone is ready in the output directory.

NOTE:
For phones which can play audio in wav format, just copy the ringtone created in the phone and set it as your ring tone. Otherwise you can convert the .wav file to .mp3 format online or by downloading a free converter software.

Enjoy your new ringtones...

For any queries : g.santoshpai@gmail.com

Tuesday, December 7, 2010

Start and Run ..... Why do we need both ???

This post is about Java Threads. Usual way of starting a Thread ( As all the Java books mention ), is to call start() method on a Thread object. Consider the following code

public class ThreadExample
{
class ThreadImpl implements Runnable
{
public void run()
{
System.out.println("Inside run method");
}
}

public static void main(String[] ar)
{
Thread t1 = new Thread(new ThreadImpl (),"T1");
Thread t2 = new Thread(new ThreadImpl (),"T2");
t1.run(); // This code doesn't start the Thread, instead calls the method run() on "t1".
t2.run();
}
}

Here, instead of t1.start(), we have used t1.run().

When start() method is called Thread is created by the underlying platform and scheduler takes care of all such Threads now on. But when we call run(), it is just another method on a Java object and is not given to Thread scheduler.

Conclusion: If you want to write a multithreaded program, then always use start() method, else you can use run().

Proof for above statement: According to Thread design document by ORACLE (Sun), A Thread in the DEAD state can never go back to RUNNABLE state. That means, it is impossible to call start() method twice on a Thread, as shown below.

Thread t2 = new Thread(new ThreadImpl (),"T2");
t2.start();
t2.start(); // Throws an Exception,as Thread cannot go to RUNNABLE from DEAD state.

Where as, run() method can be called as many times as you want like any other method.

Hence Proved.

Java Threads - Implements Runnable V/s extends Thread


Java Threads - Implements Runnable V/s extends Thread class

Threads are very important part of any computer system, that wants to do multitasking. Threads are called low-weight processes. A process is a program under execution. Program has a text part, data part. It has memory to use for it's execution. Threads share this memory, so communication between threads is very simple and not costlier compared to IPC.

Java provides support for multi threading and also in java it is very easy to play with them.

The below article is for people who already know how to implement a Thread in java. Java gives users, 2 options. Either they have to implement Runnable interface Or they have to extend from Thread class. Only then any class, say "X" can be Thread scheduled.

Thread scheduler is part of OS and not part of JVM. So the ways threads behave changes from platform to platform.

Why do we have 2 ways of creating Thread classes ?

First thing we have to keep in mind that, Java doesn't support multiple inheritance. i.e, "class A extends B,C" is not true, where as "class A implements B,C" is true.

So if a class X extends Thread, then it cannot extend from any parent (So sad :-( ). In order to avoid this, Runnable interface is defined and it is always better to use interfaces than extending from a parent.









Monday, January 11, 2010

Eclipse Problems and solutions

Problem: Eclipse opens the project and shows and ‘X’ mark at the project folder. The entire java build path etc is proper. Cleaning the propjet works, but building the project fails. The progress bar stops after showing “Copying resources to folder”.

Solution: Goto project --> properties --> Build Path . Change the output folder to some other name ( usually it will be bin , change to bin1 etc ).

Root Cause : Not known .

<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>


Problem: A java error comes .... "ClassNotFoundException a.b.c.DOMParser" .. During compile time / run time

Solution: Find out the jar file for this class and append the path to the classpth variable. Ex: add D:\Hui\xcers.jar to classpath to support DOMParser

Root Cause : No class file found in the class path .


<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>



Problem: Tomcat was getting started and closed immediately without server stating completely.

Solution: The CLASSPATH environment variable was having 2 values "D:\xx\xxxx\tools.jar;D:\xx\xxxx\xcerse.jar"
I removed the last one and the semicolon.Tomcat is coming up and running.

Root Cause: NO idea....

<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>


Problem: When compiled a project, an error is shown ==> "

The hierarchy of the type is inconsistent"


Solution: Find the classes which the faulty class extends and make those base classes compile clean / If they are missed in the project source files, add them.


Root Cause : Suppose the class name here is A and A extends B, then the error is shown ifB is not compile clean / It is missed in the project source files.




Saturday, December 12, 2009

Advantages of Being in Koramangala

Hello People ,
If you are a bachelor / married / old age and looking for a house in a good locality in bangalore ... Give first priority for Koramangala .... You have all these advantages ...

Houses and Rent : If you are a bachelor , the best area is near Forum ( 5th block ) or BDA Park ( 8th block ). You will get a 2BHL for 7-8K and a 1BHK for 3.5 - 4 K , with advance of 30K - 50K .

Food : For both veggies and non Veggies , there are restaurants almost on each and every road . All are open till midnight and some are open till 4AM . So no problem for food !!!!!!

Parks : Koramanagala has lot pf parks maintained by BDA . They are really good and you can go there with anybody at any time ......

Pubs : There are more pubs than roads in Koramangala . You can spend your weekends here .... !!!!!! ... But please "Don't Drink And Drive" ...

Hopcoms : There are many Hopcom shops , for vegetables , fruits etc .

Koramangala Plus : Koramangala Plus is a free magazine , which you get once in a month .You will get all news about hot and happenings in you area / block.

Hospitals and Medical Shops : You can find doctors all over koramangala and also medical shops .

Lots of Gods : Siva , Ganesha , SaiBaba temples are everywhere in koramangala .

Camel Ride : Every weekend , a boy comes with a camel . You can enjoy Camel Riding on saturdays .

Malls in Koramangala :
<1> Forum Mall
<2> Big Bazaar
<3> Start Bazaar
<4> Monday to Sunday
<5> Raheja Arcade
<6> BDA shopping complex
<7> Oasis Mall
<8> Lifestyle
etc etc etc ...

Koramangala is the bangalore's Hottest Area :-) .,.... Be Hot and See Hot ....


Friday, October 9, 2009

Reverse Math == Proof for 1=2

Hi ......

Here is the proof finally ....

Let
-20 = -20

Can be also written as
25-45 = 16-36

also
5 * 5 - 9*5 = 4*4 - 9*4

also
5 ^2 - 9*5 = 4^2 - 9*4

Add (9/2 )^2 on both sides
5 ^2 - 9*5 + (9/2 )^2 = 4^2 - 9*4 + (9/2 )^2

Also
5 ^2 - 9*5* (2/2) + (9/2 )^2 = 4^2 - 9*4* (2/2) + (9/2 )^2

Can also be written as
5 ^2 - 2*5* (9/2) + (9/2 )^2 = 4^2 - 2*4* (9/2) + (9/2 )^2

Are of the form a^2 - 2ab + b^2 ........

So,
(5-9/2)^2 = (4-9/2)^2

Taking square root both sides ,

(5-9/2) = (4-9/2)

Cancel common 9/2 from both sides

5 = 4 implies 1 = 0
???????????????????????????????????????????

............. Forgot Maths ???????????? ......Dont you think i should get PhD for this ?????