Java Experience---expression, Process Control __java

Source: Internet
Author: User
Tags call back terminates

today I learned the process control, including a variety of cycles, below are some experience and experience:

1. In the future, we will learn and use the graphical user interface of Java applications, graphical user interface of the operating system or application is the underlying operating instructions in the overall "packaging", such as: With the mouse click menu items, or ultimately to convert to the underlying instructions, as long as there is packaging, There will be performance weakening and restrictions, and the use of the console can be at the opposite level of control to achieve more efficient.
The 2.foreach loop is a circular statement provided by JDK5.0 that can be used to compile elements of a composite group in a simpler way.
3.java language does not provide and GOTO statements to control the jump, which improves the readability of the process control, but also reduces the flexibility of program flow control, in order to compensate for this shortcoming, Java provides continue and break to control the loop structure. In addition, return can end this method and, of course, end the loop. A break is an exit loop (for example: if there are two layers inside and outside, exit the inner loop; to exit the outer layer requires a tag that identifies an outer loop, (the Java tag is an identifier that follows the English colon (:), unlike other languages, Java is only put in before the loop statement to the effect of note: The tag after the break must be a valid label, that is, the label break statement before the loop definition, or in the loop before the outer loop of the definition, continue is to exit the loop (a continue statement of tokens can be skipped from the inner loop of multiple loops to the outer loop, performing the next round of loops identified by the label); return is not specifically used to jump out of the loop, but to end a method that will end when a return statement is executed inside the loop. The cycle naturally ends with it. (that is, from where to start the call back, like the break, continue can also follow a label, used to directly end the label to mark the cycle of the loop, restart the next cycle); that is, continue just terminates this cycle, and then begins the next loop, The break is a complete termination of the cycle, it can be understood that the role of continue is slightly more than the rest of the cycle of statements, restart the new cycle.
4. The parentheses placed within the if can only be a logical expression, that is, the return value of this expression can only be ture or false;if, else if, and then the multiple lines of code in curly braces are called code blocks, and if there is only one line in the code block, it is best not to omit the curly braces, This is because it has better readability, and it reduces the occurrence of errors.
The meaning of 5.else is "otherwise", else is itself a condition, his implied condition is: to the preceding conditions to reverse; The Else statement has a basic rule: always prioritize a small range of conditions before processing.
6. And if statements are different: (1). After each case label in the switch statement, the start and end points of the code block are very clear, so you can omit the curly braces of the code block after the case completely. Like else in an if statement, the default in the switch appears to be conditional, that is, the value of the expression expression cannot be equal to the value of any previous case. (2). The switch statement controls the type of the expression can only be byte, short, int, char, and cannot be a string, which differs from C # in that the data type of the control expression can only be integral or character type, not Boolean.
7. Unlike a while the loop condition of a Do-loop must have a semicolon (;) while the while must not, this semicolon indicates the end of the loop, and the loop body of the Do-while loop executes at least once.
8. For a For loop, the loop condition is always executed more than the loop body, because the last execution loop condition returns false, and the loop body is no longer executed. The loop iteration statement for a for loop is not put together with the loop body, so the loop iteration statement is executed even if the continue statement ends this loop when the loop body is executed. (Loop body: code that is executed repeatedly, need at the appropriate time to change the circulation of the condition to false, end cycle, otherwise the loop body has been carried out, will form a dead cycle; the loop condition is a Boolean expression that determines whether the loop body is executed or not; This part is done after the execution of a loop body Performed before the cyclic condition is evaluated, usually to control the variables in the loop condition so that the loop ends at the right time. (For example: i++;j++))
9. Because the loop iteration statement of the while and Do loop is followed by the loop body, if the loop body is not fully executed, such as using continue to end this loop, the loop iteration statement is not executed, but the loop iteration statement for the loop is not placed with the loop body. So whether or not you use continue to end this loop, the loop iteration statement gets executed as well.
The two semicolon in the 10.for loop parenthesis is required, initialization statements, cyclic conditions, iteration statement parts can be omitted, if the cyclic condition is omitted, then the cyclic condition by default is ture, which will produce a dead loop. (Dead Loop: while (1) =while (ture) =for) uses a For loop to define the initialization condition outside the loop body, and to place the loop iteration statement in the loop, very similar to the while. If you use continue to end this loop, you will cause the loop iteration statement to not be executed. There is also a role in defining the initialization statement for a for loop before the loop: You can enlarge the scope of the variable defined in the initialization statement. (Consequences of scope enlargement: If the method has another loop that also needs to define a loop variable, then I can no longer use I as a loop variable (the variable defined in the For loop, whose scope is valid only within that loop, and the variable cannot be accessed after the for loop terminates) is more common in comparison:
int temp=0;
for (int i=0;i<10;i++) {System.out.println (i+ "\ n") temp=i;}
System.out.println ("Loop End")
Use a variable Templ to save the value of the loop variable I, making the program clearer, and the variable I and templ responsibilities clearer.
11. Assuming that the outer loop is n times and the inner layer is m, the loop body of the inner loop actually needs to perform n*m times. (Outer loop general Tube line, inner layer pipe column.) )
12. The import statement at the beginning of the source file is the function of importing the scanner class defined in the Java.util package. Scanner.in represents keyboard input, a Java object provided by the system that is associated with input to the console, Scanner.out is output. Describe some of the common methods:
The functionality of the Java.util.Scanner class is not limited to the reading of the console input data, and its objects can also be associated with strings, files, or other data sources.
(1). Construction method Public Scanner (InputStream source) For example, Scanner sc=new Scanner (system.in);
(2). Public Sting Next () reads the next word, using a spaces or newline character as a marker for separating the words. For example, String name=sc.next ();
(3). public int Nextint () reads an integer, an error occurs if the next word entered cannot be resolved to a valid integer (for example, a non-numeric character such as a Chinese character).
(4). public double nextdouble () reads a double-precision floating-point number, and an error occurs if the next word entered cannot be resolved to a valid floating-point number.
(5). Public boolean Nextboolean () reads a Boolean value, and if the next word entered cannot be resolved to a valid Boolean value (TRUE or FALSE), an error

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.