I am a beginner with the java language and programming as a whole.
I understand that to call methods from another class, we call that method with:
ClassName.methodName(arguments);
For example, when we want to find the square root of an integer using the Math classs:
int x = 4;
int root = (int)(Math.sqrt(x));
However, when we use certain methods in other classes, such as the charAt() method in the String class, we access that method using something like:
String str = "Greetings!";
char ch = str.charAt(0);
This is also true for other methods in the String class such as: codePointAt() and compareTo().
Why do we call methods differently when using methods from certain classes like the String class? How do we know when to call methods like this as opposed to the other way?
Thanks!