I just wanna know of what is the use of | and ^ in java. I took an exam in java yesterday for a company.
They have questions that I dont know if I answered it correctly or not so whats the use of the symbol
above. I've reproduce a small example that I have created :

import java.awt.*;

public class Sample {

Sample() {

int var = 10;

GetString(var);
}

private void GetString(int i) {

System.out.println("\n");

for(int j=1; j<=i; j++) {
System.out.print(j);
}

System.out.println("\n");
}

public static void main(String args[]) {

Sample s1 = new Sample();

int x = 2 | 3;
int y = 2;

System.out.print("Result : ");
System.out.println( x ^ y );
System.out.println("Execution Successfull !");
}
}

What are bitwise operators ? you use them for what purpose ? thanks.

0

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

As already stated they are used when we need to do operations with bits. The | symbol is used to do an OR, which means that if one or both of the operands is 1 then the result is also 1. For example the following:

int x = 2 | 3;

will result in 3 since 2 in binary is 0001 and 3 in binary is 0011 so if we do an OR we have

0001 = 2
0011 = 3
--------
0011 = 3

The first two bits of number 3 will be 0 since we do an OR on two zeros, but the last two bits will be 1 since we do an OR on zero and one (result = 1) and on one and one (result = 1).

The ^ operator is the XOR operator which returns 1 only if one of the operands is 1.
so the x ^ y will be 3 ^ 2 which is

Does it turns into applet, servlet or application ormidlet ?