What are the characteristics of object-oriented?
The so-called encapsulation is to encapsulate objective things into abstract objects Class, and the class can allow its own data and methods to be operated only by trusted classes or objects, and hide information from untrusted ones. Encapsulation is one of the characteristics of object-oriented and the main characteristic of the concepts of objects and classes. (Recommended study: java common interview questions)
Inheritance means that the subclass obtains the attributes and methods of the parent class. For example, if a dog is a type of animal, it can also be said that it inherits the characteristics of the animal, or that the dog is a subclass of the animal.
Polymorphism means that a method can only have one name, but it can have many forms. That is, multiple methods with the same name can be defined in the program, which is described by "one interface, multiple methods". You can pass Method parameters and type references
Five principles: Single Responsibility Principle SRP Open and Closed Principle OCP Replacement Principle LSP Dependency Principle DIP Interface Separation Principle ISP
Member variables and local variables The difference
* A: Different positions in the class
* Member variables: outside the methods in the class
* Local variables : In the method definition or method declaration
* B: Different locations in the memory
* Member variables: In the heap memory (member variables belong to objects, objects into heap memory)
* Local variables: in stack memory (local variables belong to methods, methods are pushed into stack memory)
* C: different life cycles
* Member variables: exist when the object is created and disappear when the object disappears
* Local variables: exist when the method is called and disappear when the method is called
* D: Different initialization values
* Member variables: have default initialization values
* Local variables: no default initialization values, must be defined, assigned, and then can be used.
The difference between static variables and member variables
* Static variables are also called class variables. Member variables are also called object variables
* A: Different ownership
* Static variables belong to classes, so they are also called class variables
* Member variables belong to objects, so they are also called instance variables (object variables)
* B: Different locations in memory
* Static variables are stored in the static area of ??the method area
* Member variables are stored in the heap memory
* C: Memory appearance time is different
* Static variables are loaded as the class is loaded, and disappear as the class disappears
* Member variables follow the object's It exists when it is created and disappears when the object disappears
* D: Different calls
* Static variables can be called through class names or through objects
* Member variables can only be called through the object name
The difference and application of this and super
* A: What do this and super stand for
* this: represents the reference of the current object, whoever calls me, I will represent that person
* super: represents the reference of the parent class of the current object
* B: The difference between the use of this and super
* a: Calling member variables
* this. Member variables call member variables of this class or of the parent class Member variable
* super. Member variable calls the member variable of the parent class
* b: Calls the constructor method
* this(...) calls the constructor method of this class
* super(...) calls the constructor method of the parent class
* c: calls the member method
* this. The member method calls the member method of this class, also You can call the method of the parent class
*super.Member method calls the member method of the parent class
What are the methods of sorting? Please list the
sorting methods: insertion sort (direct insertion sort, Hill sort), exchange sort (bubble sort, quick sort), selection sort (direct selection sort, heap sort), Merge sort, distribution sort (box sort, radix sort)
Pseudo code of quick sort.
The difference between String, StringBuffer and StringBuilder.
The length of String is immutable;
The length of StringBuffer is variable. If you frequently operate on the content in the string, especially if the content is When modifying, use StringBuffer. If String is needed in the end, use StringBuffer's toString() method; thread safety;
StringBuilder is starting from JDK 5 and adds an equivalent method for single thread use to the StringBuffer class. class; you should generally use the StringBuilder class in preference because it supports all the same operations, but is faster because it does not perform synchronization.
The difference between Overload and Override. Can an Overloaded method change the type of return value?
Answer: Method overriding Overriding and overloading Overloading are different manifestations of Java polymorphism.
Overriding is a manifestation of polymorphism between parent classes and subclasses, and overloading is a manifestation of polymorphism in a class. If a method defined in a subclass has the same name and parameters as its parent class, we say the method is overriding.
When an object of a subclass uses this method, the definition in the subclass will be called. For it, the definition in the parent class seems to be "shielded". If multiple methods with the same name are defined in a class, and they have different number of parameters or different parameter types, it is called method overloading. Overloaded method can change the type of return value.
What is the difference between final and finally?
Answer: final: modifier (keyword); if a class is declared final, it means that it cannot Derived new subclasses cannot be inherited as parent classes, so a class cannot be declared both abstract and final; declaring variables or methods as final ensures that they will not be changed during use. ; Variables declared as final must be given an initial value when declared, and can only be read in subsequent references and cannot be modified; methods declared as final can also only be used and cannot be overloaded.
finally: Provide a finally block to perform any cleanup operations during exception handling; if an exception is thrown, the matching catch clause will be executed, and then control will enter the finally block (if any ).
Several common operating abnormalities.
java.lang.nullpointerexception (null pointer exception)
java.lang.classnotfoundexception (the specified class does not exist)
java.lang.arithmeticexception (mathematical Operation exception)
java.lang.arrayindexoutofboundsexception (array subscript out-of-bounds exception)
IOException (input and output exception)
Two common problems with array operations are out-of-bounds and empty Pointer
* A:Case demonstration
* a:ArrayIndexOutOfBoundsException: Array index out of bounds exception
* Reason: You accessed a non-existent index.
* b: NullPointerException: Null pointer exception
* Reason: The array no longer points to the heap memory. And you also use array names to access elements.
* int[] arr = {1,2,3}; * arr = null; * System.out.println(arr[0]);
How does JAVA language handle exceptions? What do the keywords: throws, throw, try, catch, and finally mean? Can exception be thrown in try block?
Answer: Java handles exceptions through object-oriented methods, classifies various exceptions, and provides a good interface.
In Java, each exception is an object, which is an instance of the Throwable class or other subclasses. When an exception occurs in a method, an exception object is thrown. The object contains exception information. The method of calling this object can catch the exception and handle it.
Java's exception handling is implemented through 5 keywords: try, catch, throw, throws and finally. Generally, try is used to execute a program. If an exception occurs, the system will throw an exception. At this time, you can catch it by its type, or finally by the default handler. to handle.
Use try to specify a program that prevents all "exceptions". Immediately after the try program, a catch clause should be included to specify the type of "exception" you want to catch.
Thethrow statement is used to explicitly throw an "exception".
throws is used to indicate various "exceptions" that a member function may throw.
Finally ensures that a piece of code is executed no matter what "exception" occurs.
You can write a try statement outside a member function call, and write another try statement inside the member function to protect other code. Whenever a try statement is encountered, the "exception" frame is placed on the stack until all try statements are completed.
If the next level try statement does not handle a certain "exception", the stack will expand until it encounters a try statement that handles this "exception".
When the server receives the form data submitted by the user, does it call the Servlet's doGet() or doPost() method?
Answer: The

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

The settings.json file is located in the user-level or workspace-level path and is used to customize VSCode settings. 1. User-level path: Windows is C:\Users\\AppData\Roaming\Code\User\settings.json, macOS is /Users//Library/ApplicationSupport/Code/User/settings.json, Linux is /home//.config/Code/User/settings.json; 2. Workspace-level path: .vscode/settings in the project root directory

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

DependencyInjection(DI)isadesignpatternwhereobjectsreceivedependenciesexternally,promotingloosecouplingandeasiertestingthroughconstructor,setter,orfieldinjection.2.SpringFrameworkusesannotationslike@Component,@Service,and@AutowiredwithJava-basedconfi

itertools.combinations is used to generate all non-repetitive combinations (order irrelevant) that selects a specified number of elements from the iterable object. Its usage includes: 1. Select 2 element combinations from the list, such as ('A','B'), ('A','C'), etc., to avoid repeated order; 2. Take 3 character combinations of strings, such as "abc" and "abd", which are suitable for subsequence generation; 3. Find the combinations where the sum of two numbers is equal to the target value, such as 1 5=6, simplify the double loop logic; the difference between combinations and arrangement lies in whether the order is important, combinations regard AB and BA as the same, while permutations are regarded as different;

java.lang.OutOfMemoryError: Javaheapspace indicates insufficient heap memory, and needs to check the processing of large objects, memory leaks and heap settings, and locate and optimize the code through the heap dump analysis tool; 2. Metaspace errors are common in dynamic class generation or hot deployment due to excessive class metadata, and MaxMetaspaceSize should be restricted and class loading should be optimized; 3. Unabletocreatenewnativethread due to exhausting system thread resources, it is necessary to check the number of threads, use thread pools, and adjust the stack size; 4. GCoverheadlimitexceeded means that GC is frequent but has less recycling, and GC logs should be analyzed and optimized.

fixture is a function used to provide preset environment or data for tests. 1. Use the @pytest.fixture decorator to define fixture; 2. Inject fixture in parameter form in the test function; 3. Execute setup before yield, and then teardown; 4. Control scope through scope parameters, such as function, module, etc.; 5. Place the shared fixture in conftest.py to achieve cross-file sharing, thereby improving the maintainability and reusability of tests.

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa

Use classes in the java.time package to replace the old Date and Calendar classes; 2. Get the current date and time through LocalDate, LocalDateTime and LocalTime; 3. Create a specific date and time using the of() method; 4. Use the plus/minus method to immutably increase and decrease the time; 5. Use ZonedDateTime and ZoneId to process the time zone; 6. Format and parse date strings through DateTimeFormatter; 7. Use Instant to be compatible with the old date types when necessary; date processing in modern Java should give priority to using java.timeAPI, which provides clear, immutable and linear
