Java basic part of Android interview questions

1. Eight basic data types and packaging types and their differences?

 基本:             byte   short   char      int      long  float  double  boolean  

包装类:           Byte   Short  Character  Integer  Long  Float  Double  Boolean 

Large / Small / (byte): 1 2 2 4 8 4 8 1

The difference: the basic data types are placed on the stack, the size is determined before compilation, and the speed is fast and the function is weak.    

          The packaging class is placed in the pile to determine the size when running. The speed is slow and the function is strong. 

the reason:

Java is an almost pure object-oriented programming language, but for the convenience of programming, basic data types that are not objects are introduced. However, in order to be able to treat these basic data types as objects, Java has introduced corresponding packaging for each basic data type. Type (wrapper class), the wrapper class of int is Integer. Since JDK 1.5, an automatic boxing/unboxing mechanism has been introduced, so that the two can be converted to each other.

2. What is boxing? What is unboxing? 

Packing: basic data types are converted to packaging 

Unboxing: Convert the packaging class to the basic data type 

3. The difference between "==" and "equals()"

The main difference is that the former is a method, the latter is an operator

(1) Compare the basic types of java:

  You can only use "==" to compare basic types, not "equals", where "==" compares the values ​​of two basic types

(2)  Compare String

== compares whether the storage memory address is the same

   Whether the stored content of equals comparison is the same

4. The difference between String, StringBuffer and StringBuilder?? String string constant
StringBuffer string variable (thread safety)

StringBuilder string variable (non thread safe

String is a string constant, and StringBuilder and StringBuffer are both string variables, that is, once the String object is created, the object cannot be changed, but the objects of the latter two are variables and can be changed

A summary of the three uses : 1. If you want to manipulate a small amount of data, use = String

           2. Operate large amounts of data under a single-threaded string buffer = StringBuilder

           3. Operate large amounts of data under multithreaded operation string buffer = StringBuffer

Will keep updating based on my own learning


Guess you like

Origin blog.csdn.net/u010256329/article/details/79851249