OneBite.Dev - Coding blog in a bite size

declare a boolean in java

Code snippet on how to declare a boolean in java

boolean buttonPressed = false;

This code is declaring a boolean variable called buttonPressed. The variable is given a value of false - this is because a boolean variable can be either true or false. In this case, if the button has not been pressed, its value is false. The variable can then be used to check if the button has been pressed in the program. For example if an if statement is used to check if the button has been pressed, the boolean variable is used to keep track of if the button has been pressed or not.

java