Essay on basic introduction to Java (3) JavaSE version, essay javase
The previous section wrote about some precautions for operators. The beginning of this section is still an explanation of some precautions for operators!
In addition to >, >=, <, <=, ==, !=, comparison operators need to pay attention to instanceof: check whether it is an object of the class, for example: "Hello" instanceof String, return the result bit true .
1. Operation characteristics of logical operator
& (AND): as long as one of both sides of the operation is false, the result will definitely be false. Only when both sides are true, the result will be true; Operation characteristics of
| (OR) : As long as one of the two sides of the operation is true, the result will definitely be true. Only if both sides are false, the result will be false;
^ (XOR) operation characteristics: If the results of both sides of the operation are the same, the result will be false, and the results of both sides will be false. Different, the result is true;
! The operational characteristics of (not): judging the other side of things; the operational characteristics of
&& (short-circuit double AND): basically the same as the & operation, except that when the left side of && is false, the right side does not participate in the operation, and both sides of & are Operation;
|| (short-circuit double OR) operation characteristics: basically the same as | operation, except that when the left side of || is true, the right side does not participate in the operation, and both sides of | must be operated;
2. Bit operators
& (AND bit operator): The operation characteristics are the same as the logical operator &, but here it is for binary bit operations, for example: 6&3=2; (binary principle: 110&011=010), any number and bit is 1 The & operation is the original number (the action takes certain significant digits);
| (or operator): The operation characteristics are the same as the & of the logical operator, but here it is for binary bit operations, for example: 6|3=7 ; (Binary principle: 110|011=111);
^ (XOR operator): The operation characteristics are the same as the logical operator ^, except that here it is for binary bit operations, for example: 6^3^3 = 6, Note: When a number is XORed with the same number twice, the result is still the number itself (functioning as an encryption effect)
~ (inversion operator): The operation characteristics are consistent with ! in the logical operator.
<< (left shift operator): The number of bits shifted to the left is actually the number of times the data is multiplied by 2. Can complete power of 2 operations!
>> (right shift operator): The number of bits shifted to the right is actually the power of the data divided by 2. For the vacancies that appear in high positions, use whatever the original high position is to fill the vacancies!
>>> (unsigned right shift operator): When the data is shifted right, the vacancies in the high bits will be filled with 0 no matter what the original high bits are.
Exercise:
1.//The most efficient way to find out what is 2 times 8? Answer: System.out.println(2<<3);
2. Swap the values of two integer variables?
Answer:
When developing, use the form of third-party variables because it is easy to read.
int c ;
c = a;
a = b;
b = c;
Don’t use this method. If the values of the two integers are too large, they will exceed the range of int and will be forced to convert. The data will
change.
a = a + b; //a = 3 + 5;a = 8;
b = a - b; //3+5-5 = 3;b = 3;
a = a - b; // 3+5-3 = 5;a = 5;
Used during interviews.
a = a ^ b; //a = 3 ^ 5;
b = a ^ b; //b = (3^5)^5; b = 3;
a = a ^ b; //a = ( 3^5)^3; a = 5;
The above is the Java basic introductory essay (3) JavaSE version, the content of the essay javase. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use OAuth2.0's access_token to achieve control of interface access permissions? In the application of OAuth2.0, how to ensure that the...

Discussing the hierarchical architecture in back-end development. In back-end development, hierarchical architecture is a common design pattern, usually including controller, service and dao three layers...

Questions and Answers about constant acquisition in Java Remote Debugging When using Java for remote debugging, many developers may encounter some difficult phenomena. It...

Confused with choosing Java project management tools for beginners. For those who are just beginning to learn backend development, choosing the right project management tools is crucial...

Exploring the application of ultimate consistency in distributed systems Distributed transaction processing has always been a problem in distributed system architecture. To solve the problem...

How to convert names to numbers to implement sorting within groups? When sorting users in groups, it is often necessary to convert the user's name into numbers so that it can be different...

Analysis of the reason why Python script cannot be found when submitting a PyFlink job on YARN When you try to submit a PyFlink job through YARN, you may encounter...

How to dynamically configure the parameters of entity class annotations in Java During the development process, we often encounter the need to dynamically configure the annotation parameters according to different environments...
