Reputation: 29
I'm just new to java .I made two java files. One is Main.java which contains the main method and the other one is Second.java which contains some fields and methods. After that I created the object of "Second" in the Main.java and call the fields and methods from Second. And then I compiled both of the file and it output the result of the fields and methods from Second. Then I put one more method in the Second.java file and call that method in the Main.java. At that time, I only have to recompile the Main.java file and that method was called. I don't have to recompile the Second.java file. How's that work? Doesn't the Second.java file has to be recompiled after some modification?
( I used the notepad for better understanding of java compiling process)
Upvotes: 1
Views: 82
Reputation: 123670
javac
automatically recompiles dependencies when it finds a corresponding .java
file.
You will notice that if you delete both .class
files and build only Main.java
with javac Main.java
, then Second.class
will still be generated.
If you then delete or move Second.java
but leave Second.class
in place, and modify Main.java
to call a new method, then javac
will find the old class, be unable to recompile it, and give you the error about missing methods that you expected.
Upvotes: 2