Win in Java Basics Interview (5)

 

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

       hashCode () method of the object corresponding to the hash value of the integer. It is used to hash-based collections, such as Hashtable, HashMap, LinkedHashMap like. It equals () method is particularly close relationship. The object is determined to be equal Java specification, the use of two equal () method must have the same hash code.

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

        Byte stream data to interact directly with the terminal, and the data is subjected to character stream needs to be processed after the output buffer.

        Under development for more bytes of data processing, for example, pictures, movies, text, and the biggest benefit is that it can be a stream of characters to deal effectively with the Chinese. If there are Chinese in the daily development process, with a character stream, if not, we recommend the use of a byte stream.

        When using OutputStream output data even without close the output stream, then the content can be normal output; if not closed, but conversely writer will not be able to normal output buffer contents have not been emptied in special circumstances can not close character-output stream may be used flush () method forcibly empty the buffer.

43, what is java serialization, how to achieve java serialization? Please explain the role or Serializable interface.

       We will sometimes java object becomes a stream of bytes spread out or recover from a byte stream into a java object, for example, to java objects are stored to the hard disk or transferred to other computers on the network, a process that we you can write your own code to put a java object becomes a byte stream re-transmission format.

       However, jre itself provides this support, we can call the writeObject method OutputStream to do, if you want to help us do java, the object to be transferred must implement the serializable interface, so, javac will compile-time special handling, compiled classes can be operated writeObject method, which is called serialization. Needs to be serialized Serializable class must implement the interface, which is a mini interface, no need to implement a method, the implements Serializable only to the object is marked serialized.

       For example, in web development, if the object is stored in a Session in, tomcat in the Session object should restart serialized to disk, the object must implement Serializable. If the object is to go through a distributed network transmission system, the object is transferred must implement the Serializable interface.

44, describe the principle mechanism JVM class document loading?

       The JVM is loaded by a class and its subclasses ClassLoader achieved, Java ClassLoader is an important component of the Java runtime system. It is responsible for finding and class loading class files at run time.

45, heap and stack What is the difference.

       heap translated into the heap, stack to stack translation

       java memory is divided into two categories, one is the stack memory, one is the heap memory. Stack memory means the program enters a method, assigns the local variable belongs to a private memory space for a separate internal storage for the method of this method, when the end of this method, the stack allocated to this method will release the stack the variable will also release.

        Heap and stack effect is different memory, generally used for storing data that is not current methods stack, for example, new objects are created on the heap, so it will not disappear with the end of the process. After the local variables used in the method of final modification, on the heap, instead of the stack.

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

        GC is a garbage collection means (Gabage Collection), memory handling is where programmers prone to problems, and forget or false memory recovery program will lead to instability or even collapse of the system, provided Java GC function can automatically monitor whether the object is more than scope so as to achieve the purpose of automatically reclaims the memory, Java language does not provide a display method operation of the release of allocated memory.

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

       Java language in a notable feature is the introduction of garbage collection mechanism to enable c ++ programmers the most headache solved the problem of memory management, which allows Java programmers in the preparation of the program no longer need to consider memory management. Since the garbage collection mechanism, Java objects are no longer in the "scope" concept, and only the object reference have no "scope."

       Garbage collection can effectively prevent memory leaks, efficient use of memory can be used. Garbage collector is usually as a separate low-level thread to run, heap memory is dead or not used for a long time to clear and recover under unpredictable circumstances, the programmer can not be called real-time garbage collector for a All objects or objects for garbage collection.

        Recovery mechanisms have a generation copy garbage collection and marking garbage collection, incremental garbage collection.

48. What is the basic principle is that the garbage collector? The garbage collector can immediately reclaim memory? Is there any way the initiative to inform the virtual machine garbage collection?

        For GC, when a programmer to create an object, GC began monitoring address, size and use of the object. Typically, GC using the records have all the objects and managing the heap (heap) to the embodiment of FIG. In this way identify which objects are "reachable", which objects are "unreachable." When the GC identify targets for the "unreachable", GC has the responsibility to reclaim the memory space.

        Programmers can be performed manually System.gc (), notify the GC run, but the Java language specification does not guarantee that GC will perform.

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

       In the method of the first function appears throws; and throw appear in the function thereof. throws represents a possibility of abnormal, not necessarily these anomalies occur; throw an exception is thrown, throw it must perform some kind of throws an exception.

       throw throw an exception object, but only one behind throws with exception class can have more.

50, java will be a memory leak it, please describe simple.

        Memory leaks in case of java: long life cycle of an object held by the short life cycle of an object reference to it is a memory leak may occur, despite the short life cycle of an object is no longer needed, but because of the long lifetime of an object held by its reference cause can not be recycled, which is what happens in the scene java memory leaks, quite literally, a programmer might create an object, the future no longer have to use this object, which has been cited, but that is not the object useless is garbage collected, which is the case in java memory leak may occur, for example, cache system, we load an object in the cache (for example, on a global map object), then it has no longer used, this object has been cached references, but is no longer used.

Guess you like

Origin www.cnblogs.com/pwl-hhf/p/11781069.html