Java basic types and reference types

Source: Internet
Author: User
Tags float double

The basic types of Java are Byte, short (not used), int, long, float (to be used sparingly), Double,char, Boolean (either false, or True)

For the Boolean example, the following:

The value of int a=3;if (A>2)//a>2 is true and cannot be written like this if (1) System.out.println ("Awesome"); ElseSystem.out.println ("dumb"); The following if most direct if ( true) System.out.println ("Awesome"); ElseSystem.out.println ("dumb");

An interesting computational question:

int A=5;int b=a++ + ++a + ++a + a++; System.out.println (b);//28 (5+7+8+8)


The minimum and maximum values for Java primitive types (raw data types) are calculated as follows:

System.out.println ("Byte Minimum:" +byte.min_value); System.out.println ("Byte max:" +byte.max_value); SYSTEM.OUT.PRINTLN ("Short Minimum Value:" +short.min_value); SYSTEM.OUT.PRINTLN ("Short Maximum Value:" +short.max_value); SYSTEM.OUT.PRINTLN ("int min value:" +integer.min_value); SYSTEM.OUT.PRINTLN ("int max:" +integer.max_value); System.out.println ("Long min Value:" +long.min_value); System.out.println ("Long max:" +long.max_value);


The values for the corresponding base types are as follows:


The reference data type of Java has a class, an array, an interface. For example, a string is a class

A brief excerpt from Baidu knows one answer:


Java Data type graph:                                             ┏ numeric ━┳━ integer type: byte short int long              ┏ basic data type ━━┫              ┗━ float: float double              ┃                            ┣ character type: Char                                          data type ╋                            ┗ Boolean: boolean                            ┃                            ┏ Classes (Class)              ┗ reference data Type ━━╋ Interface (interface)                                             ┗ Array (array) Java data types are divided into basic data types (raw data types) and reference data types; 1. The basic eight categories can be clearly seen in the figure; This type of data variable is immediately allocated to his memory space after the declaration. such as: short A;  Java will look for a two-byte block to the A variable in the available memory space, 2. The reference data type is a pointer to the three, C + + +, which points to the object entity (the specific value) in a special way, which does not allocate memory when declared, but only stores a memory address. It would be nice to know what the data structure is. Popular speaking, one, remember very enough; second, say the memory, talk about the address is basically referring to rather than basic; Thirdly, you can understand the memory address is your study number, and the object entity is you, every time you find through the study number, this is the reference; the application of this knowledge point: 1. " = = "function in the reference data type, to determine whether the memory address is equal, want to judge the content entity with EQUALS;2, the basic value of the transfer of the copy is copied, modified the original value is unchanged; the value of the reference pass through the address, modified the original value changes.


Java basic types and reference 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.