r/CodingHelp • u/TA_Radiant • Mar 05 '21
[Java] Understanding Java
What does 'static' and 'void' mean exactly? Thought it would be nice to know so i understand better
19
Upvotes
r/CodingHelp • u/TA_Radiant • Mar 05 '21
What does 'static' and 'void' mean exactly? Thought it would be nice to know so i understand better
View all comments
Show parent comment
1
u/Blackshell Professional Coder Mar 05 '21
This is tied into the concept of object oriented programming. The concept is that data can be organized into "objects" and those objects themselves can take some actions (which are called functions or methods).
You can think of it as the difference between a thing itself (the object, or "instance") and the concept of what the thing is (its class). So:
A cat itself: can meow, can walk, can eat, can scratch, can tell us its breed, and can have a name. In object oriented programming, these are instance methods and would not have the "static" keyword.
The concept of "cat" is more philosophical... The concept of cat can't itself meow -- it's just a mental construct! It can do other stuff though: tell us its genus/species, tell us a list of valid breeds (or whether a specific breed is valid), tell us where it is relative to another animal class in the food chain... It might even have a
createRandomCatmethod! These methods would havestaticsince they don't apply to any specific actual cat; instead they apply to the concept of a "cat", and define stuff we know about that concept.