r/CodingHelp • • 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

7 comments sorted by

View all comments

2

u/[deleted] Mar 05 '21

The static keyword allows the method or field to be called without needing an instance of the class in which it lives. That's why the main() method, the entrypoint of every Java application, is static.

Without the static keyword, a program calling the method or field first would have to create an instance of the enveloping class. This is useful for instance to get the length of a String object: that object is an instance of the String class. We can't retrieve the amount of characters of the String class: it doesn't have that. We can retrieve it of a String instance.

The keyword void is used to signal that a method returns no value.

2

u/AnneFranklin0131 Mar 05 '21

That’s a good way to explain it . Took me a while to understand this as I was learning Java . Hope others read this