Although these 70 interview questions made people scalp numb, but I got 3 big factory offers

Talk about understanding the command mode

Encapsulate a request as an object, so that users can use different requests to parameterize customers; queue requests or record request logs, and support reversible operations.

When to use:

  • The program needs to specify, arrange, and execute requests at different times.
  • The program needs to provide an undo operation.
  • The program needs to support macro operations.

advantage:

  • In the command mode, the requester (Invoker) does not directly interact with the receiver (Receiver), and the requester (Invoker) does not contain the receiver (Receiver) reference, thus completely eliminating the coupling between each other.
  • The command mode satisfies the "open-close principle". If you add a new specific command and the recipient of the command, the caller can use the new command object without modifying the caller's code; conversely, if you add a new caller, you do not have to modify the existing specific command and receiver, new The additional callers can use the existing specific commands.
  • Since the requester's request is encapsulated into a specific command, then the specific command can be saved to a persistent medium, and the specific command can be re-executed when needed. Therefore, the command mode can be used to record logs.
  • Use the command mode to queue the requester's "request". Each request corresponds to a specific command, so these specific commands can be executed in a certain order.

An object has multiple operations, but we don't want the caller (requester) to use it directly, we add an additional object, and then let the caller use those operations through this object. For example, we have a class that can create or delete files on the disk (receiver), but we do n’t want to provide them directly to others (requesters), so we create corresponding commands for its various operations

//接收者
public class MakeFile {
  //新建文件
  public void createFile(String name) throws IOException{
    File file = new File(name);
    file.createNewFile();
  }
  //删除文件
  public boolean deleteFile(String name){
    File file = new File(name);
    if(file.exists()&&file.isFile()){
      file.delete();
    return true;
  }
     return false;
  }
}
//命令接口
public interface Command {
  void execute(String name) throws Exception;
}
//新建文件命令
public class CommandCreate implements Command {
  MakeFile makeFile;
  public CommandCreate(MakeFile makeFile) {
    this.makeFile = makeFile;
  }
  @Override
  public void execute(String name) throws Exception {
    makeFile.createFile(name);
  }
}
//删文件命令
public class CommandDelete implements Command{
  MakeFile makeFile;
  public CommandDelete(MakeFile makeFile) {
    this.makeFile = makeFile;
  }
  @Override
  public void execute(String name) throws Exception {
    makeFile.deleteFile(name);
  }
}
//请求者
public class Client {
  Command command;
  public Client setCommand(Command command){
    this.command = command;
    return this;
  }
  public void executeCommand(String name) throws Exception{
    if(command==null)
    throw new Exception("命令不能为空!");
    command.execute(name);
  }
}
public class Test {
public static void main(String args[]) throws Exception{
  //接收者
  MakeFile makeFile = new MakeFile();
  //命令
  CommandCreate create = new CommandCreate(makeFile);
  CommandDelete delete = new CommandDelete(makeFile);
  //请求者
  Client client = new Client();
  //执行命令
  client.setCommand(create).executeCommand("d://test1.txt");
  client.setCommand(create).executeCommand("d://test2.txt");
  client.setCommand(delete).executeCommand("d://test2.txt");
  }
}//执行完后在D盘会有一个test1.txt的文件,test2.txt本页创建了,不过又被删除了

The command mode should not be abused, for example: using this mode, there will be more objects (commands).

Briefly describe the difference between TCP and UDP

tcp and udp are the protocols in the transport layer of the OSI model. TCP provides reliable communication transmission, while UDP is often used to let broadcast and detail control to the communication transmission of the application.

The difference between the two is roughly as follows:

  • tcp is connection-oriented, udp is non-connection-oriented, that is, there is no need to establish a link before sending data;
  • tcp provides reliable service (data transmission), udp cannot guarantee;
  • tcp is for byte streams, udp is for packets;
  • TCP data transmission is slow, udp data transmission is fast;

Android network data encryption method

Symmetric encryption means that both the encrypted and decrypted data use the same key, and the algorithm in this respect is DES.

Asymmetric encryption , encryption and decryption use different keys. Before sending data, you must first agree with the server to generate a public key and a private key. Data encrypted with the public key can be decrypted with the private key, and vice versa. The algorithm in this regard is RSA. Both ssh and ssl are typical asymmetric encryption.

The difference between Http and Https

HTTP : HyperText Transfer Protocol (HyperText Transfer Protocol) is currently the most widely used network transfer protocol on the Internet. All WWW files must comply with this standard. The original purpose of designing HTTP was to provide a method for publishing and receiving HTML pages. It is mainly a client and server request and response standard (TCP), but it is being replaced by HTTPS.

HTTPS : Hypertext Transfer Protocol over Secure Socket Layer (Hypertext Transfer Protocol over Secure Socket Layer) or Hypertext Transfer Protocol Secure (Hypertext Transfer Protocol Secure) , which was created by Netscape in 1994 and is based on security The target HTTP channel. Simply put, it is a secure version of HTTP. That is, the SSL layer is added under HTTP, and the security foundation of HTTPS is SSL. Therefore, the encrypted detailed content requires SSL.

The main difference:

  1. URL: http usually starts with http: //, and https starts with https: //.
  2. Certificate: http does not require a certificate; https needs to apply for a certificate to ca. Generally, there are few free certificates, so a certain fee is required.
  3. Security: http information is transmitted in clear text; https is a secure SSL encrypted transmission protocol.
  4. Port: http The default port is 80; https is 443.
  5. Connection: http connection is very simple and stateless; https protocol is a network protocol built by SSL + http protocol that can carry out encrypted transmission and identity authentication, so it will be slower to establish a connection for the first time, but it is safer than http protocol.

Attachment: https advantages and disadvantages:

advantage:

  1. The certificate can be used to trust the server more.
  2. Safer and tamper-proof.

Disadvantages:

  1. https requires a certificate.
  2. Because the transmission is encrypted, it will increase the CPU consumption to a certain extent.
  3. Due to the need of https to return the key and confirm the encryption algorithm, it will be slower to establish the connection for the first time.
  4. Bandwidth consumption will increase, and the pressure on the server will be great.

Advanced Http: https://mp.weixin.qq.com/s/3TaonTzAsqqLLbJ-yrwNdw

进阶Https:https://mp.weixin.qq.com/s/lCr7NuQNLQh4Ake8yXorxg?scene=25#wechat_redirect

Briefly describe the apk packaging process

  1. Package the resource file and generate R.java file Input: res file, Assets file, AndroidManifest.xml file, Android basic class library (Android.jar file) Output: R.java, resources.arsc Tool: aapt tool Location: SDK \ build -tools \ 29.0.0 \ aapt.exe
  2. Processing aidl files, generating corresponding java file input: source code file, aidl file, framework.aidl file output: corresponding .java file tool: aidl tool tool location: SDK \ build-tools \ 29.0.0 \ aidl.exe
  3. Compile the project source code, generate the corresponding class file input: source code file (including .java file generated by R.java and AIDL), library file (jar file) output: .class file tool: javac tool tool location: Java \ jdk1.8.0 _201 \ bin \ javac.exe
  4. Convert all class files and generate classes.dex file Input: .class files (including Aidl generated .class files, R generated .class files, source files generated .class files), library files (.jar files) Output: .dex File tool: javac toolTool location: Java \ jdk1.8.0_201 \ bin \ javac.exe
  5. Package to generate apk file input: packaged resource file, packaged class file (.dex file), libs file (including .so file) Output: unsigned .apk file tool: apkbuilder.bat tool has been abandoned, changed to sdklib .jar tool location: E: \ SDK \ tools \ lib \ sdklib.jar
  6. Sign input to apk file: unsigned .apk file output: signed .apk file tool: jarsigner tool apksigner tool tool location: Java \ jdk1.8.0_201 \ bin \ jarsigner.exe SDK \ build-tools \ 29.0.0 \ lib \ apksigner.jar
  7. Align the signed apk file input: signed .apk file output: aligned .apk file tool: zipalign tool tool location: SDK \ build-tools \ 29.0.0 \ zipalign.exe

Note: The tool location is based on the win platform. Reference connection:

https://developer.android.com/studio/build/index.html?hl=zh-cn#build-processhttps://blog.csdn.net/jiangwei0910410003/article/details/50402000

The article is not easy. If you like this article, or if it is helpful to you, I hope you can like it, forward it, and follow. The article will be updated continuously. Absolutely dry goods! ! !

Published 34 original articles · Like1 · Visits 756

Guess you like

Origin blog.csdn.net/Android725/article/details/105374988