I made a change to to the source. I would have thought that the changed code be recompiled by the JVM but this did not occur. Should it have ?
No. Assuming that you are using the standard Java tool-chain, your source code is only compiled when you run the javac
. Certainly, the JVM (i.e. java
) neither compiles source code, or notices when the source code changes. Indeed, it won't even notice if ".class" files have changed1.
On the other hand, if you are using an IDE to develop / compile / run, then it (not the JVM) will typically notice when the source code changes and automatically recompile it. But if you happened to be running at the same time as you are changing your application, the changes typically won't affect the running program2.
1 - It is possible to code your application so that it notices changes and attempts to reload recompiled classes, but there are a bunch of issues and potential traps in doing that. (Loading a class multiple times gives you a different type each time ... as far as the runtime type system is concerned. It gets really awkward unless you can reload the entire application.)
2 - Some IDEs (e.g. Eclipse) notice when you make a change to a class that is being used by a class that you are debugging, and offer you the choice of relaunching the application being debugged.