What does | mean in Java?

Pipe (|) allows you to do bitwise OR operations in Java.

It basically combines together all binary bits of two numbers.

So if, say, 2 is 010 in binary code, and 6 is 110 in binary code, then 2 | 6 means joining individual bits of both numbers:

010
110
---
110

When at least one of the bits is 1, then the result is 1, otherwise 0.

Try it yourself:

int a = 2;
int b = 6;
int piped = a | b;

System.out.println(piped); // 6