Chapter 10
Numbers & Statics
The methods in the Math class are static and you can’t create instances of that class, they don’t need instance variables.
Making a class static allows it to execute without requiring any instances. The term “static” refers to behavior that is independent of an instance variable.
Call a static method using a class name ( Math.min(88,86) )
Call a non static method using a reference variable name
Song t2 = new Song ();
T2.play();
When a method or constructor is declared private, it implies that only code from within the class can call it.
The class, not the instance, is connected with a static method. As a result, it is unable to access any of its class’s instance variable values.
Because non-static methods deal with instance variables, static methods cannot access them.
You can’t create instances by making the constructor of a class using static methods private.
A static variable is a variable that all members of a class have access to. In class, instead of having one copy for each instance variable, there is just one static variable. Static variables can be accessed through a static method.
In Java, you can make a constant by declaring a variable static and final. As a name standard, Constant should use all capital letters. The value of a final instance variable cannot be changed, the final method cannot be modified, and the final class cannot be extended.
-Math methods-
Wrapping a primitive
When you need to treat a primitive like an object, wrap it.
In Java 5.0 there is a feature called autoboxing which does the conversion from primitive to wrapper object automatically.
-Fun with autoboxing-
There’s more! Wrappers
have static utility methods too!
Formatting a number to use commas
Formatting deconstructed…
-The format specifier-
The only required specifier is for TYPE
Highlights of the Calendar API