Ok...so let's further explain how the dot or Dot Notation (.) works.
Whenever you use the Dot Notation, you have to think about two things.
The object before the Dot and the method or property after the Dot.
In java, whenever you access a method or property via dot notation, you can use it as an object right away.
Let's start with stack.peek()
If you look at the documentation for Stack it has a method called peek and it returns an Object.
Stack (Java 2 Platform SE v1.4.2)
That means, aside from an initial reference to a stack when using peek you gain reference to an Object.
(Stack) (Object)
stack . peek()
Since you now have reference to an object with class Object, you can use its methods and properties right away.
Object (Java 2 Platform SE 5.0)
Basing from the documentation, you can find the toString method which returns an object with class String.
(Stack) (Object) (String)
stack. peek(). toString().
Finally, since you now have a reference to a String object, upon looking at its documentation, you can use chatAt(int index) right away.
String (Java 2 Platform SE v1.4.2)
(Stack) (Object) (String) (Character)
stack. peek(). toString(). charAt(index)
So, in summary, the dot notation allows you to gain access of the object before the dot and use its corresponding methods, fields and other properties.