0% found this document useful (0 votes)
3 views1 page

Compiler Seraching Algorithm for AC

The document outlines the compiler searching algorithm in Java for locating a class, detailing the steps taken from searching within the current method to checking for class files on the hard disk. It also explains the auto-compilation feature, where the compiler can automatically compile a class file if the file name matches the class name, eliminating the need for separate compilation. If the class name and file name differ, each class must be compiled individually.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Compiler Seraching Algorithm for AC

The document outlines the compiler searching algorithm in Java for locating a class, detailing the steps taken from searching within the current method to checking for class files on the hard disk. It also explains the auto-compilation feature, where the compiler can automatically compile a class file if the file name matches the class name, eliminating the need for separate compilation. If the class name and file name differ, each class must be compiled individually.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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.

You might also like