How does Java achieve platform independence using JVM?

When you start learning programming, one common confusion comes up: why does the same code behave differently on different systems?…