java face questions base 4

1, a.hashCode () what is the use? What is the relationship with a.equals (b)?

  Role: When we can not be repeated to such storage elements Set collection into a number of elements, is to determine whether the same elements requires a lot of calls equals () method, which will significantly reduce the presence of equals () method .hashCode () method frequency, thereby improving the efficiency

  The relationship between equals and hashcode: equals two objects are equal, then the hashcode must be equal. But the two objects are equal hashcode not necessarily equal equals.

 

2, the difference between a byte stream and a character stream

  Byte stream is the most basic, using ASCII encoding is mainly used in the processing of binary data, which is handled by byte, mainly deal with audio files, pictures, songs and other documents;

  Character stream in Unicode encoding for plain text files

 

  Byte stream can be used for any type of object, including the binary object, the character stream can process characters or strings;

  Byte stream provides the function of any type of IO processing operation, but it can not directly handle Unicode characters, and the character stream may

 

3. What is java serialization, how to achieve java serialization?

  Serialization: The process of converting a Java object byte sequence.

  Deserialized: the recovery process for the byte sequence of Java objects.

  Serialized object primarily for two purposes:
  1) the object of the byte sequence permanently saved to the hard disk, usually stored in a file;
  2) byte sequence subject to transmission over the network.

 

  Serialized class must implement Serializable

 

4, describe the principle mechanism JVM class document loading?

   All classes in Java, must be loaded into the JVM to run, this work is done by loading the JVM class loader (ClassLoader) is completed, the essence of the work done by the class loader is the class file is read from the hard disk into memory , the role is to load classes at runtime.

  By the way, step loading JVM bytecode file:

    (1) Loading: Finding and importing class files

    (2) is connected:

        Check the correctness of loading class files: Check

        Preparation: allocate memory space for the class static variable

        Analysis: The symbolic reference is converted to a direct reference

    (3) Initialization: initialize static variables, static code block

 

5, GC is the What? Why should there be GC?

  GC refers to garbage collection mechanism, meaning when an object can not be referenced by the follow-up program that the object occupies minimal memory space on the absence of a, java virtual machine from time to time to detect memory in such objects, then recover this memory space.

 

  GC existence of the programmer no longer worry about memory management, maximize the use of memory; while GC can effectively prevent memory leaks.

 

6, advantages and principles of garbage collection. And consider two kinds of recovery mechanisms.

  Advantages: garbage collection mechanism can effectively control memory leaks, and effective use of available memory

  Principle: the garbage collector is usually run as a separate thread low-level, in the case of unpredictable heap memory for a long time have died or have not used the clearing and recycling of objects

  Garbage collection mechanisms generational copy garbage collection and marking garbage collection , incremental garbage collection .

 

7, the garbage collector can immediately reclaim memory? Is there any way the initiative to inform the virtual machine garbage collection?

  can.

  System.gc()。Runtime.getRuntime().gc()

 

8, Java in, throw and throws What is the difference

   appears in the first method throws; throw occurs in the method body

   throws represents a possibility of abnormal, not necessarily these anomalies occur; throw an exception is thrown, throw it must perform some kind of thrown exception object .

 

 

9, java Object class and the method used to talk about.

  Object class is a class of java default provider, Object class is the parent of all classes, that is the definition of a class any time if there is no clear successor to a parent, then it is a subclass of Object

  toString (): returns the object information in the form of a string are usually "of the string class object name + @ + unsigned hash code hexadecimal" component

  clone():实现对象的浅复制,只有实现了Cloneable接口才可以调用该方法,否则抛出CloneNotSupportedException异常。

  getClass():final方法,返回运行时类对象。

  finalize():该方法用于释放资源

  equals():比较对象是否相同,即引用地址是否指向同一个对象

  hashCode():获得对象的哈希码

  wait(long timeout):使线程进入等待,设定一个超时间隔,如果在规定时间内没有获得锁就返回

              调用该方法后当前线程进入睡眠状态,直到以下事件发生。
                (1)其他线程调用了该对象的notify方法。
                (2)其他线程调用了该对象的notifyAll方法。
                (3)其他线程调用了interrupt中断该线程。
                (4)时间间隔到了。

  notify():唤醒在该对象上等待的某个线程。

  notifyAll():唤醒在该对象上等待的所有线程。

  

Guess you like

Origin www.cnblogs.com/javaisbest/p/12628810.html