isJavaAwtHeadless()
is a SystemUtils
that is used to check whether the headless mode is enabled for Java AWT.
Java AWT stands for Abstract Window Toolkit, which is an API used to develop Graphical User Interfaces in Java.
Many times, developers need to work on graphics-based applications without the need to display user interfaces. In these scenarios, the headless mode is enabled.
StringUtils
The definition of StringUtils
can be found in the Apache Commons Lang
package, which we can add to the Maven project by adding the following dependency to the pom.xml
file:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
For other versions of the commons-lang package, refer to the Maven Repository.
You can import the StringUtils
class as follows:
import org.apache.commons.lang3.StringUtils;
public static boolean isJavaAwtHeadless()
The method does not accept any parameters.
This method returns true
if the headless mode is enabled. Otherwise, it returns false
.
import org.apache.commons.lang3.SystemUtils;public class Main{public static void main(String[] args){boolean isJavaAwtHeadless = SystemUtils.isJavaAwtHeadless();System.out.printf("The output of SystemUtils.isJavaAwtHeadless() is '%b'.", isJavaAwtHeadless);}}
In the code above, we get whether the headless mode is enabled for Java AWT.
The output of the code will be as follows:
The output of SystemUtils.isJavaAwtHeadless() is 'false'.
Running the code above in your system can give a different output, depending on your machine.