One: Assign value
1. Assign a value to the base data type, int a=b;//Copy the value of B to a, and if you modify the value of a, the value of B is not affected.
2. Assigning values to reference types,
public class Text {public static void main (string[] args) {person a=new person (); Person B=a;//system.out.println (B.age); b.age=14; System.out.println (a.age);}} Class Person{int age=15;}
Output results: 14
Solution: Reference a points to a heap space, then B also points to the space, AB shared a heap of space, when the b.age=14 changes, a also follows the change. (String Although it is also a reference, but)
Second: self-increasing self-reduction
- Prefix increment (decrement): ++i (--): Performs an increment (decrement) operation before executing the statement.
- Suffix increment (decrement): i++ (i--): Executes the statement before the increment (decrement) operation is performed.
int i=1; System.out.println (i++); i=2; System.out.println (++i);
Results: 1
3
Three: Relational operators
- Composition: Greater than (>) less than (<) less than or equal (<=) greater than or equal to (>=) equals (= =) Not equal (! =)
- Result: The result of the Boolean type is generated.
- equals (= =) and not equals (! =) apply to all basic types, while other comparators do not apply to Boolean types, such as True>false, which have no practical meaning.
- The Equals (= =) and not equals (! =) comparison is the reference to the object.
- We know = = and! = is a reference to compare objects, but what if we want to compare the values of the objects directly? This can be compared using the Equlas () method, but this method does not work with basic data types, basic data types with = = and! = it can be compared. Note: Equals () defaults to a comparison reference, but most classes override Equals () to compare the object's contents, and if we create a class, Equals () cannot compare the contents of the object because we do not redefine and override this method.
public class Text {public static void main (string[] args) {string a=new string ("abc"); String B=new string ("abc"); System.out.println (A.equals (b)); True A's class string overrides Equlas () to compare the contents of the object, so ab equals person a1=new person (); Person B1=new person (); System.out.println (A1.equals (B1)); False the custom class does not overwrite Equals (), so the original equals () can only compare addresses. }}class person{int i=15;}
Result: True
False
Operator of Java Basics