An Easy Way to Check Boolean System Properties

An Easy Way to Check Boolean System Properties

Suppose you want to pass a Boolean system property, -DDEBUG=true or -DDEBUG=false, from the command line. Normally, you’d probably use the following in source code to retrieve it:

 boolean b = Boolean.valueOf(System.getProperty("DEBUG")).booleanValue();if(b) {    //do something;}or just treat it as a string system property:if(System.getProperty("DEBUG").equalsIgnoreCase("true")) {    //do something;}

The following code offers an easier way to do the same thing:

 public class GetBoolean {    public static void main(String args[]) throws Exception {        if(Boolean.getBoolean("DEBUG")) {            System.out.println("Debug is on");        } else {            System.out.println("Debug is off");        }    }}

The GetBoolean class is tested under JDK1.3.1 with the following output:

 D:foo>java -DDEBUG=true GetBooleanDebug is onD:foo>java -DDEBUG=false GetBooleanDebug is offD:foo>java -DDEBUG=TRue GetBooleanDebug is onD:foo>java -DDEBUG=Yes GetBooleanDebug is offD:foo>java GetBooleanDebug is off
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several