Java is the future !: July 2010

Sunday, July 25, 2010

PhraseOMatic (A cool program)

public class PhraseOMatic{
public static void main(String [] args ) {


String[] stat1={"matt","john","harry","mary"};
String[] stat2={"is getting","works like","is"};
String[] stat3={"mad","crazy","smart"};

//size of each array
int len1=stat1.length;
int len2=stat2.length;
int len3=stat3.length;

//pick a random word from each statement

int rand1= (int) (Math.random() * len1);
int rand2= (int) (Math.random() * len2);
int rand3= (int) (Math.random() * len3);

//make a phrase

String phrase = stat1[rand1]+ " " + stat2[rand2] + " "
+ stat3[rand3];

//print
System.out.print("Statement: " + phrase);

}
}

Saturday, July 24, 2010

99 bottles of beer

Again a universal program for looping.

About:

"99 Bottles of Beer" is a traditional song in the United States and Canada. It is popular to sing on long trips, as it has a very repetitive format which is easy to memorize, and can take a long time to sing. In particular the song is frequently sung by children on long bus trips, such as class field trips, or on Scout and/or Girl Guide outings. The song is derived from the English "Ten Green Bottles".

The lyrics are simple:

Ninety-nine bottles of beer on the wall, Ninety-nine bottles of beer.
Take one down, pass it around, Ninety-eight bottles of beer on the wall.
The same verse is repeated, each time with one less bottle. The song is completed when the singer or singers reach zero.

So I made the program for this.

Source code:

public class HelloWorld{
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("No more bottles of beer on the wall");
}
}
}

Friday, July 23, 2010

I see Java 2 and Java 5.0, but was there a Java 3 and 4? And why is it Java 5.0 but not Java 2.0?

The joys of marketing...when the version of Java shifted from 1.1 to 1.2, the changes to Java were so dramatic that the marketers decided we needed a whole new "name", so they started calling it Java 2, even though the actual version of Java was 1.2. But versions 1.3 and 1.4 were still considered Java2. There never was a Java 3 or 4. Beginning with Java version 1.5, the marketers decided once again that the changes were so dramatic that a new name was needed (and most developers agreed), so they looked at the options. The next number In the name sequence would be 3: but calling Java 1.5 Java 3 seemed more confusing, so they decided to name It Java 5.0 to match the "5" in version "l.5" So, the original Java was versions 1.02 (the first official release) through 1.1 were just "Java" Versions 1,2,1.3, and 1.4 were "Java 2" And beginning with version 1.5,Java is called "Java 5.0" But you'll also see it called "Java 5" (without the ".0") and "Tiger" (its original code-name). We have no idea what will happen with the next release.. :-)

Source: HFJ

You don't need any IDE?

I was going through the Head-First book and found something strange.

Check this one out.

You do not need any other development tool. such as an Integrated
Development Environment (IDE). We strongly recommend that you not
use anything but a-basic text editor until you complete this book (and
especially not until after chapter 16). An IDE can protect you from some of the details that really matter. so you're much bener off learning from the command-line and then. once you really understand what's happening. move to a tool that automates some of the process.

Cool ah?

I will follow that.

Thursday, July 22, 2010

First day with Eclipse

Umm, So 4th semester exams are over. Now I am all set for Java. Just finished downloading the Eclipse IDE. Made the first Java program ( A universal program "Hello World !" )

Eclipse is good. Let me see how does it work. The software is free and you can download it from the link given below.

Download Eclipse