Java Learning Note-day1-Welcome to correct!

Source: Internet
Author: User

Categories of constants:
1): Literal constants (which are immutable)
2): Custom Constants

Binary conversions:
1): Other binary go to decimal:
The coefficient * cardinality on each one (the cardinality of the x mechanism is x) ^ weighted power (numbering from the right, starting at 0, each of which is the weighted value of that digit)
Binary 1000 binary: 4
100 =1*2^2+0*2^1+0*2^0
=4+0+0
=4

Data type:
1): When defining a long or float type variable, add 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 accept a value of type int.
This is a self-made data monitoring, if not in their range, the error.

Interview questions:
1): Short s = 1;
s = s + 1;

Short S = 1;
S+=1;

There is a problem with both of these codes, if so, why?
Answer: The first problematic, like the +=,-= extension operator, actually hides a coercion type conversion. If S+=1 is not equivalent to: s = s+1, but is equivalent to S = (data type of s) (s+1);


Logical operators:
^: Logical xor: The same is false, and the difference is true;


Bit operations (understanding):
To do bit operations, you first need to convert the data into binary.
Interview questions:
Exchange values for two variables:
int a = 10;
int B = 20;
1): Use third-party variables
2): Use the XOR or realize:
Left: A,b,a
Right: a ^ b
A = a ^ b;
b = a ^ b;
A = a ^ b;
3): How to add Variables:
A = a + B;
b = a A;
A = a-B;
4): One sentence to fix:
B = (A + b)-(a = b);
b = 30-20 = 10,a = 20;

<<: Left highest bit discarded, right 0;
SYSTEM.OUT.PRINTLN (3 << 2);
Move the left data to the power of the second
3*2^2 = 12;
>>: Shift right: The highest bit is 0, the left side is 0, the highest is 1, the left is 1
System.out.println (>> 2);
Move the left data/2 to the power of the second
24/2^2 = 6
>>>: Unsigned Right SHIFT, whether the highest bit is 0 or 1, left 0

Java Learning Note-day1-Welcome to correct!

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.