Observer pattern

When we implement the Observer pattern, we usually refer to the
data as the Subject and each of the displays as Observers. Each of these
observers registers its interest in the data by calling a public method in the
Subject. Then, each observer has a known interface that the subject calls
when the data change. We could define these interfaces as follows:
abstract interface Observer {
//notify the Observers that a change has taken place
public void sendNotify(String s);
abstract interface Subject {
//tell the Subject you are interested in changes
public void registerInterest(Observer obs);

still not clear for me…
May someone Please tell me how Observer pattern works?

Same idea as a Listener.

Using the Pattern terminology:

The Subject is created with value = 1.
One or more Observers are created and registered with the Subject via the registerInterest method.
Something happens to change the value of the Subject from 1 to 2.
The Subject informs all of it observers that the change has occurred.
The Observers take action as needed.

Real World example.

You (the subject) get a new phone with a new number.
You inform your friends (the observers) of your new number.

May you give a sample code about observe pattern?