aspose file tools*
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "const syntax." Watch "const syntax." New topic
Author

const syntax.

Asaf Karass
Greenhorn

Joined: Mar 08, 2001
Posts: 14
hello.
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
Bartender

Joined: Oct 18, 2000
Posts: 4121

Asaf,
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 8.3.1.2, but I would really advise getting something a little more readable as a language reference. Look in the JavaRanch Bunkhouse for some suggestions.
HTH,
-Nate
[This message has been edited by Nathan Pruett (edited March 16, 2001).]


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

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: http://aspose.com/file-tools
 
subject: const syntax.