Java interview technology point

JAVA basis (there are eggs at the end of the text)

JAVA in several basic types, how many bytes each? Can

这里写图片描述  下图单位是bit,非字节 1B=8bit 这里写图片描述

String be inherited? why?

不可以, because the String class has a final modifier, and the final modified class cannot be inherited, and the implementation details are not allowed to change. Usually we define String str=”a”; in fact, there is still a difference between String str=new String(“a”).

The default is to call String.valueOf to return the String instance object. As for which one to call depends on your assignment, such as String num=1, the call is Public static String valueOf(int i) { Return Integer.toString(i); }

The latter is called the following part: Public String(String original) { This.value = original.value; This.hash = original.hash; } Finally our variables are stored in a char array Private final char value[];

also recommended technical tutorials for everyone:

String, Stringbuffer, StringBuilder.

String String constants (final modifiers, not inherited), String is a constant that cannot be changed after creation. (String objects can be created via StringBuffer and StringBuilder (usually two string manipulation classes).) StringBuffer String variable (thread safe), which is also in the final category, is not allowed to be inherited. Most of the methods are synchronized, including the commonly used Append method, which is also synchronized (synchronized). It has been around since jdk1.0. Its toString method performs object caching to reduce element copy overhead. Public synchronized String toString() { If (toStringCache == null) { toStringCache = Arrays.copyOfRange(value, 0, count); } Return new String(toStringCache, true); }

StringBuilder String variable (non-thread safe) It has been around since jdk1.5. Like StringBuffer, the same interface and class are inherited and implemented. The method is basically the same except that it is not modified by synch. The difference is that when the last toString, it will return a new object directly. Public String toString() { // Create a copy, don’t share the array Return new String(value, 0, count); What is the difference between }

ArrayList and LinkedList.

ArrayList and LinkedList both implement the List interface, with the following differences: 1, ArrayList is an index-based data interface, the bottom layer is an array. It can randomly access elements with O(1) time complexity. Correspondingly, LinkedList stores its data in the form of a list of elements, each element being linked with its previous and subsequent elements. In this case, the time complexity of finding an element is O ( n). 2. Compared to ArrayList, the insertion, addition, and deletion of LinkedList are faster, because when the element is added to any position of the collection, there is no need to recalculate the size or update the index like an array. 3. LinkedList takes up more memory than ArrayList because LinkedList stores two references for each node, one for the previous element and one for the next element.

讲讲类 instantiation order, such as parent class static data, constructor, field, subclass static data, constructor, field, when new, their execution order.

What are the differences between the Map classes, HashMap is thread-safe, and what is the Map used, what are their internal principles, such as storage, hashcode, capacity expansion, default capacity, etc.

hashMap is thread insecure, HashMap is implemented by array + linked list + red black tree (JDK1.8 added red black tree part), using hash table to store, Refer to the link: Why does JAVA8's ConcurrentHashMap give up segmentation locks, what's the problem, if you design, how do you design. Reference:

Is there a sequence of Map implementation classes, and if so, how are they guaranteed to be ordered?

TreeMap and LinkedHashMap are ordered (TreeMap defaults ascending, LinkedHashMap records the insertion order). Reference:

The difference between abstract classes and interfaces, can classes inherit multiple classes, can interfaces inherit multiple interfaces, and classes can implement multiple interfaces?

1. Abstract classes and interfaces cannot be instantiated directly. To instantiate, abstract class variables must point to subclass objects that implement all abstract methods. Interface variables must point to class objects that implement all interface methods. 2, the abstract class to be inherited by the subclass, the interface to be implemented by the class. 3, the interface can only be a method declaration, the abstract class can be used to declare the method, you can also do the method 4, the variables defined in the interface can only be public static constants, the variables in the abstract class are ordinary variables. 5. The abstract methods in the abstract class must all be implemented by the subclass. If the subclass cannot implement the parent class abstract method, then the subclass can only be an abstract class. Similarly, when an interface is implemented, if the interface method cannot be fully implemented, the class can only be an abstract class. 6, the abstract method can only be declared, can not be achieved. Abstract void abc(); cannot be written as abstract void abc(){}. 7, there can be no abstract methods in the abstract class 8, if there is an abstract method in a class, then this class can only be an abstract class 9. Abstract methods must be implemented, so they cannot be static or private. 10, the interface can inherit the interface, and can inherit more than the interface, but the class can only inherit from a single root.

What is the difference between inheritance and aggregation?

inheritance refers to the ability of a class (called a subclass, subinterface) to inherit another class (called a parent class, a parent interface), and can add its own new features, inheritance is a class The most common relationship with classes or interfaces and interfaces; in Java such relationships are clearly identified by the keyword extends, which is generally not controversial at design time; 这里写图片描述  聚合是关联关系的一种特例,他体现的是整体与部分、拥有的关系,即has-a的关系,此时整体与部分之间是可分离的,他们可以具有各自的生命周期,部分可以属于多个整体对象,也可以为多个整体对象共享;比如计算机与CPU、公司与员工的关系等;表现在代码层面,和关联关系是一致的,只能从语义级别来区分; 这里写图片描述

tells you that the difference between nio and bio is 啥, talk about the reactor model. The principle of

reflection, the three ways of reflecting the creation of an instance of the class are

reflection, the difference between Class.forName and ClassLoader.

describes several implementations of dynamic agents, respectively speaking the corresponding advantages and disadvantages.

Jdk cglib jdk bottom layer is to use the reflection mechanism, it needs to be based on the interface mode, which is due to Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this); Cglib is based on the asm framework, which implements a non-reflective mechanism for proxying, using space for time, and proxy efficiency is higher than jdk

The difference between proxy and cglib implementation

同上(based on invocationHandler and methodInterceptor)

Why CGlib can implement proxy for interface.


final uses

to write three singleton mode implementations.

How do I automate all hashcode and equals implementations for subclasses in the parent class? What are the advantages and disadvantages of doing this.

Please combine the OO design concept with the role of access modifiers public, private, protected, default in application design.

access modifier, mainly indicating the scope of the modified block, easy to isolate protection

同类同同包包包包类 Different classes of non-subclasses 
  • 1
  • 2

Private √ Default √ √ Protected √ √ √ Public √ √ √ √ Public: The most widely defined modifier in the Java language, commonly referred to as "public". The classes, properties, and methods that are decorated by them are not It can only be accessed across classes and allows cross-package access. Private: The narrowest modifier in the Java language for access restrictions, commonly referred to as "private." The class and attribute modified by it And methods can only be accessed by objects of this class, their subclasses can not be accessed, and even cross-package access is not allowed. Protect: An access modifier between public and private, commonly referred to as a "protective shape." The class that is modified by it, Attributes and methods can only be accessed by methods and subclasses of the class itself, even if the subclasses are accessible in different packages. Default: no access modifier, usually called "default access mode". In this mode, only access in the same package is allowed. ask.

Deep copy and shallow copy difference.

Array and linked list data structure description, the difference between the respective time complexity

error and exception, CheckedException, RuntimeException

Please list 5 runtime exceptions.


In your own code, if you create a java.lang.String object, can this object be loaded by the class loader? Why

says your understanding of the hashCode and equals methods in a java.lang.Object object. In what scenario, you need to re-implement these two methods.


In jdk1.5, generics are introduced, and the existence of generics is used to solve problems. The essence of

gene is the parameterized type, which means that the data type being manipulated is specified as a parameter. The advantage of generics is that type safety is checked at compile time, and all casts are automatic and implicit. In order to improve the code reuse rate

such a.hashcode() What is the use, and What is the relationship between a.equals(b).

hashcode The hashcode() method provides the hashCode value of the object, which is a native method, and the default value returned is the same as System.identityHashCode(obj).

Usually this value is a number consisting of a part of the binary bits of the object header. It has a certain meaning of the object, but it is definitely not the address.

The effect is: use a number to identify the object. For example, in a similar collection class such as HashMap, HashSet, etc., if an object itself is used as the Key, it is necessary to implement Hash writing and searching based on this object. How does the object itself implement this? It is based on a number such as hashcode, and only numbers can be used for calculations and comparisons.

hashcode is unique The hashcode can only be said to be an identifier object. In the hash algorithm, the object can be relatively discrete, so that the data can be quickly narrowed down according to the key when searching for data, but the hashcode is not necessarily unique, so the hash algorithm is positioned. After the specific linked list, you need to cycle through the linked list, and then use the equals method to compare whether the Key is the same.

equals relationship with hashcode Equals equals two objects, then the hashcode must be equal. But two objects with equal hashcode are not equal equals. Https://

Is it possible that 2 unequal objects have the same hashcode.


Java How does the internal work of HashSet work?

JVM Knowledge

Whenever a stack memory overflow occurs.

If the stack depth requested by the thread is greater than the depth allowed by the virtual machine, a StackOverflowError exception will be thrown. If the virtual machine cannot apply for enough memory space while dynamically expanding the stack, an OutOfMemoryError exception is thrown. Reference:

JVM memory structure, Eden and Survivor ratio.

jvm What is the complete GC process, how the object is promoted to the old age, and talk about the main jvm parameters you know.

You know which kinds of garbage collectors, their respective advantages and disadvantages, focus on cms, including principles, processes, advantages and disadvantages

garbage recycling algorithm implementation principle.

When there is a memory overflow, how do you troubleshoot it.

JVM Learn about the memory model, such as reordering, memory barrier, happen-before, main memory, working memory, etc.

Simply talk about the class loader you know.

Talk about the reflection mechanism of JAVA.

What are the JVM parameters for your online application?

-server  Xms6000M  -Xmx6000M  -Xmn500M  -XX:PermSize=500M  -XX:MaxPermSize=500M  -XX:SurvivorRatio=65536  -XX:MaxTenuringThreshold=0  -Xnoclassgc  -XX:+DisableExplicitGC  -XX:+UseParNewGC  -XX:+UseConcMarkSweepGC  -XX:+UseCMSCompactAtFullCollection  -XX:CMSFullGCsBeforeCompaction=0  -XX:+CMSClassUnloadingEnabled  -XX:-CMSParallelRemarkEnabled  -XX:CMSInitiatingOccupancyFraction=90  -XX:SoftRefLRUPolicyMSPerMB=0  -XX:+PrintClassHistogram  -XX:+PrintGCDetails  -XX:+PrintGCTimeStamps  -XX:+PrintHeapAtGC  -Xloggc:log/gc.log

g1 differs from cms in that the throughput priority and response priority garbage collector options.

Cms is a collector that targets the shortest recovery pause time. Implemented based on a mark-and-clear algorithm. Compared with cpu resources, it is easy to cause fragmentation. G1 is a server-oriented garbage collector, which is the default collector of jdk9, based on the mark-finishing algorithm. Can use multi-core, multi-cpu, retain generation, achieve predictable pause, controllable. Http:// Please explain the meaning of the jvm parameter as follows: -server -Xms512m -Xmx512m -Xss1024K -XX:PermSize=256m -XX:MaxPermSize=512m -XX:MaxTenuringThreshold=20 XX: CMSInitiatingOccupancyFraction=80 -XX:+UseCMSInitiatingOccupancyOnly.

Server mode start Minimum heap memory 512m Up to 512m 1m per thread stack space Permanent generation 256 Maximum permanent generation 256 The maximum conversion to the old age inspection times 20 Cms recycling time: 80% memory usage The command JVM does not start the CMS garbage collection cycle based on the data collected at runtime.

Open Source Framework Knowledge

Simply talk about the tomcat structure and its class loader flow.

tomcat How to tune, which parameters are involved.

讲讲 Spring loading process.

Talk about the propagation properties of Spring transactions.

Seven kinds of propagation attributes. Transactional behavior The so-called transaction propagation behavior means that if a transaction context already exists before starting the current transaction, there are several options to specify the execution behavior of a transactional method. The following constants representing the propagation behavior are included in the TransactionDefinition definition: TransactionDefinition.PROPAGATION_REQUIRED: If the transaction currently exists, join the transaction; if there is currently no transaction, create a new transaction. TransactionDefinition.PROPAGATION_REQUIRES_NEW: Create a new transaction and suspend the current transaction if there is a transaction. TransactionDefinition.PROPAGATION_SUPPORTS: If the transaction currently exists, join the transaction; if there is no transaction currently, continue to run in a non-transactional manner. TransactionDefinition.PROPAGATION_NOT_SUPPORTED: Runs in a non-transactional manner, suspending the current transaction if there is currently a transaction. TransactionDefinition.PROPAGATION_NEVER: Runs in a non-transactional manner, throwing an exception if there is currently a transaction. TransactionDefinition.PROPAGATION_MANDATORY: If the transaction currently exists, join the transaction; if there is no transaction, throw an exception. TransactionDefinition.PROPAGATION_NESTED: If a transaction currently exists, create a transaction to run as a nested transaction for the current transaction; if there is currently no transaction, the value is equivalent to TransactionDefinition.PROPAGATION_REQUIRED. Https://

Spring How to manage transactions.

Programming and declarative Same as above

Spring How to configure the transaction (specifically some key xml elements).

Talk about your understanding of Spring, the principle of non-single injection? Its life cycle? The principle of loop injection, the principle of aop implementation, talk about several terms in aop, how they work with each other.

The core components: bean, context, core, singleton injection are created by a singleton beanFactory. The life cycle is enabled by the interface when it is created. The loop injection is through the post processor. Aop is actually a dynamic proxy through reflection. Pointcut, advice, etc. Aop related:

Springmvc DispatcherServlet initialization process.

入口 is the ds configured in web.xml. ds inherits HttpServletBean, FrameworkServlet, and initializes the bean and instance through the init method. The initServletBean is the method to actually complete the context work and bean initialization. Http://


3. Technical tutorial recommended: