I've got this statement in Java:
System.out.println(3|4);
Why is the output 7?
I've got this statement in Java:
System.out.println(3|4);
Why is the output 7?
Since question asks what is pipe operator (|) in Java, without specifying anything particularly about "OR" logic, it may be useful to note, that this operator is so to say - redefined, when we deal with exceptions.
Since Java SE 7, catching multiple, disjointtypes having no inheritance relation exceptions in one catch block, also involves | operator, which, in this case, serves as just piping/chaining logic, and has nothing to do with "OR", because in case of "OR", disjoint would have been allowed.
If, before Java 7, whenever you needed to catch multiple exceptions, you needed to write separate catch blocks, since Java 7, you can do:
try {
...
} catch (FileNotFoundException | SQLException e) {
...
}