Q: const?

J

Jakob Bieling

Hi,

now this may seem like a very very basic question .. how do I define
constant in Java? In C++ you do 'static int const max_chars = 255;' ..
just in case I was not using the correct terminology to describe what I
am looking for.

Thanks!
 
J

Joan

Jakob Bieling said:
Hi,

now this may seem like a very very basic question .. how do I define
constant in Java? In C++ you do 'static int const max_chars = 255;' ..
just in case I was not using the correct terminology to describe what I
am looking for.

Thanks

static final int STOP = 0;
 
E

Eric Sosman

Jakob said:
Hi,

now this may seem like a very very basic question .. how do I define
constant in Java? In C++ you do 'static int const max_chars = 255;' ..
just in case I was not using the correct terminology to describe what I
am looking for.

static final int max_chars = 255;

There are semantic differences between `final' and
`const'. Don't just make textual substitutions and
assume you understand what they mean; read your Java
textbook.
 
J

Joan

Eric Sosman said:
static final int max_chars = 255;

There are semantic differences between `final' and
`const'. Don't just make textual substitutions and
assume you understand what they mean; read your Java
textbook.

Good point, but for me it is either provide no help by just saying "it is
not supported so
take your little problem and go home" or
to provide some guidance as to what might be done instead should they
wish to investigate further.
 
E

Eric Sosman

Joan said:
Good point, but for me it is either provide no help by just saying "it is
not supported so
take your little problem and go home" or
to provide some guidance as to what might be done instead should they
wish to investigate further.

Joan, I don't understand your response. I pointed
the original questioner to `final' as a substitute for
some uses of `const', and warned him that the two were
not exactly the same. Do you think I told him too much?
Too little? Or what?
 
J

Joan

Joan, I don't understand your response. I pointed
the original questioner to `final' as a substitute for
some uses of `const', and warned him that the two were
not exactly the same. Do you think I told him too much?
Too little? Or what?
Oh, Sorry Eric, I wasn't thinking too much.
I have been a little paranoid lately and thought you
were criticizing me rather than giving advice to the OP
 
J

Jakob Bieling

Eric Sosman said:
static final int max_chars = 255;

There are semantic differences between `final' and
`const'. Don't just make textual substitutions and
assume you understand what they mean; read your Java
textbook.


Thank you! I will :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top