By Alvin Alexander. Last updated: June 4, 2016
In short, static Java variables and methods are instantiated only once for a class. Because of this you’ll hear these referred to as class variables, as opposed to the more common instance variables. That’s because you can deal with these directly at the class level, without needing to have an instance of the class instantiated.
The Java Math
class is a good example of this. The Math
class has many static methods like Math.abs()
, Math.ceil()
, and many more static methods. Another more common example of this is how the System.out.println()
method works. out
is a static field in the System
(java.lang.System
) class, and then you call the println()
method on that field.