I want to know when does a transaction gets registered in a block ? Is there any queue type of structure where the transactions get stored before getting included in a block by miner ??? As in let's say if i have transferred 1 eth to my friend and announce that transaction to the block chain, how much time will it take to get included in a block and block to get attached to the block chain ? And also on what basis miners select which transactions to include in the block, is it on the first come first serve basis ? And if they don't want my transaction to get included in the block they are about to mine then in that case what happens to my transaction and the amount of ether i have send to my friend ???
There is a lot to understand regarding this question, but I will answer it in a very simple way.
Approximately every 15 seconds, a new block gets created that includes many transactions in it. If you sent 1 ETH to your friend, this transaction may be included in this specific block. If not, it may be included in the next, or the next, and so on.
Miners are the ones who create blocks and choose transactions. If a miner mines a block, and chooses your transaction to be included in that block, then your transaction will have executed successfully.
A big aspect to understand is gas. With each transaction you make, you pay a small amount of gas as a fee to the network (read: miners). You can choose how much gas you send (anywhere from less than $0.001 to >$1000 and beyond), but typically transactions are sent with whatever is average at the time of sending.
When a miner chooses a transaction to be included in a block, they get paid that fee that the user paid for their transaction. Typically, miners choose the transactions that will yield the most profit, so they will simply choose transactions that pay the highest fee.
If you send too little gas, and other people continuously send transactions with more gas, your transaction could potentially be stuck pending for a very long time. In order to get around this, you can resend the same transaction with a higher gas price, thus incentivizing a miner to include it in the next block.