Gurgaon Jobs, Companies and Consultants

Those who are looking for job in Gurgaon can visit this site : Gurgaon Jobs. Here you will find email ids/contact no of "Companies in Gurgaon" and also of "Placement Consultants in Gurgaon"

Tuesday, April 28, 2009

Amazing Script for Twitter Users

Today found one very good script which makes www.twitter.com very user friendly.

What value it will add to twitter :

  • Links in tweets are automatically expanded and replaced with the target page title if available
  • Hashtags are converted to Twitter search links
  • Auto-pagination is enabled as you get to the bottom of the current page. No need to click more button again and again
  • Media like YouTube videos and Twitpic images are included in-line in tweet
  • replies are included underneath the latest tweet, indented and smaller
  • Hovering over a tweet shows default actions like star (save), reply, and retweet
  • Long URLs are automatically shortened if the tweet you are typing in exceeds the length limit.
  • Twitter names get autocomplete launched by typing an @ in a tweet
  • Twitter bio text gets inserted into following/followers list
  • A tiny smilie face is added to the Twitter icon of those people who are following you
  • When viewing a specific Twitter user, Local time is added if the user's time zone is in their profile.
  • When viewing a specific Twitter user, their social graph is inserted in the bio area. Notes can be added to any user's Twitter page
  • When viewing a specific Twitter user, Map to user's location is inserted if location or geo coordinates are in their profile
  • You can add people( followers/following) to groups that show up in the Twitter sidebar

To use this script you must have Firefox.

Install link for Troys Twitter Script : http://tiny.cc/twitterscript

Try it if you are a twitter user if not register yourself(http://tiny.cc/twittersignup) its fun...

Enjoy....

Naresh

Thursday, April 23, 2009

Wednesday, April 22, 2009

Make Money from Twitter

I just want to share my expereince with a new concept i had found on Internet World.

How to start
:
--------------

To start earning money you need to have twitter account.
If not go to this url for signup : https://twitter.com/signup.

Once that is done next register your self with TwtAd
using this url : http://twtad.com/?id=777

How
TwtAd works :
----------------------

During registration they will ask you two things :

a) Your twitter account username and password
b) Paypal email id So if you have already paypal account then you can give that one otherwise
register yourself as individual on Paypal using this URL : http://tiny.cc/iTMIa. At paypal if you
want to give you account details or not its upto you. I had skipped that till i was about to
receive money from TwtAd.


After registration with TwtAd you can select ADS to be posted on your twitter account.
At first time i had selected 3 Ads which is max allowed in a day. Because of that my account was suspended by twitter considering as spamming. So be careful try with only one AD in start.

Once you select your AD then TwtAd guys will use paypal apis and will post tweet in your
account with URL mentioned for AD in it. If someody clicks it you will earn from it.
So in this way more clicks more earnings in your TwtAd account.

Each Ad has price with it for eample 0.1$, 0.7$, 0.8$...so choose max price AD.

You can withdraw amount from TwtAd only when it will reach to 20$ minimum balance.

One of the cool things is, you can have as many Twitter profiles as you want and post the ads on each one from the same TwtAd account.

Also TwtAd has a pretty referral concept as well - for each referral, you will receive 20% of their earnings for life.

So a simple, easy and fun way to earn money...

Enjoy....


Tuesday, April 21, 2009

An easy way to repay your home loan

Though it is advisable to increase your equated monthly installment to reduce your home loan tenure and help you repay your loan faster, you still need to keep it at comfortably manageable levels to be on the safer side.

Why is this the case you may wonder. A valid argument for you is, I would rather save on the huge interest cost by managing to pay a higher EMI, rather than pay a lesser EMI and face a long loan tenure.

There is a solution to get the best out of both the situations. The solution is to prepay.

You need not worry about the long tenure as you can prepay the amount that is around 3-4 times your EMI periodically like once a quarter or when your year end bonus comes through.

This will effectively help you manage your loan and consistently bring down the outstanding loan amount, as it will directly reduce the principal you owe the bank. Here the only thing you need to take into account is the prepayment fee, which some banks levy if your prepayment exceeds beyond a particular amount.

This could be anywhere between 1 per cent and 3 per cent of your outstanding loan amount. In this case, a handy strategy is to prepay within the limits specified by the bank periodically, which will significantly reduce your outstanding debt and help you close the loan early.

On the other hand, you can still consider prepaying in bulk if you wish to do so, in spite of the prepayment fee if the interest saved is significantly higher.

Here are some reasons that indicate why you should adopt this strategy.

a. Ideally banks offer loan amounts up to a limit of around 50 per cent of your income. This does not mean you should utilise the entire limit available.

Keeping EMI repayments within 30-40 per cent of your budget will help you save nearly 30-50 per cent of your income.

Money management experts recommend that you should try and save up to 60 per cent of your income to help you have enough funds to access, when in need. Though a home is an investment by itself in terms of a fixed asset, you would still need funds that can be liquidated at will, especially if you are a first time home buyer.

The right kind of investments will help you reap rich rewards long term and by saving in spite of EMI repayments will ensure that you start early to save more.

b. A long term loan like a home loan is a debt that is part of your budget every month. If you invest too much into it, there might not be adequate funds to manage a huge list of other expenses that will tend to accumulate with time. For example, you need to make allowances for future expenses like children's education, emergency funds for a job loss or the loss of one income in a situation where two people have taken a joint loan.

c. There might be spikes in interest rates. In such a scenario usually banks will increase the loan tenure in order not to put the borrower in a tight spot by increasing his EMI. In such a scenario if you can manage a slightly higher EMI you can request the bank to adjust the EMI, instead of extending your loan tenure.

d. On the positive side, when your income graph soars with time, as it is bound to under normal circumstances where promotions and job changes take place, you can always choose the prepayment route. It is best not to commit a higher sum that will burn a hole in your pocket, rather it should be the other way around where you can actually control the repayment pattern of your home loan.

e. A home loan may not be the only debt you incur. You might end up taking an education loan for your children or a personal loan for some other purpose. Your debt liability will be taken into account before banks sanction such loans. At such a juncture you will be in a position to leave enough room for one more loan, if need be. This could enable you to invest in a second home also in the long run.

f. Last but not the least, it is very easy to be stressed if some unexpected situation upsets the apple cart. You should have contingency plans in place to avoid your finances toppling like a house of cards leading to undue stress. Your life is something to be enjoyed and cherished, so don't entangle yourself in a web of debt and spoil the fun.



Tuesday, April 14, 2009

JMS : Java Messaging Service : HelloWorld / Sample Program!!

Recently i had learnt JMS and personally i have to do lot of google to write simple Hello World program. With all my learnings i want to save time of others who want to use JMS.

Basics :

You can read What is JMS ? Artchitecture of JMS ? from any site, some references :
http://en.wikipedia.org/wiki/Java_Message_Service
Also can refer Tutorial pdf in zip JMSHelloWorld.zip


Hope after some reading u are familar with terms of JMS. Let me summarize.
Basically core of JMS is Queues and Topics. I will stick to just queues.
For Queue we have Sender, Receiver who push and pop messages from it.
Overall we will register queue with unique name at JMS server(through command).
Then in our java code we will create ONE sender to send messages in queue AND
ONE receiver which will receive messages from Queue.

We will need one third party JMS Provider(mq: Open Message Queue) which will allow us to register Queues and that will provide us one JMS broker with whom we will connect. JMS Broker will take care of routing messages between queue. JMS broker will maintain messages either on file system or JDBC.

Softwares required :

I have JDK 1.5 installed on my PC and i had downloaded standalone Open Message Queue 4.3 from sun site. https://mq.dev.java.net/

Otherwise u can also download j2eesdk1.4 which is Sun Application Server
and it has same message queue as one component.

Now installing these software is easy just doing next next wizard. I had installed Open Message Queue at D:\software\Sun\MessageQueue.

U will need jms.jar(download from sun site) and imq.jar(after installation of MQ find from there) for Java development. These jars are also part of JMSHelloWorld.zip.

How to use Open Message Queue(MQ) :

For reference and install guide check one of PDF in JMSHelloWorld.zip. After installing we will need to learn few command line utilites of it i.e D:\software\Sun\MessageQueue\mq\bin.

Basically it has imqbrokerd.exe which is JMS Broker mind it. This has to be always RUNNING.
This is default broker which MQ provides and we will use same in our sample program.
So this broker listens on TCP port 7676. So identity of broker is localhost:7676.

Let us register queues in this broker :

Create one file pass.txt with content as :
imq.imqcmd.password=admin

Run this command :

imqcmd create dst -u admin -passfile pass.txt -b localhost:7676 -t q -n TestQueue

Check help of these commands for details or if any error.

So till now we had started our JMS Provider imqbrokerd.exe AND through commands registered one queue TestQueue. Now let us write Java :

JMSSenderWithoutJNDI.java :

QueueConnectionFactory connectionFactory = new QueueConnectionFactory();
/*This line will by default will provide u connection to JMS broker running at ur local machine

if u have ur broker at remote PC then use
connectionFactory.setProperty(ConnectionConfiguration.imqAddressList, "pcnamexyz:7676");

if u have broker over Internet(on webserver) use
connectionFactory.setProperty(ConnectionConfiguration.imqAddressList, "http://domainxyz:8080/imqhttp/tunnel");
*/
QueueConnection conn = connectionFactory.createQueueConnection();

QueueSession session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
/* NOTE : in same session do not create sender and receiver of same queue
*/
Queue queue = new Queue("TestQueue"); // other way is session.createQueue("TestQueue")

QueueSender sender = session.createSender(queue);

TextMessage textMessage = session.createTextMessage();

textMessage.setText("hello world");

sender.send(textMessage);
It is very simple to understand. We got connectionfactory and then created connection to JMS broker and then created one session and on session u can create sender, receiver. On sender
simple use send method.

JMSReceiverWithoutJNDI.java :

QueueConnection conn = connectionFactory.createQueueConnection();

QueueConnection conn = connectionFactory.createQueueConnection();

QueueSession session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

Queue queue = new Queue("TestQueue");
QueueReceiver receiver = session.createReceiver(queue);

conn.start(); // VERY critical step otherwise wont receive message

while(true) {
Message message = receiver.receive();
if (message instanceof TextMessage) {
TextMessage msg = (TextMessage) message;
System.out.println("Reading message: " + msg.getText());
} else {
// Means end of messages
break;
}
}

So our sample program is ready for run. Run sender and then run Receiver and see u got message printed at receiver or not. If yes then say thanks to me, if no try to resolve errors
or contact me on yahoo messenger for that go to link on right hand side.

Download JMSHelloWorld.zip which has sample programs, pdf tutorials, jars for reference.


Key Points for a decision whether to use JMS or not :

1. OpenMessageQueue supports peristence storage of queue messages means even if u restart
PC, messages will remain persisted. By default it uses File System to store messages at example
location : D:\software\Sun\MessageQueue\var\mq\instances\imqbroker\fs370.
U can also configure JDBC to store messages of queue.

2. OpenMessageQueue supports sending messages to a queue on local machine, remote machine or through internet. For internet/http they provide one war file imqhttp.war which needs to be deployed in Web Server(like Tomcat) and url of that can be used to send messages in Queue over internet. See pdf tutorials in zip for details.

Wednesday, April 08, 2009

Java Comparable vs Comparator

Both are used for sorting of java objects. but they are different from usage point of view.

Example Class : Employee has fields id, name, age.

java.util.Collections provides two methods which everybody uses for sorting in Java :

public static > void sort(List list)

Contract of this method is passed list elements MUST implement Comparable interface

public static void sort(List list, Comparator c)

Contract of this method is you have to pass your own defined Comparator

Now if you do not use neither Comparable nor Comparator what will happen :
In that at compile time it will give error when you will use Collections.sort();

Comparable :

Your Employee class must implement this interface which will force to write

public int compareTo(Employee employee1)

This method will return

+ve value if current object greater than employee1
-ve value if current object less than employee1
zero if current object equal to employee1

So if you want to sort by AGE of employee then compare that to return value.

Comparator :

You have to define new class like AgeComprator which will implement Comparator interface
that will force to write

public int compare(Employee emp1, Employee emp2)

This method will return
+ve value if emp1 greater than emp2
-ve value if emp1 less than emp2
zero if emp1 equal to emp2

So if you want to sort by AGE of employee then compare that field on emp1 and emp2
and accordingly return appropriate value.

Difference between two :

As you see in case of Comparable you can compare only by one of the field of Employee
either by Id, Name or Age. But using Comparator you can define three different comparators
and use any of them as per your need by passing in Collections.sort method. That's the basic difference between two.

General practice is to use Comparable for sorting in Natural order which can be based on any one of the field of Employee i.e natural sorting Otherwise if you need sorting by any of field of Employee then use Comparator.

In you program you can use BOTH use Comparable for natural ordering and use Comparator if you need to do sorting by any field other than implemented in Comparable for natural order.


Example of Comparator very good approach :

Instead of defining many classes IdComprator, NameComprator, AgeComprator,
use concept of enum so that it conveys to user what are options availaible for sorting.
See this :

public class EmpComparator implements Comparator {

________public enum SortOption {
__________SORT_BY_ID((short)1),
__________SORT_BY_NAME((short)2);

__________private short id;
__________private SortOption(short id) {
____________this.id = id;
__________}

__________public short getId() {
____________return id;
__________}
________}

________private SortOption selection;

________public
EmpComparator (SortOption selection) {
___________this.selection = selection;
________}

_______public int compare(
Employee emp1, Employee emp2){
________if(this.selection.compareTo(SortOption.SORT_BY_NAME) ==0) {
__________return
emp1.getName().compareTo(emp2.getName());
________} else {
__________return new Long(
emp1.getId()).compareTo(new Long(emp2.getId()));
________}
_______}
}

Java Thread : yield() Versus sleep(n)


If you call sleep(n), the sleeping thread will do nothing for that duration of the sleep. If no other thread wants CPU, then the CPU will remain idle.

if no other thread waiting, in case of sleep it is guaranteed that CPU will be idle for given time .


In contrast, if you call yield() , the yielding thread will carry on processing almost straight away
only if
no other thread wants CPU.

if no other thread waiting, in case of yield CPU will be in use same thread will continue processing.

Java Threads : Implement Runnable vs Extend Thread

Approach 1 :

class RunnableEgClass implements Runnable {

public boolean printThreadName;

public void run() {

if(printThreadName) {
System.out.println("Name : " + Thread.currentThread().getName());
}

}

}


Approach 2 :

class ThreadEgClass extends Thread {

public boolean printThreadName;

public void run() {

if(printThreadName) {
System.out.println("Name : " + Thread.currentThread().getName());
}

}

}


Usage of both :

public class TestThreads {

public static void main(String args[]) {

// Create 3 threads using approach 1
RunnableEgClass sharedObject = new RunnableEgClass();
sharedObject.printThreadName = true;

//Now u can use this same object and create n threads by passing it in constructor
Thread thread1 = new Thread(sharedObject); thread1.start();
Thread thread2 = new Thread(sharedObject); thread2.start();
Thread thread3 = new Thread(sharedObject); thread3.start();

// Create 3 threads using approach 2
ThreadEgClass thread4 = new ThreadEgClass();
thread4.printThreadName = true;
thread4 .start();

ThreadEgClass thread5 = new ThreadEgClass();thread5 .start();
thread5.printThreadName = true;
thread5.start();

ThreadEgClass thread6 = new ThreadEgClass();
thread6.printThreadName = true;
thread6 .start();
}
}


Two basic differences :

1. In Runnable each Thread is sharing same object whose run method will be called
but in extend each Thread is unique object. So Runnable allows sharing object across threads.
So if u see above example with Approach 1 we just need to set printThreadName once for all
three threads.
But with Approach 2 we need to set printThreadName three times for each thread. Clearly saving few lines of code.

2. After Extending Thread class that class will not be able to extend any other class. Multiple
Inheritance not supported in java.

Tuesday, April 07, 2009

Inside into JVM

A class file constains stream of bytecodes and for JVM these bytecodes are instructions.
Each JVM instruction consist of
a) one byte opcode : 3 reserved opcodes, 200 standard opcodes, 25 quick variations of some opcodes for dynamic binding
b) zero or more operands
opcode tells JVM what to do.
Example :
a7 goto(opcode)
fff9 operand which defined offset to jump
Menemonic for above instruction is goto and bytecode is a7 hex.
JVM architecture :
-------------------


JVM architecture


















Runtime Data Areas Shared Across Threads











In JVM Memory Locations are 32 bit long so there can be 2power32 memory locations.
Each memory location is of 1 byte. So maximum data stored is of 1byte*2power32=4294.96MB.
So each memory address will take 32 bits if need to store in some register.
Primitive Types : byte - 8bits,short (16 bits), int(32 bits), long (64 bits), float (32 bits), double (64 bits), and char (16 bits) and Object handle(32bits) pointer for address of object on heap.
JVM has stack oriented design so have very few registers.
Suppose a Thread is executing a method then
  • a new Stack Frame is created each time a method is invoked. A stack frame holds statefor current executing method (local variables, the parameters with which it was invoked, its return value (if any), and intermediate calculations).
  • Program Counter or PC register : If the thread is executing a Java method (not a native method), the value of the pc register indicates the next instruction to execute.
  • optop ,frame register ,vars register : point to various parts of the stack frame of the currently executing method
Basically a stack frame contains the state of one Java method invocation.

Wednesday, April 01, 2009

Did you know?

Einstein retarded?

Einstein couldn't speak fluently until after his ninth birthday. His parents thought he was mentally retarded.

Invention of the microwave oven

The microwave oven was invented after a researcher walked by a radar tube and a chocolate bar melted in his pocket.

Cuttle fish blood

The colour of cuttle fish blood is blue and it has 3 hearts.

Libya's flag

Libya is the only country in the world with a solid, single-colored flag, it's green.

Caesar superstar

Julius Caesar’s autograph is worth about $2,000,000.

Domestication

In the last 4000 years no new animals have been domesticated.

Hyoid bone

The hyoid bone, in your throat, is the only bone in the body not attached to another bone.

Hot Lightning

The heat a lightning bolt produces is five times hotter than the surface of the sun.

Pearls vs Vinegar

Pearls melt in vinegar.

Atomic fart

If a man farted non-stop for six years and nine months and then lit it he would produce an explosion equal to the power of the first atomic bomb.

Muscles

A caterpillar has 2000 muscles, as compared to man who has only 656 muscles.

Cockroaches vs glue

Cockroaches' favorite food is the glue on envelopes and on the back of postage stamps.

Toast and War

French toast was known as German toast until World War One.

Giraffe's baby

When a giraffe's baby is born it falls from a height of 2 meters, normally without being hurt.

Earth quakes and lightning

The Earth experiences 150 earth quakes each day and is hit by lightning 100 times a second.

Blue whale

A blue whale needs 3 tonnes of food everyday.

PageRank

The basis of Google's search technology is called PageRank™, and assigns an "importance" value to each page on the web and gives it a rank to determine how useful it is. However, that's not why it's called PageRank. It's actually named after Google co-founder Larry Page.

All eyes on you

The butterfly has 1200 eyes. These are compound eyes consisting of thousands of hexagonal shaped omatidea. Each omatidea, or miniscule sensor, is directed at a slightly different angle from the others. Collectively they are directed in every direction -- up, down, forwards, backwards, left and right. Because of this, butterflies are able to see in virtually every direction simultaneously.

Albania maps

Until 1994, world maps and globes sold in Albania only had Albania on them.

Busy bees

Bees have to suck about 4 million flowers to produce 1kg of honey.

Bladder size

The bladder of an average person can hold 350 ml to 550 ml of urine. Generally, a person feels like they need to urinate when approximately 200 ml of urine fills up in the bladder.

Google's start

Google started as a research project at Stanford University, created by Ph.D. candidates Larry Page and Sergey Brin when they were 24 years old and 23 years old respectively (a combined 47 years old).

The Guinness Book holds a record of its own

The Guinness Book of Records holds the record for being the book most often stolen from public libraries.