Deeper Java object-oriented preparatory articles (1. Control structure) 1. Introduction: It is well known. Object-oriented is important for Java language, how to study Java-oriented object. For beginners, it is very important. Before the object. There are three basic premise that we need to do a knowledge: 1. Control structure, structured programming foundation. 2. In-depth research method. 3. Familiar with the Java object array. This chapter introduces you the first premise. Control structure. Control structure: 1. Because the object is a structured program, it is necessary to understand the control structure. The general program statement is performed in a sequence according to the order determined by programming. Structure can be divided into (sequence structrue). Select structural structure. The three structures are all languages. The sequential structure is default in Java. 2. In Java, the flowchart and pseudo code is proposed to make the program design more specifications, the program is easy to understand, the structure is clear. 3. Select the structure: divide if (radio) IF..EELSE (multiple choice) Switch A1: IF structure:, for example, false code: if student's grade is grade is get "passed" here to point out the code indentation emphasizes the inheritance structure of structured programming. It can also be clarified. Give people feel comfortable. The pseudo code transformed into a Java statement is: if (studentgrade> = 60) System.out.prinln ("pass"); A2: IF / ELSE structure, for example, false code: if student grade Is Greater Than OR Equal to 60 Print "Pass" Else Print "failed" Convert to Java statement is: IF (StudentGra De> = 60) System.out.Println ("Passed"); Else System.outprintln ("failed"); It is seen that the pseudo code and the actual Java statement are very close, so that the programmers are more clear. At time Java also proposed a unique three-yuan operator "?:" The above Java program is writable as: system.outprintln (studentgrade> = 60? "passed": "failed");
This allows the program length to shorten the run time. A3. Syntax error concept: A fatal logic error makes the program failure, not a logical error of a dead logic error does not affect the run. But the result will result. A4.WHILE loop: You can repeated actions when the cycle condition is true. Among them, the composite statement is a single statement. The format expression is: Expression 1 While (Expression 2) {statement expression 3} A5. For loop (control counter). In many cases, it is used as a control counter. Controls a statement to execute n times. The format is for (control variable initial value; cycle condition; control variable incremental expression); for example: for (int counter = 1; counter <= 10; counter ); A6: Switch multi-selection structure, format is switch () case 1: statement Break; case 2: statement break;. Default: Switch in CASE needs Break, Break aborts current Switch, turn to the next sentence. Default is the default value. If the corresponding case is not found, execute the default, the label after Case can only be constant plastic expressions, value is shaped Any combination of constant characters and integer constants.
A7: do / while. No matter whether the condition is composite to execute it. Summary: Whether you write the program is a large scale or a small applet, it can use the above structure, so understand these structures, consist, Syntax. And realization conditions are very important, and it is also based on OOP. This is one of the more object-oriented preparatory classes. The next chapter is, research methods, followed by understanding arrays.