JAVA back-end test questions (1), java back-end test questions

Source: Internet
Author: User

JAVA back-end test questions (1), java back-end test questions

The weather turns cloudy on January 1, June 7, 2017. Good mood.

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

1. What is GC? Why GC?

GC (GarbageCollection) is a mechanism for garbage collection. In Java, developers cannot use pointers to manage the memory freely. GC is the way JVM manages the memory (actually an object. The Java Virtual Machine can automatically identify and collect garbage, but generally does not immediately release their memory space. You can also use the System in the program. gc () to force garbage collection, but note that the system does not guarantee the immediate release of memory. GC frees Java developers from tedious memory management and makes program development more efficient.

GC principle:

Java memory management is actually object management, including object allocation and interpretation.

For programmers, The new Keyword is used to allocate objects. When releasing an object, they only need to assign null values to all references of the object so that the program cannot access this object, we call this object "inaccessible ". GC recycles the memory space of all "inaccessible" objects.

For GC, when a programmer creates an object, GC starts to monitor the address, size, and usage of the object. Generally, GC records and manages all objects in heap by Directed Graphs. This method is used to determine which objects are "reachable" and which objects are "inaccessible ". When GC determines that some objects are "inaccessible", GC has the responsibility to recycle the memory space. However, to ensure that GC can be implemented on different platforms, Java does not strictly regulate many GC behaviors. For example, there are no clear rules on the types of recycling algorithms used and when to recycle them. Therefore, the implementers of different JVMs often have different implementation algorithms, which brings a lot of uncertainty to the Development of Java programmers.

2. What is the difference between interfaces and abstract classes?

The interface is the abstraction of actions, and the abstract class is the abstraction of the source. The abstract class indicates what this object is. The interface indicates what the object can do. For example, for men and women (if they are classes), their abstract classes are human. Note: they are all human beings. People can eat, dogs can also eat, you can define "eat" as an interface, and then let these classes implement it. Therefore, in advanced languages, a class can only inherit one class (abstract class) (just as humans cannot be both biological and non-biological ), however, multiple interfaces (meal and walking interfaces) can be implemented ).

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

(1) abstract classes and interfaces cannot be directly instantiated. to instantiate them, the abstract class variables must point to subclass objects that implement all abstract methods, and the interface variables must point to class objects that implement all interface methods.

(2) abstract classes must inherit from the quilt class, and interfaces must be implemented by the quilt class.

(3) The interface can only be used as a method declaration. The abstract class can be used as a method declaration or a method implementation.

(4) The variables defined in the interface can only be public static constants, and the variables in the abstract class are common variables.

(5) The abstract methods in the abstract class must be implemented by all the quilt classes. If the subclass cannot all implement the parent class abstract methods, the subclass can only be an abstract class. Similarly, when a class implements an interface, if the interface methods cannot be fully implemented, the class can only be an abstract class.

(6) abstract methods can only be declared and cannot be implemented. interfaces are the design results, and abstract classes are the reconstruction results.

(7) abstract classes can have no abstract methods.

(8) If an abstract method exists in a class, the class can only be an abstract class.

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

(10) An interface can inherit an interface and inherit more than one interface, but the class can only inherit from one interface.

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

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

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

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

3. Why is Mybatis a semi-automatic ORM ing tool? What is the difference between it and automation?

Hibernate is a fully automated ORM ing tool. It can be directly obtained based on the object relationship model when you use Hibernate to query associated objects or associated set objects, so it is fully automated. Mybatis is a semi-automatic ORM ing tool that needs to manually write SQL statements to query associated objects or associated set objects.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.