How bad is our Java base? A video-induced impression

Source: Internet
Author: User
Tags bitwise float double

Use this article to warn yourself.

The junior is coming to an end.

I began to contact Java from the beginning of the semester, 2.5, during a very hard self-study, also participated in the project, full of their Java Foundation should be good, but today on the internet to see a video to find out how "shallow", I know their Java foundation is still poor. Writing a program is not a function can be implemented, but also to consider the efficiency. Perhaps the definition of a variable will only occupy a few bits, a for loop will only consume a few milliseconds, but when a piece of code to form a large system, the drawbacks are revealed, as the video says, we write a project will only be 12306.

Perhaps it is trained we are taught not enough, some things still have to work hard to explore, even the basic knowledge, it is not to be underestimated, because the foundation is not as you think of your simple.

Below is a look at the video to make notes, experienced experts are sure to know, hope not to spray.

Package Test;import Java.math.bigdecimal;public class TestData {/** * data type: base data type reference data type (custom) * Basic data type: byte short in T long float double Char Boolean * byte 1 2 4 8 4 8 2 * * float:32 bit (1+8+23) sign bit + power finger          bit + value bit * double:64 bit (1+11+52) */public static void Main (string[] args) {//Assign a value to char type four methods char c1 = ' a ';           Direct Assignment Char C2 = 97;     ASCII code Assignment char c3 = ' \u4e2d ';         The Unicode encoding assignment is followed by a 16 binary char c4 = ' \ t ';   Escape character System.out.println (c1+ "&" +c2+ "&" +c3+ "&" +c4+ "&");                a&a& in &&//int type assignment int n1 = 30;           Direct Assignment int n2 = 0b11110; Binary Assignment 0b+ | | 30=16+8+4+2 | |              Except 2 15_0 7_1 3_1 1_1 0_1, 11110int n3 = 0x1e; 16 binary Assignment 0x+ | |               Turn binary 00011110 to 16 binary 1E int n4 = 036; 8 binary Assignment 0+ | | Except 8 3_6 0_3 36system.out.println (n1+ "|" +n2+ "|" +n3+ "|"   +n4+ "|");   30|30|30|30|//char+int+string first do the addition and then splicing System.out.println (' 1 ' +1+ "1"); 501 Char 1 means that the ASCII code is 49+1+ "1" = 501//string+Int+char splicing and splicing System.out.println ("1" +1+ ' 1 ');     111//char+char do addition System.out.println (' 1 ' + ' 1 ');        98 49+49=98//2.0-1.1system.out.println (2.0-1.1);      0.8999999999999999system.out.println (2.0f-1.1f);  0.1/** * double:2.0 to 2 binary 10.0000000000000000 (16 bits truncated) * 1.1 to 2 binary 01.0001100110011001 (12 in 1, fractional: 0.1*2=0.2_0 0.2*2=0.4_0 0.4*2=0.8_0 0.8*2=1.6_1 0.6*2=1.2_1 0.2*2=0.4_0) * Subtract 0.1110011001100111 to 10 binary-0.8999999999999999 * Float is calculated by double and then rounded to 0.9f * Workaround: Use BigDecimal */bigdecimal b1=new BigDecimal ("2.0"); BigDecimal b2 = b1.subtract (New BigDecimal ("1.1"));            System.out.println (B2); 0.9}}

Package test;//operator public class Testoperator {public static void main (string[] args) {//modulo operator symbol bit depends on the first number System.out.pri       Ntln (5%3);      2system.out.println ( -5%3);      -2system.out.println (5%-3);     2system.out.println ( -5%-3);       -2system.out.println (2%2);      0system.out.println ( -2%2); 0//non-short-circuit operator [& |]        and short-circuit operator [&& | |] int num = 5;if (++num < 4 && num++ > 1) System.out.println ("Qwer");    SYSTEM.OUT.PRINTLN (num);//The result is: 6//The short-circuit operator before it is judged to be false is no longer executed (opposite to operation, pair or operation) num = 5; if (++num < 4 & num++ > 1) System.out.println ("Qwer"); SYSTEM.OUT.PRINTLN (num);//The result is that the 7//non-short-circuit operator is fully executed//bitwise operator//When a positive number%2 n-times, is equivalent to & (2 of the N-1) System.out.println ((100&1        ) ==100%2);        TrueSystem.out.println ((100&3) ==100%4);        TrueSystem.out.println ((100&7) ==100%8);      TrueSystem.out.println ((100&15) ==100%16);      TrueSystem.out.println ((100&31) ==100%32);  Implementation of true//Permissions 1: Permissions 1 2: Permissions 2 4: Permissions 3 8: Permissions 4//with their and express permissionssuch as 3=1+2 7=1+2+4 9=1+8//with their own rights & a permission of the representative number can be informed that they have the right to System.out.println ((9&1) ==1);       True indicates permission 1system.out.println ((9&2) ==2);       FalseSystem.out.println ((9&4) ==4);       FalseSystem.out.println ((9&8) ==8); true//Exchange two numbers without the aid of a third space//using bitwise XOR operator int a = 1;int b = 2;a = a ^ b;b = a ^ B;a = a ^ b;          System.out.println (A + "" +b); 2 1//plus subtraction a = 1; b = 2; A = a + B; b = a A; A = a-B;        System.out.println (A + "" +b); 2 1//non-limited use for loop//print A-Z for (int i = 97;i<123;i++) {System.out.print (char) i);}//Is this really good? Look at the following: System.out.println (); for (Char c= ' a '; c<= ' z '; C + +) {System.out.print (c);}//The second only 16 bits that take advantage of char the first one also needs to take advantage of the 32 bits of int}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

How bad is our Java base? A video-induced impression

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.