"How to set a single bit?"
Use the |
operator.
"Why I need use|=
in my i2c project?"
Because that is a simple way to set bits. Seriously, you need to do some reading on bitwise operators in Java.
and so on.
"What is the importance of setting specific bits and not all 8 bits?"
It is determined by the specified behavior of the hardware device you are attempting to control. Read the device manual / documentation.
In fact, the code is will physically writing all 8 bits of the byte. It is just that only one of the bits will be changing.
"When I will write in registers?"
You typically write in registers when you need to make the device do something.
"According to the table below the correct to set bit 6 is 0x20 and not 0x40."
It depends on whether you number bits starting at zero or at one. That "table" (actually it is code) is numbering bits from one. That is NOT the normal convention for numbering bits, which partly explains why that answer got 2 downvotes. (Hint: people generally downvote answers because they are misleading or wrong. You should pay attention to this and be selective in what you read.)
If you take the time to read up on bitwise operators, you should be able to understand that code. You should always attempt to understand code for yourself rather than just blindly assuming that it is correct ... 'cos you found it on StackOverflow or something.