object-oriented

Process oriented focuses more on each step and sequence of things, while object oriented focuses more on what the participants are and what each needs to do

JDK JRE JVM

JDK: Java development toolkit JRE: Java runtime environment JVM: Java VIRTUAL machine

= = and equals

Equals: object compares the contents of two strings with the values in the stack. The base type is a variable value, and the reference type is the address of the memory object in the heap

String x = "string"; String y = "string"; String z = new String("string"); System.out.println(x==y); // true System.out.println(x==z); // false System.out.println(x.equals(y)); // true System.out.println(x.equals(z)); // true String str1 = "hello"; String str2 = new String("hello"); String str3 = str2; Println (str1 == str2); // Pass system.out.println (str1 == str2); //false System.out.println(str1 == str3); //false System.out.println(str2 == str2); //true System.out.println(str1.equals(str2)); //true System.out.println(str1.equals(str3)); //true System.out.println(str2.equals(str3)); //trueCopy the code

Explain why local variable inner classes and anonymous inner classes can only access local final variables

Final can be modified: classes (cannot be inherited), methods (cannot be overridden), variables (cannot change values)

String, StringBuilder, StringBuffer

StringBuilder and StringBuffer operate on the original object. StringBuffer is thread-safe. StringBuilder is not thread-safe. StringBuilder>StringBuffer>String

The difference between overloading and overwriting

Overloading: occurs in the same class, the method name must be the same, the parameter type must be different, number, order, different, method return value and access modifier can be different, occurs at compile time; Overwrite: the method name and parameter list must be the same, the return value range is less than or equal to the parent class, the exception orientation is less than or equal to the parent class, and the access modifier range is greater than the parent class. If the rich parent class method is private, the method cannot be overwritten.

Interfaces and abstract classes

  • Abstract classes can have ordinary member functions, whereas interfaces can only have public abstract methods
  • Member variables in an abstract class can be various, whereas member variables in an interface can only be public static final
  • Abstract classes can inherit only one, whereas interfaces can implement multiple
  • Interfaces are designed to constrain behavior, while abstract classes are designed to reuse code,
  • Abstract class is the abstraction of class essence, expression is the relation of is A, and interface is the abstraction of behavior, expression is the relation of like A, the core of interface is to define behavior, that is to implement what the class can do, as for who is the subject, how to achieve, interface does not care.

– Usage scenarios: Use abstract classes when you focus on the essence of a thing, use interfaces when you focus on an operation.

Difference between a List and a Set

1. An ordered List of objects in the order in which they were entered, repeatable, allowing multiple null elements. The iterator interface can be used to fetch all the elements in the iterator, and get(int index) can be used to obtain the Set element with the specified index: Iterator Iterator Iterator Iterator Iterator Iterator Iterator Iterator Iterator Iterator Iterator Iterator Iterator Iterator Iterator

Set<String> Set = new HashSet<>(); set.add("1"); set.add("2"); set.add("3"); set.add("3"); Iterator<String> iterator = set.iterator(); while (iterator.hasNext()) { String nest = iterator.next(); System.out.println(nest); }Copy the code

The equals and hashCode

ArrayList and LinkList

ArrayList: Based on dynamic array, continuous memory storage, suitable for subscript access (random access), expansion mechanism: Because the array length is fixed, you need to create a new array if the array length exceeds, and then copy the data from the old array to the new array. If the data is not inserted at the end of the array, it will also involve element movement (copy the data later, insert the new element). Using the tail insertion method and specifying the initial capacity can greatly improve performance. 8. LinkList: based on linked lists, can be stored in scattered memory, suitable for insertion and deletion, not suitable for query: To iterate through a LinkList one by one, you must use an Iterator instead of a for loop, because the list must be reiterated every time the for body gets an element through get (I), which can be very costly.

What is the difference between HashMap and HashTable, and what is the underlying implementation of HashMap?

(2) HashMap allows null keys and values, while HashTable does not allow the underlying implementation: array + linked list implementation

How to implement an IOC container

3. Reflection to determine the classes to be delivered to IOC management. 4. Dependency injection for the classes to be injected

What is bytecode? What are the benefits of bytecode adoption?

Java source code — — — — — — — — – > > compiler JVM executable Java bytecode (that is, the virtual instruction) — — — — — — — — — — — — — > > JVM JVM interpreter — — — — — — — — > machine executable binary machine code — — — — > program is running

Advantages of using bytecode: Java language solves the low efficiency of traditional interpreted languages to some extent by means of bytecode, while retaining the portability of interpreted languages, so Java programs run more efficiently. Moreover, because bytecode is not specific to a specific machine, therefore, Java programs can run on many different computers without recompiling.

The last

Welcome to pay attention to the public number: the future has light, receive a line of large factory Java interview questions summary + the knowledge points learning thinking guide + a 300 page PDF document Java core knowledge points summary! These are some of the things that the interviewer should ask during the interview. These include basics, Java collections, JVMS, multi-threaded concurrency, Spring principles, microservices, Netty and RPC, Kafka, diaries, design patterns, Java algorithms, databases, Zookeeper, distributed caching, data structures, and more.