Oct 14, 2011

Accessors and Mutators in JAVA

Accessors:
API's or methods which were used to get the current state of an object.

Mutators:
API's or methods which were used to change the state of an object.
Ex: set(int a);

An object has mainly two things state and behaviour.. State denotes the instance variables of a class and Behaviour denotes the methods or API's in class[ which is blueprint of an object] .
class Animal{
private int color;

  public void getColor(){
  return color;
  }
public setColor(int color){
this.color = color;
}
}

In this program, getColor is an Accessor setColor is Mutator

Oct 10, 2011

RPM Differs

Last week i was travelling in a bike with my father riding it, that time a car overtaken us. Suddenly i had a doubt regarding speed, here it goes the conversation.
Me: Dad..
Dad: Yes, Dear
Me: If the car is running at the same speed of a bike, will the two will reach at the same dear
Dad: No, the car will reach first.
Me: How come , both are running at the same speed?
Dad: Even-tough they run at same speed, their RPM Differs..




Aug 18, 2011

Mulitple Catch Blocks in JDK 7

public static void main(String args[]) {
Scanner scnr = new Scanner(System.in);
String number = scnr.next();
try {
if (number.length() > 5) {
throw new IllegalArgumentException();
}
Integer.parseInt(number);

} catch (NumberFormatException | IllegalArgumentException e) {
e.printStackTrace();
}
}

Aug 17, 2011

Print a Diamond using JAVA


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Diamond {

public static void main(String[] args) {
Diamond diam = new Diamond();
diam.checkInput();
}

private void draw(int N, int counter, String sym) {
int max=0;

for (int i = 0; i < N;) {

for (int j = 0; j <= (N - i) / 2; j++) {
System.out.print(" ");
}
for (max = 0; max <= i; max++) {
System.out.print(sym);


}

System.out.println();

i = i + counter;


}


for (int i = (max - counter); i > 0;) {

for (int j = 0; j <= (N - i) / 2; j++) {
System.out.print(" ");
}
for (int k = i; k > 0; k--) {
System.out.print(sym);
}

System.out.println();
i = i - counter;

}
}

private String getInput() {
String value = null;

BufferedReader buf = new BufferedReader(
new InputStreamReader(System.in));
try {
value = buf.readLine();

} catch (IOException e) {
e.printStackTrace();
}
return value;
}

private void checkInput() {
System.out.print("Enter the Value of N:");
int N = Integer.parseInt(getInput());
System.out.print("\n Enter the Value for counter: ");
int counter = Integer.parseInt(getInput());
System.out.println("\n Enter the Diamond Symbol:");
String symbol = getInput();

System.out.println("Vaildating Check wait for 2 sec");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {

e.printStackTrace();
}
if( N>0  && N%2 !=0  && counter >0 && counter%2 == 0 && counter
draw(N, counter, symbol);
}
else{
System.out.println("invalid data");
}



}

}

Aug 4, 2011

How to Unsubscribe from Snap Deal?

If you are getting annoyed with so many snap deal alerts, you can unsubscribe them from your mobile.
For that, please Click Here..

Notes:

  • Please enter your mobile number there and Click Summit Button there, you will be getting a verification pin in your mobile.
  • Please Enter the verification pin and provide the reason for un-subscription, if not you can choose "Others" in the List and provide your reason below
  • Once done, Click "Confirm to Un Subscribe ", you will be getting un-subscription confirmation message in your mobile
Then be happy :) 


Aug 3, 2011

Internet Explorer Users have low IQ

On average, Internet Explorer used were far than worst, where IE6 users were at the bottom. However, IE8 users performed slightly better. Other well known browsers like Firefox, Chrome and Safari were in the middle of the list and had small differences among them. Camino and IE with Chrome Frame were on top along with Opera. These users had the best average score.

In 2006, the same study says that IE was performing well. So this study may not be true.

Study By: AptiQuant, “psychometric consulting” firm

Aug 2, 2011

Can you make out 37 using five 5's

The Solution is very simple..
2^5 =32. To get 2, we can use ((5+5)/5)
So the answer is 

     (5+5)       
[   -------    ] ^ 5  + 5 ==>  2^5 + 5 = 32+ 5 =37
        5

Its quite complex, but by solving this, it will strength your aptitude skills.

Hot Water in WaterBottle

Usually we used to have a water bottle in office desks. We fill water in the morning. On a Monday morning, i found one of my friends bottle in the pantry and he used to drink only hot water. So i washed that bottle with cold water and filled it completely with hot water and carried to his desk. He thanked me for this activity at start. After few minutes, he felt thirsty and he drank  the water from the bottle. Suddenly he spitted the water on the floor and he started scolding me that Water is too hot.
I didn't realize that the water would be so hot. Even his water bottle would be like a flask not a plastic one.