Java-preliminary Understanding-Chapter III-comparison operator logical operators

Source: Internet
Author: User
Tags arithmetic operators bitwise operators logical operators

I. GENERAL class of Operators

All operator types are enumerated first: arithmetic operators, assignment operators, comparison operators, logical operators, bitwise operators, and ternary operators.

What is named operator, which is called operator, is it a symbolic representation of the operation? you can see some of the original books in English.

This section discusses comparison operators and logical operators, which are still part of the Java Language Foundation. Until the syntax, functions, and arrays are finished, the study of the Java language is really going to be done.

Two.

Before exploring the comparison operators, try to re-learn one of the problems encountered in the video. The fault of this DOS is that there is no main class, there are only two reasons for this problem: the Java Run class name is wrong, the path of the class is incorrect. The second error is highlighted here. The path to the class is not correct, Java is a class file that runs under the current path, and the path is not correct, which means we have changed the path. In DOS, enter set CLASSPATH, and the console will display the classpath directly. Here also understand that there is no classpath in the system, in order to be able to start some class files in any directory, so that these classes of files in a centralized folder, this folder is called Classpath.

For classpath knowledge points, there are some things worth pondering. The first is to set up this classpath, there are permanent, temporary, borrowed.

Note : The above understanding Classpath still has some, deviation. For example, if you start to show a path in DOS that defines classpath, and the DOS window has not been closed, set classpath=d:\source\1, and then d:\source\ 01 folder to write Demo.java source program, and then compile in DOS, and run, see DOS detection results.

The final result shows that the source program we started writing is the Demo.java in the D:source\01 folder, then DOS is compiled, the compiled Demo.class run file and the Demo.java source file are in a folder. But when the Java command tool starts the class run file, it goes directly to the D:source\1 file to find the Demo.class class file. This means that set classpath= ..... is to require the Java tool to go directly to the corresponding file to search for a certain type of file, if not, it will appear to be unable to find or load the main class.

Three. Comparison operators

The comparison operator will have the result after the operation. As long as it is an operator, there will be results after the operation is finished.

The result of the comparison operator is either true or false.

Common people know that greater than, less than ... A special comparison operator is described here, and so on or equal to.

Take a look at the following two statements: System.out.println (3=2); System.out.println (3==2); After a DOS authentication, the previous one was wrong and the latter one was correct.

Four. Logical operators

Here we come back to the question of how to learn. What is logic? Why do we have logical operators?

Logic is a relationship, there are so several types, with, or ...

The presence of logical operators is customized for the Java language. In our daily life, we can write 2<x<5; directly. However, it is not possible to write this in the Java language, which is two expressions. Why can't you write like that? Because it's a two-expression? It is said in the video that Java does not support these two expressions, so a logical operator is constructed to concatenate two types of Boolean expressions.

Five. Classification of logical operators

The above-mentioned logical operator is an expression that joins a Boolean type, and the Boolean type is the output is true or false, which is the logical operation.

There are many logical operations, first describing two kinds of,& and, | or, the symbol is more unique.

Use of & with logical operators: int x=3; System.out.println (x>2&x<5); Output to True in DOS. As you can see, the logical operators are connected to logical expressions, and the output is a Boolean type of data.

This is done directly in the output statement of the logical operation, then can be in the output statement outside, and then output by the output statement? The results are as follows:

The practice in the video is directly in the output statement, as follows:

This means that the output statement can be used directly as a computed site. Why does Java have to be set up like this? What is the principle of doing this?

I have added a Java statement that reads as follows, Ture and false are keywords, and the logical operator compares two Boolean data in nature, judging by the law of the operation (that is, the and operation, whether the result is true or false).

Note : We analyzed the above three cases, the video, only explained the System.out.println (X<5&X>2); This situation. In the actual analysis, I felt such a long formula, the bottom layer has three steps. First, the left and right sides of the & judgment, to obtain the left and right side of the logical operation of the result, ture or false, and then the two Boolean data for the & operation, and finally to obtain a result. There is no difference between writing the output statement and the inside, but if it is written in true&true this form, it is equivalent to omitting two operations and making a third step directly.

Note: For False&false, I wrote in the above three forms, the results are as follows, very interesting:

First, the output statement outside the definition, and finally output statements directly, the DOS display operation is normal.

The second, in the output statement directly in the operation, DOS direct error. This shows that the underlying operation is not the same in the first and second forms. Why does DOS get an error in this case? I changed an output statement in int a=3; System.out.println (x<1&x>2); This is the True&false form of truth, but DOS is still an error. However, when I write System.out.println directly in the output statement (true&false);D The OS results show that it works correctly. This is very strange, what is the mechanism behind it? If the output statement is calculated directly on both sides of the,& operation must be given is correct, or error, then given a Boolean data, this will not tube. → The above statement is completely wrong, it does not make sense, carefully observe the following, we found that the variable was written wrong, the definition is written in a, but in the output statement is written in X, which led to DOS error is not found X.

Here, I suddenly understand the sentence, the computer is to help people to calculate the tool. We write programs by learning these advanced computer languages. These programs are all in the daily life of computing ideas into code, using these programs instead of people to calculate, and even beyond the computational power of people.

Five. | or operator

For the | operator, in the form of the above & operator, there is no more explanation.

Here again in a sentence, the high-level computer language is an extremely symbolic collection, will be used in all kinds of symbols, such as the various logical operations here, to symbolize it, and use the original symbols on the keyboard, such as:%,^,& to represent.

Java-preliminary Understanding-Chapter III-comparison operator logical operators

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.