In this program, how can false be equal to true:
public class Wow { public static void main(String[] args) { if ( false == true ){ // \u000a\u007d\u007b System.out.println("How is it possible!!!"); } } }
Typically, you use == and != with primitives such as int and boolean, not with objects like String and Color. With objects, it is most common to use the equals() method to test if two objects represent the same value.
In Java, there is a variable type for Boolean values: boolean user = true; So instead of typing int or double or string, you just type boolean (with a lower case "b"). After the name of you variable, you can assign a value of either true or false.
In Java, you must declare a method of the boolean type in order for it to return a boolean value. The boolean method will return the boolean value, true or false. You can either return the variable containing a boolean value or use conditional statements to decide the returned value.
The same section also says: "The Java Virtual Machine encodes boolean array components using 1 to represent true and 0 to represent false.
Well, I'll be generous and assume that this question was asked out of innocence.
The Java compiler parses Unicode escape sequences very early in the process. In particular, it does this before stripping comments or checking for syntax. Since \u000a
is a newline, \u007d
is the character "}" and \u007b
is the character "{", the parser is actually parsing this program:
public class Wow{ public static void main(String[] args) { if ( false == true ){ // }{ System.out.println("How is it possible!!!"); } } }
This program will always print the "impossible" output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With