1. Basic object-oriented features
Encapsulation, inheritance, polymorphism,
Encapsulation: Encapsulation of objective things into classes
Inheritance: Inheriting a class, you can use all of the functionality of this class and extend these functions without writing the original class
Polymorphic: Child objects call the parent object, and the parent object operates differently depending on the currently called child object
To implement polymorphism: overwrite, reload
The difference between 2.final\finally\finalize
Final declares methods, properties, classes, respectively, that the method is not overwritten, that the property is not mutable, that the class is not inheritable
Finally is part of the exception handling, which means that always executes
Finalize is a method of the object class that calls this method when the garbage collector executes. This method can be overridden to provide garbage collection when other resources are recycled, and the JVM does not guarantee that this method is always called
3,int and integer
int is one of the eight basic types of Java, and integer is the encapsulated class of int
int initial value is 0,integer initial value is null
cannot be used with each other
4. Overloading and rewriting
Overloaded overload, which indicates that there are multiple methods with the same name in a class, but whose argument list is different
Rewrite: A method in a subclass is exactly the same as the parent class, rather than completely overwriting this method in the parent class, so that the class throws fewer exceptions than the parent class.
5. Abstract classes and interfaces
Parameters |
Abstract class |
Interface |
The default method implementation |
Can have the default method implementation |
The implementation of a completely abstract, non-existent method |
Realize |
Extends, if the subclass is not an abstract class, you need to provide an implementation of all the methods declared in the abstract class |
Implements need to provide implementations of all declarative methods in the interface |
Constructors |
can have |
Can't have |
Differences from normal Java classes |
Can not be instantiated, other no difference |
A completely different type |
Access modifiers |
Public/protected/default |
Public, JDK9 can use private |
Main method |
Can have the main method and can run |
No |
Inherited |
Can inherit a class and implement multiple interfaces |
Only one or more interfaces can be inherited |
Speed |
Fast |
Time to find a way to achieve |
Add a new method |
You can provide the default implementation |
The implementation class must be changed |
6. Use and implementation of reflection
Use reflection to get the type information of an object during run time
Realize:
GetClass () method, Class.forName () method, using Class. class, Implementing getClassLoader with the ClassLoader ()
7.Session and the difference between cookies,
- The cookie is stored on the browser and the session is stored on the server
- Cookies are unsafe, session safe
- Session will be saved in the server for a certain period of time, will occupy the server, affect the performance
- A single cookie cannot hold more than 4k of data, and many browsers can save only 20 cookies
- Login information placed in session, others placed in cookies
Java interview (1)