Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please explain every line

 
suresh krishan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


output

/*
*
The Date for United States:
In FULL is Tuesday, May 9, 2006
In LONG is May 9, 2006
In MEDIUM is May 9, 2006
In SHORT is 5/9/06

The Date for United Kingdom:
In FULL is 09 May 2006
In LONG is 09 May 2006
In MEDIUM is 09-May-2006
In SHORT is 09/05/06

The Date for Germany:
In FULL is Dienstag, 9. Mai 2006
In LONG is 9. Mai 2006
In MEDIUM is 09.05.2006
In SHORT is 09.05.06

The Date for France:
In FULL is mardi 9 mai 2006
In LONG is 9 mai 2006
In MEDIUM is 9 mai 2006
In SHORT is 09/05/06

* */
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
What you have is an array of locales (or locations) and an array of date formats. You go through the different countries, then for each country you print the date in each of the formats, with the spelling used in that country. Note that in North America the month precedes the day, and in Europe the day precedes the month.

It is unfortunate that one has to use an array of names {"FULL", "SHORT" etc }, rather than having an enum. If the constants were enum members, one could use their toString method to print FULL, SHORT, etc.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, did you copy that code from anywhere? It looks like code from a book printed in 2006, unless it has taken over 5 years from your running it to asking for the explanation
 
suresh krishan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually im just started java, im confused why array is used why dont use method and consructor... im reading from cbt nuggets tutorial, in that always he used method and constructors.. but suddenly how array in coming im confused... please help friends i want to become a good application developer..
 
suresh krishan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and please explain why particularly int and locale array is used.. how do i find that array in api doc
 
suresh krishan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there anybody to help me out
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd guess that arrays are being used simply because it's an example demonstrating how to use arrays. So it's creating an array of locales an an array of styles (as used by DateFormat.getDateInstance()), and printing out the date in each combination of style and locale.

The Java tutorials have got more about arrays here: http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
 
Winston Gutkowski
Bartender
Pie
Posts: 9477
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suresh krishan wrote:and please explain why particularly int and locale array is used.. how do i find that array in api doc

It's 'Locale', not 'locale' (a good first lesson; compilers are NOT forgiving about that sort of mistake). And if you click on that word in this sentence, you'll see its API.

Winston
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12020
25
Chrome Java Linux
  • 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suresh krishan wrote:is there anybody to help me out
You realize this is a forum - not a chat, right? waiting 12 whole minutes before begging for someone to answer comes across as a little rude. Everyone on this site is a volunteer, and gives what time they can.
 
dennis deems
Ranch Hand
Posts: 808
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think the example is demonstrating the use of arrays per se; I think it's demonstrating how you use Locale and DateFormat to produce region-appropriate date strings in a variety of formats. I think arrays are used because they can be instantiated very easily, enabling the author to generate a number of examples in a very short space.

This looks very familiar. I'd bet a doughnut it's from the K&B discussion of DateFormat.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That shows the hazard of rushing ahead of yourself. You ought to have sought a tutorial about arrays, and read that. Then you could have asked us questions about what you don’t understand, and we would have been keen to help.
 
suresh krishan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks friends... but i dont know how this Locale api is related to this program... dont know what are the things taken this program from Locale api.. could anybody explain in detail..
 
suresh krishan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Locale api there only given Locale constructors but in this program Locale array is used.. how?
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12020
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can have an array of any class or interface type. No class has an explicit 'array' constructor.
 
suresh krishan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why using array String in this program.. i could not find this array in Locale api...
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The String array is for printing out the names of the formats. If there had been an enum for the formats, you could have called toString() on the format objects, but they are only ints, so you have to copy their names into an array.

We can see an enum would have been more object-oriented, but enums hadn’t been introduced into Java™ when the DateFormat class was written.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic