Java basic problem record

1. boxing and unboxing

  Packing: automatic basic data types to wrapper type reference data types i.e.

  Unboxing: converting the type of wrapper for the basic data types

2. Java's basic data types 8

Keyword Byte count range Defaults
boolelan 1byte true、false false
byte 1byte -128~127 0
short 2byte   0
int 4byte   0
long 8byte   0L
float 4byte   0.0F
double 8byte   0.0D
char 2byte   '\ U0000'

 

   

 

 

 

 

3. int and Integer of difference

   int is the base type, and is a reference type Integer, Integer is a packing of the int, int is the unpacking of the Integer. The default value is 0 int, Integer and the default is null. int no need to instantiate can be used, and Integer need to instantiate before use

4. Why should there have int Integer

   Java is an object-oriented language, the basic data types int, can not meet the object-oriented features, using the method of packaging can be Integer values ​​and operating values ​​together, so that only operate on external data api, improved data security, and at the same time as the collection of such containers map it is object-oriented, just use int in java can not meet their needs.

The difference between bytes and characters

   Byte is the basic unit of storage capacity, and the character numbers, letters, various symbols and characters of other languages.

The four basic characteristics 6. Java

   Encapsulation, abstraction, inheritance, and polymorphism.

   Package: The data on the data and the method of operating the package in a class, such that the external access can only be operated through the interface provided to the class, to avoid the operation to bring the user directly to the risk of data

   Abstract: A series of objects have in common characteristics sum up, the process of constructing class, including data abstraction and abstract behavior in terms of both abstract objects which only concerned with the behavior and attributes, rather than focus on specific behaviors and achieve these attributes.

   Inheritance: inheritance information obtained from an existing class to create a new class, a new class is a subclass, the old class as a parent class.

   Polymorphism: allowing objects of different sub-types respond differently to the same message.

   Polymorphism understood:

    The method of overload, the method override (subclass) and an interface

7. Java objects created in four ways

   1. Create a new object using the key sub

   2. Use reflection to create objects (newInstance Class category)

   3. Using clone (implement Cloneable interface)

   4. deserialization mechanism 

8. String str = new String ( "abc") to create several objects

   If the String Pool no strings abc, you need to create one in the String Pool abc, abc and then create a heap in java, that is, we need to create two objects, if there is, you only need to create an object in the java heap It can be.

9.  String Pool

   String constant pool holds all the string literal, it already exists in the compiler, add a string in the program will run during this dynamic of constant pool.

   Before a string constant pool Java 7 running time constant pool, is a permanent generation Java heap after being moved, the string constant pool put in permanent substituting prone OutOfMemoryError.

10. The reflective

    Reflection during the program run, for any class, can be aware of any and all properties of the class method, for any one object can call any of its methods and properties, this dynamic access to information and dynamic invocation object function method is called reflection mechanism of Java language.

  Clas get object methods are: 

    Class.getClass()、Class.forName()、ClassLoader.loadClass。

Guess you like

Origin www.cnblogs.com/yhcjr/p/11532408.html