File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes const syntax. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "const syntax." Watch "const syntax." New topic

const syntax.

Asaf Karass

Joined: Mar 08, 2001
Posts: 14
what is the const syntax?
I want to put a int array as a const.
where in the JavaDoc can I find this stuff?
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

The syntax for a constant in Java is final so you would do something like:

To make a constant called CONSTANT_NUM for your class, and set it to 10. (static final makes it a constant for every object in the class, and final by itself makes it constant just for the current object. That means you can leave out the value and assign it a value in the class constructor. Then you can't change it afterwards. That means you can make each object have a different constant if you wanted. Pretty cool , huh? )
You can find this in the JLS in section, but I would really advise getting something a little more readable as a language reference. Look in the JavaRanch Bunkhouse for some suggestions.
[This message has been edited by Nathan Pruett (edited March 16, 2001).]

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Asaf Karass

Joined: Mar 08, 2001
Posts: 14
will this work for a final int array :
int m = 2;
final int array[] = new int[500];
array[1] = m;

btw - I know what static is.
I agree. Here's the link:
subject: const syntax.
jQuery in Action, 3rd edition