In the most literal sense,
on has to do with contact between surfaces,
in has to do with enclosure and containment.
The pen is on the book. The book is on the table. The
man is on the roof. The newspaper is on the floor. The
picture is on the wall.
The water is in the glass. The car is in the garage. The
students are in the gym. The chocolates are in the box. The
milk is in the refrigerator.
For non-literal usage, it is not always possible to predict exactly
which preposition is to be used. These may have to be learned as
expressions.
on my mind, on fire, on tap, on the run
in a good mood, in trouble, in the way
CJ