20165203 Java Programming Second week Java Learning summary

Source: Internet
Author: User
Tags bitwise bitwise operators logical operators

Summary of learning contents of teaching Materials chapter II (i) identifiers

Attention:

    • Identifiers consist of letters, draw lines, dollar signs, and numbers, and are unlimited in length.
    • The first character of an identifier cannot be a mathematical character.
    • The identifier cannot be a keyword.
    • Identifiers cannot be true, FALSE, and null.
    • Letters in identifiers are case-sensitive.
(ii) Basic data types (emphasis)-[four types]

Logical Type: Boolean (different from C language)
Integer type: Byte, short, int, long
Character type: Char
Float type: float, double

-[Related content analysis]
data type keyword constant variable byte memory data range
Boolean true, false declaration with Boolean
int 123,6000,077,0x3abc use int to declare 4 -2^31~ (2^31-1)
byte range int constant declaration in byte 1 -128~127
Short range of int constants use short to declare 2 -2^15~2^15-1
long denoted by the suffix L, 108l,07123l using long to declare 8 -2^63~2^63-1
Char characters in Unicode tables enclosed in single quotes, ' A ', ' B ' using char to declare 2 (unsigned bit, and no negative char) 0~65535
Data Type Constants variables bytes allocated by the data Data Accuracy
float with the suffix F or f, cannot be omitted, 453.5439f,21379.987f use float to declare 4 8-digit valid digits
Double can have a suffix D or D, but can be omitted, 2389.539d,2318908.987 use double to declare 8 16-digit valid digits
(c) Array 1. Declaring an array

One-dimensional array: float boy [];
Two-dimensional array: char cat [];

2. Assigning elements to an array

Array name =new array element type [number of array elements]
Boy = new Float[4];
or float boy[] = new float [4];
Two-dimensional arrays:
int mytwo[][];
mytwo = new int [3][4];
or int mytwo [] = new int [3][4];

3. Use of array elements

Index starting from 0:

Use of 4.length

One-dimensional array: The value of "array name. Length" is the number of elements in the array
Two-dimensional array: The value of "array name. Length" is the number of one-dimensional arrays it contains.
For example: float a[] = new float [12];
int b[][] = new int [3][6];
Then the a.length was 12,b.length to 3;

5. Initialization of arrays

Float boy[] = {21.3f,23.89f,2.0f,2.3f,778.98f};
int a[][] = {{1},{1,1},{1,2,1},{1,3,3,1},{1,4,6,4,1}};

6. Reference to an array (the first address of the element)

Two arrays of the same type if they have the same reference, they will have exactly the same elements.

public class Example2_4 {    public static void main(String args[ ]) {        int a[] = {1,2,3,4};        int b[] = {100,200,300};        System.out.println("数组a的元素个数="+a.length);        System.out.println("数组b的元素个数="+b.length);        System.out.println("数组a的引用="+a);        System.out.println("数组b的引用="+b);        a=b;        System.out.println("数组a的元素个数="+a.length);        System.out.println("数组b的元素个数="+b.length);        System.out.println("a[0]="+a[0]+",a[1]="+a[1]+",a[2]="+a[2]);        System.out.print("b[0]="+b[0]+",b[1]="+b[1]+",b[2]="+b[2]);    }}   
# # # (c) Operators and expressions
operator Combination Direction Note
+ - from left to right priority is weaker than multiplication
* / % from left to right priority is stronger than plus and minus
The value of
++x (--x) add 1 to the value of x and then use the value of x x + + (x--)x is used first, and then the value of x is added 1
    • Precision of arithmetic blending operations
      Sort: byte short char int long fioat double

Usage Rules:
1. In the expression, + + has the ++double type data + +, as double calculation
2. Expression + + The highest precision is the float type data + +, according to float type calculation
3. The highest precision in the expression is a long integer + +, which is calculated as long
4. The highest precision of + + in the expression is lower than int + +, which is calculated by int type

易错点:允许把不超过byte、short、char的取值范围的算术表达式的值赋给byte、short、char型变量
-Relational operators
operator Notes
> < >= <= priority is stronger than = = and! =
== != the priority is weaker than the above
-logical operators and bitwise operators
logical Operators Notes
&& | |! When you join an expression, the result of the expression must be true or false
Bitwise Operators Notes
& | ^ Note that inverse is still ^
易错点:注意逻辑运算符的短路性。
-Statement aspect
    • The value of an expression in a Swith statement can be a byte, short, int, char
    • The case constants are also byte, short, int, char, and are different

    • Looping statements: Attention to the combination of break and continue
    • For statements and Arrays:
      Form: for (declaring loop variable: array name) {
      P
      }
      Note: The Declaration environment variable must be a variable declaration and cannot be a variable that has already been declared.

      -About the calling method of the class:

      Because there is no specific contact, talk about some of their own understanding:
      The next class is called to read the value entered by the user.
      The Hasnext class is called to determine if the value is out of range.

Problems in teaching materials learning and the solving process
In the study of application examples, for the comparison of sorting method and binary find the method has forgotten, I looked carefully.
Binary Lookup method
Comparison sorting method
In class, I also want to learn the specific C language in the search method and sorting methods summed up.

Problems in code debugging and the resolution process

Q1: There's a

A: Runtime should be Java < main class name, and the main class name do not add a suffix. And then there's the result.

Q2: There's a

A:import java.util.* in the util wrong spell into the until. and two times there have been such problems, should be brought to the attention of the future. Once resolved, run the correct result:

Code Hosting

Script Run

Other (sentiment, thinking, etc., optional)

This week's study is the Java Grammar study, although has the certain C Language Foundation, but I still did not take lightly, recalls carefully the Java grammar and the C language grammar the same point and the difference, and has found out own C language some loopholes.
Can say this week harvest quite abundant, not only consolidated the C Language Foundation, but also understood the Java grammar, in oneself attempts the programming, the own brain to design the algorithm, sometimes, oneself also will attempt to use the original C language practice in the Java language programming, oneself seems to have found the key which opens another door, I hope I'll keep working on it.

Resources

Binary Lookup method
Comparison sorting method

20165203 Java Programming Second week Java Learning 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.