Java Summary 2016.01.24

Source: Internet
Author: User

This week I learned the loop statements, nested loops and methods, and here is a summary of this week's learning:

While and Do/while statements, the following points need to be noted:
1. While is a prior cycle, that is, the first judgment in the execution, such as the judgment of the false is not executed at once; Do/while is a posteriori cycle, which is performed at least once.

2. The variable used for the loop is usually a local variable, because it is useless to loop over the variable.

3.do/while Loop Note that the ";" number is added to the while judgment statement.

The difference between 4.a+=b and a=a+b: A+=b will automatically convert type A, a=a+b will be converted to the maximum type (if the type B >a will be an error).

5. Continue: The end of the cycle, after the statement does not execute, and then do the next cycle.

6. Break: Jump directly out of the nearest loop statement.

For loop and loop nesting, there are a few things to note:
1. In Java, two strings to compare the size of the expression: Str1.compareto (STR2); compare equal: Str1.equals (STR2); Returns a Boolean value.
2. Determine if the value entered is valid, using the method: identifier. hasnextint (); int can be substituted for other numeric types.
3. Program writing to follow the "low coupling, single principle", that is, a variable, a method is best to do only one thing.
4. For loop: Format (expression 1; expression 2; expression 3) {
Loop Body}
5. Loop nesting, outer loop control row, Inner loop control column.

method, which is called the function in the C language, this chapter should pay attention to the following questions:
1. Object class: Is the ancestor of all classes, can put any type of data, that is, the object array can be put int,string,double even method data types.

2. Classes cannot be used directly, but are instantiated and reused by objects.

3. Definition of method: modifier 1 modifier 2 ... Return value type method name (formal parameter list) {Java statement block}
Use of method: return value = (optional) method name (parameter);

4. String exception: Java.lang.StringIndexOutOfBoundsException

5. Null pointer exception: Java.lang.NullPointerException

6. Formal parameters: formal parameter; argument: The actual parameter when the method is called, with a value.

7. Method parameter passing is passed by value, that is, the parameter is called only the value of the argument, the argument is not changed, but the array is called by the array reference, the value is modified after the method executes.

8. Public indicates that the method defined is common and can be called in any program.

9. Static indicates that the method is static, belongs to the class level, has no static at the object level, and declares the object first when called

Java Summary 2016.01.24

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.