Java Basic data types

Source: Internet
Author: User

http://www.verejava.com/?id=1699255932129

/**java is divided into 4 classes of 8 basic data Types 4 classes: 1. Integral type (Byte,short,int,long) 2. Floating-point type (float,double) 3. Character type (char) 4.         Boolean (Boolean) */public class basedatatype{public static void Main (string[] args) {//integer byte, short, int, long       BYTE A1=1;      Byte occupies 1 bytes = 8 bits -2^7~2^7-1 ( -128~127) short a2=10;     Short accounts for 2 bytes = 16 bits -2^15~2^15-1 int a3=100;    int accounts for 4 bytes = 32 bits -2^31~2^31-1 long a4=1000;        Long takes 8 bytes = 64 bits -2^63~2^63-1 System.out.println (A1);        SYSTEM.OUT.PRINTLN (A2);        SYSTEM.OUT.PRINTLN (A3);        System.out.println (A4);    */* Note: 1. Integer assignment if beyond the storage range compile error loss accuracy *//float float, double double b1=10.1;   Double takes 8 bytes = 64 bit float b2=12.2f;        Float accounts for 4 bytes = 32-bit float b3= (float) 13.3;        System.out.println (B1);        System.out.println (B2);        SYSTEM.OUT.PRINTLN (B3); /* Note: 1. Float data default is double type, if you want to assign to float type must be forced type conversion, for floating-point number of forced type conversion twoOne way is: directly in the back plus F one is: in front plus (float) *//char char is a single character enclosed in single quotation marks char c1= ' a ';        Char takes 2 bytes = 16 bits char c2= ' 1 ';        Char c3= ' good ';        SYSTEM.OUT.PRINTLN (C1);        System.out.println (C2);        System.out.println (C3); /* Note: 1. In the computed storage, the numbers and letters accounted for 1 bytes, while the kanji accounted for 2 bytes, Java in order to solve this problem, so defined char accounted for 2 bytes to uniformly store letters and Kanji 2.    The difference between char and string is that strings are multiple characters enclosed in double quotes *///Boolean Boolean Boolean d1=true;        Boolean 1 bytes = 8-bit Boolean d2=false;        System.out.println (D1);        System.out.println (D2); /* Note: 1. A Boolean type of true cannot be equal to 1, false also not equal to 0, this and C language to distinguish */}}/* Review Summary: 1. Divide the basic data type variable by the data type that belongs to: 8 basic data types (Byte,short,int, Long,float,double,boolean,char) Reference data type variables: variables except for 8 basic data types are reference variable 2. String is not part of the base data type of the reference data type */

http://www.verejava.com/?id=1699255932129

Java Basic 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.