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 Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enum problem

 
Tarun Chauhan
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy ! I am not able to understand enum even though I have tried many sources. Could anyone suggest me some online resources where I could look it up.

My doubts and questions are :
(1). Is enum is a class or a method.
(2). If enum is a class then why don't we declare it with class keyword.

It would be very nice of anyone who could show me a complete program (and not a snippet) in which enum has been used.
 
Manuel Leiria
Ranch Hand
Posts: 171
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Hungry Joe:
Howdy ! I am not able to understand enum even though I have tried many sources. Could anyone suggest me some online resources where I could look it up.

My doubts and questions are :
(1). Is enum is a class or a method.
(2). If enum is a class then why don't we declare it with class keyword.

It would be very nice of anyone who could show me a complete program (and not a snippet) in which enum has been used.


(1). Is enum is a class or a method.

enum is a special kind of class, with an instance that represents each value of the enum
 
Shoumin Li
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If enum is a class then why don't we declare it with class keyword.
I think is'a custom of c,
and many programer had used c/c++,(and many old language)
To attact the c/c++ programer ,Java kept some custom from C/C++
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy there Hungry Joe,

First off, welcome to the ranch. We've found that things stay friendler when people use their real names as their display names, so I'd ask you to update your display name to follow that policy.

Second, since this question was posed in the beginner's forum, it's most useful to think of enums as being very similar to normal classes. They can have there own variables, constructors and methods.

hth,

Bert
[ July 25, 2007: Message edited by: Bert Bates ]
 
Tarun Chauhan
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about the name. I read the naming policy after Bert Bates adviced me to.
 
Jinny Morris
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tarun -

The example on p. 673 of Head First Java by Kathy Sierra and Bert Bates seems to me to be a "complete program" using an enum - and if you write another class called something like TestEnum and move their main function to that class you should have a pretty good example of the enum's use.

I just finished an expression parser that uses an enum for the arithmetic operations - I could send it to you if you'd like, but since I'm just a beginner it's not so much a "perfect" example of Java programming!

Try experimenting with the Sierra and Bates example - it all becomes more obvious once you've tried out some things with it.
 
Tarun Chauhan
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jinny,

Thanks for suggesting the example in Head First Java. Unfortunately, I have the old edition and 'enum' was not discussed in it. I just need to see a working program that uses 'enum'. It would be great if you send me your program. Thanks again.
 
Jinny Morris
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tarun -

I sent the zipped source files to your gmail address - please let me know if any of it doesn't make sense!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic