Computers Windows Internet

The syntax of the java. Conditional constructions. - Default methods for interface

must necessarily match the name of the class whose main () method is called when the Java machine starts up.

  • Object - the class from which to inherit all objects in Java, including arrays and strings ().
  • Access specifiers are individual for each member (specified before the declaration).
  • All class members are by default open to scope package... The default scope is a cross between private and protected, see.
  • Each * .java file can contain only one class declared as public and accessible from the outside.
  • The definition and declaration of a class is always in one file, it is impossible to put prototypes in headers.
  • Pointers are missing.
  • All class variables are actually references to objects, not the objects themselves. Their initialization for use must be done through new<конструктор-класса>(...) .
  • Based previous paragraph- when assigning one object variable to another, only the reference is changed but not the object copy.
  • Variables in a function are passed by value if it is elementary types(int, byte, long, etc ...), or by reference if they are objects.
  • The public static members of a class are accessed through the dot operator. , and not through ::, which in my opinion introduces some external confusion.
  • There is no destructor, but there is finalize ().
  • Finalize () should not be confused with the C ++ destructor. finalize () is called garbage collection only, which has nothing to do with the object going out of scope and the absence of at least one reference to this object.
  • You can force garbage collection by calling the Runtime.gc () method on the current Runtime object or the static System.gc () method. Judging by the experiments carried out, freeing memory only works within virtual machine Java and once allocated memory in the OS does not return until the machine ends.
  • In Java-style coding, functions throw exceptions instead of returning code. systemic errors or errors in the logic of the virtual machine. Therefore, a lot of functions must be executed inside the try (...) catch (...) (...) block that handles the exception, or the method that calls them must explicitly indicate through throws the list of exceptions thrown by these functions that are not handled by them, for processing by their methods up the call stack.
  • Exceptions are divided into and.
  • The try (...) block can also end with a finally (...) block, which is executed regardless of the presence / absence of exceptions in the previous try (...) block. It is convenient to use this to perform any required actions regardless of the results of executing a block of code, for example, to automatically release all resources allocated in it.
  • char is not a single-byte type like with C / C ++, it is a 16-bit type that supports unicode strings.
  • bool is known as boolean in Java.
  • Conditional constructs accept only boolean type of variables or expressions. This means that the code is like:
    int a; ... actions on the variable a ...; if (a) (...)
    Not true from the point of view Java syntax and will not compile.
  • Constants are declared final and not const.
  • All arrays are objects.
  • Even string constants (like "any string const") are objects.
  • For strings (the String class), only one operator is defined - +, concatenation.
  • Comparison of strings is done through the bool equals () method of the String class, for example s1.equals (s2).
  • The content of String objects is constant and does not imply changing a single element of the string, this is done for performance reasons. If you need such operations, you can use the StringBuffer class.
  • When concatenating an uninitialized string with a non-empty string, you get null + non-empty-string, for example s + = "| string"; will be equal to "null | string"
  • Arrays have a public member variable length, strings don't have instead, they use the length () method.
  • Java do not support multiple inheritance. Some of its functions are performed through "interfaces". Interfaces support multiple "inheritance" implementations of multiple interfaces in a single class, and in general many (interfaces) to many (classes) relationships and vice versa.
  • Interfaces allow the creation of links through which you can refer to objects of classes that implement these interfaces. True, the dynamic search for a suitable method when accessing through the reference-interface requires a lot of overhead, therefore it is not desirable.
  • Instead of enums, you can use interfaces without method declarations in them. In this case, all interface variables must be initialized when the interface is defined and their values ​​will automatically be constant. After that, through implements they can be "connected" to the defined class.
  • Also, since JDK 5 there are externally classic enumerations - enum. In fact, this is not just a list of named constants, but a special class inherited from the superclass Enum. Each element of the enumeration is an object of this class. The numeric value of an enumeration object can be obtained with the ordinal built-in function.
  • Custom operator overloading familiar in C ++, in Java not supported.
  • To work in an object environment with "primitive types" (int, float, char, etc ...), Java uses autoboxing / autoboxing into wrapper types (Integer, Float, Character, etc ...). In fact, this is an implementation of operator overloading for several built-in classes that implement the functionality of primitive types + object methods.
  • super - a keyword that allows you to call the constructor of a superclass from a subclass, or refer to a member of the superclass of a hidden member of the subclass.
    • When used as a constructor - super should always be first operator in the constructor of the subclass.
  • For determining abstract methods, the abstract keyword is used, a class containing an abstract method must also be defined as an abstract class ....
  • final prohibits overriding methods in child classes. For "short" methods declared as final, this keyword has the same effect as inline in C ++ - in subclasses instead of calling a function. may be inserted superclass method bytecode into calling class method code.
  • final also prohibits inheriting from a class declared as final.
  • Namespaces(namespace) in Java are implemented as packages(package).
  • To connect packages use import, you can also use import static ..(*|) to import static members of the class.
  • Java supports threads through the built-in Thread class and the Runable interface. For synchronization, use the synchronized specifier before the method in the class description, or synchronized ( ) (...) for a block of code synchronized with ... For signals between synchronized threads, methods of the parent Object class are used: wait () / notify () / notifyAll ().
  • transient - a modifier indicating that the value of an object / variable does not need to be "held" when saving an object, for example, when serializing it before writing it to disk / database. It is logical to mark variables containing unique identifiers runtime and other similar information that makes sense only in the current instance of the java process.
  • instanceof - runtime operation, returns true if there is a link to the class , or it can be cast to a reference to this class, otherwise false.
  • assert - Java assertions are used in much the same way as in C: assert [: Assertion fail description], but need to keep in mind that they are "embedded" into the compiled bytecode, and can be included with running java-ea.
  • this (...) - can be used inside the constructor of a class to call another constructor of the same class, matching the signature of the arguments.
  • Instead of templates are used generalizations, looks very similar: class CLASS_NAME (...). In generalizations it is forbidden use primitive types ( int, byte, char, etc ...). The parameters can be used only classes.
    In addition, supported limited types, by specifying the superclass for the parameter classes. For example, declaring a "generic class" class CLASS_NAME in which only descendant classes of the general numeric class Number are allowed.
  • It is convenient to use System.arraycopy () to quickly copy arrays.
  • Programming is writing the source code of a program in one of the programming languages. There are many different languages programming, thanks to which all kinds of programs are created that solve a certain range of problems. A programming language is a set of reserved words with which to write source programs. Computer systems are unable (yet) to understand human language, and even more so, human logic (especially feminine), so all programs are written in programming languages, which are subsequently translated into computer language or machine code. Systems that translate the source code of a program into machine code are very complex and, as a rule, they are created by more than a dozen months and more than a dozen programmers. Such systems are called integrated programming environments or tools.

    Programming languages ​​like regular languages ​​are different ways communicate with the computer the way you want it to work. Programming languages ​​allow us to step by step instruct a computer on how to manipulate data, collect data from users, and display things on the screen, among other things.

    Way down at the microscopic level, the computer's processor sends electrical signals back and forth that control how it works. Pieces of data are stored as variables, which are basically containers that hold data. So, for example, if a variable is to contain a number, we have to say so, and we won't be allowed to put anything else in it like a letter. Statically typed also means that all variables will be checked before the program even starts, and we will be presented with an error if we forget to declare a data type or declare an invalid one. "Object-oriented" is an object-oriented language built around the concept of objects. In the physical world, look around a room and think of each thing as an object. For example, I have a mug on my desk right now. As an object, this name is "mug" and it has properties like its color and how much liquid it will hold. We can also send messages to objects, so for my mug I might need to know, "Is this empty?" For example, we can use the Camera object to take a picture.

    • "Statically typed".
    • Programming at its core is really about working with data.
    There is absolutely no connection between the two languages.

    A programming system is a huge thoughtful visual environment where you can write the source code of the program, translate it into machine code, test, debug, and much more. Additionally, there are programs that allow you to perform the above actions using the command line.

    You have probably heard the term "a program is written under Windows or under Linux, Unix" more than once. The fact is that programming environments for translating a programming language into machine code can be of two types - compilers and interpreters. Compiling or interpreting a program specifies how the program will continue to run on the device. Programs written in the Java language always work on the basis of interpretation, while programs written in C / C ++ - compilation. What is the difference between these two methods?

    The two languages ​​are written differently and work differently, but both allow us to work with programming functions such as variables, methods, operators, and even objects. The language itself is a collection of keywords and symbols that we collect to express how we want our code to work.

    Each line of code has certain rules about how it should be built and what is or is not allowed. Remember that programming languages ​​are abstractions, which means they abstract away the true fundamentals of how a computer works in things that we can more easily understand. Behind the scenes, it really is all and zeros, but we don't need to worry about it. We can think in these abstract terms to express our ideas and commands, and these abstractions apply to all different types programming.

    The compiler, after writing the source code at the time of compilation, immediately reads the entire source code of the program and translates it into machine code. After which the program exists as a whole and can only be executed in that operating system in which it was written. Therefore, programs written under Windows cannot function under Linux and vice versa. The interpreter will step through or line by line execution of the program each time it is executed. During the interpretation, not executable code is generated, but virtual code, which is subsequently executed by the Java virtual machine. Therefore, on any platform - Windows or Linux, Java programs can be executed in the same way if there is a virtual Java machine in the system, which is also called the Runtime System.

    - Default methods for interface

    Here are some of the keywords that indicate the type of data we will use and store in variables. Since the decimal place can change or float, it is important to know that these values ​​may technically be inaccurate. Other primitive data types include bytes, short and long. An object differs from a primitive data type in that it has more complex properties and methods available to it, whereas primitive data types are limited and simple. A variable is basically a container used to store data.

    Object Oriented Programming

    Object-oriented programming is based on objects, which is somewhat similar to our world. If you look around you, then you can definitely find something that will help you more clearly understand the model of such programming. For example, I am now sitting at a table and typing this chapter on a computer that consists of a monitor, system unit, keyboard, mouse, speakers, and so on. All of these parts are the objects that make up the computer. Knowing this, it is very easy to formulate some kind of generalized model for the operation of the entire computer. If you do not understand the intricacies of the software and hardware properties of a computer, then we can say that the System unit object performs certain actions that are shown by the Monitor object. In turn, the Keyboard object can correct or even set actions for the System unit object that affect the operation of the Monitor object. The presented process characterizes very well the entire object-oriented programming system.

    Here are the basic syntax rules

    Let's take a look at an example. Let's take a look at each numbered part. The first word in a variable declaration is the data type, which tells us what data will be stored in the variable. The second word is a variable name, which can be whatever you want, following a few basic rules. Variable names must not contain spaces or special characters; they can only have letters, numbers and underscores. The equal sign is an operator, that is, it performs a certain operation for us. It's an assignment operator, meaning we use it to assign values ​​to variables. Finally, the last character on this line is a semicolon, which is used to complete this statement. However, they do not have to start with a number. ... Some other examples of variable declarations using some of the basic data types that we have covered are as follows.

    Imagine some powerful software containing hundreds of thousands of lines of code. The entire program is executed line by line, line by line, and in principle, each of the subsequent lines of code will necessarily be linked to the previous line of code. If you do not use object-oriented programming, and when you need to change this program code, for example, if you need to improve some elements, you will have to do a lot of work with all the source code of this program.

    Methods are used to organize our code in reusable chunks that save us a lot of time and energy. The second word in the method is the data type that will be returned. The next name is the name of the method. Method names follow roughly the same rules as variable names: letters, numbers, and underscores, but they cannot start with a number.

    Immediately after the name, we see two parentheses with nothing in between. The parenthesis is needed, but when it is empty, it means that we are not passing any data or variables when the method is called. If one or more variables were included between the parenthesis, then we will have to pass the corresponding values ​​or variables in the parenthesis when we call this method.

    Object-oriented programming is much simpler, let's go back to the example of a computer system. Let's say you are no longer satisfied with a seventeen-inch monitor. You can safely exchange it for a twenty-inch monitor, of course, if you have certain material resources. The exchange process itself will not entail huge problems, unless you have to change the driver, and wipe the dust from under the old monitor and that's it. Object-oriented programming is based on approximately this principle of operation, where a certain part of the code can represent a class of homogeneous objects that can be easily modernized or replaced.

    Line 1 ends with an open curly brace, and the corresponding closing curly brace is on the line. This documentation is archived and not supported. The most obvious change when switching between programming languages ​​is the change in syntax.

    Although the syntax of each language expresses the method differently, the functionality is the same. Description functionality, parameters, and object return values, with some exceptions, is valid for all languages. For example, consider a square function as it is implemented in each of these three scripting languages.

    Object-oriented programming very easily and clearly reflects the essence of the problem being solved and, most importantly, makes it possible, without prejudice to the entire program, to remove unnecessary objects by replacing these objects with newer ones. Accordingly, the overall readability of the entire program's source code becomes much easier. It is also important that the same code can be used in completely different programs.

    Increment and decrement operators

    Note that scripting languages, unlike programming languages, are loosely typed. In other words, you do not need to specify the data type of the parameter or the return value when declaring the function. Instead, variables are automatically converted to the appropriate data type.

    This similarity is only superficial. Let's now take a quick look at what class, object, method, and instance variables mean. Example: A dog has conditions - color, name, breed, as well as behaviors such as tail curl, barking, food. This is in the methods, where the logic is written, the data is processed and all actions are performed. Instance variables. Each object has its own unique set of instance variables. The state of the object is generated by the values ​​assigned to these instance variables.

    • An object.
    • Objects have states and behavior.
    • A class can contain many methods.
    Let's see how to save the file, compile and run the program.

    Classes

    At the core of all Java programs are the classes on which object-oriented programming is based. In fact, you already know what classes are, but you don't know it yet. In the previous section, we talked about objects using an example of the structure of an entire computer. Each object from which a computer is assembled is a representative of its own class. For example, the Monitors class unites all monitors, regardless of their types, sizes and capabilities, and one specific monitor on your table is an object of the monitors class.

    Follow the next steps -. Open a command prompt window and change to the directory where you saved the class. If multiple words are used to form the class name, each first letter of the first word must be in uppercase. All method names must begin with a lowercase letter.

    • Open notepad and add the code as above.
    • If there are no errors in the code, command line will take you to the next line.
    • Class names.
    • For all class names, the first letter must be in uppercase.
    • Example: class.
    The names used for classes, variables and methods are called identifiers.

    This approach makes it very easy to simulate all kinds of programming processes, making it easier to solve the assigned tasks. For example, there are four objects of four different classes: monitor, system unit, keyboard, and speakers. To play a sound file, use the keyboard to give the command system unit, the very action of giving a command, you will observe visually on the monitor and, as a result, the speakers will play a sound file. That is, any object is part of a certain class and contains all the means and capabilities of this class. There can be as many objects of the same class as needed to solve the problem.

    All identifiers must begin with a letter, currency symbol, or underscore character.

    • After the first character, identifiers can be any combination of characters.
    • The keyword cannot be used as an identifier.
    • Most importantly, identifiers are case sensitive.
    Like other languages, you can modify classes, methods, etc. Using modifiers. There are two categories of modifiers -.

    We will consider more details about modifiers in the next section. Local Variables Class Variables Instance Variables. ... Arrays are objects that store multiple variables of the same type. However, the array itself is an object on the heap. We'll look at how to declare, build, and initialize in the next chapters.

    Methods

    When the playback example was given sound file, then it was mentioned about giving a command or a message, on the basis of which certain actions were carried out. The task of performing actions is solved using the methods that each object has. Methods are a set of commands with which you can perform certain actions with an object.

    Incrementing and decrementing

    The values ​​in this enumerated list are called enumerations. By using enumerations, you can reduce the number of errors in your code. For example, if we were looking at an app for a fresh juice store, we could limit the glass size to small, medium, and large. This will make sure that it will not allow anyone to order any sizes other than small, medium or large.

    The above example would give the following output. Note. Enumerations can be declared as their own or within a class. Methods, variables, constructors can also be defined inside enumerations. These reserved words cannot be used as constants or variables or any other identifier names. Basically, if you need to create a new class, and there is already a class that has some code that you need, then you can get a new class from the existing code.

    Each object has its own purpose and is designed to solve a certain range of problems using methods. For example, what good would the Keyboard object be if you could not press keys and still be able to issue commands? The Keyboard object has a certain number of keys with which the user gains control over the input device and can issue the necessary commands. Processing of such commands occurs using methods.

    This concept allows you to reuse the fields and methods of an existing class without rewriting the code in the new class. In this case, the existing class is called the superclass and the derived class is called the subclass. Interfaces play a vital role when it comes to the concept of inheritance. The interface defines the methods that the receiving class must use. But the implementation of the methods is completely consistent with the subclass.

    Object Oriented Programming Concepts and Principles

    Stay tuned for more content in this series. Find out what to expect from this tutorial and how to get the most out of it.

    • Save the file to your hard drive when prompted.
    • When the download is complete, run the installer.
    For now, stick to the default perspective and view. Your development environment is ready for action. The structured programming paradigm is very data-driven: you have data structures and then program instructions act on that data.

    For example, you press the Esc key to cancel any action and thereby give a command to the method assigned to this key, which solves this problem at the program level. The question immediately arises about the number of methods of the Keyboard object, but there can be a different implementation here - from defining methods for each of the keys (which, in general, is unreasonable), to creating one method that will monitor the general state of the keyboard. That is, this method monitors whether a key was pressed, and then, depending on which of the keys is involved, decides what to do.

    So, we see that each of the objects can have at its disposal a set of methods for solving various problems. And since each object is an object of a certain class, it turns out that the class contains a set of methods that are used by various objects of the same class. In Java, all methods you create must be owned or part of a particular class.

    Java syntax and semantics

    In order to speak and read in any foreign language, it is necessary to learn the alphabet and grammar of that language. A similar condition is observed in the study of programming languages, with the only difference, it seems to me, that this process is somewhat easier. But before you start writing the source code of the program, you must first solve the problem posed to you in any form convenient for you.

    Let's create a class that is responsible, for example, for a phone, which will have only two methods: turning this phone on and off. Since we do not know the syntax of the Java language now, we will write the Phone class in an abstract language.

    Class Phone
    {
    Include () method
    {
    // operations to turn on the phone
    }
    Disable () method
    {
    // operations to turn off the phone
    }
    }

    The Phone class might look something like this. Note that the curly braces represent the beginning and end of the body of a class, method, or any sequence of data, respectively. That is, the parentheses indicate the belonging to a method or class. Each open parenthesis must have a closing parenthesis. In order not to get confused, they are usually put at the same level in the code.

    Now let's write the same class in Java only.

    Class Telefon
    {
    void on ()
    {
    // body of the on () method
    }
    void off ()
    {
    // body of the off () method
    }
    }

    The class keyword in the Java language declares a class, followed by the name of the class itself. In our case, this is Telefon. Just a few words about the register of the record. In almost all programming languages, it is important to keep the names recorded in the case in which they were made. If you wrote Telefon, then such a spelling as telefon or TELefoN will give an error during compilation. As it was written initially, so it is necessary to write further.

    Reserved or keywords are written in their specific case, and you cannot use them by giving their names to methods, classes, objects, and so on. Spaces between words don't matter as the compiler simply ignores them, but they are important for the readability of the code.

    There are two methods in the body of the Telefon class: on () - turns the phone on and the off () method - turns off the phone. Both methods have their own bodies and, in theory, they should contain some kind of source code describing the necessary actions of both methods. For us now, it doesn't matter how these methods are implemented, the main thing is the syntax of the Java language.

    Both methods have parentheses on (), inside which parameters can be written, for example on (int time) or on (int time, int time1). With the help of parameters, there is a kind of connection between the methods and the outside world. The on (int time) method is said to take a time parameter. What is it for? For example, you want your phone to turn on in certain time... Then an integer value in the time parameter will be passed to the body of the method, and based on the received data, the phone will be turned on. If the parentheses are empty, then the method takes no parameters.

    Comments (1)

    In the Telefon class, the bodies of both methods have an entry after two slashes: //. Such an entry denotes comments that will be ignored by the compiler, but are needed for readability of the code. The more information you comment out while writing the program, the more chances you will have to remember in a year what you have been working on all this time.

    Comments in Java can be of three types, they are:

    //, /*…*/ and /**…*/

    Comments written using the // operator must be located on one line:

    // One line
    !!! Error! You cannot wrap to the second line!
    // First line
    // Second line
    // …
    // Last line

    Comments using the / *… * / operators can span multiple lines. At the beginning of your comment put / *, and at the end, when you are finished commenting the code, put the * / operator. The last kind of comment / ** ... * / is used when documenting the code and can also be located on any number of lines.

    Java data types

    Data types exist in Java to set an arbitrary value. In the Telefon class, we have created two methods. Both methods had no parameters, but when the example of the on (int time) method with the time parameter was given, it was said about passing a value to the method. This value indicated the time by which the phone was supposedly to be turned on. The int specifier defines the type of the time value. Java 2 ME has six data types.

    Byte - small integer value from –128 to 128;
    short - short integer value in the range from –32768 to 32767;
    int - contains any integer value from –2147483648 to 2147483647;
    long is a very large integer value, from –922337203685475808 to 9223372036854775807;
    char is a Unicode character constant. Range this format from 0 to 65536, which is 256 characters. Any character of this type must be written within single quotes, for example: ‘G’;
    boolean - a boolean type, has only two values: false - false and true - true. This type is often used in loops about which a little later. The idea is very simple - if you have money in your pocket, presumably this is true, and if not, then false. Thus, if there is money, we go to the store for bread or beer (underline the necessary), if there is no money, we stay at home. That is, it is such a logical value that contributes to the choice further action your program.

    To declare some required value, the following entry is used:

    Int time;
    long BigTime;
    char word;

    The semicolon operator is required after the entries and is placed at the end of the line. You can combine several ads of the same type, separated by commas:

    Mt time, time1, time2;

    Now let's improve our Telefon class by adding some values ​​to it. We no longer need the on () and off () methods, we will add new methods that can really solve certain problems.

    Class Telefon
    {
    // S - display area
    // w - display width
    // h - display height
    int w, h, S;
    // method that calculates the display area
    vord Area ()
    {
    S = w * h;
    }
    }

    So, we have three variables S, w and h, which are responsible, respectively, for the area, width and height of the display in pixels. The Area () method calculates the area of ​​the phone screen in pixels. The operation is useless, but very indicative and easy to understand. The body of the Area () method has acquired itself and has the form S = w * h. In this method, we simply multiply the width by the height and assign or, as they say, store the result in the variable S. This variable will contain the values ​​of the display area this phone.

    Now we come close to the operators of the Java language, with which you can perform all sorts of operations. Operators of the Java language, as well as of other programming languages, have their own purposes. So there are arithmetic operators, increment and decrement operators, logical operators, and relational operators. Let's take a look at each of the above operators.

    Arithmetic operators

    All arithmetic operators are very simple and are similar to the operators for multiplication "*", division "/", addition "+" and subtraction "-" used in mathematics. There is the modulo operator "%" and the situation with the operator equal to "=" is a bit confusing at first glance. The operator equals in programming languages ​​is called the assignment operator:

    Here you assign the value 3 to the variable x. And the operator "equal" in programming languages ​​corresponds to writing two consecutive operators "equal": "==". Let's look at an example of what the various arithmetic operators can do.

    Int x, y, z;
    x = 5;
    y = 3;
    z = 0;
    z = x + y;

    In this case, z will have the value of the sum of x and y, that is, 8.

    The variable x had a value of 5, but after such a record, the previous value is lost and the product z * x (8 * 5) is written, which is 40. Now, if we continue our code further, the variables will look like this:

    // x = 40;
    // y = 3;
    // z = 8;

    The addition and subtraction operators have the same purposes as in mathematics. Negative numbers are similarly related.

    The decrement “––” and increment “++” operators are very specific, but very simple. There are often times in programming when you need to increase or decrease a value by one. This is often found in loops. The increment operation increases the variable by one.

    Int x = 5;
    x ++;
    // Here x is already 6

    The decrement operation decreases the variable by one.

    Int x = 5;
    x--;
    // x is 4

    Increment and decrement operations can be post and prefix:

    Int x = 5;
    int y = 0;
    y = x ++;

    In the last line of code, first the value x is assigned to y, this is the value 5, and only then the variable x is increased by one. It turns out that:

    The prefix increment is:

    Int x = 3;
    int y = 0;
    y = ++ x;

    And in this case, first the variable x is increased by one, and then it assigns the already increased value to y.

    Relational operators

    Relation operators allow you to check the equality of both parts of an expression. There is an equality operator "==", operators are less than "<» и больше «>", less than or equal to "<=» и больше или равно «>= ", As well as the negation operator"! = ".
    9 == 10;

    This expression is not true, nine is not equal to ten, so its value for this expression is false.

    Here, on the contrary, the negation operator indicates the inequality of the expression, and the value will be true. Greater than, less than, greater than or equal to and less than or equal operators are similar to the corresponding operators from mathematics.

    Logical operators

    There are two logical operators. The AND operator, denoted by &&, and the OR operator, denoted by two forward slashes "||". For example, there is an expression:

    A * B && B * C;

    In the event that only both parts of the expression are true, the value of the expression is considered true. If one of the parts is incorrect, then the value of the entire expression will be false.
    In contrast to the "&&" operator, there is the "||" operator, which is not in vain called "OR".

    A * B || B * C;

    If any part of the expression is true, then the entire expression is considered true. Both operators can be combined in one expression, for example:

    A * B || B * C && C * D || B * A;

    With the help of this expression I have led you, it seems to me, into a difficulty, isn't it? The fact is that in Java, as in mathematics, there is a priority or the so-called hierarchy of operators, with the help of which it is determined which of the operators is more important, and, therefore, is checked first. Let's consider using a list the precedence of all the available operators in the Java language:

    , ., (),
    !, ~, ++, - -, + (unary), - (unary), new,
    *, /, %,
    +, –,
    <<, >>, >>>,
    <, <=, >, >=,
    = =, !=,
    &, ^, |,
    &&,
    ||,
    ?:,
    =, +=, –=, *=, /=, %=, |=, ^=, <<=, >>=, >>>=.

    The operator associativity in the list follows from left to right and from top to bottom. That is, everything that is to the left and above is older in rank and more important.