Beer-Homer-SimPSon-PS-Vita-Wallpaper

The Beer Song in Java

Beer-Homer-SimPSon-PS-Vita-Wallpaper
How do you learn a new language efficiently? The answer is: if you are thrown into a situation where you need to know the language to survive. RIT is such a place for learning new computer languages. Most of the professors would speak the language fluently, but they won’t spoon feed you. You need to communicate back, ’cause without that you are not getting that grade. And hence, a survival situation emerges. To learn more about this pedagogy, listen to this TED talk:

Let’s get to coding now. The first program I wrote in Java is the classic “Hello World!” program. I’m assuming everyone, who is starting java, is past that point. I want to recommend a very good beginner book. It’s called Head First Java by Kathy Sierra et al. So the code I’m about to “refine” is from the first chapter of that book. It’s called the Beer Song! The Beer Song is a classic, simple program that implements basic integer, variable assignment, while and if loops in any program. Hence, it is a good introduction to start writing code in a new language. To know more, go to: http://www.99-bottles-of-beer.net/

Our goal is to produce the following lyrics:

99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

And so on – 97, 96, 95 bottles of beer and in the end when the number of bottles reaches 1 and eventually zero, the lyrics would be:

1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.

No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.

In the Head First Java book, the code is given as:

public class BeerSong{
	public static void main(String[] args){
		int beerNum = 99;
		String word = "bottles";

		while (beerNum > 0){

			if (beerNum == 1){
				word = "bottle";
			}

			System.out.println(beerNum + " " + word + " of beer on the wall");
			System.out.println(beerNum + " " + word + " of beer");
			System.out.println("Take one down.");
			System.out.println("Pass it around.");
			beerNum = beerNum - 1;

			if (beerNum > 0){
				System.out.println(beerNum + " " + word + " of beer on the wall");
			}
			else{
				System.out.println("No more bottles of beer on the wall");
			}
		}
	}
}

The code gives the output:

99 bottles of beer on the wall
99 bottles of beer
Take one down.
Pass it around.
98 bottles of beer on the wall
98 bottles of beer on the wall
98 bottles of beer
Take one down.
Pass it around.
97 bottles of beer on the wall
97 bottles of beer on the wall
97 bottles of beer
Take one down.
Pass it around.
96 bottles of beer on the wall
96 bottles of beer on the wall
96 bottles of beer
Take one down.
Pass it around.
95 bottles of beer on the wall
95 bottles of beer on the wall
95 bottles of beer
Take one down.
Pass it around.
94 bottles of beer on the wall
94 bottles of beer on the wall
94 bottles of beer
Take one down.
Pass it around.
93 bottles of beer on the wall
93 bottles of beer on the wall
93 bottles of beer
Take one down.
Pass it around.
92 bottles of beer on the wall
92 bottles of beer on the wall
92 bottles of beer
Take one down.
Pass it around.
91 bottles of beer on the wall
91 bottles of beer on the wall
91 bottles of beer
Take one down.
Pass it around.
90 bottles of beer on the wall
90 bottles of beer on the wall
90 bottles of beer
Take one down.
Pass it around.
89 bottles of beer on the wall
89 bottles of beer on the wall
89 bottles of beer
Take one down.
Pass it around.
88 bottles of beer on the wall
88 bottles of beer on the wall
88 bottles of beer
Take one down.
Pass it around.
87 bottles of beer on the wall
87 bottles of beer on the wall
87 bottles of beer
Take one down.
Pass it around.
86 bottles of beer on the wall
86 bottles of beer on the wall
86 bottles of beer
Take one down.
Pass it around.
85 bottles of beer on the wall
85 bottles of beer on the wall
85 bottles of beer
Take one down.
Pass it around.
84 bottles of beer on the wall
84 bottles of beer on the wall
84 bottles of beer
Take one down.
Pass it around.
83 bottles of beer on the wall
83 bottles of beer on the wall
83 bottles of beer
Take one down.
Pass it around.
82 bottles of beer on the wall
82 bottles of beer on the wall
82 bottles of beer
Take one down.
Pass it around.
81 bottles of beer on the wall
81 bottles of beer on the wall
81 bottles of beer
Take one down.
Pass it around.
80 bottles of beer on the wall
80 bottles of beer on the wall
80 bottles of beer
Take one down.
Pass it around.
79 bottles of beer on the wall
79 bottles of beer on the wall
79 bottles of beer
Take one down.
Pass it around.
78 bottles of beer on the wall
78 bottles of beer on the wall
78 bottles of beer
Take one down.
Pass it around.
77 bottles of beer on the wall
77 bottles of beer on the wall
77 bottles of beer
Take one down.
Pass it around.
76 bottles of beer on the wall
76 bottles of beer on the wall
76 bottles of beer
Take one down.
Pass it around.
75 bottles of beer on the wall
75 bottles of beer on the wall
75 bottles of beer
Take one down.
Pass it around.
74 bottles of beer on the wall
74 bottles of beer on the wall
74 bottles of beer
Take one down.
Pass it around.
73 bottles of beer on the wall
73 bottles of beer on the wall
73 bottles of beer
Take one down.
Pass it around.
72 bottles of beer on the wall
72 bottles of beer on the wall
72 bottles of beer
Take one down.
Pass it around.
71 bottles of beer on the wall
71 bottles of beer on the wall
71 bottles of beer
Take one down.
Pass it around.
70 bottles of beer on the wall
70 bottles of beer on the wall
70 bottles of beer
Take one down.
Pass it around.
69 bottles of beer on the wall
69 bottles of beer on the wall
69 bottles of beer
Take one down.
Pass it around.
68 bottles of beer on the wall
68 bottles of beer on the wall
68 bottles of beer
Take one down.
Pass it around.
67 bottles of beer on the wall
67 bottles of beer on the wall
67 bottles of beer
Take one down.
Pass it around.
66 bottles of beer on the wall
66 bottles of beer on the wall
66 bottles of beer
Take one down.
Pass it around.
65 bottles of beer on the wall
65 bottles of beer on the wall
65 bottles of beer
Take one down.
Pass it around.
64 bottles of beer on the wall
64 bottles of beer on the wall
64 bottles of beer
Take one down.
Pass it around.
63 bottles of beer on the wall
63 bottles of beer on the wall
63 bottles of beer
Take one down.
Pass it around.
62 bottles of beer on the wall
62 bottles of beer on the wall
62 bottles of beer
Take one down.
Pass it around.
61 bottles of beer on the wall
61 bottles of beer on the wall
61 bottles of beer
Take one down.
Pass it around.
60 bottles of beer on the wall
60 bottles of beer on the wall
60 bottles of beer
Take one down.
Pass it around.
59 bottles of beer on the wall
59 bottles of beer on the wall
59 bottles of beer
Take one down.
Pass it around.
58 bottles of beer on the wall
58 bottles of beer on the wall
58 bottles of beer
Take one down.
Pass it around.
57 bottles of beer on the wall
57 bottles of beer on the wall
57 bottles of beer
Take one down.
Pass it around.
56 bottles of beer on the wall
56 bottles of beer on the wall
56 bottles of beer
Take one down.
Pass it around.
55 bottles of beer on the wall
55 bottles of beer on the wall
55 bottles of beer
Take one down.
Pass it around.
54 bottles of beer on the wall
54 bottles of beer on the wall
54 bottles of beer
Take one down.
Pass it around.
53 bottles of beer on the wall
53 bottles of beer on the wall
53 bottles of beer
Take one down.
Pass it around.
52 bottles of beer on the wall
52 bottles of beer on the wall
52 bottles of beer
Take one down.
Pass it around.
51 bottles of beer on the wall
51 bottles of beer on the wall
51 bottles of beer
Take one down.
Pass it around.
50 bottles of beer on the wall
50 bottles of beer on the wall
50 bottles of beer
Take one down.
Pass it around.
49 bottles of beer on the wall
49 bottles of beer on the wall
49 bottles of beer
Take one down.
Pass it around.
48 bottles of beer on the wall
48 bottles of beer on the wall
48 bottles of beer
Take one down.
Pass it around.
47 bottles of beer on the wall
47 bottles of beer on the wall
47 bottles of beer
Take one down.
Pass it around.
46 bottles of beer on the wall
46 bottles of beer on the wall
46 bottles of beer
Take one down.
Pass it around.
45 bottles of beer on the wall
45 bottles of beer on the wall
45 bottles of beer
Take one down.
Pass it around.
44 bottles of beer on the wall
44 bottles of beer on the wall
44 bottles of beer
Take one down.
Pass it around.
43 bottles of beer on the wall
43 bottles of beer on the wall
43 bottles of beer
Take one down.
Pass it around.
42 bottles of beer on the wall
42 bottles of beer on the wall
42 bottles of beer
Take one down.
Pass it around.
41 bottles of beer on the wall
41 bottles of beer on the wall
41 bottles of beer
Take one down.
Pass it around.
40 bottles of beer on the wall
40 bottles of beer on the wall
40 bottles of beer
Take one down.
Pass it around.
39 bottles of beer on the wall
39 bottles of beer on the wall
39 bottles of beer
Take one down.
Pass it around.
38 bottles of beer on the wall
38 bottles of beer on the wall
38 bottles of beer
Take one down.
Pass it around.
37 bottles of beer on the wall
37 bottles of beer on the wall
37 bottles of beer
Take one down.
Pass it around.
36 bottles of beer on the wall
36 bottles of beer on the wall
36 bottles of beer
Take one down.
Pass it around.
35 bottles of beer on the wall
35 bottles of beer on the wall
35 bottles of beer
Take one down.
Pass it around.
34 bottles of beer on the wall
34 bottles of beer on the wall
34 bottles of beer
Take one down.
Pass it around.
33 bottles of beer on the wall
33 bottles of beer on the wall
33 bottles of beer
Take one down.
Pass it around.
32 bottles of beer on the wall
32 bottles of beer on the wall
32 bottles of beer
Take one down.
Pass it around.
31 bottles of beer on the wall
31 bottles of beer on the wall
31 bottles of beer
Take one down.
Pass it around.
30 bottles of beer on the wall
30 bottles of beer on the wall
30 bottles of beer
Take one down.
Pass it around.
29 bottles of beer on the wall
29 bottles of beer on the wall
29 bottles of beer
Take one down.
Pass it around.
28 bottles of beer on the wall
28 bottles of beer on the wall
28 bottles of beer
Take one down.
Pass it around.
27 bottles of beer on the wall
27 bottles of beer on the wall
27 bottles of beer
Take one down.
Pass it around.
26 bottles of beer on the wall
26 bottles of beer on the wall
26 bottles of beer
Take one down.
Pass it around.
25 bottles of beer on the wall
25 bottles of beer on the wall
25 bottles of beer
Take one down.
Pass it around.
24 bottles of beer on the wall
24 bottles of beer on the wall
24 bottles of beer
Take one down.
Pass it around.
23 bottles of beer on the wall
23 bottles of beer on the wall
23 bottles of beer
Take one down.
Pass it around.
22 bottles of beer on the wall
22 bottles of beer on the wall
22 bottles of beer
Take one down.
Pass it around.
21 bottles of beer on the wall
21 bottles of beer on the wall
21 bottles of beer
Take one down.
Pass it around.
20 bottles of beer on the wall
20 bottles of beer on the wall
20 bottles of beer
Take one down.
Pass it around.
19 bottles of beer on the wall
19 bottles of beer on the wall
19 bottles of beer
Take one down.
Pass it around.
18 bottles of beer on the wall
18 bottles of beer on the wall
18 bottles of beer
Take one down.
Pass it around.
17 bottles of beer on the wall
17 bottles of beer on the wall
17 bottles of beer
Take one down.
Pass it around.
16 bottles of beer on the wall
16 bottles of beer on the wall
16 bottles of beer
Take one down.
Pass it around.
15 bottles of beer on the wall
15 bottles of beer on the wall
15 bottles of beer
Take one down.
Pass it around.
14 bottles of beer on the wall
14 bottles of beer on the wall
14 bottles of beer
Take one down.
Pass it around.
13 bottles of beer on the wall
13 bottles of beer on the wall
13 bottles of beer
Take one down.
Pass it around.
12 bottles of beer on the wall
12 bottles of beer on the wall
12 bottles of beer
Take one down.
Pass it around.
11 bottles of beer on the wall
11 bottles of beer on the wall
11 bottles of beer
Take one down.
Pass it around.
10 bottles of beer on the wall
10 bottles of beer on the wall
10 bottles of beer
Take one down.
Pass it around.
9 bottles of beer on the wall
9 bottles of beer on the wall
9 bottles of beer
Take one down.
Pass it around.
8 bottles of beer on the wall
8 bottles of beer on the wall
8 bottles of beer
Take one down.
Pass it around.
7 bottles of beer on the wall
7 bottles of beer on the wall
7 bottles of beer
Take one down.
Pass it around.
6 bottles of beer on the wall
6 bottles of beer on the wall
6 bottles of beer
Take one down.
Pass it around.
5 bottles of beer on the wall
5 bottles of beer on the wall
5 bottles of beer
Take one down.
Pass it around.
4 bottles of beer on the wall
4 bottles of beer on the wall
4 bottles of beer
Take one down.
Pass it around.
3 bottles of beer on the wall
3 bottles of beer on the wall
3 bottles of beer
Take one down.
Pass it around.
2 bottles of beer on the wall
2 bottles of beer on the wall
2 bottles of beer
Take one down.
Pass it around.
1 bottles of beer on the wall
1 bottle of beer on the wall
1 bottle of beer
Take one down.
Pass it around.
No more bottles of beer on the wall

As you can see by now, the code is faulty and the authors mention that. So it’s our job to debug! Let’s start debugging (the word ‘debug’ was coined by the Amazing Grace. Read about her: http://en.wikipedia.org/wiki/Grace_Hopper).

The first thing I want to fix is the extra output ” bottle(s) of beer on the wall”. The extra output continues till the last iteration. When you look at the code and try to understand it, you’ll see that the error occurs at line 18 of the source code. The conditional at line 18 wants to say that, when the number of bottles of beer is greater than zero, keep using that ” bottle(s) of beer on the wall” in the lyrics, but when the number is zero, say “No more bottles of beer on the wall”. It does say “No more bottles of beer on the wall” in the end but ends up producing the extra output. So that was a bad way to implement the last line.

The reason why the extra output occurs is because the while loop produces one output and on top of that the if loop also produces that output till the number becomes zero. So our solution to that problem would be to produce the last line “No more bottles of beer on the wall” without producing the extra output.

I decided to organize the code a bit and divided into three parts – an if conditional which will deal with the output when the number of bottles is one, since it is during that iteration we need the “no more bottles…” phrase; the second part is what happens when the number of bottles is greater than 1 and the last part defines what happens if it’s neither 1, nor greater than 1. Since it is inside a while loop which stops at 0, the last part essentially defines what happens at 0. The code is as follows:

/**
 *
 * @author Syed Tousif Ahmed
 * The Beer Song
 * Debugged version of the source code from
 * Head First Java, Second Edition
 * by Kathy Sierra et al.
 *
 */

public class BeerSong{
	public static void main(String[] args){
		int beerNum = 99; //I got 99 problems but a beer ain't one. Defining the initial number of beer
		String word = "bottles"; //the variable that takes care of the small grammar in the lyrics

		while (beerNum > 0){ //The loop from 99 stops at 0

			//The first part
			if (beerNum == 1){
				word = "bottle"; //Again, when the number of bottles is one, the grammar should be singular
				System.out.println(beerNum + " " + word + " of beer on the wall," + " "
						+ beerNum + " "+ word + " of beer.");
				//when it is one and we have taken a beer, there will be no more bottles of beer
				//hence including this statement here separately as it is the only instance
				//in the lyrics when it happens
				System.out.println("Take one down and pass it around, no more bottles of beer on the wall.");
				System.out.println();
			}

			//The Second Part - pretty easy to understand
			if (beerNum > 1){
				System.out.println(beerNum + " " + word + " of beer on the wall," + " "
						+ beerNum + " "+ word + " of beer.");
				System.out.println("Take one down and pass it around, " + (beerNum - 1)
						+ " " + word + " of beer on the wall.");
				System.out.println();
			}

			//The Third Part (although it is part of the if statement)
			//defines what happens when the above conditions do not exist
			//Since the loop stops at 0 defined by while loop being greater than zero,
			//this part prints out your responsibilities when there is no more beer
			//and you have a deadline of finishing the code!!!
			else{
				System.out.println("No more bottles of beer on the wall, no more bottles of beer.");
				System.out.println("Go to the store and buy some more, 99 bottles of beer on the wall.");
			}

			beerNum = beerNum - 1; //The equation that defines consumption of a beer!
		}
	}
}

The output is what we expect:

99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

97 bottles of beer on the wall, 97 bottles of beer.
Take one down and pass it around, 96 bottles of beer on the wall.

96 bottles of beer on the wall, 96 bottles of beer.
Take one down and pass it around, 95 bottles of beer on the wall.

95 bottles of beer on the wall, 95 bottles of beer.
Take one down and pass it around, 94 bottles of beer on the wall.

94 bottles of beer on the wall, 94 bottles of beer.
Take one down and pass it around, 93 bottles of beer on the wall.

93 bottles of beer on the wall, 93 bottles of beer.
Take one down and pass it around, 92 bottles of beer on the wall.

92 bottles of beer on the wall, 92 bottles of beer.
Take one down and pass it around, 91 bottles of beer on the wall.

91 bottles of beer on the wall, 91 bottles of beer.
Take one down and pass it around, 90 bottles of beer on the wall.

90 bottles of beer on the wall, 90 bottles of beer.
Take one down and pass it around, 89 bottles of beer on the wall.

89 bottles of beer on the wall, 89 bottles of beer.
Take one down and pass it around, 88 bottles of beer on the wall.

88 bottles of beer on the wall, 88 bottles of beer.
Take one down and pass it around, 87 bottles of beer on the wall.

87 bottles of beer on the wall, 87 bottles of beer.
Take one down and pass it around, 86 bottles of beer on the wall.

86 bottles of beer on the wall, 86 bottles of beer.
Take one down and pass it around, 85 bottles of beer on the wall.

85 bottles of beer on the wall, 85 bottles of beer.
Take one down and pass it around, 84 bottles of beer on the wall.

84 bottles of beer on the wall, 84 bottles of beer.
Take one down and pass it around, 83 bottles of beer on the wall.

83 bottles of beer on the wall, 83 bottles of beer.
Take one down and pass it around, 82 bottles of beer on the wall.

82 bottles of beer on the wall, 82 bottles of beer.
Take one down and pass it around, 81 bottles of beer on the wall.

81 bottles of beer on the wall, 81 bottles of beer.
Take one down and pass it around, 80 bottles of beer on the wall.

80 bottles of beer on the wall, 80 bottles of beer.
Take one down and pass it around, 79 bottles of beer on the wall.

79 bottles of beer on the wall, 79 bottles of beer.
Take one down and pass it around, 78 bottles of beer on the wall.

78 bottles of beer on the wall, 78 bottles of beer.
Take one down and pass it around, 77 bottles of beer on the wall.

77 bottles of beer on the wall, 77 bottles of beer.
Take one down and pass it around, 76 bottles of beer on the wall.

76 bottles of beer on the wall, 76 bottles of beer.
Take one down and pass it around, 75 bottles of beer on the wall.

75 bottles of beer on the wall, 75 bottles of beer.
Take one down and pass it around, 74 bottles of beer on the wall.

74 bottles of beer on the wall, 74 bottles of beer.
Take one down and pass it around, 73 bottles of beer on the wall.

73 bottles of beer on the wall, 73 bottles of beer.
Take one down and pass it around, 72 bottles of beer on the wall.

72 bottles of beer on the wall, 72 bottles of beer.
Take one down and pass it around, 71 bottles of beer on the wall.

71 bottles of beer on the wall, 71 bottles of beer.
Take one down and pass it around, 70 bottles of beer on the wall.

70 bottles of beer on the wall, 70 bottles of beer.
Take one down and pass it around, 69 bottles of beer on the wall.

69 bottles of beer on the wall, 69 bottles of beer.
Take one down and pass it around, 68 bottles of beer on the wall.

68 bottles of beer on the wall, 68 bottles of beer.
Take one down and pass it around, 67 bottles of beer on the wall.

67 bottles of beer on the wall, 67 bottles of beer.
Take one down and pass it around, 66 bottles of beer on the wall.

66 bottles of beer on the wall, 66 bottles of beer.
Take one down and pass it around, 65 bottles of beer on the wall.

65 bottles of beer on the wall, 65 bottles of beer.
Take one down and pass it around, 64 bottles of beer on the wall.

64 bottles of beer on the wall, 64 bottles of beer.
Take one down and pass it around, 63 bottles of beer on the wall.

63 bottles of beer on the wall, 63 bottles of beer.
Take one down and pass it around, 62 bottles of beer on the wall.

62 bottles of beer on the wall, 62 bottles of beer.
Take one down and pass it around, 61 bottles of beer on the wall.

61 bottles of beer on the wall, 61 bottles of beer.
Take one down and pass it around, 60 bottles of beer on the wall.

60 bottles of beer on the wall, 60 bottles of beer.
Take one down and pass it around, 59 bottles of beer on the wall.

59 bottles of beer on the wall, 59 bottles of beer.
Take one down and pass it around, 58 bottles of beer on the wall.

58 bottles of beer on the wall, 58 bottles of beer.
Take one down and pass it around, 57 bottles of beer on the wall.

57 bottles of beer on the wall, 57 bottles of beer.
Take one down and pass it around, 56 bottles of beer on the wall.

56 bottles of beer on the wall, 56 bottles of beer.
Take one down and pass it around, 55 bottles of beer on the wall.

55 bottles of beer on the wall, 55 bottles of beer.
Take one down and pass it around, 54 bottles of beer on the wall.

54 bottles of beer on the wall, 54 bottles of beer.
Take one down and pass it around, 53 bottles of beer on the wall.

53 bottles of beer on the wall, 53 bottles of beer.
Take one down and pass it around, 52 bottles of beer on the wall.

52 bottles of beer on the wall, 52 bottles of beer.
Take one down and pass it around, 51 bottles of beer on the wall.

51 bottles of beer on the wall, 51 bottles of beer.
Take one down and pass it around, 50 bottles of beer on the wall.

50 bottles of beer on the wall, 50 bottles of beer.
Take one down and pass it around, 49 bottles of beer on the wall.

49 bottles of beer on the wall, 49 bottles of beer.
Take one down and pass it around, 48 bottles of beer on the wall.

48 bottles of beer on the wall, 48 bottles of beer.
Take one down and pass it around, 47 bottles of beer on the wall.

47 bottles of beer on the wall, 47 bottles of beer.
Take one down and pass it around, 46 bottles of beer on the wall.

46 bottles of beer on the wall, 46 bottles of beer.
Take one down and pass it around, 45 bottles of beer on the wall.

45 bottles of beer on the wall, 45 bottles of beer.
Take one down and pass it around, 44 bottles of beer on the wall.

44 bottles of beer on the wall, 44 bottles of beer.
Take one down and pass it around, 43 bottles of beer on the wall.

43 bottles of beer on the wall, 43 bottles of beer.
Take one down and pass it around, 42 bottles of beer on the wall.

42 bottles of beer on the wall, 42 bottles of beer.
Take one down and pass it around, 41 bottles of beer on the wall.

41 bottles of beer on the wall, 41 bottles of beer.
Take one down and pass it around, 40 bottles of beer on the wall.

40 bottles of beer on the wall, 40 bottles of beer.
Take one down and pass it around, 39 bottles of beer on the wall.

39 bottles of beer on the wall, 39 bottles of beer.
Take one down and pass it around, 38 bottles of beer on the wall.

38 bottles of beer on the wall, 38 bottles of beer.
Take one down and pass it around, 37 bottles of beer on the wall.

37 bottles of beer on the wall, 37 bottles of beer.
Take one down and pass it around, 36 bottles of beer on the wall.

36 bottles of beer on the wall, 36 bottles of beer.
Take one down and pass it around, 35 bottles of beer on the wall.

35 bottles of beer on the wall, 35 bottles of beer.
Take one down and pass it around, 34 bottles of beer on the wall.

34 bottles of beer on the wall, 34 bottles of beer.
Take one down and pass it around, 33 bottles of beer on the wall.

33 bottles of beer on the wall, 33 bottles of beer.
Take one down and pass it around, 32 bottles of beer on the wall.

32 bottles of beer on the wall, 32 bottles of beer.
Take one down and pass it around, 31 bottles of beer on the wall.

31 bottles of beer on the wall, 31 bottles of beer.
Take one down and pass it around, 30 bottles of beer on the wall.

30 bottles of beer on the wall, 30 bottles of beer.
Take one down and pass it around, 29 bottles of beer on the wall.

29 bottles of beer on the wall, 29 bottles of beer.
Take one down and pass it around, 28 bottles of beer on the wall.

28 bottles of beer on the wall, 28 bottles of beer.
Take one down and pass it around, 27 bottles of beer on the wall.

27 bottles of beer on the wall, 27 bottles of beer.
Take one down and pass it around, 26 bottles of beer on the wall.

26 bottles of beer on the wall, 26 bottles of beer.
Take one down and pass it around, 25 bottles of beer on the wall.

25 bottles of beer on the wall, 25 bottles of beer.
Take one down and pass it around, 24 bottles of beer on the wall.

24 bottles of beer on the wall, 24 bottles of beer.
Take one down and pass it around, 23 bottles of beer on the wall.

23 bottles of beer on the wall, 23 bottles of beer.
Take one down and pass it around, 22 bottles of beer on the wall.

22 bottles of beer on the wall, 22 bottles of beer.
Take one down and pass it around, 21 bottles of beer on the wall.

21 bottles of beer on the wall, 21 bottles of beer.
Take one down and pass it around, 20 bottles of beer on the wall.

20 bottles of beer on the wall, 20 bottles of beer.
Take one down and pass it around, 19 bottles of beer on the wall.

19 bottles of beer on the wall, 19 bottles of beer.
Take one down and pass it around, 18 bottles of beer on the wall.

18 bottles of beer on the wall, 18 bottles of beer.
Take one down and pass it around, 17 bottles of beer on the wall.

17 bottles of beer on the wall, 17 bottles of beer.
Take one down and pass it around, 16 bottles of beer on the wall.

16 bottles of beer on the wall, 16 bottles of beer.
Take one down and pass it around, 15 bottles of beer on the wall.

15 bottles of beer on the wall, 15 bottles of beer.
Take one down and pass it around, 14 bottles of beer on the wall.

14 bottles of beer on the wall, 14 bottles of beer.
Take one down and pass it around, 13 bottles of beer on the wall.

13 bottles of beer on the wall, 13 bottles of beer.
Take one down and pass it around, 12 bottles of beer on the wall.

12 bottles of beer on the wall, 12 bottles of beer.
Take one down and pass it around, 11 bottles of beer on the wall.

11 bottles of beer on the wall, 11 bottles of beer.
Take one down and pass it around, 10 bottles of beer on the wall.

10 bottles of beer on the wall, 10 bottles of beer.
Take one down and pass it around, 9 bottles of beer on the wall.

9 bottles of beer on the wall, 9 bottles of beer.
Take one down and pass it around, 8 bottles of beer on the wall.

8 bottles of beer on the wall, 8 bottles of beer.
Take one down and pass it around, 7 bottles of beer on the wall.

7 bottles of beer on the wall, 7 bottles of beer.
Take one down and pass it around, 6 bottles of beer on the wall.

6 bottles of beer on the wall, 6 bottles of beer.
Take one down and pass it around, 5 bottles of beer on the wall.

5 bottles of beer on the wall, 5 bottles of beer.
Take one down and pass it around, 4 bottles of beer on the wall.

4 bottles of beer on the wall, 4 bottles of beer.
Take one down and pass it around, 3 bottles of beer on the wall.

3 bottles of beer on the wall, 3 bottles of beer.
Take one down and pass it around, 2 bottles of beer on the wall.

2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottles of beer on the wall.

1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.

No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 botles of beer on the wall.

That’s for today. Happy Coding!

Java Diary

java8-logo

The Java Diary would record journal entries and tutorials throughout my career in Java Programming Language. The first resource I’m using is the “Java: A Beginner’s Guide, Fifth Edition by  Herb Schildt”. Help yourself and read my entries as I explain what I learn, in my terms. If you can explain better and refine my understanding, please do so! My comments section is open.

Visa Conundrum: 7 Tips on Getting a Schengen Visa

I wish visas didn’t exist. I wish so because of the limitations it creates for someone to travel all around the world at anytime. In Bangladesh, getting a tourist visa for anywhere is moderately tough. People in Bangladesh who get the tourist visa for Europe usually have a nice, bulky bank statement, or are famous and in their middle age having a white collar job. If you do not have any of those and/or you are a teen and you don’t have a bank account/job yet, it’s pretty much guaranteed that you won’t get a visa to Europe. Either you have to apply through your parents and your parents have to have the aforementioned criteria or you could pull some strings at the Embassy if your parents are politically involved/has relations somehow. I used the latter option in Bangladesh to get visas for the countries I visited so far, until I applied for a Schengen visa to Poland on my own.

I applied for the Schengen visa through the Swedish embassy in Bangladesh and was rejected under the reason, which I’m paraphrasing, that they can’t establish whether I’m going to Poland for tourism purpose or for immigration purpose. Why in hell would I immigrate to Europe when I had a US visa already issued in my passport for a bachelors program at RIT for 5 years? When I was handing in my application, I read somewhere in the embassy that Bangladesh is considered as an “Orange” nation in that embassy and has a history of people migrating illegally. I know it’s the fault of some of the people in Bangladesh but, what kind of classification is that? If you are pointing at our skin color, please get it right. You could say “50 shades of brown” nation. Anyhow, somewhere in the Swedish embassy, it even said that you won’t be given a visa if your purpose is to see your boy/girl friend. Is Hitler in command for that embassy or what? So I went to USA without travelling to Poland that time and went to Poland later with some help (an invitation letter) from a special friend of mine.

Things are quite easy when it comes to applying for a visa in USA. All you need to maintain is correct information in the application and sufficient means of travel. That is, you need to have the money to travel and feed yourself while travelling. If you could show this to the embassy, you should get a visa unless there is some other reason I don’t know of. So I am going to Germany and to other unplanned, European destinations  this summer and here is the step by step procedure I followed to get a Schengen visa:

Step 1: Visit the website. If you are applying for a visa to any country in Europe, you’ll find the visa information usually in the embassy website (duh…but many people keep asking me about the visa procedure and requirements). In USA, there are states allocated to each embassy. For instance, the New York embassy of Germany won’t serve someone from California. So do that.

Step 2: From the website, find out the required documents needed to apply for the Schengen visa. Some embassies have tougher requirements than others. Some have thorough details of how much you need to show in your bank statement. So it’s a good idea to check multiple embassies and be flexible in your travel. Remember, Schengen visa allows you to travel to 25 countries. So you could apply for a visa to any of those 25 countries and later travel to your desired destination through cheap train/airline tickets.

Step 3: Know how to fill up the Schengen visa application. For the visa to Poland, I used tips from a fellow blogger: (http://bubbleofblah.com/schengen-visa-application/) and for the visa to Germany, I used this document from the Abu Dhabi embassy: (http://de.vfsglobal.ae/pdf/VIDEX_General_User_Guidelines_190613.pdf). Do a google search on ‘how to fill up the Schengen visa’ and you’ll get a lot of sample applications.

Step 4: Have your airline booking, hotel booking, bank statement, passport info, other residency info in a foreign country that you’re staying at, lined up. For the bank statement, a general rule of thumb is to have $100 per day allocated for your travel. So for instance: if you are going for 20 days, you should show $2000 in your bank statements (which can include a credit card if you have one). You won’t usually require $2000 for food and hotel in Europe, but most of the embassies see $100 as a good amount to survive the day anywhere in Europe.  I’m a college student, so I’m always looking for ways to save money.

  • Use http://www.bewelcome.org to couch surf and meet new people and make new friends. It’s a good way to socialize and roam Europe within a budget.
  • And use http://www.seat61.com to find out about cheap train tickets all around Europe. If you want to fly, use http://www.ryanair.com for cheap airline tickets within Europe.
  • And use http://www.booking.com to book hotels/hostels for free and use those documents for the visa application. If you later on change your mind about staying in a hotel and couch surfing instead, you can always cancel the booking without any fees.
  • For the airline ticket, periodically check several websites. I use kayak.com, onetravel.com, airfare.com, studentuniverse.com, and norwegian.com to find my cheapest, international ticket to Europe. You should search for recent articles in the internet which talk about when to get the cheapest ticket. Usually for travel during December, the cheaper tickets are available during October and for travel during summer, you should buy the ticket during April/May. Also keep in mind that there are cheaper airports to travel to. So for instance, flying into Frankfurt is cheaper than flying into Paris.
  • The embassies ask you to book the ticket and not to buy it, but you can’t really book a ticket with the online booking websites I mentioned – they charge immediately after you book it. You need to buy a ticket from a travel agent as they can book the ticket for the visa and charge you after the visa is issued –  if you can’t take the risk of not getting a visa. I took the risk and that’s what I do :).

Step 5: Buy an insurance that covers 30,000 euros during your travel anywhere in the world for treatment and also ships you back to your country/state of residence, if you had an accident (basically, if you die). You can buy an insurance for 10-15$ from insubuy.com. They also give you the letter which is required for the application.

Step 6: Include all those documents which you think are relevant in establishing that you live where you live and would come back to that place after you travel. I mean, come on, no authority likes illegal immigrants. So if you want to travel, be a traveler. Don’t have any intentions other than travelling. There is a separate procedure for immigration and you should go through that. If you illegally immigrate, you would be ruining the visa procedure for the others and I don’t want that. The easiest way for you to immigrate might be to fall in love with someone from that country and marrying him/her! Wouldn’t that be interesting, huh?

I included my I-20 form from college, my college ID card, ISIC card, driver’s license, enrollment verification, rent, utility bill, class schedule etc.

Step 7: This is important (only if the embassy you are applying at has vague application requirements and asks you to provide additional, relevant documents). Write a cover letter (tips for writing the cover letter: http://bubbleofblah.com/schengen-visa-application/). In the cover letter list the documents you submitted precisely and explain in few words what they are intended for. Don’t be a waffle bot and write a lengthy essay. Also, it is in your favor if you explain the documents which support that you are going to return to the place where you came from. My college info were enough to explicate that point. I don’t know why the Swedish Embassy in Bangladesh weren’t convinced of that.

The German Embassy in New York had very friendly, smart and intelligent staff. They returned all of the extraneous documents I included in my application (including the cover letter) and gave me the visa in two business days. Kudos to the Germans!

I know the visa procedure is a hassle but you’ll forget about it once you reach Europe and start roaming around all the scenic places and meeting new people! I wish John Lennon’s words were true…imagine  there’s no countries…imagine all the people living life in peace..and the world will be as one…

Disclaimer: Everything I said above is in no way affiliated to any government/consul/embassy and I am not in any way responsible for you or any of your actions, if you have followed the steps I mentioned (I am just saying this so that I don’t get involved in any legal consequence(s) and not saying that I just wrote 1500 words of useless advice). So be responsible and honest and have a nice trip! :)

I Started Cooking

Those days are gone, when I could shout at my mom from my room to give me food. In college, either you eat from college dining services or you eat outside in restaurants or you cook your own food. Since I’ll be living in an off campus house from the next academic year, I have decided to give cooking a try. It’s a new thing, I’ve never done it, so today I felt adventurous and went grocery shopping for the first time. I was planning to use the kitchen at my work place on campus. So I bought all the essentials from this shop called PriceRite which is known to have a low price for food and went directly to the kitchen.

The tough part was finding out an easy enough recipe. I cooked rice first, cause that was the easiest (I’m from South Asia and that should explain my affinity towards rice), but now I wanted to cook something with the chicken breasts that I bought. When I searched the internet for recipes that include chicken breasts, I ended up with all these fancy names and a lot of ingredients were missing from the groceries I bought. So I said screw it. Somebody, somewhere in this planet must have said once that “Cooking is an art” and taking it literally I decided to trim the chicken breast and chopped it into pieces:

IMG_20140622_180741~2

Next I marinated the chicken with pepper and salt and left it at one corner for sometime while I chopped some vegetables (carrots, cucumber, peppers, greens etc.)

I took out the sauce pan now, put some canola oil in it and heated it up. I put the chopped chicken in it and started putting all kinds of spices that I found in the closet of the kitchen:

IMG_20140622_184501~2

Next I put all the vegetables onto the sauce pan:

IMG_20140622_185432~2And I was dancing to some Indie music which was playing in my phone. I tossed the dish and played around with the heater until I got the desired color on my canvas! Next I made sure if the chicken was really cooked, by eating one piece of the chicken from the pan (Oh boy, what an excitement it was!). I put my hard work into a plate and served it with a little bit of ranch dressing.

The final product:

IMG_20140622_190734~2

It took me an hour I guess. Not bad for the first time I’d say. On a scale of 1 to 10, I would give it a 5 for the taste. Anyway, it filled my stomach for the rest of the night.

UPDATE: I cooked more! Bananas worshipping a strawberry on top of a blueberry embedded mountain of pancakes!

10356252_10152558571994686_3525943340434173038_n

Setting up RIT Email (Google app email) in Android

As the title says, this post is specifically for RIT people. However, you are welcome to read it to gain insights on this simple solution to a problem, even if you are not from RIT. So as I was setting up my RIT email in my Nexus, I encountered a problem because RIT uses Gmail Apps for student email and on top of that they have Single Sign-On (SSO) for the sign in process, which basically means google doesn’t store our password. When you sign in through gmail.com, you type username@g.rit.edu in the address and then leave the password blank and press enter. It then directs you to RIT’s server where you put your RIT issued computer username and password and then only you get to see your mail in Gmail. Now for the android (may be valid for iOS too), to set up an email, you have to take some extra steps.

Step 1: Go to start.rit.edu and click on the “Google Apps at RIT” on the sidebar

Step 2: Enter your username and password

Capture

 

Step 3: In the next page, enter a new password in “Google Apps Password” Box. Note that you will be creating a new password. Your RIT computer password stays the same. (This was the “thing” that was keeping us from creating an account in Android apps or other mail clients!)

Capture
Step 4: Now there are two ways you can set up the email in Android. One is to set it up using the “Email” app in Android and the second is to use the “Gmail” app. I’m attaching the screen shots from the “Gmail” app which is pretty much self explanatory (Add account>Google>Existing>Email & Password> Additional configurations which you can customize). Just remember to use the “new password” you created in Step 3 and email as username@g.rit.edu. That should set the email!

This slideshow requires JavaScript.

Step 5: Now if you want to use the “Email” app, first you have to do a little tweak to your RIT email (that is, enabling IMAP for the RIT gmail). Log in to your RIT email using a computer and do the following (copied from google support).

Enable IMAP in your Gmail settings

  1. Click the  gear in the top right.
  2. Select Settings.
  3. Click Forwarding and POP/IMAP.
  4. Select Enable IMAP.
  5. Click Save Changes.

Step 6: Now do the following (copied from google support):

  1. Enable IMAP in your Mail settings.
  2. Open the Email application.
  3. Tap  and the Settings
  4. In the top corner, tap  select Next to get started with setup.
  5. Enter your full Google Apps email address and password, then tap Next.
  6. For ‘Username,’ enter your full Google Apps email address
  7. Tap IMAP account.
  8. Update the Incoming Settings:
    1. For ‘IMAP server,’ enter ‘imap.gmail.com’
    2. For ‘Port,’ enter ‘993’
    3. For ‘Security type,’ select ‘SSL/TLS”
  9. Tap Next and fill in the Outgoing Settings.
    1. For ‘SMTP server’ enter ‘smtp.gmail.com’
    2. For ‘Port,’ enter ‘465’
    3. For ‘Security type,’ select ‘SSL/TLS”
  10. Tap Next and continue through the setup options.

Hopefully, this will solve the problem and you’ll be more active in checking your school email cause remember, RIT’s policy says that anything that is sent to your school email (for instance: a letter by professor, quiz dates, exam dates etc.) is assumed to be read by the student regardless they actually checked their email or not. That means, you can’t use the excuse to your professor that you didn’t check/get the email. So stay updated instead and do your work!

A Cinematic Bus Ride

I never judged people critically on their phone usage. It’s a good device. Keeps us connected. But it’s true that it feels quite disturbing after sometimes, to witness people looking down on their phone all the time. I went further and peeked at what they do. I mean, I didn’t literally saw what they wrote to their girl/boy friend, mum, dad etc. I just looked at the gestures used on the phone and it was mostly “swipes” (duh. Newton’s laws are also…duh). Similar to scroll on the computer. What Facebook, Twitter, Tumblr and other major social networks did is that they involved a dynamic webpage with infinite scroll or “swipe”. So it is difficult to come to an end and you are hooked to the website in the process. I propose an easy solution. Get out and explore the world. The exploration is infinite till your existence. So again, you’ll get hooked. But hooked to the reality, not to the finite dimensions of the virtual. Here’s an itinerary for a great activity to do in Rochester, NY. It’s adapted from an article in therochesterinsomniac.com. I tried it myself and it was a lot of fun!

Step 1: Wherever you are, reach Main and Stone Bus stop, which is right next to the Chase building at Rochester. I reached there from RIT. So you need to take the bus number 24 from RIT, which drops you off exactly at that point – Main and Stone. Use Google Maps to get a sense of direction. It’s a great tool. If it’s not accessible, use common sense!

IMG_0289

Step 2: Look for bus No. 1. There are several of them. Make sure you get into the one labelled “Lake to Charlotte”. After all, it’s Charlotte Beach that we are going to.

Step 3: Hop into the bus. Chat with people. Read a book. Look at the city from the window. It’s ok to listen to music on your ipod. But listen to a couple of tracks and then do something else. That is, do different activities. I read pages from Richard Branson’s autobiography. Listened to a man and his frustrations of not having a male grandchild ’cause he wants to take him fishing. And then listened to an expectant mother, while she says she’s done if it’s a girl. Quite a contrast!

Step 4: Your last stop is the beach. Get down. Enjoy. Take pictures.

This slideshow requires JavaScript.

Step 5: Walk down the pier. It’s beautiful. Don’t move away from the splashes of the waves. It’s their way of welcoming you.

IMG_0311IMG_0314

Step 6: Reach the end of the light house and look into the distant horizon. You might find something!

IMG_0317

Step 7: Try the local specialties before boarding the same bus back. I tried hots from Harbour hots and had delicious fudge from the Abbotts!

IMG_0335 IMG_0336

Step 8: Create your own trip and let me know!

Lost in Pronunciation

Girl: Butter or oil?
Me: Butter
Girl: What would you like on your pasta?
Me: Can I have chicken, peppers and herbs please? 
Girl: Sorry, what?
Me: Chicken, peppers and herbs please. (with my voice a bit elevated)
Girl: Sorry, we don’t give hearts in here.
Me: I mean, HERBS. Am I saying it wrong?
Girl: Oh you mean ‘erbs! For one second, I thought you asked me to give you a heart. 
Me: Well that would be nice too! 
Girl: Sorry, I don’t do that.

I studied my subjects in UK English for the major part of my schooling. And it has been only a year that I am adapting myself to US English. The Americans were successful in changing the way I say ‘Maths’. Now I say, ‘Math’. And now, I found out that, in US English, they pronounce “herbs” with h muted. Upon further inquiry, I found out it’s a french word and the h is muted in french. Well Americans, if you would like to pronounce herbs the french way, why can’t you pronounce croissant as kʁwa.sɑ̃

I won’t complain as long as the pasta keeps my stomach happy!