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.


public static boolean compileClasses(String string)


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.


throws NullPointerException, If string is null.


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(); 

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

    //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