Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if I modify class in project while application is still running?

Tags:

java

eclipse

jvm

I use Eclipse and have some project compiled and running. Then I decide to modify some class. It seems that running project doesn't catch up changes, but if I run another instance of project then it does see changes. The question, how does Eclipse rule this out? Because I see that .class files are stored as single instance and later changes just overwrite previous. It maybe JVM who load classes in memory and don't touch them even if they changed. But I would like to hear complete story.

like image 777
Павел Avatar asked Feb 23 '14 12:02

Павел


1 Answers

When a program runs, it reads the .class file into memory and uses that copy from then on.

If you change, it doesn't re-read the file and load/link it again, that would be more complicated. There are class loaders which do this automagically, but this is not default behaviour. (It is also very unreliable as you might change the class in an incompatible way e.g. modify a field, or method signature)

Generally speaking, software is implemented in the simplest way imaginable. It is more likely to work and be understood if it is simple. This should be your guiding principle when trying to understand how computers work.

like image 78
Peter Lawrey Avatar answered Oct 04 '22 03:10

Peter Lawrey