Java basic data type space-consuming view __java

Source: Internet
Author: User
Java has a total of 8 basic data types, respectivelyInteger: Byte (Byte), short (shorter), long (Long Integer), int (integer) decimal type: Float (single-precision floating-point type), double (double-precision floating-point type) Character: Char Boolean: Boolean Eight basic data type parameter tables
Note: (1) If you write a long type value, you need to add the letter L after the value, both uppercase and lowercase (2) The value range of the decimal type is described in scientific notation (3) Float type decimal, need to add letter F after decimal, case-insensitive, such as 4.09f or 4.09F (4) The amount of space that a Boolean takes up depends on the implementation of the Java Virtual Machine (JVM), possibly 1bit, or 8bit.
Use statements to view the space code used by a data type is as follows: You need to find an encapsulation type of each data type to get their footprint.
public class Yufa {

	/**
	 * @param args */public
	static void Main (string[] args) {
		//TODO Auto-generat Ed method stub
		//need to find each type of encapsulation type
		int a=byte.size;
		int b=short.size;
		int c=integer.size;
		int d=long.size;
		int e=float.size;
		int f=double.size;
		int g=character.size;
		
		System.out.println ("Occupied space of byte type--" +a/8+ "byte--");
		System.out.println ("The short type occupies the space-" +b/8+ "bytes--");
		System.out.println ("Occupied space of int type-" +c/8+ "bytes--");
		System.out.println ("Occupied space of long type--" +d/8+ "bytes--");
		System.out.println ("float-type occupancy space-" +e/8+ "bytes--");
		System.out.println ("Occupy space of double type--" +f/8+ "bytes--");
		System.out.println ("Char-occupied space-" +g/8+ "bytes--");		
	}




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.