"Big Data-Phase II" Java Foundation fourth day job

Source: Internet
Author: User
Tags bitwise bitwise operators

1. Sort the bitwise operations, especially the left and right shifts (with or without symbols) to your blog.

The emphasis is on the operation process of clear negative numbers.

Public static void main (String[] args)  {    //operator Demo          int a = 3;    int b = 6;         //+ -  symbol &NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN (" +a =  " +  (+a));                 //3    system.out.println ("-b =  "  +  (-B) );                //-6  The    //+ - * / %  arithmetic operator     system.out.println ("Arithmetic operator: ");     system.out.println (" a + b = " +  (a + b));         //9    system.out.println ("a - b  =  " +  (a - b));        //-3      System.out.println ("a * b = "  +  (a * b)); &NBSP;&NBSP;&NBSP;&NBSP;//18     system.out.println ("a / b = "  +  (a / b));         //0    system.out.println ("A % b  =  " +  (a % b));    //3         system.out.println ("--------------------I am a split Line-------------------");             //+= -= *= /= %= Assignment Operators      SYSTEM.OUT.PRINTLN ("assignment operator:");     system.out.println ("a += b = "  +   (a += b));        //9     System.out.println ("a -= b =  " +  (a -=b));             //3    system.out.println ("a *= b = "  +  (a *= &NBSP;B));         //18    system.out.println ("A  /= b =  " +  (a /= b));             //3    system.out.println ("a %= b = "  +   (a %= b));        //3         system.out.println ("--------------------I am the dividing Line-------------------");     / /== != > < >= <=  comparison operator     system.out.println (" Comparison operator: ");     system.out.println (" a == b =  " +  (a == &NBSP;B));    &nbsP;    //false    system.out.println ("a != b = "  +  (a != b));             // True    system.out.println ("a > b = "  +  (a > &NBSP;B));            //false     system.out.println ("a < b = "  +  (a < b));             //true    system.out.println (" a >= b =  " +  (a >= b));         //false    system.out.println ("a <= b = "  +  ( A&NBSP;&LT;=&NBSP;B));        //true         system.out.println ("--------------------I am the split Line-------------------");             // | & ^ ! | |  && logical operator     boolean b1 = false;    boolean  b2 = true;    system.out.println ("b1 | b2 = "  +   (B1&NBSP;|&NBSP;B2));        //true     System.out.println ("b1 & b2 = "  +  (B1&NBSP;&AMP;&NBSP;B2));         //false    system.out.println ("b1 ^ b2  = " +  (B1&NBSP;^&NBSP;B2));             // True    system.out.println ("!b1 ="  +  (!B1));                   &nbsP;     //true    system.out.println ("b1 | |  b2 =   +  (b1 | | &NBSP;B2));     //ture     system.out.println ("b1 &&  b2 =  " +  (B1&NBSP;&AMP;&AMP;&NBSP;B2)); //false           system.out.println ("--------------------I am a split Line-------------------");           //<< >> >>> | &     ^    ~ Bitwise Operators     int x = -9;         //1111 0111    int y = 5;             //0000 0101     system.out.println ("x << 2 = "  +  (x << 2));         //-36    /*     signed left shift process           1111 0111    11|11  011100    */    system.out.println ("x >> 2 =   " +  (x >> 2));        //-3     /*     signed right Shift process         1111 0111         111111 01|11    */     system.out.println ("x >>> 2 = "  +  (x >>> 2));     //... ... ...    /*     unsigned Right shift process          1111 1111    1111 1111     1111 1111    1111 0111        0001111 1111     1111 1111    1111 1111    1111 0  | 111    */    system.out.println ("x | y =   " +  (x | y));            &NBSP;//-9&NBSP;&NBSP;&NBSP;&NBSP;/*&NBSP;&NBSP;&NBSP;&NBSP;...&NBSP;1111&NBSP;0111&NBSP;&NBSP;&NBSP;&NBSP, .....  0000 0101        --------------         1111 0111         and Operations       Full 0 for 0     the remainder is 1.     */    system.out.println ("x & y = "  +   (x & y)); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//5    /*    ... 1111 0111    ... 0000  0101        --------------         0000 0101         or operations      full 1 is 1 The rest of the      is 0.     */    system.out.println ("x ^ y = "  +   (x ^ y));            //-14     /*    ... 1111 0111    ... 0000  0101        --------------         1111 0010          XOR Operation     0, 1 is 1 The rest of the      is 0.     */        system. OUT.PRINTLN ("~x = "  +  (~x));                 //8    /*    ... 1111  0111        --------------         0000 1000         inverse operation     0 variable 0.     */    }

2.byte to hexadecimal string representation programming principles and implementation methods are organized into blogs.

{    public static void main (String[] args)  {         byte b = 5;         SYSTEM.OUT.PRINTLN (CONVERT (b));     }        public  static string convert (byte b)      {         int low = b & 0x0F;         int high =  (b >> 4)  & 0x0F;                 char[] arr = {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' D ', ' E ', ' F ',};                 return   "0x"  + arr[high] + arr[ Low] ;            } 

3. Define a function to calculate the and of all elements of an integer array.

public static void Main (string[] args) {int X = Sum (New int[]{100,100,100,105});        System.out.println (X);        } public static int sum (int[] arr) {int sum = 0;        for (int i = 0;i < Arr.length; i++) {sum + = Arr[i];    } return sum; }

4. Copy of the array.

        public static void main (String[] args) {             int[] arr1 = {1,2,3,4,5 };            int[] arr2 = new  int [arr1.length];            arrcopy ( ARR1,ARR2);            for  (int i =  0;i < arr2.length ;i++ )              {                 system.out.println (Arr2[i]);             }         }               &nbSp;     private static void arrcopy (INT[]&NBSP;ARR1,INT[]&NBSP;ARR2) {                 for  (int  i = 0;i < arr1.length ;i++ )                  {                     arr2[i] = arr1[i];                 }         }

5. Heap memory By default is

----------------------------------------


The default size of heap memory is 1/4 of native memory.



This article is from the "Fan Penguin" blog, please be sure to keep this source http://xpenguin.blog.51cto.com/4912157/1771068

"Big Data-Phase II" Java Foundation fourth day job

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.