File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enumerated type

 
Melissa Lee
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,
am new to Java, & need some HELP!!!

In pascal when I want to declared type like enumerated type
for eg date : 1 .. 31
How do I do that in Java ?
I know in JDK 1.5 there enum class
so I declare wz it
public enum weekdays ( monday, tues, etc)
But how about if I want to declare date that are from 1 to 31, need I mentioned all the 31 numbers or there's another way to do it.

Thanks in advance
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a Sun article about enums. I have to admin I haven't used them ... the first time I tried my version of Eclipse didn't like them and I keep forgetting to try again. Let us know how they work for you.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33670
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"new jav",

We're pleased to have you here with us, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks,
Jeanne
Bartender
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would need to declare all of the values explicitly for the enum. There's probably little good reason to enumerate days of the month, however.

Here's another article on enum.
 
Melissa Lee
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops forgot to read about the naming policy.

Thanks Stan & Jeff for the link, it’s really helpful.
It just don’t work wz the J2SE 1.4, will need the 5.0 for it to work.
For enumerating the days of the month, it’s my homework to convert the date : 1 .. 31 in pascal to java, guess will have to declare it as int and then use an if statement to print an error message if somebody enter a number outside of that range.
Else can I use the “throw exception”, but don’t really know much about this rules can somebody help me out or provide me with some good links.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic