Java Foundation II

Source: Internet
Author: User
Tags arithmetic operators binary to decimal decimal to binary logical operators

1. What is an identifier

2. Naming specification for identifiers

3. Mastering keywords and reserved words

4. Mastering variables

5, master Eight kinds of basic data types

6. Mastering Operators

First, identifiers

Identifiers are sequences of characters that Java uses when naming features such as packages, classes, methods, parameters, variables, and so on

Rules:

1, consisting of letters (including Chinese, English, Japanese, Russian, etc.), numbers, underscore ' _ ' and dollar sign ' $ '.

2, can not start with a number eg:int 123a = 1;

3. Case-sensitive: int a = 1 and int a=1 are not the same.

4, the length is unlimited. (General programming length of not more than 15 characters)

5. Cannot be reserved words and keywords in java: int class = 1 can contain reserved words and keywords: int aint=1.

Identifier naming habits:

1. See the name of the known meaning.

2, Hump-type naming:

Class Name: The first letter of the word, the identifier of multiple words, the first letter of each word is bigger

Eg:studentscore do not use pinyin in English

Variable name, method name, parameter name: first letter lowercase, the first letter of each remaining word capitalized.

Eg:studentscore

Ii. Types of data

Binary: 0-1,512 256 128 64 32 16 8 4 2 1

Octal: 0-7, 49 7 1

Decimal: 0-9,

Hex: 0-9abcdef.

Binary to octal: 1010 1010, take the Triad 212

Https://jingyan.baidu.com/article/39810a23e3779db636fda6c5.html

Binary to decimal: 1010 1010, starting from right to left 0, Radix * Cardinality of the power, add can be.

Https://jingyan.baidu.com/article/597a0643614568312b5243c0.html

Binary ext. 16:1010 1010, four-in-a AA

Https://jingyan.baidu.com/article/47a29f24292608c0142399cb.html

Octal binary to binary: 123, 31 octal numbers are divided into three binary numbers, with three-bit binary weighted add-on

octal to decimal, octal to 16, decimal to binary, etc. Baidu can:

Https://jingyan.baidu.com/article/495ba84109665338b30ede98.html

Third, the source code, anti-code, complement

  The original code: is the binary representation of the number of the way, the highest bit is the sign bit, the rest of you represent the value size

first place is " 0 "represents a positive number

first place is " 1 "represents a negative number

  Anti-code:

The inverse code of the positive number is the same as the original code; the inverse of the negative number is the sign bit and the remaining bits are reversed.

Complement:

the complement of positive numbers is the same as the original code; +1

  Why? Is this the design of the complement?

    in order for the negative number of the expression to be added to its inverse, it overflows exactly 0 , so the design of the complement.

complement - Original Code ( -1 Reverse ) (Reverse +1 ? )

Four or eight types of data

1. Basic Data type

Boolean type--boolean

Character Type--char

Integer type--byte,short,int,long

Floating-point--float,double

2. Java want programmers to use the memory reasonably, so design different data types, when you just want to express a relatively small number, then you apply a small space-occupying type, conversely, large type.

3. integer Type

Int as int a=3;

Long as long a=3l;

  Int the maximum value that a type can express is + billion more

Range of basic data types:

1 , Long bit Range, very large

2 , int bit range billion,-21 billion

01111111 11111111 11111111 11111111

3 , Short bit -32768 , 32767

4 , Byte 8 bit -128,127

5 , Char bit \uffff 0-65535

6 , float (single-precision floating-point type) 32-3.4e38,3.4e38

7 , Double (double-precision floating-point type) 64-1.7e308,1.7e308

8 , Boolean using reference constants, True/false

V. Conversion of data types

1 , Boolean A type cannot be converted to any other base data type.

2 , automatic type conversion: The data Type value range is small to large.

3 , coercion type conversion: The value range of the data type is large to a small range of values. A cast character is required. (xxxx to convert the data type)

Vi. Constants and variables

Constant: ' Non-changing amount '

123 numbers

Int a=123;

a=124;

True False Boolean value

"Hello World" This is a string constant, in the constant pool, 1.7, and previously in the method area, after 1.7 it is in heap memory.

3.14

3.14f

' A ' string

Char type

Variables: Save data in program execution, such as int a=1;a is a variable.

Java constants, there are 2 kinds of meaning, I explained separately:
The 1th meaning, is a value, the value itself, we can call it constant, give a few examples:
Integral type constant: 123
Real constant: 3.14
Character constant: ' A '
Logical constants: TRUE, False
String constants: "HelloWorld"
It's just a matter of saying, like 7, we can say "a constant of type int 7"
-------
There is another, is the landlord asked this:
The 2nd meaning, the immutable variable, is also called a constant, syntactically speaking, plus final, using the final keyword to decorate a variable, and then as long as the assignment is not changed, it can not be assigned again, according to an example:
final int i = 0;
Then the value of this I is absolutely can not be changed, can only be 0, so that is immutable variable, this sentence seems contradictory, in fact, not contradictory, this sentence so understand:
I is a variable of type int, the variable itself is variable (can be changed), but now it is final, so immutable, so it is immutable variable.
Java constants, there are 2 kinds of meaning, I explained separately:
The 1th meaning, is a value, the value itself, we can call it constant, give a few examples:
Integral type constant: 123
Real constant: 3.14
Character constant: ' A '
Logical constants: TRUE, False
String constants: "HelloWorld"
It's just a matter of saying, like 7, we can say "a constant of type int 7"
-------
There is another, is the landlord asked this:
The 2nd meaning, the immutable variable, is also called a constant, syntactically speaking, plus final, using the final keyword to decorate a variable, and then as long as the assignment is not changed, it can not be assigned again, according to an example:
final int i = 0;
Then the value of this I is absolutely can not be changed, can only be 0, so that is immutable variable, this sentence seems contradictory, in fact, not contradictory, this sentence so understand:
I is a variable of type int, the variable itself is variable (can be changed), but now it is final, so immutable, so it is immutable variable.

Seven, operator

1. Arithmetic operators: + 、-、 *,/,%, + + 、--

Int a=1;

Int b=2;

Int c=a+b;

When using/or%, the second number cannot be 0.

When the number is all integral type, there will be an endless situation, superfluous directly discarded.

1.0*3/2=1

2. Assignment operators

=

int i;

I=1;

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

I+=1; i=i+1;

3. Relational operators

< > <= >= = = =!

4 , logical operators

Boolean b1=true;

Boolean b2=true;

Boolean b3=true;

sum up B1 is true and B2 thought it was true and B3 Is also true.

&& It's all true, it's fake.

| | all false for false results, true

5 , String connector

+

when + When the left and right connection strings are used, we use the + , is the meaning of the connection.

" 123 " + " 456 "

6, trinocular operator

X? Y:z

7 , using () parentheses prioritize local processing.

1+2*3+4

Java Foundation II

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.