Java Basic data type correlation

Source: Internet
Author: User

Previous data types are not clear, later work needs, the TCP protocol to send data, to account for a few bytes of several bytes, the circle, thoroughly to tidy up.
Java explicitly defines the specific data type for each data type, and different data types occupy different memory spaces.

Data type: base data type, reference data type

Basic data types: numeric, character (char), BOOL (Boolean)
Numeric type: integer type (byte, short, int, long), floating-point type (float, double)

Reference data types: Classes (Class), interfaces (interface), arrays ([])

This is the classification of some data types, basically no use, summed up a commonly used simple data except that the array is the basic data type, the others are referenced.
The integer default is int, and the decimal number defaults to double.

The most commonly used is the following occupied memory space:
Byte 1 bytes
Short 2 bytes
Char 2 bytes
int 4 bytes
Float 4 bytes
A long 8 bytes
Double 8 bytes
Kanji 2 bytes

Apart from this, there is a mutual conversion.
Byte--short--int--long--float--double

Char--int--long--float--double
From left to right is from low type to high type, conversion is auto-conversion, reverse requires casting
For example: short a = 1;
int b = A;

int c = 1;
Short d = (short) C;

Java underlying data type related

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.