The SE base basic data type for the Java interview summary

Source: Internet
Author: User

1, the size of the nine basic data types, and their encapsulation class

What are the eight basic data types that are often tested to eight basic data types and their encapsulation classes during our interviews or exams? What are their encapsulation classes?

First, the eight basic data types are: int, short, float, double, long, Boolean, Byte, Char, and their encapsulation classes are: Integer, short, float, double, long, Boolean , Byte, Character.

Because encapsulation classes have methods and properties after encapsulation of the basic data types, they can then be used to manipulate the data, such as parseint (string s) in the Ingeter object, which converts the string to the int type, and so on. We all know that some types of data will have a default value, the base data type is not the same as the default value of the package type, such as int i, if the value I is not assigned to the default is 0, but the integer j, if not assigned, then J is null, because the wrapper class produces an object, and the object default value is null.

Common methods are int intvalue (), static integer valueOf (int i), string toString (), Static integer parseint (string s).

The tip:string type is not a basic data type, it is actually a final decoration, so it cannot be inherited.

A variable of type string usually has two methods of assignment: a direct assignment, such as String a = "Hello World", or a constructor, such as String b = new string ("Hello World"), so is a and b here equal? What difference do they have?

If you use = For comparison, they are not equal, because "=" compares the values of the base data type for equality or if the object is the same object, and the variable A and variable B point to two different objects, why do you say so? First, to understand the assignment of the 2 variables, for the expression string a = "Hello World", a String object "Hello World" is first created, and the string is actually placed in a string buffer, and then point A to the object, and for string B = New string ("Hello World"); two objects are created one is the "Hello World", which is placed in the string buffer, and the other is the object constructed by the new method, the object new string (), which holds the "Hello World "Object, this object is placed in the heap memory, and b points to the new String () object, which is obviously a different two objects, so they use" = "to compare the result is false.

This result is true if compared with the Equals () method, because the Equals () method compares the contents of the object, and their contents are "Hello World".

It is also worth reminding that the string buffer will only be stored once for the same string. If we write string a = "Hello World" at the same time, string b = new string ("Hello World"), then the string buffer actually has only one Hello World string, and when you assign a value to B, the string buffer is checked for The string "Hello World", if any, is not created, directly new string (), and then assigned a value, so in this case, the expression string b= new string ("Hello World") also creates only one object.

The SE base basic data type for the Java interview summary

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.