Let’s start by defining JDK (Java Development Kit), JRE (Java Runtime Environment), and JVM (Java Virtual Machine).
JDK (Java Development Kit)
JDK contains everything that will be required to develop and run Java application.
JRE (Java Run time Environment)
JRE contains everything required to run Java application which has already been compiled. It doesn’t contain the code library required to develop Java application.
JVM (Java Virtual Machine)
JVM is a virtual machine which work on top of your operating system to provide a recommended environment for your compiled Java code. JVM only works with bytecode. Hence you need to compile your Java application(.java) so that it can be converted to bytecode format (also known as the .class file). Which then will be used by JVM to run application. JVM only provide the environment It needs the Java code library to run applications.
JDK vs JRE vs JVM
The below chart shows the different features of each of the Java technologies.
*Image Courtesy : Oracle Corporation
Now as per diagram you can identify what is the difference.
JRE = JVM + Required Library to run Application.
JDK = JRE + Required Library to develop Java Application.
In order to understand portability in Java you need to understand what happens to java code from start to finish.
1- Java Source Code (Written by Developer) (Machine Neutral)
2- Compiled Code / Byte Code (Compiled by javac) . (Machine Neutral)
3- Byte Code executed (Executed by JVM) (Machine Specific)
In step 2, javac (Java Compiler) converts Java code to byte code. This can be moved to any machine(Windows / Linux) and executed by JVM. JVM reads the bytecode and generates machine specific code. In order to generate machine specific code JVM needs to be machine specific. So every type of Machine(Windows / Linux / Mac) has a specific JVM. So in this way the coder doesn’t need to bother with generating byte code. JVM takes care of portability. So the final answer is Java is Portable but JVM is Machine Specific.