Java Interview Questions - Java Basics

1. What are the aspects of object-oriented features

Packing: Packaging data and methods, and access to data can only be done through defined interfaces.

Inheritance: The subclass inherits some data types or methods of the parent class, and overrides or directly calls these methods.

Polymorphism: Allows objects of different subclasses to respond differently to the same message. Calling the same method with the same object reference does different things.

2. Access modifiers

Private>default>protected>public

3. Constructor, constructor cannot be inherited, cannot be overridden, but can be overloaded.

4. The two objects have the same value, so their hash codes should also be the same. But if the hashcodes are the same, their values ​​are not necessarily the same.

5. Neither abstract classes nor interfaces can be instantiated, but references to abstract classes and interface types can be defined. If a class inherits an abstract class or implements an interface, it must implement all abstract methods. Otherwise the class will still be declared abstract. The members in the interface are all public, and the member variables in the interface are basically constants. Both abstract classes and interfaces can contain static member variables.

6. Abstract methods are neither static nor local, nor can they be modified with synchronized.

7. An interface can inherit an interface, and an abstract class can implement an interface.

8. Anonymous Inner Class An anonymous inner class that can inherit or implement other interfaces. This method is commonly used in swing programming to implement event monitoring and callbacks.

Anonymous inner classes cannot define any static members or methods. A method cannot be abstract, it must implement all abstract methods of an interface or an abstract parent class, cannot define a constructor, access member variables or member methods of an outer class must be modified with static, and an inner class can access private variables and methods of an outer class.

9. Conversion between data types: To convert a string type to a basic data type, call valueof(String).

Convert the basic data type to a string type and call the ValueOf() method.

10. String reverse, call reverse();;;;

11. Runtime exception Arithmetic exception, type conversion exception, illegal parameter exception, subscript out of bounds exception, null pointer exception, security exception.

12. Lis:t: Access elements with specific miniatures, there can be repeated elements, Set cannot store repeated elements, map stores key-value pairs, and the mapping relationship can be one-to-one or many-to-one. Both Set and Map have hash-based storage implementations.

13. Process: A program with a certain independent function is a running activity on a certain data set, and is an independent unit of the operating system for resource allocation and scheduling. Thread: The specific entity of the process, the basic unit of cup scheduling and allocation, and the basic unit of independent operation smaller than the process. The division scale of threads is smaller than that of processes. This makes multi-threaded programs highly concurrent. Processes usually have independent memory units during execution, and threads can share memory. Multi-threaded programming usually brings better performance and user experience.

14. The steps of JDBC operation database: load the driver, create a connection, create a statement, execute the statement, process the result, and close the resource.

15. During database programming: connection pool is used to store connections. Since a lot of overhead is required to establish a connection each time, especially when the data server is not local, the overhead caused cannot be ignored. Therefore, several connections can be placed in the connection in advance. In the pool, it can be obtained directly from the connection pool when needed. Returns the connection pool at the end without closing the connection.

16. There are not only regular expression operation methods in Java, but also pattern representing regular expression objects. Provides a rich API for various regular expressions.

17. Six principles and one rule: single responsibility principle, open and closed principle: open to extension, closed to modification, dependency inversion principle: interface-oriented programming. The Liskov Substitution Principle. Subtypes can be used to replace supertypes at any time. The principle of interface isolation, the interface should be small and specialized rather than large and complete. Aggregate reuse principle: The Law of Demeter, an object should know as little as possible about other objects.

18. Common design patterns:

Ø Factory pattern: The factory class can generate different subclass instances according to conditions. These subclasses have a common abstract parent class and implement the same methods, but these methods perform different operations on different data. When the subclass is obtained , you can call methods in the base class regardless of which subclass instance is returned.

Ø Proxy mode: Provide a proxy object for an object, and the proxy object controls the reference of the original object. In actual development, according to the purpose of use, the proxy can be divided into remote proxy, virtual proxy, protection proxy, firewall proxy, synchronization acting.

Ø Adapter proxy: Transform the interface of a class into another interface expected by the client, so that classes that cannot be used together due to interface mismatch can work together.

Ø Template method pattern: Provide an abstract class, implement part of its logic in the form of concrete methods or constructors, and then declare some abstract methods to break the subclass to implement the remaining logic. Different subclasses can implement these abstract methods in different ways to achieve different logical business.


Guess you like

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