Java Foundation Fourth day

Source: Internet
Author: User


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.

/*

Class Demo {


public static void Main (string[] arge) {

int a =-4; 1111 1100

int B = a >> 2;//1111 1111

int B = A >>> 2 0011 1111

System.out.println (b);

}

}

*/

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

public static void Main (string[] arge) {
byte A = 28;
byte low = (Byte) (A & 0x0f);
byte hight = (byte) ((A & 0xf0) >>4);

Char[] Array = {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' D ', ' E ', ' F '};


System.out.println ("0x" + array[hight] + array[low]);
}
}

*/

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

Package forth_day;


/**

* Define functions to calculate the and of all elements of an integer array

*

* @author Admin

*

*/

public class Sum {

public int sumdata (int[] arr) {

int temp = 0;

for (int i = 0; i < arr.length; i++) {

Temp = temp + arr[i];

}

return temp;

}


public static void Main (string[] args) {

Sum sum = new sum ();

Int[] arr = {5, 1, 4, 5, 2, 4, 77, 54, 12, 52, 55};

int result = Sum.sumdata (arr);

SYSTEM.OUT.PRINTLN (result);

}

}

4. Copying of arrays

Package forth_day;/**4. Copy of the array * @author Admin * */public class CopyData {public int[] Copy_data (int[] arr) {int[] Copyrst = New Int[arr.length];for (int i = 0; i < arr.length; i++) {copyrst[i] = arr[i];} return Copyrst;} public static void Main (string[] args) {int[] arr = {4, 8, 5, 9999};int[] result=new copydata (). Copy_data (arr); for (int i = 0; i < result.length; i++) {System.out.print (result[i]+ "");}}}

5. Heap memory default is 1/4,

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

JAVA-XMX//Set heap memory max

-XMS//Set heap memory initial value

ClassName//class name

A: The default maximum heap memory is 1/4 of physical memory, when running a Java program, you can-xms the initial heap memory size,-XMX set the maximum heap memory size;


Java Foundation Fourth day

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.