Java language related (below)

Difference between JAVA and C/C++

1. The operation process is different . The JAVA source program is compiled into bytecode files by the compiler, and then interpreted and executed by the JVM. And C++/C generates executable binary code after compiling and linking. Therefore, the execution speed of C/C++ is faster than that of JAVA.
2. Cross-platform. JAVA can be cross-platform, but C++/C cannot.
3.JAVA has no pointers, C++/C has pointers.
4.JAVA does not support multiple inheritance, but multiple interfaces can be implemented at the same time to achieve a similar purpose.
C++ supports multiple inheritance.
5.JAVA does not need to manage memory and has a garbage collection mechanism. C/C++ requires
explicit .
6. JAVA does not support operator overloading. C/C++ supports operator overloading.
7. Each data type in JAVA occupies a fixed number of bytes on different platforms, while C/C
++ .

Advantages of JAVA

1. Cross-platform. The JAVA language can "compile once, run anywhere". The meaning of cross-platform: No matter whether the Java program is compiled on the Windows platform or the Linux platform, the compiled program can be run on other platforms. The compiler will compile the JAVA code into a bytecode file, and then interpret and execute it on the JVM. Since the bytecode is independent of the platform, JAVA can be executed well across platforms.

2. Garbage collection mechanism.

3. Get rid of hard-to-understand things in C++, such as pointers and operator overloading.

4. Has better security . For example, JAVA has array boundary detection, but C/C++ does not.

1. Can there be multiple main() methods in the same .java file?

The main() method can be defined in each class, but only the main() method in the class decorated with public and the
same can be used as the entry method of the whole program.

2. Access control of classes and members in JAVA

Class access control . Access control of members can be modified with public and non-public

access modifier the same class the same package Subclasses from different packages Non-subclasses of different packages
public * * * *
protected * * *
default * *
private *

3. The difference between final finally finalize.

Final can be used to modify classes, variables and methods
1. When a class is modified by final, it means that the class cannot be inherited . Methods in a class are
declared final by default.
2. When final modifies a variable of a basic data type, it means that the value cannot be changed after being initialized ;
when final modifies a variable of a reference type, it means that the reference cannot point to
other .
Note: variables decorated with final must be initialized. It can be initialized at definition time
or in the constructor.
3. When a method is modified as final, it means that the method cannot be overridden by subclasses .

The usage of finally :
finally is a part of exception handling and can only be used in try-catch statements, indicating that this code will be executed under
normal circumstances . Often used in situations where resources need to be released.

Usage of finalize: It is a method of the Object class, which will call the finalize() method
of the reclaimed object when the garbage collector executes .

4. What are the benefits of generics?

Check type safety at compile time to ensure that only objects of the correct type can be put into the collection;
eliminate casts
The essence of generics is " parameterized types ", or that types can be passed as parameters to a class or is the method.

When creating a collection, specify the data type of the elements of the collection. The collection can only save elements of the specified type, avoiding the use of forced type conversion .

The bytecode generated by the Java compiler does not contain generic information, and the generic type information will be erased during compilation processing. This process is called type erasure. Type erasure can be simply understood as converting generic java code into ordinary java code, but the compiler is more direct, converting generic java code directly into ordinary java bytecode.

The main process of type erasure is as follows:
1. Replace all generic parameters with their leftmost boundary (the topmost supertype) type.
2. Remove all type parameters

15. What open source software do you know?  

1.JDK
2.Eclipse
3.Tomcat
4.MySQL

Guess you like

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