We are about to switch to a new forum software. Until then we have removed the registration on this forum.
can anyone help me understand why static and short where used in the local variables in this code?
http://studio.sketchpad.cc/sp/pad/view/ro.9LZizxKsIAY4F/latest?
Answers
Are you asking what static and short are?
short is, like
int
, one of the Java Primitive Datatypes. It is half an int. If you are storing some small numbers, you could store them in shorts to save a little bit of space:static, declares a variable to be an unchanging constant when used with final.
In a short sketch this careful specification of small, unchanging variables might be about good style rather than functionality. If you try clone-modifying @GoToLoop 's sketch and replace
final static short
withint
... does anything change?Actually a primitive or String
final
field variable doesn't needstatic
in order to reach compile-time constant! L-)Rather,
static
is used to prohibit fields to be created more than once when its class is instantiated. :-Bsoooooo, im still a wee bit confused on what static and final mean. I am sorry im just pretty new to programming and I havent learned these things in my class yet (the language im using im pretty sure is processing). ( I read your link @jeremydouglass ) The only thing i understand from this is that short CAN be replaced with int right? because short is half of an int (which is pretty cool too). Sorry guys thank you both so much for the help.
Actually it is a long stretch to call Processing a programming language! @-)
It's rather a framework + PDE (its IDE) on top of the Java language! ~O)
And it's not bound to Java only! It's available for JS, Python, Android, etc. \m/
final
-> Such variable can only use the assignment operator=
(and its "siblings") once only!static
-> Such field is created once only, no matter how many times its class is instantiated!Im still kind of confused with final. So, then why did you use it the way you did in the jumping block example? and im still confused with static omg im so sorry again im really new to all of this .-.
Both
final
&static
aren't necessary for any program to function.You can keep or remove them. Won't make any actual difference! :-j
hehehe ok thanks man ^_^"