# Today I Learned

Some of the things I've learned every day since Oct 10, 2016

## 95: Static Variables and Methods (Java)

In the Java programming language, both variables and methods within a class can be static or non-static. For a variable or method to be static means that it can be accessed without referencing an instance of the containing class.

If something is non-static, for example a method $\texttt{m}$ belonging to a class $\texttt{C}$, one must use an instance of $\texttt{C}$ to call $\texttt{m}$:

$\texttt{C c = new C();}$

$\texttt{c.m();}$

whereas if $\texttt{m}$ was static, it could simply be called with reference to the class itself:

$\texttt{C.m();}$

Static methods can be called with reference to class instances, but this is generally considered poor form.