Java obfuscation and Java Obfuscation
Differences between HashMap and HashTable in Java
① Historical reasons: Hashtable provides the obsolete Dictonary class, And HashMap is an implementation of the Map interface introduced by Java1.2.
② HashMap allows empty key-value pairs, whereas HashTable does not.
③ HashTable synchronization, but HashMap non-synchronization, is more efficient than HashTable
Briefly describe the difference between throw and throws in the exception.
① Throw indicates an action that throws an exception. throws indicates a state, indicating that a method may throw an exception.
② Throw is used in method implementation, while throws is used in method declaration.
③ Throw can only be used to throw one exception, while throws can throw multiple exceptions.
Differences between memory overflow and Memory leakage
Memory overflow out of memory means that the program does not have enough memory space to use when applying for memory. For example, if an integer is applied, however, if a long value is saved to it, the memory overflow occurs.
Memory leakage memory leak refers to the failure of the program to release the applied memory space after applying for memory. The memory leakage hazard can be ignored once, but the memory leakage accumulation result is very serious, no matter how much memory, sooner or later.
Memory leak will eventually cause out of memory!
Memory overflow means that the amount of memory you need to allocate exceeds what the system can offer. If the system cannot meet your needs, it will cause an overflow.
Memory leakage means that you apply to the system to allocate memory for use (new), but do not return it after use (delete ), as a result, the memory you applied for cannot be accessed by yourself (maybe you have lost its address), and the system cannot allocate it to the required program again. A plate can only contain four fruits in a variety of ways. If you have five fruits, you cannot eat them if you drop them. This is overflow! For example, stack overflow occurs when the stack is full. Stack Overflow also occurs when the stack is empty. That is, the allocated memory is insufficient to put down the data sequence, which is called memory overflow.
Memory leakage can be classified as follows:
① Frequent Memory leakage. Code with Memory leakage will be executed multiple times, resulting in a memory leak each time it is executed.
② Occasional Memory leakage. Memory leakage occurs only in certain environments or operations. The frequency and frequency are relative. For a specific environment, unexpected events may become frequent. Therefore, the test environment and test method are crucial for detecting memory leaks.
③ One-time memory leakage. The code with Memory leakage is executed only once, or due to algorithm defects, there will always be only one piece of Memory leakage. For example, if the class constructor allocates memory but does not release the memory in the destructor, the memory leakage only occurs once.
④ Implicit Memory leakage. The program continuously allocates memory during the running process, but it does not release the memory until it ends. Strictly speaking, there is no memory leakage because the program releases all requested memory. However, if a server program needs to run for several days, weeks, or even months, failing to release the memory in time may eventually exhaust all the system memory. Therefore, we call this type of Memory leakage an implicit memory leak.
From the perspective of user programs, memory leakage does not cause any harm. As a general user, the memory leakage does not exist. The real danger is the accumulation of Memory leakage, which will eventually consume all the memory of the system. From this point of view, one-time memory leakage is not harmful because it will not accumulate, while implicit memory leakage is very harmful, because it is more difficult to detect than frequent and occasional memory leaks.