I've started learning java. I've understood so far that method calls are:
object.methodname(arguments)
although I think more broadly I've discovered that it's actually:
receiver.methodname(arguments)
and that a receiver might not necessarily be an object. or perhaps my understanding of object is wrong. I get that a class defines a type, and an object is an instance of the class. And that calling a method is sending a message to an object, and the message has to be something the object understands as defined by the methods in its class.
But... what about:
import java.lang.Math
double x = 16;
double y = Math.sqrt(x);
double z = Math.pow(x,y);
is Math an object? I don't believe so. My understanding so far is that Math is a "package class" in the java.lang package. I don't yet really understand what a "package class" is other than that it's some kind of pre-written library of functions I can use...
But if it's a class, then that means sometimes a receiver can be a class and doesn't necessarily have to be an object...?
...or is Math an object/instance of some other class?
I've googled every combination of java/receiver/object/class/etc that i can think of and can't find anywhere that really clears this up for me. I'd appreciate any insights anyone can offer me to clear it up.
Thanks!
Math is a class! But those are static methods :) which means Math does not need to be instantiated as an object to be used. You just use it directly.
Packages are just ways to organize/categorize classes.
"receiver" is not common jargon in Java and O.O.