Know Your Variables — Chapter 3

  1. Primitive — Holds fundamental values including integers, booleans, and floating point numbers.
  2. Object References — Holds references to objects.

Naming conventions for a class,method, variable

  1. It must start with a letter or an underscore (_), or dollar algn ($). You can’t start a name with a number.
  2. After the first character, you can use numbers as well.
  3. It shouldn’t be one of Java’s reserved words.

Object References

  • There is no such thing as an object variable. (Only an object reference variable)
  • It holds something like a pointer.
  • Objects live on the garbage collectible heap.
  • Performing arithmetic operations in Java(increments etc.) on a reference variable, is not possible unlike C.
  • Unless an object reference is final, one Dog object could refer to another Dog object later.
  • Objects can also be assigned as null.

A bit about being null

  • null is a value.
  • If there is only one reference to a particular object, then once its set to null (deprogrammed), the object is lost.
  • Unlike primitives, every lost object goes into garbage collection(GC).

Arrays

  • An array could also be considered an object reference as it holds the references to the primitives/object references inside of it.
  • An array itself is never a primitive (regardless of what the array holds), it is always an object.
  • Accessing an unassigned index on an array of objects will give null.
  • Accessing a value within an unassigned index on an array of objects will give a runtime error.

Vocabulary

--

--

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....