Java EE Fundamentals (iii)

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

1. Java Language Foundation (basic usage of logical operators)
    • A: What are logical operators
      • &,|,^,!
      • &&,| |
    • B: Case Demo
    • Basic usage of logical operators

    • Precautions:

      • A: Logical operators are typically used to concatenate expressions or values of type Boolean.
      • B: Expression: It is the Java syntax that joins a constant or variable with an operator.
        • Arithmetic expression: A + b
        • Comparison expression: a = = B (conditional expression)
    • C: Conclusion:
    • & Logic with: False if False.
    • | Logical OR: TRUE if true.
    • ^ Logical XOR: The same is false, and the difference is true.
    • The logical non: false is true, and false if not true.
      • Features: An even number does not change itself.
2, the Java Language Foundation (logical operators && and & differences)
    • A: Case Demo
      • What is the difference between && and &?
        • A: The end result is the same.
        • The b:&& has a short circuit effect. The left side is false and the right side is not executed.
        • & whether the left is false or true, the right side will execute
    • B: similarly | | and | The difference? (Student self-study)
    • C: Who is used in development?
      • &&,| |,!
3. Java Language Basics (basic usage of bitwise operators 1)
    • A: What are bitwise operators
      • &,|,^,~,>>,>>>,<<
    • B: Case Demo

      • Basic usage of bitwise operators 1

      • The use of &,|,^,~

      • &: There are 0 0
      • |: There are 1 1
      • ^: same 0, different 1
      • ~: Bitwise REVERSE
4. Java Language Basics (features of bitwise XOR or operators and interview questions)
    • A: Case Demo

      • Characteristics of bitwise XOR OR operator

      • ^ Features: one data to another data bit XOR or two times, the number itself is unchanged.

    • B: Interview questions:

      • Please implement the exchange of two integer variables yourself
      • Note: In the course of lectures later, I did not explicitly specify the type of data, the default int type.
5. Java Language Basics (basic usage of bitwise operators 2 and interview questions)
    • A: Use of case presentation >>,>>>,<<:
      • <<: Left highest bit discarded, right 0
      • >>: The right shift is 0, the left side is 0, the maximum is 1, the left side is 1
      • >>>: Unsigned right shift whether the highest bit is 0 or 1, the left side is 0
      • The results of 2 * 8 are calculated most efficiently
6. Java Language Basics (basic usage of ternary operators)
    • A: The format of the ternary operator
    • (Relational expressions)? Expression 1: Expression 2;
    • B: Execution flow of ternary operators
    • C: Case Demo
      • Get the maximum value in two numbers
7. Java Language Foundation (ternary operator)
    • A: Case Demo
      • Compare whether two integers are the same
    • B: Case Demo
      • Gets the maximum value in three integers
8, the Java Language Foundation (keyboard input basic format explanation)
    • A: Why use the keyboard to enter data
      • A: In order to make the program data more consistent with the developed data
      • B: Make the program more flexible
    • B: How to implement keyboard input?
      • Take the format first.
      • A: Guide Package
        • Format:
          • Import Java.util.Scanner;
        • Position:
          • Above the class.
      • B: Create a keyboard entry object
        • Format:
          • Scanner sc = new Scanner (system.in);
      • C: Getting data from an object
        • Format:
          • int x = Sc.nextint ();
    • C: Case Demo
      • Keyboard input 1 integers, and output to the console.
      • Keyboard input 2 integers, and output to the console.
9. Java Language Foundation (keyboard entry 1)
    • A: Case Demo
      • Keyboard input Exercise: Keyboard input two data, and the two data summed, output its results
    • B: Case Demo
      • Keyboard input Exercise: Keyboard input two data, get the maximum value in both data
10. Java Language Foundation (keyboard entry 2)
    • A: Case Demo
      • Keyboard input Exercise: Keyboard input two data, compare whether the two data is equal
    • B: Case Demo
      • Keyboard input Exercise: Keyboard input three data, get the maximum value of these three data
11. Java Language Foundation (sequential structure statement)
    • A: What is a Process Control statement
      • Process Control statement: The execution flow of the program can be controlled.
    • B: Classification of flow control statements
      • Sequential structure
      • Select structure
      • Loop structure
    • C: Execution Process:
      • From the top down, execute in turn.
    • D: Case Demo
      • Output a few words to see the effect can be
12, Java Language Foundation (select Structure if statement format 1 and its use)
    • A: Select the classification of the structure
      • If statement
      • Switch statement
    • B:IF statements have several formats
      • Format 1
      • Format 2
      • Format 3
    • Format of the C:IF statement 1
    • if(比较表达式) {    语句体;}
    • D: Execution Process:
      • The value of the comparison expression is evaluated first to see if its return value is true or false.
      • If true, the statement body is executed;
      • If False, the statement body is not executed;
13. Java Language Foundation (select Structure if statement considerations)
    • A: Case Demo
      • A: Comparing expressions whether simple or complex, the result must be a Boolean type
      • B:IF Statement Control Statement Body if it is a statement, curly braces can be omitted;
        • If it is more than one statement, you cannot omit it. Never omit the suggestion.
      • C: Generally speaking: there is no semicolon on the left curly brace, there is no left brace for the semicolon
14, Java Language Foundation (select Structure if statement format 2 and its use)
    • Format of the A:IF statement 2
    • if(比较表达式) {    语句体1;}else {    语句体2;}
    • B: Execution Process:
      • The value of the comparison expression is evaluated first to see if its return value is true or false.
      • If true, executes the statement body 1;
      • If False, executes the statement body 2;
    • C: Case Demo

      • A: Get a larger value from two data
      • B: Determine whether a data is odd or even, and whether the output is odd or even

      • Note: Else there is no comparison expression after, only if there is.

15, the Java Language Foundation (if statement of the format 2 and ternary of the mutual conversion problem)
    • A: Case Demo
      • If statement and ternary operator complete the same effect
    • B: Case Demo

      • The difference between an if statement and a ternary operator

      • Ternary operators can be implemented using the IF statement. Conversely, it is not established.

      • When does the IF statement implementation not use ternary improvement?

        • When the If statement controls an operation that is an output statement, it cannot.
        • Why? Because the ternary operator is an operator, the operator should have a result, not an output, after the operation.
16, Java Language Foundation (select Structure if statement format 3 and its use)
    • Format of the A:IF statement 3:
    • if(比较表达式1) {    语句体1;}else if(比较表达式2) {    语句体2;}else if(比较表达式3) {    语句体3;}...else {    语句体n+1;}
    • B: Execution Process:

      • First, the comparison expression 1 is evaluated to see if the return value is true or FALSE,
      • If true, executes the statement body 1,IF statement end.
      • If False, then the comparison expression 2 is evaluated to see if the return value is true or FALSE,

      • If true, executes the statement body 2,IF statement end.

      • If False, then the comparison expression 3 is evaluated to see if the return value is true or FALSE,

      • If all is false, the statement body n+1 is executed.

    • C: Note: The last else can be omitted, but it is recommended not to omit, you can be out of range error value hints
17. Java Language Foundation (choose Structure if statement Format 3 exercises)
    • A: Exercise 1
    • 需求:键盘录入一个成绩,判断并输出成绩的等级。90-100 优80-89  良70-79  中60-69  及0-59   差
    • B: Exercise 2

      • Demand:

        • Keyboard input x value, calculate y and output.

        • X>=3 y = 2 * x + 1;

        • -1<x<3 y = 2 * x;
        • X<=-1 y = 2 * x-1;
18. Java Language Foundation (select nested use of structure if statement)
    • A: Case Demo
      • Requirements: Get the maximum value from three data
      • Nested use of the IF statement.
19, the Java Language Foundation (select structure switch statement format and its interpretation)
    • The format of the A:switch statement
    • switch(表达式) {      case 值1:        语句体1;        break;        case 值2:        语句体2;        break;        …        default:            语句体n+1;        break;}
    • Format interpretation of B:switch statements

    • C: Face question
      • Can byte be used as a switch expression?
      • Can long be used as a switch expression?
      • Can string be used as an expression of switch?
    • C: Execution Process
      • Evaluates the value of an expression first
      • Then match the case, and execute the corresponding statement if there is one, otherwise execute the default control statement
20, Java Language Foundation (choose the structure switch statement practice)
    • A: Integer (given a value, the output corresponds to the day of the week)
21. Java Language Basics (considerations for choosing a structure switch statement)
    • A: Case Demo
      • A:case can only be constants, cannot be variables, and values after multiple case cannot appear the same
      • Can B:default be omitted?
        • It can be omitted, but it is not recommended, because it is used to prompt for incorrect conditions.
        • Special cases:
          • case, you can fix the value.
          • A,b,c,d
      • Can c:break be omitted?
        • The last one can be omitted, the other best not to omit
        • There is a phenomenon: case penetrating.
        • In the end, we recommend not omitting
      • D:default must be at the end?
        • No, it can be anywhere. But the suggestion at the end.
      • The end condition of the E:switch statement
        • A: It's over when you hit the break.
        • B: The closing curly brace to switch is over.
22. Java Language Foundation (choose Structure Switch statement practice)
    • A: See Program Write results:
    • int x = 2;int y = 3;switch(x){    default:        y++;        break;    case 3:        y++;    case 4:        y++;}System.out.println("y="+y);
    • B: Look at the program to write the results:

    • int x = 2;int y = 3;switch(x){    default:        y++;    case 3:        y++;    case 4:        y++;}System.out.println("y="+y);
23. Java Language Foundation (choose the difference between a struct if statement and a switch statement)
    • A: Summarize the respective usage scenarios for the switch statement and the IF statement
    • Switch recommends determining the fixed value when
    • If it is recommended to determine the interval or range
    • B: Case Demo
      • Use switch statements and if statements, respectively, to achieve the following requirements:
        • Keyboard entry month, output corresponding to the season

Java EE Fundamentals (iii)

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.