20145216 Shi Yao "java Program Design" 2nd Week study Summary

Source: Internet
Author: User

20145216 Java Programming 2nd week of study summary

Summary of learning contents of textbook

Chapter III Basic Grammar

3.1 types, variables, and operators

• Type

• Basic Types

•整数:short(占2字节)、int(占4字节)、long(占8字节)•字节:byte•浮点数:float(占4字节)、double(占8字节)•字符:char(汉字、英文字符都是双字节的)•布尔:boolean(true/false不能与其他类型进行运算)

• Class type

• Variables: The data staging location is called a variable in the program language, the variable cannot be named with a number as the beginning, or some special characters cannot be used, and the variable name cannot be the same as the Java keyword, nor can it have the same name as the Java reserved word.

• Operators

• Arithmetic operations: + 、-、 *,/,%

• Relational operations:>, >=, <, <=, = =,! = (Note Do not perform equality operations on floating-point numbers)

• Conditional operator: conditional expression? Return value when established: return value on Failure

• Logical operations: With (&&), or (| | ), Non-(! ) (The result of the operation is a Boolean value: TRUE or False)

• Bitwise OPERATION: The result of the operation is a bit string (bit vector), often used for mask operation

•与(&):全1为1,有0则0•或(|):全0为0,有1则1•非(~):书上说是补码,按我们的习惯应该是反码•异或(^):相同为0,不同为1•左移(<<):最右补0•算术右移(>>):右移后,正数最高位补0,负数最高位补1•逻辑右移(>>>):右移后,最高位总是补0

• Increment, decrement: i++, I--、 ++i 、--i

• Assignment Values: =, + =,-=, *=,/=,%=, &=, |=, ^=, <<=, >>=

Note: X=y refers to the value of y assigned to X, and X==y is the comparison of whether x is equal to Y.

• Type Conversion

•短->长(widening)是安全的,长->短(narrowing)必须强制转换•类型转换 •短->长(widening)是安全的,长->短(narrowing)必须强制转换

3.2 Process Control

structured programming (structured programming) consists of three statements

• Order

• Branches: If, If...else, If...else if, switch...case (if the exact value of the judgment is not many, and conforms to the four types of byte, short, int, char, it is recommended to use the switch statement; If the interval is judged, Or if the result is a Boolean type, you should use the IF statement)

• Loops: For, while, Do...while

Problems in teaching materials learning and the solving process

Problem: the example program in the book P63 bit operation:

BYTE number = 0;

System.out.println (~number);

Displaying a result of-1

Resolution process:

~ denotes the complement operation, the complement operation is to change all bits 0 to 0,byte into memory 1 bytes, number stored 0 in memory is Bit 00000000, by the complement operation becomes 11111111, which in the computer is represented by an integer is-1.

Problems in code debugging and the resolution process

Question: I first read the code in the book several times, and then try to write it myself, I find it is always unclear when to use System.out.printf, when to use SYSTEM.OUT.PRINTLN.

Solution: By surfing the internet Baidu, found that the two respectively applicable situation:

If the output is a string then use printf () good, but if the output is a single character with println () good.

For example:

int i = 1, j = 2, k = 3;

System.out.printf (the value of "%d +%d is%d \ n", I, J, K); //If it is the output string with printf good

SYSTEM.OUT.PRINTLN (i + "value" + "+" + j + "value is" + K ");

int m = 47;

System.out.printf ("%d\n", m);

System.out.println (m); If it is output single character with println good

Using idea, I managed to run the following 4 pieces of code:

• variables:

operator

Switch Conditional type:

for Cycle:

Problem: The first time you write this code, you miss "2" in the statement "%d*%d=%2d".

Solution: Because it is unclear why to write%2d, so the Internet to find information, get the following explanations:

System.out.printf ("%d*%d=%2d", X, Y, z);

%d is output as a decimal integer, and%2d is the output of at least two characters in a decimal integer.

Operation Result:

If x=1,y=2,z=2, 1*2= 2 (note that the last 2 occupies two characters in length)

If x=2,y=5,z=10, 2*5=10

Other (sentiment, thinking, etc., optional)

The first time I used idea, I found that it was really handy to write Java programs with this software, and many of the sentences would be all out with just the initials. By reading more books on the code, and then try to write their own, and find errors, solve the problem, I feel that my understanding of Java and understanding of the next step, I think the blind spot through self-study slowly master is I study this course the biggest harvest.

Learning progress Bar /Cumulative) new/cumulative)
lines of code (newBlog volume (Learning time (new/cumulative) Important growth
Goal 4500 rows 30 Articles 350 hours Be able to use Java freely
First week 150/150 2/2 15/15 Learn basic Java-related knowledge
Second week 200/350 1/3 20/35 Learn the basic syntax of Java
Resources
    • Java Learning Notes (8th Edition)
    • Java Learning Note (8th Edition) Learning Guide

20145216 Shi Yao "java Program Design" 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.