Compiler searching algorithm for finding a class
================================================
1. In a Java program we can access one class from other classes
2. When we access one class from other classes, compiler follows
below steps or algorithm for finding the accessed class 'Add'
1. first it searches class Add in current method main() method
as method local innner class, if available Compiler uses it
2. if not found in method, Compiler searches class Add in current class Calc
as class level innner class, if available compiler uses it
3. if not found in Calc, Compiler searches class Add in current Calc.java
as outer class, if available compiler uses it
4. if not found in Calc.java, Compiler searches class Add in hard disk
for Add.class, if found, it also seraches Add.java
1. If both Add.class and Add.java files found
Compiler compares timestamp, latest modified time
2. Which file timestamp is more, compiler uses it
and logic is executed from that class Add
//Calc.java
class Calc {
main method {
Add.add(10,20);
Auto compilation
=================
1. When we access one class (Add) from another class (Calc),
we no need to compile the first class java file Add.java,
we can compile the second class java file (Calc.java) directly
2. The Compiler software automatically compiles
the first class java file Add.java automatically.
3. Compiler can find the class's .java file automatically
only if we save .java file name with class name Add
4. If we create the java file and the class name with different names,
we will not auto compilation, we must compile each class separately.