Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: What is the difference?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default What is the difference?

    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.print(beerNum + " " + word + " of beer on the wall, ");
    			System.out.println(beerNum + " " + word + " of beer.");
    			System.out.print("Take one down.");
    			System.out.println(" Pass it around.\n");
    			beerNum=beerNum - 1;
     
    			if (beerNum == 0) {
    				System.out.println("No more bottles of beer on the wall, no more bottles of beer.");
    				System.out.println("Go to the store and but some more, 99 bottles of beer on the wall.");
    			}
    		}
    	}
    }

    I am new to java. I am referring Head First Java. I am practicing all its codes. There is with the beer Song. I have corrected the error in it. But I have question: What is the difference between mentioning "String word" (in line 3 of code) and only "word" (in line 7).


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: What is the difference?

    When you code a data type like String before a variable name, you are defining the variable as that datatype.
    Take a look at the tutorial:
    Variables (The Java™ Tutorials > Learning the Java Language > Language Basics)

  3. The Following User Says Thank You to Norm For This Useful Post:

    soul_samir (February 11th, 2012)

Similar Threads

  1. Difference Between JDK 5,6 & 7
    By wadey in forum Java Theory & Questions
    Replies: 5
    Last Post: February 2nd, 2012, 09:07 AM
  2. Difference between jboss 4.x,5.x and 6.x
    By vairam in forum Member Introductions
    Replies: 1
    Last Post: May 3rd, 2011, 09:49 AM
  3. [SOLVED] Difference between == and equals.
    By goldest in forum What's Wrong With My Code?
    Replies: 9
    Last Post: December 18th, 2010, 03:15 PM
  4. Replies: 1
    Last Post: August 13th, 2010, 06:58 AM
  5. Need to know this difference
    By arvind in forum Java Theory & Questions
    Replies: 2
    Last Post: January 19th, 2010, 06:24 AM