Java ( )

Java ( )

1.1 Java

Java Java Sun (Stanford University Network) 1995 Java (James Gosling) Java Java 1.0-1.4 5.0...8.0...13.0 jdk 8.0

1.2 Java

Java

1.3 Java

(1) JVM: Java Java (2) Windows linux MacOS (3) : Java (4)

1. Java ? 2. JVM ? ==> JVM Java JVM JVM 3. Java JVM

1.4 JDK JRE JVM

  1. JVM: Java Java
  2. JRE: Java JVM(Java Java )
  3. JDK: Java JRE
  4. JDK > JRE > JVM

1.1 Java

JDK

  1. Windows linux MacOS
  2. 32 64

3. java : ( )

1.2 DOS

DOS ?

  1. /

2. / cmd 4. Windows + R --> cmd 5. / shift + / 6.

| | | | :------------------ | :-------------------------------- | | | D: D | | dir | | | cd | | | cd 1/2.... | | | cd .. | | | cd/ | | | cls | | | exit | |

1.3 JAVA_HOME

? 1./// 2.C:/windows/notepad.exe , 3. DOS : C:\windows> notepad.exe C:\windows , notepad.exe, , D:\abc> notepad.exe : D:\abc , notepad.exe, : D:\abc notepad.exe , path path:... C:\Windows;..., path C:\Windows , . path , . Java//? java (javac: ,java: ) jdk :C:\develop\Java\jdk1.8.0_162 : 1. JAVA_HOME , C:\develop\Java\jdk1.8.0_162 2. 1 JAVA_HOME , path path, : %JAVA_HOME%\bin;... 3. DOS : C:\develop\Java\jdk1.8.0_162\bin> javac.exe C:\develop\Java\jdk1.8.0_162\bin , javac.exe, , D:\abc> javac.exe : D:\abc , javac.exe, : D:\abc javac.exe , path path:... %JAVA_HOME%\bin;..., path JAVA_HOME , C:\develop\Java\jdk1.8.0_162\bin javac.exe , , path , javac.exe , JAVA_HOME , , : path:... C:\develop\Java\jdk1.8.0_162\bin;..., : C:\develop\Java\jdk1.8.0_162\bin javac ,

HelloWorld

2.1

1.

.txt .java

2. JVM (.class)

  1. JVM Java Java JVM 0 1 0 1 (.class )
  2. ( ) JVM ( ) ? javac ( ) javac .java HelloWorld.java : javac HelloWorld.java HelloWorld.class

3. JVM

( ) ( ) ? JVM ? java ( ) : java java HelloWorld

2.2 HelloWorld

1. HelloWorld.txt .java HelloWorld.java (ctrl+s)

public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }

2. : javac .java .class ( ) javac javac .java javac HelloWorld.java

  1. javac
  2. (.java)
  3. javac .java

3. : java (.class) jvm java java java HelloWorld

  1. java
  2. (.class)
  3. Use running java command , the file name can not write back the extension .class.

2.3 FAQs for beginners to write HelloWorld

  1. Illegal character problem. The symbols in Java are all in English format.
  2. Capitalization issues. Java language is case sensitive (case-sensitive).
  3. Display the file extension in the system to avoid the HelloWorld.java.txt file.
  4. The java file name after the compilation command needs to have the file suffix .java.
  5. Class file name (class name) after running the command without the file suffix .class.
  6. Don't write main as mian.

2.4 Installation and configuration of Notepad++ software

Software download address:

Link: https://pan.baidu.com/s/15DaxTdbiVqGVjrRlU2lXbQ Extraction code: 6y7p --Share from Baidu SkyDrive Super Member V6 Copy code

3. comments and keywords

3.1 Notes

Concept: Adding comments to the code can improve the readability of the code. The comment contains the information of the program, which can help the programmer to better read and understand the program. Comments can be added anywhere in the Java source file , and the Java compiler does not compile the comments in the code, which means that the comments in the code have no effect on the program. Therefore, developers can not only write the description text of the code and the designer's personal information in the comments, but also use the comments to block some undesired code.

Classification: Java provides three types of code comments, namely single-line comments, multi-line comments, and document comments.

1. Single-line comment:

//
Mark for single-line comments, from the symbol
//
Everything from the beginning to the end of the change line is ignored by the compiler as comments. The syntax format is as follows:

//footnotes int Age; //declare a variable of type int, used to store information age, copy the code

2. Multi-line comments:

/* */
Mark for multi-line comments, symbols
/*
versus
*/
All the content in between is the content of the comment. The content in the comment can be wrapped. The syntax format is as follows:

/* Note content 1 Note content 2 */ Copy code

3. Document notes:

/**...*/
Mark up documentation comments. symbol
/**
versus
*/
The contents in between are all document annotation contents. When the documentation comment appears before the declaration (such as class declaration, class member variable declaration, class member method declaration, etc.), it will be read by the Javadoc documentation tool as the content of the Javadoc document . The format of document comments is the same as that of multi-line comments. For beginners, documentation comments are not very important, just understand. Examples are as follows: Note: You must develop good coding habits. Software coding standards mentioned in readability first, efficiency second , so the programmer must add the appropriate amount of comments in the program to improve the readability and maintainability of the program. It is recommended that the total amount of comments in the program account for 20%~50% of the total amount of program code .

3.2 Keywords

Introduce: Email: @before is the user name, and after @ is which email address is used.

zhangsan@163.com correct zhangsan@qq.com correct zhangsan_nigulasi@qq.com correct zhangsan@nigulasi@qq.com wrong @Understand that it has a special meaning and usage in the mailbox, and can not be used indiscriminately. It is regarded as a keyword in the mailbox name Copy code

In other words, keywords are some words that have been given a specific meaning in Java, and these words cannot be used as identifiers. All letters in the keyword are lowercase or displayed in color in the advanced editor. The keywords in Java are shown in the following table:

intpublicthisfinallybooleanabstract
continuefloatlongshortthrowthrows
returnbreakforstaticnewinterface
ifgotodefaultbytedocase
strictfppackagesupervoidtryswitch
elsecatchimplementsprivatefinalclass
extendsvolatilewhilesynchronizedinstanceofchar
protecedimporttransientdafaultdouble

3.3

Java (_) ($) Java

// time akb48 _interface O_o BMW $$$ // 300warrior // public // User Name //

Java Java

  1. ( )
  2. ( )
  3. ( )
  4. userLastName user_last_name

4.1

y = x + 5; //5 , b = a + 5.5; //5.5 , 5 , 5.5 ,

java java

1 2

  1. 1314 520

  2. 13.14 5.20

  3. java

    ''
    ''
    ( 2 )

    A:'a' B: '' , C:' ' , D:'ab' E: ' ' F: ' '
  4. true false true false

  5. java

    ""
    ""
    (0 1 2 ....)

    A:"a" B: "" C:" " D "ab" E " " F " "
  6. null

4.2

C Java

System.out.print("Hello!"); // "Hello"

C Java print ln

System.out.println("Hello!"); // "Hello"

public class SystemOutDemo { public static void main(String[] args) { //println() //(1) :1314 520 System.out.println(1314); System.out.println(520); //(2) : 13.14 5.20 System.out.println(13.14); System.out.println(5.20); //(3) : System.out.println('a'); //System.out.println('');//: '' System.out.println(' ');//: ' ' System.out.println(' ');//: ' ' //System.out.println(' ');//: ' ' 2 //(4) System.out.println("a"); System.out.println(""); System.out.println(" "); System.out.println("ab"); System.out.println(" "); System.out.println(" "); //(5) System.out.println(true); System.out.println(false); //(6) //System.out.println(null);//: null } }

4.3

y = x + 10; //10 b = a + 6.6; //6.6 ( ) , java , x,y x: 2 y: 12 x: 6 y: 16 x,y , x,y ( ) a,b a: 2.2 b: 8.8 a: 3.3 b: 9.9 a,b , a,b ( ) x,y,a,b , , , ( : ) : , , ,

1 2

1. byte 1 -128 127 short 2 3 int 4 21 int long 8 19 long L/l 2. float 4 float F/f : float 4 , , long double 8 double 3. char 2 4. boolean 1 true false

3

1. , 2. , , a. b. Java c. , d. Java **int = 21;** 3. , , ( , ): ;// = ;// ( , ): = ;//, ( , ): 1, 2, 3;// 1 = 1;// 2 = 2;// 3 = 3;// ( , ): 1 = 1, 2 = 2, 3 = 3;

4 8 1

public class VariableDemo { public static void main(String[] args) { /* ( , ): ;// = ;// */ byte a;//byte (1 ) , a a = 66;//66 byte a System.out.println(a);//byte (1 ) a : 66 a = 88;//88 byte a , 66 System.out.println(a);//byte (1 ) a : 88 /* ( , ): = ;//, */ short b = 100;//short (2 ) , b, 100 System.out.println(b);//short (2 ) b : 100 /* ( , ): 1, 2, 3;// 1 = 1;// 2 = 2;// 3 = 3;// */ int c, d, e;//int (4 ) , c,d,e c = 200;//200 int c d = 300;//300 int d e = 500;//500 int e System.out.println(c);//int (4 ) c : 200 System.out.println(d);//int (4 ) d : 300 System.out.println(e);//int (4 ) e : 500 /* ( , ): 1 = 1, 2 = 2, 3 = 3 ; */ //long , f,g,h //600L f //700L g //800L h long f = 600L, g = 700L, h = 800L; System.out.println(f);//long (8 ) f : 600 System.out.println(g);//long (8 ) g : 700 System.out.println(h);//long (8 ) h : 800 } }

5 8 2

public class VariableDemo { public static void main(String[] args) { //float //float a, // //float a = 6.6;//: 6.6 double , 8 , 4 float float a = 6.6F; System.out.println(a);//a //double //double b, double b = 8.8; System.out.println(b);//b //char //char c1, char c1 = 'a'; System.out.println(c1);//c1 //char c2 = '';//: '' //System.out.println(c2);//c2 //char c3 = 'ab';//: '' 2 //System.out.println(c3);//c3 //boolean : true false //boolean d1, boolean d1 = true; System.out.println(d1);//d1 d1 = false;//false d1 , System.out.println(d1);//d1 //d1 = 100;//: //System.out.println(d1);//d1 } }

long L( ) float F( )

4.4

String

457
String ( ) byte < short < int < long < float < double char int

Java int + int int + long ==> long + long ( int long: , , ) int + long ==> int + int ( long int: , , ) 1. ( ) : ( ) 2. : (1) , (2)byte/short/char , int (3)byte short char-->int-->long-->float-->double byte (1 ) 5: 00000101 byte short (2 ) 1 0, 0, , 5, 00000000 00000101 byte int (4 ): 3 0, 0, , 5 00000000 00000000 00000000 00000101 byte long (8 ): 7 0, 0, , 5 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000101 : , 0, 0, ( )

1

public class ConvertDemo { public static void main(String[] args) { int i = 1; byte b = 2; /* b byte ,i int , , byte (1 ) b int (4 ): byte b 3 0 int , int ( 4 ), byte x, 1 */ //byte x = b + i; //System.out.println(x); /* b byte ,i int , , byte (1 ) b int (4 ): byte b 3 0 int , int ( 4 ), int y, 4 */ int y = b + i; System.out.println(y);//3 } }

2

public class ConvertDemo { public static void main(String[] args) { int i = 1; double d = 2.5; /* i int ,d double , , int (4 ) i double (8 ): .0 : 1 1.0 double , double ( 8 ), int x, 4 */ //int x = i + d; //System.out.println(x); /* i int ,d double , , int (4 ) i double (8 ): .0 : 1 1.0 double , double ( 8 ), double y, 8 */ double y = i + d; System.out.println(y); } }

( ) ( ) ( ), (1) (2) ( ) 2. = ( ) ; long (8 ) 5: long num = 5L; long int (4 ): int a = (int)num;//num int , int a : long (8 ) 5: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000101 long int (4 ): , 0, 5 00000000 00000000 00000000 00000101 long short (2 ): , 0, 5 00000000 00000101 long byte (1 ): , 0, 5 00000101 : , , 0, 1, ( )

3

public class ConvertDemo { public static void main(String[] args) { double d = 1.5; /* d double ( 8 ), int x( 4 ) : , */ //int x = d; //System.out.println(x); /* d double ( 8 ), int x( 4 ) double int : , double int double int: , */ int y = (int) d; System.out.println(y); } }

4

public class ConvertDemo { public static void main(String[] args) { short s = 1; /* s short ,1 int , , short (2 ) s int (4 ): short s 2 0 int , int ( 4 ), short s, 2 */ //s = s + 1; //System.out.println(s); /* s short ,1 int , , short (2 ) s int (4 ): short s 2 0 int , int ( 4 ), short s, 2 int , short ( 2 ), 2 0, , 2 */ s = (short) (s + 1); System.out.println(s); } }

( )

4.5 ASCII

0 1 0 1 0 1 : 0 1 ? ASCII : ASCII

'A' ---> 65 ---> 1000001 ,ASCII +1 'a' ---> 97 ---> 1100001 ,ASCII +1 '0' ---> 48 ---> 110000 ,ASCII +1 ASC 1000001 ---> 65 ---> 'A' 1100001 ---> 97 ---> 'a' 110000 ---> 48 ---> '0'

ASCII int char

public class ConvertDemo { public static void main(String[] args) { //char ch, 'A' char ch = 'A'; System.out.println(ch);//A /* : byte/short/char , , int ch char , , int : char int ? ASCII : 'A' 65, */ System.out.println(ch + 1);//66 /* : byte/short/char , , int ch char , , int ASCII : 'A' 65, : ch + 1 66 int 66 char : int char ? ASCII : int 66 'B' */ System.out.println((char) (ch + 1));//B } }

5.1

blog.csdn.net/xw1680/arti

5.2 (2 10 1024)

1. (bit): 0 1 b 2. (Byte): 8 B 1B = 8b 1024B = 1KB 1024KB = 1MB 1024MB = 1GB 1024GB = 1TB ....

1 8

java

6.1

Java +( ) -( ) *( )/( ) %( ) Java

+ 12.45f + 1527.45
- 4.56 - 0.164.4
* 5L * 12.45f62.25
/ 7/23
% 12 % 102
+ - +5 -7 +

1

public class OperatorDemo { public static void main(String[] args) { int a = 3; int b = 2; System.out.println(a + b);//3 + 2: 5 System.out.println(a - b);//3 - 2: 1 System.out.println(a * b);//3 * 2: 6 //3/2: int/int int System.out.println(a/b);//3/2: 1 //int * double/int ==> double/ int ==> double/double ==> double System.out.println((a * 1.0)/b);//3.0/2 ==> 3.0/2.0 ==> 1.5 } }

2 %

/* % : ( ) = (/: ) ...... (%: ) : 1. : %2 0 %2 0 2. 0: 0: 3. %/, , , int num, 1234 int num = 1234; : num%10 : num/10%10 : num/100%10 : num/1000%10 */ public class OperatorDemo { public static void main(String[] args) { System.out.println(10 % 2);//0 10 System.out.println(11 % 2);//1 11 System.out.println(100 % 25);//0 100 25 System.out.println(100 % 26);//22 100 26 System.out.println("---------------"); int num = 1234; System.out.println(num % 10);//4: 1234 10 = 123 .... 4(%) //System.out.println(num/10);//123 1234 10 = 123(/) .... 4(%) System.out.println(num/10 % 10);//3 123 10 = 12(/) ... 3(%) //System.out.println(num/100);//12 1234 100 = 12(/) ... 34(%) System.out.println(num/100 % 10);//2 12 10 = 1(/) ... 2(%) System.out.println(num/1000 % 10);//1 } }

3 +

/* + 1. ( , ) 2. ( ) */ public class OperatorDemo { public static void main(String[] args) { System.out.println(5 + 5);//10 /* int + char ==> int + int ==> int : char ==> int ASCII 'A' 65 */ System.out.println(5 + 'A');//5 + 65: 70 /* : byte/short/char , , int char + char ==> int + int ==> int : char ==> int ASCII 'A' 65 char ==> int ASCII 'B' 66 */ System.out.println('A' + 'B');//65 + 66: 131 System.out.println("Hello" + "World"); //"5+5="+5+5: //"5+5="+5: + "5+5=5" //"5+5=5"+5: + "5+5=55" System.out.println("5+5=" + 5 + 5);//5+5=55 //() , 5+5 10 //"5+5="+10: + "5+5=10" System.out.println("5+5=" + (5 + 5));//5+5=10 } }

6.2

= ( )

int a = 100; // 100 a /* ( a number) ( 123 "book") ( 45*12) */

Java Java

+= a += b;a = a + b;
-= a -= b;a = a - b;
*= a *= b;a = a * b;
/= a/= b;a = a/b;
%= a %= b;a = a % b;
&= a &= b;a = a & b;
|= a |= b;a = a | b;
^= a ^= b;a = a ^ b;
<<= a <<= b;a = a << b;
>>= a >>= b;a = a >> b;
>>>= a >>>= b;a = a >>> b;
+= a += 1 a = a + 1

4

public class OperatorDemo { public static void main(String[] args) { int a = 10, b = 20; a += b;//a = a + b System.out.println(a);//30 System.out.println(b);//20 int c = 30, d = 20; c %= d;//c = c % d = 30%20 = 10 System.out.println(c);//10 System.out.println(d);//20 } }

5

public class OperatorDemo { /* 1.+=,-=,/=,*=,%= , 2. , , */ public static void main(String[] args) { short s = 1; /* s short ,1 int , , short (2 ) s int (4 ): short s 2 0 int , int ( 4 ), short s, 2 */ //s = s + 1; //System.out.println(s); /* s short ,1 int , , short (2 ) s int (4 ): short s 2 0 int , int ( 4 ), short s, 2 int , short ( 2 ), 2 0, , 2 */ s = (short) (s + 1); System.out.println(s); //2 short s2 = 1; /* +=,-=,/=,*=,%= , */ s2 += 1;//s2 = (short)(s2 + 1); System.out.println(s2); //2 /* 10 int (4 ), byte (1 ) : ? 10 , byte , : byte b = (byte)10; */ byte b = /*(byte)*/10; System.out.println(b);//10 } }

6.3

1 1

(++) (--) 1. : 1(++) 1(--) 2. : (1) : ++a,--a (2) : a++,a-- 3. : (1) : ++/-- , ++ ++, , 1 -- --, , 1 (2) : ( , ) ++/--: ++/--, (++) (--)1, ++/-- ++/--: , ++/-- , (++) (--)1 : ---- a++: a 1 a--: a 1

6

public class OperatorDemo { public static void main(String[] args) { int a = 2; //++ , a++;//a = a + 1 = 2 + 1 System.out.println(a);//3 int b = 2; //++ , ++b;//b = b + 1 = 2 + 1 System.out.println(b);//3 System.out.println("-----------------"); int c = 2; /* ++ , ++ c , c 1, c 3, 3 d,d 3 */ int d = ++c; System.out.println(c);//3 System.out.println(d);//3 System.out.println("-----------------"); int e = 2; /* ++ , ++ e , e (2) f, f 2, e 1, 3 */ int f = e++; System.out.println(e);//3 System.out.println(f);//2 System.out.println("-----------------"); int x = 4; //5 6 /* (x++)+(++x)+(x*10) (x++): ++ , x 4, x , 5 4 + (++x)+(x*10) (++x): ++ , x 1,x 6, 6 4 + 6+(x*10) x*10 --> 6*10 : 60 4 + 6 + 10 : 70 */ int y = (x++) + (++x) + (x * 10); //4 + 6 + System.out.println(x);//6 System.out.println(y);//70 } }

6.4

true false

== 2 == 3false
< 2 < 3true
> 2 > 3false
<= 5 <= 6true
>= 7 >= 7true
!= 2 != 3true
7
```java
public class OperatorDemo {
public static void main(String[] args) { int a = 10, b = 20; boolean result = (a == b); System.out.println(result);//false System.out.println(a != b);//10 != 20: true System.out.println(a > b);//10 > 20: false System.out.println(a >= b);//10 >= 20: false System.out.println(a < b);//10 < 20: true System.out.println(a <= b);//10 <= 20: true System.out.println(a == b);//10 == 20: false System.out.println(a = b);//20 b a, a }

}

## 6.5 7 8 5 6 ( 7:00 PM\~8:00 PM) ( 5:00 PM\~6:00 PM) true( ) false( ) ```text ( : true/false ), , true, false , true, false : (1) & (shift+7): , , , true, true : false false false false (2) |(shift+\): , , , , true : true true true true (2) !(shift+1): ,!true false,!false true

8

public class OperatorDemo { public static void main(String[] args) { int a = 10, b = 20, c = 30; System.out.println(a > b & a > c);//10 > 20 & 10 > 30 ==> false & false ==> false System.out.println(a < b & a < c);//10 < 20 & 10 < 30 ==> true & true ==> true System.out.println(a > b & a < c);//10 > 20 & 10 < 30 ==> false & true ==> false System.out.println(a < b & a > c);//10 < 20 & 10 > 30 ==> true & false ==> false System.out.println("--------------------"); System.out.println(a > b | a > c);//10 > 20 | 10 > 30 ==> false | false ==> false System.out.println(a < b | a < c);//10 < 20 | 10 < 30 ==> true | true ==> true System.out.println(a > b | a < c);//10 > 20 | 10 < 30 ==> false | true ==> true System.out.println(a < b | a > c);//10 < 20 | 10 > 30 ==> true | false ==> true System.out.println("--------------------"); System.out.println(a > b ^ a > c);//10 > 20 ^ 10 > 30 ==> false ^ false ==> false System.out.println(a < b ^ a < c);//10 < 20 ^ 10 < 30 ==> true ^ true ==> false System.out.println(a > b ^ a < c);//10 > 20 ^ 10 < 30 ==> false ^ true ==> true System.out.println(a < b ^ a > c);//10 < 20 ^ 10 > 30 ==> true ^ false ==> true System.out.println("--------------------"); System.out.println(!true);//false System.out.println(!false);//true } }

&& A && B =
|| A || B =
! !A =
ABA&&BA||B
:-----:-----:--------:----------
truetruetruetrue
truefalsefalsetrue
falsetruefalsetrue
falsefalsefalsefalse
```text
&&: false, : true,
:
(1) &&: & , &&
(2) : ,
: , &&
```
9
```java
public class OperatorDemo {
public static void main(String[] args) { int a = 2; /* (3>5)&&(++a>2) 3>5 false && , false, false, (++a>2) true false, && , (++a>2) */ System.out.println((3 > 5) && (++a > 2));//false System.out.println(a);//2: ++a ,&& int b = 2; /* (3>5)&(++b>2) 3>5 false & , false, false, (++b>2) , b 3 */ System.out.println((3 > 5) & (++b > 2));//false System.out.println(b);//3: ++b ,& System.out.println("-------------------"); int c = 2; /* (3<5)||(++c>2) 3<5 true || , true, true, (++c>2) true false, || , (++c>2) */ System.out.println((3 < 5) || (++c > 2));//true System.out.println(c);//2: ++c ,|| int d = 2; /* (3<5)|(++d>2) 3<5 true | , true, true, (++d>2) , d 3 */ System.out.println((3 < 5) | (++d > 2));//true System.out.println(d);//3: ++d ,| }

}

## 6.6 | | | | | :-------- | :------------ | :------- | | & | | a & b | |/| | | a/| b | | ~ | | ~a | | ^ | | a ^ b | | << | | a << 2 | | >> | | b >> 4 | | >>> | | x >>> 2 | & | ^ ~ | A | B | A&B | A\|B | A^B | ~A | | :---- | :---- | :---- | :---- | :---- | :---- | | 0 | 0 | 0 | 0 | 0 | 1 | | 1 | 0 | 0 | 1 | 1 | 0 | | 0 | 1 | 0 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 0 | 0 | ```text 1 1 1 0 12 8 8 0000 0000 0000 1100 12 & 0000 0000 0000 1000 8 0000 0000 0000 1000 8 2 0 0 1 4 8 12 0000 0000 0000 0100 4 | 0000 0000 0000 1000 8 0000 0000 0000 1100 12 3 1 0 31 22 9 0000 0000 0001 1111 31 ^ 0000 0000 0001 0110 22 0000 0000 0000 1001 9 4 1 0 0 1 123 -124 ~ 0000 0000 0111 1011 123 1111 1111 1000 0100 -124

& | ^

ABA&BA|BA^B
truetruetruetruefalse
truefalsefalsetruetrue
falsetruefalsetruetrue
falsefalsefalsefalsefalse
10
```java
public class OperatorDemo {
public static void main(String[] args) { short x = ~123;// short x 123 // System.out.println("12 8 " + (12 & 8)); // System.out.println("4 8 " + (4 | 8)); // System.out.println("31 22 " + (31 ^ 22)); // System.out.println("123 " + x); // System.out.println("2>3 4!=7 " + (2 > 3 & 4 != 7)); // System.out.println("2>3 4!=7 " + (2 > 3 | 4 != 7)); // System.out.println("2<3 4!=7 " + (2 < 3 ^ 4 != 7)); }

}

<< >> >>> 0 2 ![ ](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/eaff843e090a48f08961521078d7366a~tplv-k3u1fbpfcp-zoom-1.image) short 9115 0010 0011 1001 1011 18230 -29076 ![ ](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/bc7773c100a4447fa26fc29f51fb5581~tplv-k3u1fbpfcp-zoom-1.image) 0 1 2 ![ ](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/80b0dd6d35b94b839548fd33619260d6~tplv-k3u1fbpfcp-zoom-1.image) short 9115 0010 0011 1001 1011 4557 2278 ![ ](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/aa5d930f3f00406ca12760ee93ea84e8~tplv-k3u1fbpfcp-zoom-1.image) short -32766 0010 0011 1001 1011 -16383 -8192 ![ ](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/bb44da943278468fa8fc4c6c682e2501~tplv-k3u1fbpfcp-zoom-1.image) 0 2 int -32766 1111 1111 1111 1111 1000 0000 0000 0010 2147467265 1073733632 ![ ](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/780d7eba5f40486ebb2d8b9dd4f1acb2~tplv-k3u1fbpfcp-zoom-1.image) <font size=3 color=green face= > 11 ```java public class OperatorDemo { public static void main(String[] args) { int a = 24; System.out.println(a + " " + (a >> 2));//6 int b = -16; System.out.println(b + " " + (b << 3));//-128 int c = -256; System.out.println(c + " " + (c >>> 2));//1073741760 } }

byte short >>> byte short >>>

12 byte short

public class OperatorDemo { public static void main(String[] args) { byte a = (byte) (-32 >>> 1); System.out.println("byte " + a); //-16 short b = (short) (-128 >>> 4); System.out.println("short " + b); //-8 } }

6.7

1. : = 1 ? 2 : 3; 2. : (1) 1 , true false (2) 1 true, 2 (3) 1 false, 3

13

import java.util.Scanner; public class OperatorDemo { public static void main(String[] args) { int iInput; Scanner sc = new Scanner(System.in); // System.out.println("Input number"); iInput = sc.nextInt(); // System.out.println(iInput % 2 != 0 ? " " : " "); } }

14 3 5

import java.util.Scanner; public class OperatorDemo { public static void main(String[] args) { int iInput; Scanner sc = new Scanner(System.in); // System.out.println("Input number"); iInput = sc.nextInt(); // // 3 3 5 boolean bool = iInput % 3 == 0 ? ((iInput % 5 == 0) ? true : false) : false; System.out.println(" 3 5 " + bool); } }

15 ( )

public class OperatorDemo { /* 180kg 200kg : 1. int w1 w2, , 2. w1 w2 , boolean result 3. result */ public static void main(String[] args) { //1. int w1 w2, , int w1 = 180, w2 = 200; //2. w1 w2 , boolean result boolean result = (w1 == w2) ? true : false; //3. result System.out.println(" ? " + result); System.out.println("---------------"); String s = (w1 == w2) ? " " : " "; System.out.println(" ? " + s); } }

16 ( )

public class OperatorDemo { /* 180kg 200kg : 1. int w1 w2, , 2. , w1 w2 , int max 3. max */ public static void main(String[] args) { //1. int w1 w2, , int w1 = 180, w2 = 200; //2. , w1 w2 , int max int max = (w2 > w1) ? w2 : w1; //3. max System.out.println(" : " + max); } }

17

public class OperatorDemo { /* 150cm 210cm 165cm : 1. 3 int h1,h2,h3 , 2. h1 h2 , int temp 3. temp h3 , int max 4. max */ public static void main(String[] args) { //1. 3 int h1,h2,h3 , int h1 = 150, h2 = 210, h3 = 165; //2. h1 h2 , int temp int temp = (h1 > h2) ? h1 : h2; //3. temp h3 , int max int max = (temp > h3) ? temp : h3; //4. max System.out.println(" : " + max);//210 } }

6.8

a = 7 >> 5 * 6 ^ 9/3 * 5 + 4; /* */ a = (7 >> (5 * 6)) ^ ((9/3 * 5) + 4); //

6.9

Java Java Java

1 ()
2 ++ -- + - ~
3 */%
4 + -
5 << >> >>>
6 < <= > >= instanceof
7 == !=
8 &
9 ^
10 |
11 &&
12 ||
13 = += -= *=/= %= <<= >>= &= ^= |= >>>=