Skip to content

Tag: if-statement

Why the if condition runs the other way

the value passed fromjsonObject.getString(“firstName”); to firstNameValidateUser is null as it doesn’t have any value, I need to run the following code which contain String firstName=jsonObject.getString(“firstName”);…. till returnedUser = new User(firstName, lastName, user.userName, user.password, birthDate, position,qualification,email); when the value of firstNameValidateUser is null. How do I check it,I have used the if condition to check if the firstNameValidateUseris null ,but from

Nested if-else behaviour without braces

Consider the following unformatted nested if-else Java code My question is: according to the Java language specifications, to what if does the else branch apply? By hand-reformatting and adding braces, which of these two is correct? Block 1: Block 2: Answer From the Java Language Specification: The Java programming language, like C and C++ and many programming languages before them,