Basic concepts of Java basics

  1. What are the advantages of the Java language?
    1. Java is pure object-oriented language
    2. Platform independent. Java Interpretation Language, the compiler compiles the Java code to generate bytecode files, which are then interpreted and executed by the JVM (Java Virtual Machine).
    3. Java provides a class library that needs to be built in. For example support for multithreading.
    4. Has better security and robustness. Java provides a security mechanism to prevent malicious code attacks. In addition, exception handling, garbage collector, etc. are also provided to ensure the robustness of the program.
    5. Provides support for web application development. For example Servlet, JSP can be used to develop web applications. Socket, a class library that RMI can use to develop distributed applications.
    6. It removes the features that are difficult to understand and easy to confuse in the C++ language. Such as pointers, header files, multiple inheritance, etc.
  2. What are the similarities and differences between Java and C/C++
    1. Java is an interpreted language. C/C++ is a compiled language, and the source code is compiled and linked to generate executable binary code.
    2. Java is a pure object-oriented language, and C++ has the characteristics of both procedural and procedural programming.
    3. Java has no concept of pointers
    4. Java provides a garbage collector to achieve automatic garbage collection. In the C++ language, developers are required to manage the allocation of memory (including application and release).
    5. Java does not support operator overloading, has no preprocessor, does not provide a goto statement (but goto is a reserved keyword in Java), and is platform independent.
  3. Why do you need the method public static void main(String[] args)?
    • public static void main(String[] args) is the entry method of the java program. When the JVM runs the program, it will first look for the main() method. Generally speaking, to execute a method of a class, you need to instantiate an object of the class, and call the method through this object. In view of this, the modifier of main() is public static, a static method, when the program is loaded, the main method can be called.
  4. What is the order in which Java programs are initialized?
    • In the Java language, when an object is instantiated, all member variables of the class where the object is located must be initialized first, and only after all the member variables of the class are initialized, the constructor of the class where the object is located will be called to create the object.
    • The execution order is as follows: parent class static variable, parent class static code block, child class static variable, child class static code block, parent class non-static variable, parent class non-static code, parent class constructor, child class non-static variable, child class Class non-static code block, subclass constructor.
  5. What are scopes in Java?
    • First, explain that there is no global variable or global function in Java
    • In the Java language, there are three types of variables: member variables, static variables, and local variables.
      • The scope of member variables is the same as the scope of the instantiated object of the class. Member variables also have 4 scopes, the corresponding modifiers are public (all visible), private (current class visible), protected (current class, same package, subclass visible), default (current class, same package visible)
      • Static variables do not depend on a specific instance, but are shared by all instances, that is, as long as a class is loaded, the JVM will allocate storage space for the static variables of the class.
      • The scope of a local variable, inside the curly braces in which it is placed.
    • It should be noted that public, private, protected, and default can only be used to modify member variables, not local variables. private and protected cannot be used to modify classes, only public, abstract, fianl can be used to modify classes
  6. What is a constructor?
  7. Why some interfaces in Java don't have any methods?
  8. What does the clone method do in Java?
  9. What is the reflection mechanism?
  10. How to achieve something similar to function pointers in C language?

            

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324445189&siteId=291194637