Java Basic Course Learning Notes (2)

Source: Internet
Author: User
Tags binary to decimal bitwise modifiers

Key points of knowledge:

Keyword Identifiers Comment constants, binary and binary conversion variable data types and type conversion operator statements 1: Keywords (master)(1) the words (2) that are given a specific meaning by the Java language feature: all lowercase.        (3) Precautions: A:goto and const exist as reserved words. B: High-level notebooks like notepad++ have special color tags on keywords

Keywords used to define access rights modifiers

Private

Protected

Public

Keywords for defining classes, functions, variable modifiers

Abstract

Final

Static

Synchronized

Keywords used to define the relationship between classes and classes

Extends

Implements

Used to define instance and reference instances, and to determine the keywords

New

This

Super

instanceof

Keywords for exception handling

Try

Catch

Finally

Throw

Throws

Keywords for the package

Package

Import

Other modifier keywords

Native

Strictfp

Transient

Volatile

Assert

2: identifier (master)(1) is to give classes, interfaces, methods, variables, such as the name of the sequence of characters (2) composition of the Rules: A: English uppercase and lowercase letter B: Digital c:$ and _ (3) Note: A: Cannot start with a number B: cannot be a keyword in Java C: Case-sensitive (4) common naming rules Then (see name) A: Package All lowercase single-level package: lowercase Example: liuyi,com multi-level package: lowercase, and use. Separate Example: Cn.itcast,com.baidub: Class or interface one word: First capitalization example: Student,d Emo multiple words: Each word capitalized for example: Helloworld,studentnamec: Method or variable one word: First Letter Lowercase Example: name,main multiple words: Starting with the second word, each word capitalized for example: St Udentage,showallnames () D: constant all uppercase one word: uppercase example: PI multiple words: Uppercase and separated by _ Example: Student_max_age 3: note (master)(1) The text that explains the program (2) Category: A: Single-line comment//B: Multiline comment/**/C: Documentation Comment (later)/** */(3) wrote a annotated version of the HelloWorld case.  We're going to write a procedure in the back.  Requirements: Analysis: Implementation: Code embodiment: (4) The role of annotations A: Explain the program, improve the reading of the code.    B: Can help us debug the program. Later, we will explain a more advanced debugging tool 4: Constant (Master)(1) In the course of program execution, the amount of the value does not change (2) Classification: A: Literal value of the constant B: custom constant (after) (3) Literal constant A: string constant "Hello" B: integer constant 12,23 C: decimal constant 12.345 D: character constant ' a ', ' a ' , ' 0 ' E: Boolean constant true,false F: null constant Null (later) (4) provides four representations of integer constants in Java A: binary consists of 0, 1. To 0bBeginning. B: Octal system by 0, 1, ... 7 composition. To 0Beginning. C: Decimal by 0, 1, ... 9 composition.  Integers are decimal by default. D: Hex by 0, 1, ... 9,a,b,c,d,e,f (both uppercase and lowercase) are composed. To 0xBeginning. binary Overview and binary, octal, hex plots 5: Binary conversion (Learn)(1) Other decimal coefficients: is the numeric cardinality of each bit: X-Cardinality is the X-right: the data on each digit, from the right, and starting from 0, the corresponding number is the right of the data. Results: The sum of the coefficients * cardinality ^ power power. (2) Decimal to other binary in addition to the base, until the quotient is 0, the remainder reversal.  (3) The fast conversion method of the binary conversion A: the conversion between decimal and binary 8421 yards. B: Binary-to-octal, hexadecimal conversion binary to octal 3-bit combination 1,001,102 hexadecimal 4-bit combination 100110 conversion of any binary to decimal decimal to any binary conversion Fast Conversion method of the input system . Original code Inverse CodeWithin the computer, there are 3 notation numbers: The original code, the inverse code, and the complement. All data is performed in the complement. The original code: is the binary fixed-point notation, that is, the highest bit is the sign bit, "0" is positive, "1" is negative, the remaining bits represent the size of the value. Anti-code: The inverse code of positive number is the same as its original code, and the inverse code of negative number is the inverse of its original code, except the sign bit. Complement: The complement of a positive number is the same as its original code, and the complement of a negative number is the lowest of its inverse code the explanation of the inverse code complement of the original code 6: Variable (master)(1) In the execution of the program, its value in a range can change the amount of (2) Variable definition format: A: Data type variable name = initialization value;    B: Data type variable name; Variable name = initialization value; 7: Data type (master)(1) Java is a strongly typed language that provides the corresponding data types for each type of data. (2) Category: A: Basic Data Type: 4 Class 8 kinds B: Reference data type: Class, interface, array.   (3) Basic data type A: Integer occupies bytes byte 1 short 2 int 4 long 8 B: Floating-point number float 4 Double 8 C: Character Char 2 D: Boolean Boolean 1 Note:integers are type int by default, and floating-point numbers are double by default.   Long integers to be added L or L. Single-precision floating-point numbers are added F or f. 8: Data type conversion (mastering)(1) Boolean type does not participate in conversion (2) The default conversion A: From small to large b:byte,short,char--int--long--float--double c:byte,short,char between non-conversion, directly to int type Participate in the operation.  (3) Cast A: from large to small B: there may be a loss of precision, generally not recommended for such use. C: Format: Target data type variable name = (target data type) (converted data); (4) Study Questions and interview questions: #面试 # A: Are there any differences in the following two ways?float f1 = 12.345f; float F2 = (float) 12.345; B: Is there a problem with the program below, and if so, where ?BYTE B1 = 3;   byte b2 = 4; BYTE B3 = b1 + b2;//Yes, because the addition of variables will look at the type problem first, this is type promotion, so there is a problem (byte additionwill classtype lifting--int,int Assign ValueTo byte without a strong turn, so compile will error) byte b4 = 3 + 4;//No, constants, calculated first, see if the result is more than the byte range, if not more than the error                                            when defining a long or float type variable, add either L or F. integers are type int by default, and floating-point numbers are double by default. Byte,short at the time of definition, they are actually receiving a value of type int. This is self-made a data detection, if they are no longer within the scope of the error. C: What is the result of the following operation?byte B = (byte) 130; -126 (see below) D: Character participation Operationis to find the ASCII inside value ' a ', ' a ' of ' 0 ' System.out.println (' a ');//Result: aSystem.out.println (' a ' + 1);//Result: 98 E: String participation OperationHere is actually the connection of the string System.out.println ("Hello" + ' a ' + 1);    Helloa1 System.out.println (' A ' +1+ "Hello");    98hello System.out.println ("5+5=" +5+5);    5+5=55 System.out.println (5+5+ "=5+5"); 10=5+5
study questions: Why the  int range in Java is -2^31 to 2^31-1 Figure out why the range of byte types in Java is -128~127? Also understand the above problem:      byte occupies a byte 8 bits, the first is the sign bit, the maximum value is 0111 1111 that is 127, the key is this-128, some people say the first is the sign bit , that is, the remaining 7 bits represents the true value, the maximum is 111 1111, the minimum is 000 0000, the smallest is 1000 0000, that is-128, (the key is that the first is the sign bit?) Why is the negative number really worth the time and the first 1 to be counted in? )   (negative) maximum 1111 1111 for the 1 min 1000 0000 for IS-128 is this hard to understand?     1111 1111, 1000 0000 Represents the -1,-128 of the complement, in memory, is stored in the complement, not related to negative numbers, the so-called complement is their absolute value of the original code of the reverse plus +1      such as- The absolute value of 1 is 1 1 of the original code is 0000 0001 Anti-code is 1111 1110 anti-code +1 that is, the complement is 1111 1111   -128 is the absolute value of   The original code is 1000 0000 Anti-code is 0111 1111 anti-code + 1 that is 1000 0000 (supplement:) ① in memory, is stored in the complement, not related to negative numbers, are used in complement, positive numbers, negative numbers in memory are complementary forms of expression, but a positive complement and its original code is the same, The complement of negative numbers is the inverse code of the original code of its absolute value +1
128:10000000-128:10000000  (here 1 is the sign bit, also the value bit)
/* byte B = 130; Is there a problem? What can I do if I want to get the assignment right ? Exercise: Byte B = (byte) 300;*/class DataTypeDemo7 {public STA  tic void Main (string[] args) {//Because the range of byte is:-128 to 127.  And 130 is not within this range, so error.   byte B = 130;   We can use the coercion type to convert byte B = (byte) 130;  How much is the result? System.out.println (b);  }}/* Analysis Process: If we want to know what the result is, we should know how to calculate it.  And we know that the computation of the data in the computer is in the complement.   To get the complement, the first thing to do is to calculate the binary of the data.   A: Get 130 binary for this data.  00000000 00000000 00000000 10000010 This is the original code of 130, is also anti-code, or complement.   B: Intercept operation, cut into byte type.  10000010 The result is a complement.     C: Known complement to seek the original code. Sign bit number complement: 1 0000010 Anti-code: 1 0000001 Original code: 1 1111110 = -126*/
Appendix:

Precedence of operators (high-to-low)

Priority level

Describe

Operator

1

Brackets

(),[]

2

PLUS sign

+,-

3

Self-increment, non-

+ +,--,!

4

multiplication, taking surplus

*,/,%

5

Add and Subtract

+,-

6

Shift Operations

<<,>>,>>>

7

Size relationship

>,>=,<,<=

8

Equality relationship

= =,!=

9

Bitwise-AND

&

10

Bitwise XOR OR

^

11

Bitwise OR

|

12

Logic and

&&

13

Logical OR

||

14

Conditional operations

?:

Assignment operation

=, -= , *= , /= %=

16

Bit assignment operations

&=,|=,<<=,>>=,>>>=

Java Basic Course Learning Notes (2)

Related Article

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.