20145335 Shanhao "Java Programming" 2nd Week study Summary

Source: Internet
Author: User

20145335 Shanhao "Java Program Design" 2nd week study summary Textbook study summary

Type, variable, and operator

1. Type

整数:

can be subdivided into short integers (accounting for 2 bytes), int integers (4 bytes), and long integers (8 bytes). The range of integers that can be represented is long,int,short from large to small.

字节:

Byte type, which requires processing data byte by bit. An integer that can represent -128~127

浮点数:

To be used to store decimals, it is divided into float floating point (4 bytes) and double (8 bytes)

字符:

Char types are used to store signals such as character symbols.

布尔:

The Boolean type can represent True and false, which represents the logical "true" and "false".

2. Variables

    • For basic types using the corresponding keywords, some variable names can not use numbers as the beginning, or you can use some special characters. Most of the use of hump is named law

    • When you need to represent some symbols, you need to use "/" to ignore the next character, rather than the next one as part of the syntax. For example, to say "'" is to use "/".

    • See the//symbol in the program, which is a single-line comment for the Java program, and the other annotation's symbol is the multiline annotation/ and /or included.

    • When a variable declared in a method becomes a local variable, a local variable cannot be declared and no value is specified before it is used, the compiler encounters this condition and compiles the error. When you declare a variable with final qualification, a compilation error occurs if you inadvertently want to modify the final variable when you write the program later.

    • After the Java SE7, composing integers or floating-point numbers can use underscores to represent some figures more clearly.

3. Operators

    • Arithmetic operations: + 、—、 *,/, algorithms are multiplication and then added and reduced. Where the% operator calculates the remainder of the division after the result is

    • comparison, conditional operation: greater than (>), not less than (>=), less than (<), not greater than (<=), equals (= =), not equal to (!). =). Note that an equal sign (=) is the meaning of an assignment operation, such as x=y the value of y to X. Instead of comparing x, Y is equal.

    • Logical Operation:&& (and), | | (OR),! (not),&& and | | There is a shortcut operation,&& There is a false then the entire result is false, | | There is one true and the whole result is true.

    • Bitwise operations: Bitwise operations are bitwise operations, with left shift <<, right shift >> two operators

    • Increment and decrement operations: Select i++ (i--) to return the value of the variable first, then add (subtract) the variable, and if ++i (-i) indicates that the value of the variable is first added (minus), then the value of the variable is returned.

Second, type conversion

Type double to float, int to long or short because there is a loss of bytes.

In an operation, if the expression includes different types of numeric values, the operation takes the longest-length type as the primary, and the conversion of the type exists.

Third, Process Control

if...else条件式

if (conditional)

{

Description statement;

}

else{

Description statement;

The result of the conditional operation is true to execute the description statement in the IF {and}, otherwise execute the description statement in the {and} of else. If the condition is not true and does not want to do anything, else can be omitted. If more than one If...else statement is nested, the conditional one does not satisfy the conditional two that executes the if of the second statement.

switch条件式

switch (variable or expression)

{

Case integer, character, String, or enum:

Description statement;

Break

Case integer, character, String, or enum:

Description statement;

Break

...

Default

Description statement;

}

A variable or expression in the parentheses of the switch to get the value, the value must be an integer, a character, a string, and so on, then compare with the case, manipulate the corresponding description in the case, then break; Jump statement, if there is no corresponding case statement, execute the default statement, If there are no actions to handle by default, you can omit default.

while循环

while (conditional) {

Description statement;

}

While is primarily used to stop the recurrence of conditions that must be judged during the execution period. The pre-test loop, because the condition will be judged before the loop executes.

do {

Description statement;

}while (conditional type);

This is the Do...while cycle, perform some actions first, and then judge whether to repeat.

    • Break can leave the block of the current switch, for, while, Do...while, and execute the next description statement after the chunk, which is used primarily in switch to interrupt the next case comparison, in for, while, and Do...while, Mainly used to interrupt the current loop.

    • The Continue function is similar to break, but for use with loops, break ends chunk execution, and continue only skips the description statement and returns to the loop block for the next loop instead of leaving the loop.

Problems in teaching materials learning and the solving process

First, in the Java language, although the syntax of the Java language has been known before, there are problems with specific details. For the difference between the output function System.out.printf () and Syetem.out.println (), after reading the book learned that the Syetem.out.println () function will be wrapped after compiling, in the first chapter of "Hello World" This function is used, and System.out.printf () output text will not wrap, is the standard API

Reading also know some of the commonly used format of the control symbols, before the compile time can not accurately distinguish the differences between these symbols. For example,%d for decimal integer format output,%f in decimal floating-point format output,%e with scientific notation floating point output and so on.

You do not know how to set the width of a character at compile time. Later read the book know that the use of common format control characters + numbers can be reserved for the corresponding character width.

Finally there is a question about the knowledge of the Type conversion section in reading. Where the expression includes different types, the operation will be the longest type, for example, short a=1 long b=2 int c=a+b, there will be the problem of loss of precision. At first it was messy, not very well understood, and there were problems with the two solutions to the loss of precision. Later, according to the method of operation of the book, with the computer for a simple operation mastered the corresponding knowledge.

Problems in code debugging and the resolution process

When defining variables at the time of definition, it is time to be aware that there is an assignment over the range when assigning variables.

This code is left-shifted.

Here, we use the If...else statement to compile the grading code for student grades.

The following code is the 9*9 multiplication table. Example of success, but there is a question, why is the value of I starting from 2?

We also edited the practice of bitwise arithmetic and Do...while statement according to the reference of the book, and strengthened the training of Java programming.

Other (sentiment, thinking, etc., optional)

Java is a program editing class, some knowledge points and C language is the same, such as a variety of circular statements are the same, so need more programming and more practice.

You need to pay more attention to the process of compiling, not only the logical order and the problem, but also the code details.

Learning progress Bar

| Lines of code (new/cumulative) | Blog volume (Add/accumulate) | Learning time (NEW/cumulative) | Important growth |

|-------| :----------------:|:----------------:|:---------------: |:-----:|

| Target | 4000 Rows | 30 Articles | 400 hours | |

| First week | 200/200 | 2/2 | 20/20 | |

| Second week | 480/500 |  3/4 | 34/38 | |

|      Third week |   /1000 |   /7 | /60 | |

|      Week Four |   /1300 |   /9 | /90 | |

Resources
    • Java Learning Notes (8th Edition)
    • Java Learning Note (8th Edition) Learning Guide
    • ...

20145335 Shanhao "Java Programming" 2nd Week study Summary

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.