Search This Site

Custom Search

Monday, December 29, 2008

21st Century.... We are becoming lesser by the day

21st Century....

We are becoming lesser by the day

Our  communication - Wireless

Our  dress - Topless

Our  telephone - Cordless


Our  cooking - Fireless

Our  youth - Jobless


Our  food - Fatless

Our  labour - Effortless

Our  conduct - Worthless

Our  relation - Loveless


Our  attitude - Careless

Our  feelings - Heartless

Our  politics - Shameless

Our education - Valueless


Our follies -  Countless

Our  arguments - Baseless

Our Job - Thankless

Our Salary - Very Very less  

Santa Jokes

SUHAGRAAT KE DIN SARDARNI BOLI: AAJ DUNIYA KA SABSE GANDA KAAM KARDO.
SARDAR NE PENT UTARI OR POTTY KAR DI BED PE.
 
SINGH IS KING...
 
EK ADMI : YAAR YEH SCOOTY KAB LI?
SARDAR : KAL RAAT 1 LADKI MUJHE SCOOTY PE BHOT DUR LE GAYEE, SAB KAPDE UTARKE BOLI JO CHAIYE LELO, MAIN SCOOTY LE AAYA KAPDO KA KYA KARNA THA.
 
 
Santa: Ghar ka saara keemti samaan chhupa ke rakh do, mere dost aa rahe hain.
Jeeto: Kyon! Aapke dost chura lengey?
Santa: Nahin, pehchan lengey
 
A sweet girl goes to Banta's shop and said: Mujhe underwear dikhao.
Banta sharmate hue: Aaj pehan kar nahin aaya.
 
Santa: Woh ladki kitni sundar hai!
Banta: Mujhe uska naam pata hai..
Santa: Kya naam hai uska?
Banta: Woh bank mein kaam karti hai, uske counter ke upar uska naam likha tha "CHAALU KHAATA"
 
Translation from hindi to english, "Khushi ke mare uski chaati phool gayi".
Santa: Due to happiness, his chest became breast.
 
Santa ki shaadi ek Nurse se ho gayi.
Banta: Aur santa, kaisi nibh rahi hai?
Santa: Pooch mat yaar, jab tak sister na kaho, bolti hi nahi
 
In a train compartment husband: Darling, mujhe to tumhari aatma se pyar hai, tumhare jism ki mujhe koi chah nahin. Main tumhari rooh ko chahta hoon, tumhara shareer to main kutton ko daal doon.
Banta sitting on upper berth says: BOW BOW
 
Banta: Yeh chaaku kyon ubaal rahe ho?
Santa: Suicide karne ke liye
Banta: To phir ubalne kui kya zaroorat hai?
Santa: Kahin infection na ho jaaye
 
Girl: Will u marry me?
Santa: No, humare yahan shaadi sirf relatives mein hi hoti hai. Mummy ne Papa se, Didi ne Jijaji se aur Bhaiya ne Bhabhi se
 
Nurse came out with the newborn kid, Santa rushed 2 her & after seeing the kid he shouted, BETA hua BETA. She slapped him: Leave my finger, u fool, It's a gal

 
Santa dials a number. A girl receives the call.
Santa: Who r u?
Girl: Seeta here.
Santa: Maine to Chandigarh phone kiya tha, yeh to Ayodhya mil gaya
 
Santa ke bagiche mein bahut sare ped - paudhe thay, Santa naukar ko bola ped-paudhon ko pani dal.
Naukar: Sahab baarish ho rahi hai.
Santa: Abe to Chatri leke dal.
 
Banta: Truck dekhkar tum kaampte kyon ho?
Santa: Ek truck driver meri biwi lekar bhaag gaya tha, har baar lagta hai jaise usko vapas karne aaya hai.
 
Santa to Pappu: Where's Sukhna Lake?
Pappu: Pata nahi.
Santa: Kabhi ghar se bhi nikla karo.
Pappu: Who's Banta?
Santa: Pata nai.
Pappu: Kabhi ghar me bhi raha karo.
 
Santa: Do you know English?
Banta: Yes
Santa: Ok! Then tell what is the opposite of NAAG PANCHAMI?
Banta: So simple Yaar... NAAG DO NOT PUNCH ME.
 
Santa & banta sending sms 2 their gfs. Santa:mai tere mobile se apni gf ko sms bheju dekhte hain kya kahti hai? Banta: No, agar usne handwriting pehchan li to...?
 
Santa's urine report got exchanged with a ladies pregnancy report.
Dr. told santa, "you are pregnant".
Angry santa shouts at wife, "Maine pehle hi kaha tha, mujhe upar rehne de".
 
Santa was inserting dog's tail into pipe.
Banta: Oye, kutte ki dum kabhi seedhi nahi hoti.
Santa: Idiot, main to pipe bend kar raha hoon.
 
Santa: Bhaisahab time kya hua?
Man: Sham ke 6 baje hain!
Santa: Sala, subah se pooch raha hoon, sab alag alag time bata rahe hain.
 
Frog: Tumhare paas dimaag nahin hai.
Santa: Hai.
Frog: Nahin hai.
Santa: Hai.
Frog: Nahin hai & jumps into the well.
Santa: Isme suicide karne waali kya baat thi.?

Friday, December 19, 2008

New Jokes

1) What is the similarity between Bill gates and me? Dont know? So simple, He never comes to my house and I never go to his house ...EGO PRoblem

************ ********* ********* ********* *

2) We sms Each Other B'coz U Think Im Nice i Think Ur Nice U Think Im Cool i Think Ur Cool U Think Im Sweet i Think Ur Sweet U Think Im Smart i Think Ur RigHT

************ ********* ********* ********* *

3) Who Said English is Easy

Fill this blank with
Yes or No?

1. __ I don't have a BRAIN.

2. __I dont have SENSE.

3. __I am STUPID.

************ ********* ********* ********* *

4) I can't live without u. Without u I can't even imagine 2 exist. U r in my breath, I can't live without u even for a second.

HOLD ON...HOLD ON...
Itna khush hone ki jarurat nahin hai, I am talking about OXYGEN.

************ ********* ********* ********* *

5) I was writing 3 Good Lines about u i wrote:

1.. )_______

2. )_______

3. )_______

nalayak kuchh to accha kiya hota life mein, tabhi likhta.

************ ********* ********* ********* *

6) I want to Share 'EVRYTHING' with U. Your JOYS ur SADNESS, ur HAPPY MOMENTS. Every Single SECOND OF THE DAY. Let's START with Your "BANK A/C

************ ********* ********* ********* *

7) When cloud breaks rain falls, When coconut breaks water falls, When luv breaks tears fall, But.. When ur HEAD breaks.. Aailaa !!! Khali hai!

************ ********* ********* ********* *

8) U r sweet U r caring U r artist U r kind U r intelligent U r atractive U r smart thoda aur IMPROVE karo Tabhi mere jaise banoge.

************ ********* ********* ********* *

9) Aaj ye baat samjh aai,is dharti par Apki hukumat samjh aai,apko dharti par bhejna khuda ka bahana tha,kyunki ravan k bad kisi ko to aana tha..

************ ********* ********* ********* *

10) A woman worries about the future until she gets a husband. A man never worries about the future until he gets a wife..

************ ********* ********* ********* *

11) PanditJi ne apke mobile ki rashi dekh kar bataya hai ki aapke mobile pe KANJOOSI ki mahadsha mandra rahi hai. Turant 21 Sms ka yagna karvao

************ ********* ********* ********* *

12) Shukriya karo oos khuda ka k usne hume banaya hai... kyonki ek pyaara, achchha, smart,cute Handsom sa dost humne na sahi tumne to paya hai

************ ********* ********* ********* *

13) Ishq ne insaan ko kya se kya bana diya, kisiko ashiq to kisiko deewana bana diya, 2 phool ka boj na utha sakti thi mumtaj,  shahjahan ne pura taj mahal mumtaj par bana diya.

************ ********* ********* ********* *

14) There once lived 4 friends, Mad, Brain, Sumbody, Nobody. 1 day, Sumbody killed Nobody. That time Brain was in toilet Mad called the police.
Mad: Is it police station?
Police: Yes,what is the matter?
Mad: Sumbody killed Nobody
Police: R u mad?
Mad: Yes, Iam Mad
Police: Dont u have brain?
Mad: Brain is in the toilet.

************ ********* ********* ********* *

15) Main aapko dekhna chahta hoon, aapse milna chahta hoon, par yeh log bahut zalim hain kehte hain


"ZOO"bandh ho gaya kal aana...

************ ********* ********* ********* *

16) Sweet persons talk from HUTCH. Lovers talk from AIRTEL. Beggers talk from BSNL. Beuties talk from SPICE. But BRILLIANTS never talk. They send SMS

************ ********* ********* ********* *

17) Asmaan per jitne sitare hain! Ankhon main jitne ishare hain 'Samander ke jitne kinare hain " UTNE SCREW DHEELE TUMHARE HAIN " ha ha ha

************ ********* ********* ********* *

18) Wife:kal raat tum neend me mujhe gaaliya de rahe the.
Husband:Tumhe galat fehmi hui hai.
Wife:kaisi galat fehmi?
Husband:Yehi ki main soya hua tha.

************ ********* ********* ********* *

19) Sardar Director: U Should jump 2 d swiming-pool frm 100 ft Height.
Actor: i don't know swimming.
SardarDirector: don't wory, their is no water.

************ ********* ********* ********* *

20) Hi jaan_
Kya haal hai jaan_
Kaha ho jaan_
Kab miloge jaan_
Tumhari badi yaad aa rahi hai jaan_
Zyada khush na ho.
Har blank _ mein " var" word add kar lena.

Wednesday, December 10, 2008

Mast Joke

A Gujrati, a Madrasi and a sardaar were doing construction work onscaffolding on the 20th floor of a building. They were having lunch and Gujju opened his lunch box & said, "Dhokla ! If I get dhokla one more time for lunch, I'm going to jump off this building." The Madrasi opened his lunch box and exclaimed, "Idli Sambhar again! If I get idli sambhar one more time I'm going to jump off too." The sardaar opened his lunch and said, "Parontha again! If I get a parontha one more time, I'm jumping too."

The next day, the Gujju opened his lunch box, saw dhokla, and jumped to his death. The Madrasi opened his lunch, saw idli sambhar, and jumped, too. The sardaar opened his lunch, saw the parontha and jumped to his death as well.

At the funeral, Gujju's wife was weeping. She said, "If I'd known how really tired he was of dhokla, I never would have given it to him again!" The Madrasi's wife also wept and said, "I could have given him dossa! I didn't realize he hated idli sambhar so much."

Everyone turned and stared at the sardaar's wife...... The sardaar's wife said, "Don't look at me. He makes his own lunch."

Tuesday, December 9, 2008

Just a Question

Lawyer's question
 
A small town prosecuting attorney called his first witness to the stand in a trial--a grandmotherly, elderly woman.
 
He approached her and asked, "Mrs. Jones, do you know me?"

She responded, "Why, yes, I do know you Mr. Williams. I've known you since you were a young boy. And frankly, you've been a big disappointment to me. You lie, you cheat on your wife, you manipulate people and talk about them behind their backs. You think you're a rising big shot when you haven't the brains to realize you never will amount to anything more than a two-bit paper pusher. Yes, I know you."

The lawyer was stunned. Not knowing what else to do he pointed across the room and asked, "Mrs. Williams, do you know the defense attorney?"

She again replied, "Why, yes I do. I've known Mr. Bradley since he was a youngster, too. I used to baby-sit him for his parents. And he, too, has been a real disappointment to me. He's lazy, bigoted, he has a drinking problem. The man can't build a normal relationship with anyone and his law practice is one of the shoddiest in the entire state. Yes, I know him."

At this point, the judge rapped the courtroom to silence and called both counselors to the bench.

In a very quiet voice, he said with menace, "If either of you asks her if she knows me, you'll be in jail for contempt within 5 minutes!"

Monday, December 1, 2008

A Few Sweet Jokes

Hi Good Morning,
 
1. Vent: How's that you came first in a sports event but you were not given a prize. Come on... tell me what is that event?
Johny, the doll: It was slow cycle race!

2. Vent: Do you sing well?
Johny: I got second prize in my class.
Vent: Very good... How many participated?
Johny: Only two!

3. Vent: Ok... Tell me whether the winner sang well...?
Johny: No... He did not sing at all!
Vent: Then, how they selected him as winner?
Johny: They heard my song... Immediately, they selected him as winner.

4. Vent: Well, did you sing any song in public?
Johny: Once I did.
Vent: Then what happened?
Johny: The Chief Guest came and gave me Rs.2000/-
Vent: Very good. So, you got Rs.2000/- for your singing?
Johny: No... Only to stop my singing!

5. Vent: Why did you put on a cloth screen on your computer?
Johny: Because it has got windows!

6. Vent: What is the difference between you and the computer?
Johny: Computer "copy" and then paste...
But I paste and then (take) cofee!

7. Vent: Why did you have such a big password--Rama Lakshmana Seetha Kaikeyee Ravana Dasaratha?
Johny: You only said that I should have six characters!

8. Vent: Do you know Actor Kamal Haasan?
Johny: Yes... He acted with me in the movie "Avargal". He is residing opposite to my house!
Vent: Where is your house?
Johny: Opposite to his house!
Vent: Ok baba... Where are both the houses?
Johny: Opposite to each other!

9. Vent: You know anything about Rajinikanth?
Johny: I know his wife's name...
Vent: I myself don't know. Ok... What is her name?
Johny: Mrs Rajinikanth!

10. Vent: You like Kamal Haasan or Vikram?
Johny: I like Kamal Haasan...
Vent: Why?
Johny: He is "Indian"!
Vent: What about Vikram?
Johny: He is "Annian"!
Vent: Director Shankar booked as the hero for his next movie. What is the name of the movie?
Johny: "Saniyan!"

Wish you all a good health!

Good Jokes

Speeding Charges

Tyler and Katz, two judges, were each arrested on speeding charges.

When they arrived in court on the appointed day, no one was there. So instead of wasting time waiting around, they decided to try each other.

Motioning Tyler to the stand, Katz said, "How do you plead?"

"Guilty," replied Tyler.

"That'll be fifty dollars and a warning from the court," said Katz.

Katz stepped down and the two judges shook hands and changed places.

"How do you plead?" asked Tyler.

"Guilty," replied Katz.

Tyler reflected for a moment."These reckless driving cases are becoming all too common of late," he pointed out. "In fact, this is the second such incident in the last quarter hour. That'll be two hundred dollars and ten days in jail!"

Two Strangers

Two strangers, a man and a woman, meet in a cafe.

The man asks, "My Dear, would you go to bed with me for a million dollars?"

"A million dollars?" the woman inquired. "Well, yes, I guess I would."

"OK," the man said. "Would you go to bed with me for $100?"

The woman was aghast. "What kind of person do you think I am?" she exclaimed.

The man replied, "My Dear, we have already established that. We are merely haggling over the price!"

Father Of Who

A man walks into a supermarket and notices a beautiful woman staring at him.

She stares for quite some time, so finally the man asks, "Do I know you?"

The woman answers "I think you're the father of one of my kids."

The man thinks for a minute, then realizes this kid she is talking about must be the result of the one and only time he ever cheated on
his wife.

He says to the woman, "Are you that exotic dancer that was at my best friend's bachelor party about 5 years ago? You know, the one I did it with on the pool table while everyone was watching?"

The woman looks at him horrified and says, "No, I'm your son's teacher."

Firewood

Floyd picked up the phone and called the Sheriff's Office.

"Hello," he said. "Is this here the Sheriff's Office?"

"Yes it is," the voice came back. "What can I do for you?"

Floyd replied, "I'm callin' to report my neighbor, Virgil Smith. He's drillin' holes in his firewood and hidin' marijuana inside!"

"Thank you very much for the call, sir," the voice replied.

Within the hour, the Sheriff and his deputies descend on Virgil's house. They search the shed where the firewood is kept. Using axes,
they split every piece of wood, but find no marijuana. They sneer at Virgil and leave.

The phone rings at Virgil's house. "Hey, Virgil, This here's Floyd. Did the Sheriff come?"

"Yeah!" Virgil answers.

"Did they split yer firewood?" Floyd asks.

"Yep!" Virgil answers.

Floyd says, "Happy Birthday, Buddy!"

Going to Vegas

A man came home from work one day to find his wife sitting on the front porch with her bags packed.

"Where are you going?" he asked.

She answered, "I'm going to Las Vegas."

"Now what brought this on?" he asked.

She answered, "I just found out that I can make $400.00 a night doing what I do for you for free!"

He pondered that for a while, went into the house, packed his bags and returned to the porch.

His wife said, "And just where do you think you are going?"

He replied, "I'm going, too."

"Why?" she asked.

He said, "I just have to see how you are going to live on $800.00 a year!"

Sunday, November 30, 2008

Todays Jokes

A man walks into a bar with his pet monkey.  He sits down at the bar to have a drink when the bartender screams, "Did you see what your Monkey just did?"
 
"No, what?" asks the man
 
"He just ate the cue ball off my pool table.........WHOLE!"
 
"Yeah, that doesn't surprise me," replied the guy, "He eats everything in sight, I'm sorry. I'll pay for the cue ball and stuff."
 
The guy finishes his drink, pays his bill, pays for the stuff the monkey ate and leaves.  Two weeks later the guy is in the bar again and has his Monkey with him.  He orders a drink and the Monkey starts running around the bar again.  While the man is finishing his drink, the Monkey finds a bowl of Maraschino Cherries on the bar.  He grabs one, sticks it up his butt, pulls it out and eats it.  Then the Monkey finds a peanut, again sticks it up his butt, pulls it out and eats it.
 
The bartender is disgusted, "Did you see what your Monkey did now?"
 
"No, what?" replied the man.
 
"Well, he stuck a cherry and a peanut up his butt, pulled them out and ate them!" said the bartender.
 
"Yeah, that doesn't surprise me," the guy replied, "He still eats everything in sight but ever since he had to shit that cue ball, he measures everything first."

 

*************************************************************************************************************************************

 

Universal law:

"Love can neither be created nor be destroyed; only it can transfer from One girlfriend to another girlfriend with some loss of money . "


First law:

"a boy in love with a girl, continue to be in love with her and a girl in love with a boy, continue to be in love with him, until on unless
any external agent(brother or father of the gal) comes into play and break the legs of the boy."


Second law:

" the rate of change of intensity of love of a girl towards a boy is directly proportional to the instantaneous bank balance of the boy and
the direction of this love is same to as increment or decrement of the bank balance. "


Third law:

"the force applied while proposing a girl by a boy is equal and opposite to the force applied by the girl while using her sandals.
 
*************************************************************************************

Laugh about your mistakes,

But, learn from them.

Joke over your troubles,

But, gather strength from them.

Have fun with your difficulties,

But, overcome them.

That's the way to live LIFE.

*********************************************************************************************

At the scene of an accident a man was crying: O God! I have lost my
hand, oh!

Santa: Control yourself. Don't cry. See that man. He has lost his
head. 
Is he crying?

Monday, November 10, 2008

Jokes

************************************************
LITTLE LALOO

Little Lalloo was eating breakfast one morning and got to thinking about things. 'Mommy, mommy, why has daddy got so few hairs on his head?' he asked his mother. 'He thinks a lot,' replied his mother, pleased with herself for coming up with a good answer to her husband's baldness, until little Lalloo thought for a second and asked, 'So why do you have so much hair?'
************************************************
Every day, Mr. Koch has to cross the rier by ferry in order to get to work.

Waking up late one morning, he dressed quickly, ran out the door and raced to the dock. The boat was several yards away, and stepping back and taking a mighty leap, Mr. Koch landed with a crash on the deck.

"Made it!" he cried triumphantly.

"So?" said one of the passengers, "What was the rush? The boat is coming in."
************************************************
"The doctor said he would have me on my feet in two weeks."

"And did he?"

"Yes, I had to sell the car to pay the bill."
************************************************
A young woman went to her doctor complaining of pain.

"Where are you hurting?" asked the doctor.

"You have to help me, I hurt all over", said the woman.

"What do you mean, all over?" asked the doctor, "be a little more specific."

The woman touched her right knee with her index finger and yelled, "Ow, that hurts." Then she touched her left cheek and again yelled, "Ouch! That hurts, too." Then she touched her right earlobe, "Ow, even THAT hurts", she cried.

The doctor checked her thoughtfully for a moment and told her his diagnosis, "You have a broken finger."
************************************************
A woman takes a lover during the day while her husband is at work. Her 9 year old son comes home unexpectedly, sees them and hides in the bedroom closet to watch. The woman's husband also comes home. She puts her lover in the closet, not realizing that the little boy is in there already.

The little boy says, 'Dark in here.'

The man says, 'Yes, it is.'

Boy - 'I have a baseball.'

Man - 'That's nice.'

Boy - 'Want to buy it?'

Man - 'No, thanks.'

Boy - 'My dad's outside.'

Man - 'OK, how much?'

Boy - '$250'

In the next few weeks, it happens again that the boy and the lover are in the closet together.

Boy - 'Dark in here.'

Man - 'Yes, it is.'

Boy - 'I have a baseball glove.'

The lover, remembering the last time, asks the boy,'How much?'

Boy - '$750'

Man - 'Fine.'

A few days later, the father says to the boy, 'Grab your glove, let's go outside and have a game of catch. The boy says, 'I can't ., I sold my baseball and my glove.'

The father asks, 'How much did you sell them for?'

Boy -'$1,000'

The father says, 'That's terrible to overcharge your friends like that... that is way more than those two things cost. I'm going to take you to church and make you confess.'

They go to the church and the father makes the little boy sit in the confession booth and he closes the door.

The boy says, 'Dark in here.'

The priest says, 'Don't start that shit again'
.
************************************************
The manager was very angry with this beginner who wanted a very high salary. He asked him why he wanted so much money whereas he had no experience.
The beginner replied "Work is very difficult when you are a beginner. It becomes easier as you get experience."
************************************************

Microsoft Europe Chairman Selection

Microsoft Europe Chairman Selection

Bill Gates organized an enormous session to recruit a new Chairman for Microsoft Europe. 5000 candidates assembled in a large room. One candidate is Mr. Reddy an Indian (Hyderabad) guy.

Bill Gates thanked all the candidates for coming and asking those who do not know JAVA program to leave.2000 people leave the room. Reddy says to himself, 'I do not know JAVA but I have nothing to lose if I stay. I'll give it a try'

Bill Gates asked the candidates who never had experience of managing more than 100 people to leave. 2000 people leave the room. Reddy says to himself ' I never managed anybody by myself but I have nothing to lose if I stay. What can happen to me?' So he stays.

Then Bill Gates asked candidates who do not have management diplomas to leave. 500 people leave the room. Reddy says to himself, 'I left school at 15 but what have I got to lose?' So he stays in the room. 

Lastly, Bill Gates asked the candidates who do not speak Serbo - Croat to leave. 498 people leave the room. Reddy says to himself, ' I do not speak one word of Serbo - Croat but what do I have to lose?' So he stays and finds himself with one other candidate. Everyone else has gone.

Bill Gates joined them and said 'Apparently you are the only two candidates who speak  Serbo - Croat, so I'd now like to hear you have a conversation together in that language.'

Calmly, Reddy turns to the other candidate and says 'Elaa vunnavu babu'
The other candidate answers 'Baguunanu babu '

Bill Gates Congratulated them "Wonderful both of you were selected".

Don't Loose your Confidence ever.........................

My Wife : Good Joke

My Wife : Good Joke
 
The man approached the very beautiful woman in the large supermarket and asked, "You know, I've lost my wife here in the supermarket. Can you talk to me for a couple of minutes?"

"Why?"

"Because every time I talk to a beautiful woman my wife appears out of nowhere."
 

Sunday, November 9, 2008

Control Statements I

A programming language uses control statements to cause the flow of execution to advance and branch based on changes to the state of a program. Java's program control statements can be put into the following categories: selection, iteration, and jump. Selection statements allow your program to choose different paths of execution based upon the outcome of an expression or the state of a variable. Iteration statements enable program execution to repeat one or more statements (that is, iteration statements form loops). Jump statements allow your program to execute in a nonlinear fashion. All of Java's control statements are examined here.

 

If you know C/C++/C#, then Java's control statements will be familiar territory. In fact, Java's control statements are nearly identical to those in those languages. However, there are a few differences—especially in the break and continue statements.

 

Java's Selection Statements

Java supports two selection statements: if and switch. These statements allow you to control the flow of your program's execution based upon conditions known only during run time. You will be pleasantly surprised by the power and flexibility contained in these two statements.

 

if

The if statement was introduced in. It is examined in detail here. The if statement is Java's conditional branch statement. It can be used to route program execution through two different paths.

 

Here is the general form of the if statement:

 

if (condition) statement1;

else statement2;

 

Here, each statement may be a single statement or a compound statement enclosed in curly braces (that is, a block). The condition is any expression that returns a boolean value.

 

The else clause is optional.

 

The if works like this: If the condition is true, then statement1 is executed. Otherwise, statement2 (if it exists) is executed. In no case will both statements be executed.

 

For example, consider the following:

 

int a, b;

// ...

if(a < b) a = 0;

else b = 0;

 

Here, if a is less than b, then a is set to zero. Otherwise, b is set to zero. In no case are they both set to zero. Most often, the expression used to control the if will involve the relational operators. However, this is not technically necessary. It is possible to control the if using a single Boolean variable, as shown in this code fragment:

 

boolean dataAvailable;

// ...

if (dataAvailable)

ProcessData();

else

waitForMoreData();

 

Remember, only one statement can appear directly after the if or the else. If you want to include more statements, you'll need to create a block, as in this fragment:

 

int bytesAvailable;

// ...

if (bytesAvailable > 0) {

ProcessData();

bytesAvailable -= n;

} else

waitForMoreData();

 

Here, both statements within the if block will execute if bytesAvailable is greater than zero. Some programmers find it convenient to include the curly braces when using the if, even when there is only one statement in each clause. This makes it easy to add another statement at a later date, and you don't have to worry about forgetting the braces. In fact, forgetting to define a block when one is needed is a common cause of errors.

 

For example, consider the following code fragment:

 

int bytesAvailable;

// ...

if (bytesAvailable > 0) {

ProcessData();

bytesAvailable -= n;

} else

waitForMoreData();

bytesAvailable = n;

 

It seems clear that the statement bytesAvailable = n; was intended to be executed inside the else clause, because of the indentation level. However, as you recall, whitespace is insignificant to Java, and there is no way for the compiler to know what was intended. This code will compile without complaint, but it will behave incorrectly when run.

 

The preceding example is fixed in the code that follows:

 

int bytesAvailable;

// ...

if (bytesAvailable > 0) {

ProcessData();

bytesAvailable -= n;

} else {

waitForMoreData();

bytesAvailable = n;

}

 

Nested ifs

A nested if is an if statement that is the target of another if or else. Nested ifs are very common in programming. When you nest ifs, the main thing to remember is that an else statement always refers to the nearest if statement that is within the same block as the else and that is not already associated with an else.

 

Here is an example:

 

if(i == 10) {

if(j < 20) a = b;

if(k > 100) c = d; // this if is

else a = c; // associated with this else

}

else a = d; // this else refers to if(i == 10)

 

As the comments indicate, the final else is not associated with if(j<20), because it is not in the same block (even though it is the nearest if without an else). Rather, the final else is associated with if(i==10). The inner else refers to if(k>100), because it is the closest if within the same block.

 

The if-else-if Ladder

A common programming construct that is based upon a sequence of nested ifs is the if-else-if ladder.

 

It looks like this:

if(condition)

statement;

else if(condition)

statement;

else if(condition)

statement;

...

else

statement;

 

The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed. The final else acts as a default condition; that is, if all other conditional tests fail, then the last else statement is performed. If there is no final else and all other conditions are false, then no action will take place.

 

Here is a program that uses an if-else-if ladder to determine which season a particular month is in.

 

// Demonstrate if-else-if statements.

class IfElse {

public static void main(String args[]) {

int month = 4; // April

String season;

if(month == 12 || month == 1 || month == 2)

season = "Winter";

else if(month == 3 || month == 4 || month == 5)

season = "Spring";

else if(month == 6 || month == 7 || month == 8)

season = "Summer";

else if(month == 9 || month == 10 || month == 11)

season = "Autumn";

else

season = "Bogus Month";

System.out.println("April is in the " + season + ".");

}

}

 

Here is the output produced by the program:

April is in the Spring.

 

You might want to experiment with this program before moving on. As you will find, no matter what value you give month, one and only one assignment statement within the ladder will be executed.