Numbers Matter — Chapter 10

Initializing a static variable

Static variables are initialized when a class is loaded. (either the JVM or the programmer can decide to load the class).

  1. any object of that class can be created.
  2. any static method of the class runs.

Static final variables are constants

The value of a static final variable will stay the same (constant) as long as the class is loaded. Constant variable names should be in all cap, with underscores separating words. Eg: Math.PI API

Final

final variable — can’t change its value

Math methods

Math.random — returns a double between 0.0 (not including) and 1.0. double rl = Math. random 0 ;

Wrapping a primitive

There’s a wrapper class for every primitive type, and since the wrapper classes are in the java. lang package, you don’t need to import them. Mostly used to storing a primitive value inside a collection like an ArrayList or HashMap. However, the autoboxing feature added to Java 5.0 does the conversion from primitive to wrapper object automatically. Autoboxing can also be used in parameter values, return values and operand operations.

Vocabulary

static — a variable or method whose behavior doesn’t depend on an instance variable value.

--

--

Everything in my point of view. Here for you to read on....

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Upulie Handalage

Upulie Handalage

Everything in my point of view. Here for you to read on....