Java Data types

Source: Internet
Author: User

    • Java data types are divided into two main categories,

Basic data types

|------Numerical Type

|------integer type (byte,int,short,long)

|------Floating-point type (float,double)//floating-point notation for decimals

|------character type (char)

|------Boolean Type (Boolean)

Reference data type

|------Class (CALSS)

|------interface (INTERFACE)

|------Array

The value length of the base data type

Long (length integer)

Value range: Maximum value: 9223372036854775807 ~ Minimum Value: 9223372036854775808

Long Maxlong=long.max_value;long Minlong=long.min_value; System.out.println ("Long type, maximum value:" +maxlong); System.out.println ("Long type, minimum value:" +minlong);

  

Int (integer)

Value range: Maximum value: 2147483647~2147483648

        int intmax=integer.max_value; SYSTEM.OUT.PRINTLN ("int type, maximum value:" +intmax); SYSTEM.OUT.PRINTLN ("int type, Minimum value:" + (intmax+1));

Integer maximum plus 1 will become the minimum value.

Principle:

Short (shorter integer)

Value range: Maximum value: 32767~ Minimum: 32768

BYTE (bit)

Value range: Maximum value: 127 ~ Minimum: 128

char (character)

Value range: Maximum value: 255~ Minimum: 0

Float (single precision)

Value range: Maximum value: 3.4e38~ Minimum: -3.4E38

Double (dual precision)

Value range: Maximum value: 1.7E308 min.: -1.7E308

The problem occurs when the value exceeds its range of values.

For example: int a=9999999999999999; Will compile will not pass. It will tell you that the int type is out of range

  

The conversion of the data type.
Automatic conversion: The data type before conversion is compatible with the converted type, and the transformed data type is larger than the type before the conversion.
Cast: (data type to convert) variable name

int a=10;//defines an integral type a value variable float b=3.0f;//defines a floating-point B-value variable of 3.3fsystem.out.println ("a+b=" + (a+b));//auto-upward to floating-point. System.out.println ("a/b=" + (A/b));//auto-upward to floating-point. int C=8;int d=3; System.out.println ("8/3=" +c/d);//The normal answer is 2.66666666 ... If it is//the banking business needs to involve several decimal places. Here is the System.out.println ("forced transformation-------------under the---------------"); System.out.println ((float) C/D);//Forced transformation.

  

Any of these types will be converted to string.

        

Java Data types

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.