File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Enumerated type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Enumerated type" Watch "Enumerated type" New topic
Author

Enumerated type

Melissa Lee
Greenhorn

Joined: Jan 08, 2005
Posts: 4
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

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30299
    
150

"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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeff Langr
author
Ranch Hand

Joined: May 14, 2003
Posts: 762
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.


Books: Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
Melissa Lee
Greenhorn

Joined: Jan 08, 2005
Posts: 4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enumerated type