java ultra-detailed surface after finishing (continually updated) 2019.12.18

Ready to move in the spring of 2020, hard to force students preparing for the First Edition

Java SE

Please talk about how Java is supported regular expression operations?

The Java String class provides support for regular expression operations, including: matches (), replaceAll (), replaceFirst (), split (). In addition, Java can be represented by the Pattern class regular expression object, which provides a rich API for all kinds of regular expression operations, such as:

import java.util.regex.Matcher;
import java.util.regex.Pattern;
class RegExpTest {
    public static void main(String[] args) {
        String str = "成都市(成华区)(武侯区)(高新区)";
        Pattern p = Pattern.compile(".*?(?=\\()");
        Matcher m = p.matcher(str);
        if(m.find()) {
            System.out.println(m.group());
        }
    }
}

Please briefly describe regular expressions and their uses.

When programming processing strings, there is often a need to find some complex rules in line with the string. Regular Expression tool is used to describe these rules. In other words, the regular expression is to record the code text rule. For more information on computer processing time is not a value but a string, a regular expression and string matching process is performed when the most powerful tool.

Please compare the Java and JavaSciprt?

JavaScript and Java are two developed two different products. Java is a former Sun Microsystems has introduced object-oriented programming language, particularly suitable for Internet application development; and JavaScript is Netscape's products Netscape browser in order to expand the development of a function can be embedded in Web pages running Object-based and event-driven interpretive language. JavaScript is the predecessor LiveScript; and the Java language, formerly known as Oak.
Next, the similarities and differences between the two languages to make the following comparison:

  • Object-based and object-oriented: Java is a true object-oriented language, even the development of simple procedures, you must design objects; JavaScript is kind of scripting language that can be used to make the network independent, user interaction with complex software. It is an object (Object-Based) based and event-driven (Event-Driven) programming language, which itself provides a very rich internal object for designers to use.
  • Interpretation and compilation: Java source code before execution, must be compiled. JavaScript is an interpreted programming language, its source code need not compiled, interpreted by the browser execution. (Almost all browsers currently use the JIT (time compiler) technology to enhance the operating efficiency of JavaScript)
  • Strongly typed variables and types of weak variables: Java strongly typed variable checking that all variables before compiling must make a statement; JavaScript variables are weakly typed, even before the use of variables can silence Ming, JavaScript interpreter checks at run time inferred data type.
  • Code format is not the same.

How to jump out of the current multiple nested loops in Java?

Before adding a tag outermost loop such as A, then break A; can jump out of multiple loops.
(In Java support tabbed break and continue statements, the role somewhat similar to C and C ++ goto statement, but like to avoid using goto the same, you should avoid using tabbed break and continue, because it will not let you program becomes more elegant, many times even have the opposite effect, so this syntax is not really know better)

Talk about difference and & & &?

& Operator in two ways: (1) bit and; (2) a logical AND. && operator is shorted and operation.
&& is called short-circuit operation is because, if the value of the expression on the left && is false, the expression on the right will not be operational.

Examples:
For example when determining Login User authentication is not null and not an empty string, should be written as:! Username = null && username.equals ( ""), both the order can not be exchanged, but can not use the & operator! because if the first condition is not satisfied, equals the string can not be compared or will cause a NullPointerException.

int and Integer What is the difference? What is the automatic entry box?

Java is a nearly pure object-oriented programming language, but in order to facilitate the programming or the introduction of the basic data types, but in order to be able to these basic data types as object operation, Java for each elementary data types introduced corresponding type of packaging ( wrapper class), int wrapper class is Integer, from the introduction of the automatic start Java5 boxing / unboxing mechanism, so that the two can be interchangeable.

Autoboxing Java compiler is between basic data types and the corresponding type of object wrappers do a conversion. For example: the int converted into Integer, double converted to Double, and so on. On the other hand is the automatic unpacking.

Please talk about how a certain output encoded string? Such as iso8859-1 etc.

Public String translate (String str) {
     String tempStr = “”;
     try {
     tempStr = new String(str.getBytes(“ISO-8859-1″), “GBK”);
     tempStr = tempStr.trim();
     }
     catch (Exception e) {
     System.err.println(e.getMessage());
     }
     return tempStr;
 }

Please explain the difference between string and stringBuffer, stringBuilder of

  • Once the contents of the String class declaration is unchangeable, the only change in its memory points, while the contents of the object StringBuffer class can be changed. String class is immutable class, any change to the initiator generates a new String String object;
  • For StringBuffer, not directly applicable to complete instantiation of an object image by way of assignment String, it must be done by way of the constructor.
  • When the StringBuffer string processing is performed, it does not generate a new object in memory is superior to the use of string class. So in actual use, if a string is often necessary to make changes, such as inserting, deleting, etc., use StringBuffer to be more suitable for some.
  • StringBuilder, the biggest difference between StringBuffer StringBuilder is not thread-safe method
  • Compared to the StringBuffer StringBuilder has a speed advantage, it is recommended to use the StringBuilder class in most cases, but in the case of application requires thread-safe, you must use the StringBuffer class.

Please talk about Big O notation (big-O notation)

Large O symbol indicates the performance asymptotically (n -> infinity) in the worst case.
Big O when describing elements of the data structure increases, the size and performance of the algorithm how good in the worst scenario.
It may be generally described and space complexity of a time complexity of the algorithm.

You talk about the difference between arrays (Array) and list (ArrayList) of? When should I use Array instead of ArrayList?

Array and ArrayList differences:

  • Array can contain primitive types and object types, ArrayList only contains the object type.
  • Array size is fixed, the size of the ArrayList is dynamic.
  • ArrayList methods and provides more features, such as: addAll (), removeAll (), iterator () and the like.
  • For basic types of data, using an automatic packing set to reduce the coding effort. However, when dealing with the basic data types of fixed size, in this way is relatively slow.

Therefore, if the number of uncertain elements, using the ArrayList;
if a fixed number of elements, and the basic data types, arrays may use a faster rate, no automatic boxing and unboxing.

Please explain what you are passed by value and pass by reference?

Value is passed to the basic variables in terms of passing a copy of the variable change does not affect copies of the original variables
passed by reference generally to object variable in terms of passing a copy of the address of the object, and not the original object itself. Therefore, a reference to the object to operate simultaneously changing the original object.

Could you explain why there is 4.0-3.6 = 0.40000001 this phenomenon?

This reason is simple: not accurately binary decimal binary decimal expression 10, the conversion in the first calculation process computer 10 is a binary decimal binary in the calculation, the process error occurred.

Tell us about the advantages and disadvantages of Lamda expression.

advantage:

  1. concise.
  2. Very easy to parallel computing.
  3. It may represent the future of programming trends.

Disadvantages:

  1. If not parallel computing, many times faster than the conventional speed is not calculated for loop. (Parallel computing is sometimes necessary to warm up before the show efficiency advantages)
  2. Not easy to debug.
  3. If other programmers did not learn lambda expressions, code is not easy for programmers to understand other languages.

Java, ==, equals and hashCode differences and relations

Reference blog: https://blog.csdn.net/justloveyou_/article/details/52464440

Please explain what you sign "==" is the comparison?

"==" memory address compare two objects, if two objects are identical reference (point to the same address), the operator returns true.

"==" If both sides of the basic type, the value is a comparison for equality.

So if you want to compare whether the two strings are the same, to use the equal () method.

Please elaborate case equals () method

To a class does not override, it equals () method is the address comparison object.

1,来源  
    equals方法是基类Object中的实例方法,因此对所有继承于Object的类都会有该方法。   
    Object类中equals方法的实现:
    public boolean equals(Object obj) {
        return (this == obj);
    }
    很显然,在Object类中,equals方法是用来比较两个对象的引用是否相等,即是否指向同一个对象。
2,equals方法的作用
    初衷 : 判断两个对象的 content 是否相同
    必要的时候,我们需要重写该方法,避免违背本意,且要遵循一些原则
    例子:String 类重写了 equals 方法
    使用equals方法,内部实现分为三个步骤:
        先 比较引用是否相同(是否为同一对象),
        再 判断类型是否一致(是否为同一类型),
        最后 比较内容是否一致
    Java 中所有内置的类的 equals 方法的实现步骤均是如此,特别是诸如 Integer,Double 等包装器类。
    
    要遵循的原则:
    对称性: 如果x.equals(y)返回是“true”,那么y.equals(x)也应该返回是“true” ;
    自反性: x.equals(x)必须返回是“true” ;
    类推性: 如果x.equals(y)返回是“true”,而且y.equals(z)返回是“true”,那么z.equals(x)也应该返回是“true” ;
    一致性: 如果x.equals(y)返回是“true”,只要x和y内容一直不变,不管你重复x.equals(y)多少次,返回都是“true” ;
    对称性: 如果x.equals(y)返回是“true”,那么y.equals(x)也应该返回是“true”。
    任何情况下,x.equals(null)【应使用关系比较符 ==】,永远返回是“false”;x.equals(和x不同类型的对象)永远返回是“false”

Please elaborate under hashCode method

1、hashCode 的来源 
  hashCode 方法是基类Object中的实例native方法,因此对所有继承于Object的类都会有该方法。 
   
  在 Object类 中的声明(native方法暗示这些方法是有实现体的,但并不提供实现体,
  因为其实现体是由非java语言在外面实现的):
  
    public native int hashCode();

2、hashCode 简述 
    在 Java 中,由 Object 类定义的 hashCode 方法会针对不同的对象返回不同的整数。
    (这是通过将该对象的内部地址转换成一个整数来实现的,但是 JavaTM 编程语言不需要这种实现技巧)。
    
    要想进一步了解 hashCode 的作用,我们必须先要了解Java中的容器,因为 HashCode
    只是在需要用到哈希算法的数据结构中才有用,比如 HashSet, HashMap 和 Hashtable。
    
    数组+链表的结构下:
    先调用这个元素的 hashCode 方法,然后根据所得到的值计算出元素应该在数组的位置。
    如果这个位置上没有元素,那么直接将它存储在这个位置上;
    如果这个位置上已经有元素了,那么调用它的equals方法与新元素进行比较:相同的话就不存了,
    否则,将其存在这个位置对应的链表中(Java中HashSet,HashMap和Hashtable的实现总将元素放到链表的表头)。

Override equals and hashcode methods

Premise: Speaking hashCode equals method would have to say, both of which are Object class method. Since Object class is the base class for all classes, so all the class can override the two methods.

  • Principle 1: If x.equals (y) returns "true", then x and y hashCode () must be equal;
  • Principle 2: If x.equals (y) returns "false", then the x and y hashCode () possibly equal, there may be unequal;
  • Principle 3: If x and y hashCode () not equal, then x.equals (y) would return to "false";
  • Principle 4: In general, equals this method is invoked by users, but the average user will not hashcode method to call;
  • Principle 5: When an object type as an element of a collection of objects, the object should have its own equals () and hashCode () design, but also to comply with the previously mentioned several principles.

String class overrides hashCode () method, which hash address object is not necessarily the actual memory addresses.

Please explain hashCode () and equals () method What is the connection?

➀ equal (same) object must have equal hash code (or hash code).
➁ hashCode if two objects are the same, they are not necessarily the same.

Section

  • hashcode system is used to quickly search target
  • equals method used to determine whether the object is intended to coincide reference
  • When overriding the equals method and hashcode methods, member variables used in the equals method must also be used in the hashcode method, but the former as a comparative term, as the latter generates a summary of the information items, on the nature of the data used is the same, so as to ensure consistency between the two

Object if you please explain to rewrite hashCode (), then, hashCode () How calculated?

Object hashcode method is a local method, that is, using c or c ++ language implementation, the method returns an object memory address.

Guess you like

Origin www.cnblogs.com/baizihua/p/12061503.html