A little bit of knowledge about Java

Source: Internet
Author: User

Tag: SYS has a 16px post output out about the blog type conversion

One, for the storage of Java variables

The general variables are stored in stacks, heaps, and memory pools. Declared with new, it is generally placed in heap memory. Some basic types of variables and object reference variables are allocated in the function's stack memory. For a constant pool, like our usual string s1= "abc", the declared string object is stored in a constant pool.

String s1= "abc"; String s2= "abc"; string S3=new string ("abc"); System.out.println (S1= =s2); System.out.println (S1==s3);

The result of this output is true and false.

Ii. comparison of integers and int

1 integer a=new integer (+); 2 int b=128; 3 integer c=new integer (6); 4 integer d=new integer (6); 5 System.out.println (a==b); 6 System.out.println (C==d);

The result of the output is true and false

An int is a basic data type, and an integer is an object that points to an object with a reference.

There is a boxing and unpacking method between int and integer:

Packing:

// Packing // converting a base data type to an object

Unpacking:

// Packing Integer num=1; // Unpacking int // To convert an object to a base data type

Another point:

For the value of integer boxing, when Java defines a number from 128 to 127, it is boxed into an integer object, which is reused in memory and always has only one object of that value.

If the value is more than 128 or less than-127, a new integer object is newly.

Integer a=128; integer b=128; integer c=127; integer d=127;  System.out.println (a= =b);  Results falseSystem.out.println (c==d); Result Ture

A little bit of knowledge about Java

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.