Programs select workflows based on conditions. A comparison produces a boolean. For primitive numbers, == compares values. For objects, == instead checks whether the same reference is used. This distinction is especially important for text. We combine a count check with a text comparison.
01Compare numbers
count > 0 && count <= 100 requires both conditions to match. || requires at least one true condition. if and else select the appropriate block. Parentheses and braces belong to the syntax.
public class Main {
public static void main(String[] args) {
int count = 3;
String status = "READY";
if (count > 0 && count <= 100 && "READY".equals(status)) {
System.out.println("Start batch");
} else {
System.out.println("Cannot start");
}
}
}
Run / check
java Main.java02Compare text contents
"READY".equals(status) compares contents. The fixed string goes on the left so a null value on the right safely produces false. status.equals(...) would throw an exception for null.
03Test boundaries
Set count to 0, 1, 100 and 101. Allowed boundary values should be unambiguous. A later batch job also distinguishes several states rather than only READY and not READY.
With 3 and READY: Start batch
Your exercise
Set status to new String("READY"). Compare equals with ==.
Show the solution and explanation
equals still returns true. == compares references and returns false for the newly created object compared with the literal. Use equals for domain text comparisons.
Project context and sources
The example is simplified for learning. The linked source version shows its use in the project and the checks applied there.