Is Java's default value for Boolean 'true'?

boolean, java

Solution

Boolean (with a uppercase 'B') is a Boolean object, which if not assigned a value, will default to null. boolean (with a lowercase 'b') is a boolean primitive, which if not assigned a value, will default to false.

Boolean objectBoolean;
boolean primitiveBoolean;

System.out.println(objectBoolean); // will print 'null'
System.out.println(primitiveBoolean); // will print 'false'

Problem

Why does `private Boolean shouldDropTables;` assign `true` by default to the variable instead of `NULL`, like when writing `private Integer anInteger;`? I am asking because I came across some code where there was an evaluation on a `shouldDropTables` Boolean variable being `NULL` or not determining whether to execute a method.

Original source

Related problems