Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


The java.lang.Compiler.compileClasses() used to compile all classes whose name matches the specified string.

Syntax

public static boolean compileClasses(String string)

Parameters

string Specify the name of the classes to compile.

Return Value

Returns true if the compilation succeeded; false if the compilation failed or no compiler is available.

Exception

throws NullPointerException, If string is null.

Example:

The below example shows how to use java.lang.Compiler.compileClasses() method.

public class MyClass {
  public static void main(String[] args) {
    MyClass x = new MyClass();
    subMyClass y = new subMyClass();

    //printing class of x
    Class xcls = x.getClass(); 
    System.out.println(xcls);

    //printing class of y
    Class ycls = y.getClass(); 
    System.out.println(ycls);

    //returns false if the compilation failed 
    //or no compiler is available
    boolean retval = Compiler.compileClasses("MyClass");
    System.out.println("Return Value = " + retval); 
  }
}
class subMyClass extends MyClass {
  //sub class
} 

The output of the above code will be:

class MyClass
class subMyClass
Return Value = false

❮ Java.lang - Compiler