Descriptor
descriptors are keywords that you add to those definitions to change their meaning. The Java language has many descriptors, including the following:
- Accessible descriptor
- Non-accessible descriptor
- With the descriptor, you can add the corresponding keyword to the class, method, and variable. The descriptor is preceded by a declaration, as shown in the following example (italic):
public class ClassName {
//...
}
Private Boolean Myflag;
Static final double weeks = 9.5;
protected static final int boxwidth =;
public static void Main (string[] arguments) {
//body of
Accessible descriptor
Java provides a series of accessible descriptors to set access levels for classes, variables, methods, and constructors. The four levels of access are as follows:
By default, the encapsulation is visible. No descriptors are required.
- Visible only to classes (private)
- All visible (public)
- Visible to encapsulation and subclasses (protected)
Non-accessible descriptor
Java provides some inaccessible descriptors to accommodate other features.
- The Static descriptor is used to create class methods and variables.
- The final descriptor is used to finalize and implement classes, methods, and variables.
- Abstract descriptors are used to create classes and methods that are not allowed to be instantiated.
- The synchronized and volatile descriptors are used as lines.
Basic operators
Java provides a rich set of operators for manipulating variables. We can divide all Java operators into the following groups:
- Arithmetic operators
- Relational operators
- Bitwise operators
- logical operators
- Assignment operator
- Other operators
- Arithmetic operators
The use of arithmetic operators in mathematical expressions is the same as their use in algebra. The following table lists the arithmetic operators:
Assuming there are 10 total variable A and there are 20 variable B, then:
Example
operator |
Description |
Example |
+ |
Addition – increase at the other end of the operator |
A+b is 30 |
- |
Subtraction – Subtracts the operand on the right from the operand on the left |
A-b to-10 |
* |
Multiplication-multiplies the values on both ends of the operator |
A * B is 200 |
/ |
Division – Use the right-hand operand to remove the left-hand operand |
B/A is 2 |
% |
Coefficients-use the right-hand operand to remove the left operand and return the remaining number |
B% A is 0 |
++ |
Increment-Increases the value of the operand by 1 |
b++ is 21 |
-- |
Decrement – minus 1 to the operand value |
B-19 |
Relational operators
The following are the relational operators that the Java language can support.
Assuming the variable A has 10, and the variable B has 20, then:
Example
operator |
Description |
Example |
== |
Check that the values of both operands are equal, and if they are equal, then the condition is true |
(A = = B) is not true. |
!= |
Check that the values of both operands are equal, if not equal, the condition is true |
(A!= B) is true. |
> |
Check to see if the operand on the left is greater than the right-hand operand, if greater than the condition is true |
(A > B) is not true. |
< |
Check to see if the operand on the left is less than the right-hand operand, if less than the condition is true |
(A < B) is true. |
>= |
Check that the operand on the left is greater than or equal to the right-hand operand, if so the condition is true |
(A >= B) is not true. |
<= |
Check to see if the operand on the left is less than or equal to the right-hand operand, if so the condition is true |
(A <= B) is true. |
Bitwise operators
Java defines several operators that can be used for integer types, long, int,short, character, and byte types.
Bitwise Operators Act on the transport standards between binary systems and perform bitwise operations. Suppose that if a equals 60;b equals 13, now in the binary form they are as follows:
A = 0011 1100
b = 0000 1101
-----------------
a&b = 0000 1100 a|b = 0011 1101 a^b
= 0011
0001 ~a = 1100 0011
The following table lists the bitwise operators:
Suppose the integer variable A has 60, B has 13, then:
Example
operator |
description |
example |
& amp; | The
binary and operator duplicates one on the result if the two operands exist at the same time |
(A & B) is 12, that is, 0000 1100 |
| | The
binary or operator duplicates one of the results if it exists on either operand |
(A | B) is 61, that is, the 0011 1101 |
^ |
binary Xor operator to replicate a bit if it is set to one operand instead of two. |
(a ^ b) is 49, that is, the 0011 0001 |
~ |
binary supplement operator is unary, and B has the effect of flip bit |
( ~A) is-61, because it is a signed binary number, the complement of the 2 is 1100 0011 |
<< |
binary left-shift operator. The value of the left-hand operand moves to the left according to the number of bits specified by the right-hand operand. |
a << 2 is 240, that is, the 1111 0000 |
>> |
binary right shift operator. The value of the left-hand operand is moved to the right according to the number of bits specified by the right-hand operand. |
a >> 2 is 15 1111 |
>>> |
right-shift complement 0 operator. The value of the left-hand operand is moved to the right according to the number of bits specified by the right-hand operand, and the transferred value is filled with zeros. |
A >>>2 is 15, that is, 0000 1111 |
logical operators
The following table lists the logical operators:
Suppose Boolean math system variable A is true and B is false, then:
Example
operator |
Description |
Example |
&& |
Called Logic and operators. If both operands are Non-zero, then the condition is true. |
(A && B) is true. |
|| |
Called a logical OR operator. If either of the operands is Non-zero, then the condition is true. |
(A | | B) is true. |
! |
Called a logical non-operator. The logical state used as the flip operand. If a condition is true, then the logical non-operator is false. |
! (A && B) is true. |
Assignment operator
The following assignment operators are supported by the Java language:
Example
operator |
Description |
Example |
= |
Simple and operator, assigning the value of the right-hand operand to the left-hand operand |
c = A + B assigns the value of A + B to c |
+= |
Increment and assignment operator, which increases the operand on the right to the operand on the left and assigns the result to the left-hand operand |
C + + a equals c = C + A |
-= |
Minus and the assignment operator, which subtracts the right-hand operand from the left-hand operand and assigns the result to the left-hand operand |
c-= A equals c = c-a |
*= |
Multiplication and assignment operator, which multiplies the right-hand operand to the left and assigns the result to the left-hand operand |
c = a equals c = C A |
/= |
In addition to the and assignment operator, it assigns the right-hand operand to the left-hand operand and the result to the left-hand operand |
C/= A equals C = c/a |
%= |
Coefficients and assignment operators need coefficients to use two operands and assign the result to the left-hand operand |
C%= A is equal to C = c% A |
<<= |
Left-shift and assignment operators |
C <<= 2 equals c = C << 2 |
>>= |
Right Shift and assignment operator |
C >>= 2 equals c = C >> 2 |
&= |
Bitwise AND Assignment operators |
C &= 2 equals c = C & 2 |
^= |
Bitwise XOR and Assignment operators |
C ^= 2 equals c = c ^ 2 |
|= |
bitwise can OR and and assignment operators |
C |= 2 equals c = C | 2 |
Other operators
The following are some of the other operators supported by the Java language:
Conditional operator (? :)
The conditional operator is also called the ternary operator. This operator is composed of three operands and is used to evaluate Boolean mathematical system expression. The purpose of this operator is to determine which values should be assigned to the variable. This operator is written as follows:
Variable x = (expression)? Value if True:value if False
Here is an example:
public class Test {public
static void Main (String args[]) {
int A, b;
A = ten;
b = (A = = 1)? 20:30;
System.out.println ("Value of B is:" + b);
b = (A = = 10)? 20:30;
System.out.println ("Value of B is:" + b);
}
}
This will have the following results:
Value of B is:30
value of b is:20
instanceof character
This operator is used only for object reference variables. This operator checks whether the object is a unique type (type or interface type). The instanceof operator is written as:
(Object reference variable) instanceof (class/interface type)
The result is true if the type or interface type on the left side of the operator is checked by Is-a by the right side of the object that the variable refers to. Here is an example:
public class Test {public
static void main (string args[]) {
string name = ' James ';
Following'll return true since the name is type's string
boolean result = name instanceof String;
SYSTEM.OUT.PRINTLN (result);
}
This will produce the following results:
Copy Code code as follows:
This operator will still return to true if the object being compared is an assignment that is compatible with the right type. Here's another example:
Class Vehicle {} Public
class car extends Vehicle {public
static void Main (String args[]) {
Vehicle a = new Ca R ();
Boolean result = a instanceof car;
SYSTEM.OUT.PRINTLN (result);
}
This will produce the following results:
Precedence of Java operators
operator Precedence determines the grouping of terms in an expression. It affects how an expression is evaluated. A certain operator has a higher priority than the other operators, for example: the multiplication operator has a higher priority than the addition operator:
For example, X=7+3 2; Here x is assigned a value of 13, not 20, because the operator is more than the operator + by a higher precedence, so it first does the multiplication 3*2 and then adds 7.
Here, the highest precedence operator is at the top level of the table, and the lowest priority appears at the bottom. In an expression, the higher-rank precedence operator is evaluated first.
class |
operator |
Relevance of |
Suffix |
() [] . (dot operator) |
From left to right |
One dollar |
++ - - ! ~ |
From right to left |
Multiplication of |
* / % |
From left to right |
Addition of |
+ - |
From left to right |
Shift |
>> >>> << |
From left to right |
of the relationship |
> >= < <= |
From left to right |
Equal |
== != |
From left to right |
Bit and |
& |
From left to right |
Bit XOR or |
^ |
From left to right |
Bit or |
| |
From left to right |
Logic and |
&& |
From left to right |
Logical OR |
|| |
From left to right |
There are conditions. |
?: |
From right to left |
assigning values |
= + = = *=/=%= >>= <<= &= ^== |
From right to left |
Comma |
, |
From left to right |