Home >Java >javaTutorial >Some questions that appear in the JAVA written test

Some questions that appear in the JAVA written test

怪我咯
怪我咯Original
2017-06-25 10:19:511369browse

On June 7, 2017, the weather turned from sunny to cloudy. I'm in a good mood.

I took my first written test last Saturday. I felt very bad, mainly because I did not have a solid grasp of basic knowledge. Now I have summarized some of the questions in the written test as follows for easy reference in the future.

1.What is GC? Why GC?

GC (GarbageCollection) is a garbage collection mechanism. In Java, developers cannot use pointers to freely manage memory. GC is the way the JVM manages memory (actually objects). The Java virtual machine can automatically determine and collect garbage, but generally does not release their memory space immediately. You can also use System.gc() in the program to force garbage collection, but it should be noted that the system does not guarantee that it will Release memory immediately. GC allows Java developers to get rid of tedious memory management work and make program development more efficient.

Basic principles of GC:

Java’s memory management is actually the management of objects, including the allocation and release of objects.

For programmers, allocate objects using the new keyword; when releasing an object, just assign all references to the object to null so that the program can no longer access the object. We call the object "unreachable" of". The GC will be responsible for reclaiming the memory space of all "unreachable" objects.

For GC, when the programmer creates an object, GC begins to monitor the address, size and usage of the object. Usually, GC uses a directed graph to record and manage all objects in the heap. In this way it is determined which objects are "reachable" and which objects are "unreachable". When the GC determines that some objects are "unreachable", the GC is responsible for reclaiming these memory spaces. However, in order to ensure that GC can be implemented on different platforms, Java does not have strict regulations on many GC behaviors. For example, there are no clear regulations on important issues such as what type of recycling algorithm to use and when to perform recycling. Therefore, different JVM implementers often have different implementation algorithms, which brings a lot of uncertainty to the development of Java programmers.

2. What is the difference between interface and abstract class?

The interface is the abstraction of actions, and the abstract class is the abstraction of the source. The abstract class represents what this object is. The interface represents what this object can do. For example, men and women, these two classes (if they are classes), their abstract class is people. Explanation: They are all human. People can eat, and dogs can also eat. You can define "eating" as an interface, and then let these classes implement it. Therefore, in high-level languages, a class can only inherit one class (abstract class) (just as a person cannot be a living thing and a non-living thing at the same time), but it can implement multiple interfaces (eating interface, walking interface).

When you focus on the essence of a thing, use abstract classes; when you focus on an operation, use interfaces.

(1) Neither abstract classes nor interfaces can be instantiated directly. If they are to be instantiated, abstract class variables must point to subclass objects that implement all abstract methods, and interface variables must point to subclass objects that implement all interface methods. class object.

(2) Abstract classes must be inherited by subclasses, and interfaces must be implemented by subclasses.

(3) Interfaces can only make method declarations, while abstract classes can make method declarations and method implementations.

(4) Variables defined in the interface can only be public static constants, and variables in abstract classes are ordinary variables.

(5) All abstract methods in an abstract class must be implemented by the subclass. If the subclass cannot implement all the abstract methods of the parent class, then the subclass can only be an abstract class. Similarly, when a class implements an interface, if it cannot implement all interface methods, then the class can only be an abstract class.

(6) Abstract methods can only be declared, not implemented. Interfaces are the result of design, and abstract classes are the result of reconstruction.

(7) There is no need for abstract methods in abstract classes.

(8) If there is an abstract method in a class, then this class can only be an abstract class.

(9) Abstract methods must be implemented, so they cannot be static or private.

(10) Interfaces can inherit interfaces and multiple interfaces, but classes can only inherit from a single root.

(11) Both abstract classes and interfaces are used to abstract specific objects, but interfaces have the highest abstraction level.

(12) Abstract classes can have specific methods and attributes, while interfaces can only have abstract methods and immutable constants.

(13) Abstract classes are mainly used to abstract categories, and interfaces are mainly used to abstract functions.

(14) In abstract classes, if methods do not contain any implementation, derived classes must override them. All methods in the interface must be unimplemented.

3. Why is Mybatis said to be a semi-automatic ORM mapping tool? What is the difference between it and fully automatic?

Hibernate is a fully automatic ORM mapping tool. When using Hibernate to query related objects or related collection objects, it can be obtained directly based on the object relationship model, so it is fully automatic. When Mybatis queries associated objects or associated collection objects, it needs to be manually written in sql, so it is called a semi-automatic ORM mapping tool.

The above is the detailed content of Some questions that appear in the JAVA written test. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn