Android TV development! Three years of experience in Android development, a summary of general popular frameworks

Preface

Since graduating in 18 years, I have worked for two companies and have done a few large and small projects. I am very grateful to my two bosses for giving me a lot of guidance on my android growth path and the relationship between teachers and friends.

I have participated in interviews with many companies since years ago, and have also received offers from several giants, as well as from other companies. Summarizing the experience is also a review and summary of the past.

Network: layered model, TCP, UDP, HTTP, HTTPS

Hierarchical model

  • Application layer: responsible for handling specific application details, such as HTTP, FTP, DNS
  • Transport layer: Provide end-to-end basic communication for two hosts, such as TCP, UDP
  • Network layer: control packet transmission, routing, etc., such as IP
  • Link layer: operating system device drivers, network card related interfaces

UDP

  • UDP header structure: source port, destination port, length field, checksum
  • Features: unreliable, disorderly, message-oriented, fast, lightweight
  • Applicable scenarios: suitable for instant messaging, video calls, etc.
  • Application: DHCP, DNS, QUCI, VXLAN, GTP-U, TFTP, SNMP

TCP

  • TCP header structure: source port, destination port, sequence number, confirmation sequence number, SYN/ACK and other status bits, window size, checksum, emergency pointer
  • Features: Oriented to byte stream, with congestion and flow control, reliable, orderly, slow, and heavier. Flow control and congestion control are realized through sliding window
  • Applicable scenarios: file transfer, browser, etc.
  • 应用:HTTP、HTTPS、RTMP、FTP、SMTP、POP3
  • Three handshake:
1\. C->S:SYN,seq=x(你能听到吗?)
2\. S->C:SYN,seq=y,ack=x+1(我能听到,你能听到吗?)
3\. C->S:ACK,seq=x+1,ack=y+1(我能听到,开始吧)

两方都要能确保:我说的话,你能听到;你说的话,我能听到。所以需要三次握手
复制代码
  • Wave four times:
1\. C->S:FIN,seq=p(我说完了)
2\. S->C:ACK,ack=p+1(我知道了,等一下,我可能还没说完)
3\. S->C:FIN,seq=q,ACK,ack=p+1(我也说完了)
4\. C->S:ACK,ack=q+1(我知道了,结束吧)

S 收到 C 结束的消息后 S 可能还没说完,没法立即回复结束标示,只能等说完后再告诉 C :我说完了
复制代码

HTTP

  • Hypertext transfer protocol, clear text transmission, default port 80
  • POST and GET: Get parameters are placed in the url; Post parameters are placed in the request body
  • Web page access process: DNS domain name resolution, TCP three-way handshake to establish a connection, initiate HTTP request

HTTPS

  • The default port is 443, and the HTTP transmission data is encrypted using the SSL protocol, which is safe
  • Encryption process: Client/Server generates a key through asymmetric encryption, and then uses this key to symmetrically encrypt the transmission data

Algorithms: data structure, commonly used algorithms

data structure

  • Array, linked list
  • Stack, queue
  • Hash table
  • Tree, pile, figure

Commonly used algorithms

  • Sort
  • Double pointer, sliding window, string
  • Recursion, divide and conquer, dichotomy
  • Backtracking, greedy, dynamic planning

Java basics: StringBuilder, generic erasure, Exception, IO, container

StringBuilder

  • StringBuffer is thread-safe, StringBuilder is not thread-safe
  • +In fact, it is realized by StringBuilder, so the non-loop body can be used directly +, but the loop body cannot, because StringBuilder will be created frequently
  • String.concat is essentially a new String, which is inefficient and time-consuming to sort: StringBuilder <StringBuffer <concat <+

Generic erasure

  • Generics related to class structure such as modified member variables will not be erased
  • Container generics will be erased

Exception 和 Error

  • Both Exception and Error inherit from Throwable
  • Error mostly refers to unrecoverable error states, such as OOM, so there is no need to capture
  • Exception 分为 CheckedException 和 UnCheckedException
    • CheckedException: must be explicitly caught and checked by the compiler, such as io operations
    • UnCheckedException: No need to display capture, such as null pointer, array out of bounds, etc.

IO 、 NIO 、 OKIO

  • IO is stream-oriented, processing one byte at a time, NIO is buffer-oriented, generating or consuming one data block at a time
  • IO is blocking, NIO is non-blocking
  • NIO supports memory mapping
  • Compared with io and nio, okio has simpler and easier api
  • okio supports timeout mechanism
  • okio introduces ByteString space for time to improve performance
  • Okio uses the segment mechanism for memory sharing, saving copy time consumption

ArrayList、LinkedList

  • ArrayList
    • Based on array implementation, fast search: o(1), slow addition and deletion: o(n)
    • The initial capacity is 10, and the capacity is expanded through the System.arrayCopy method
  • LinkedList
    • Realization based on doubly linked list, slow search: o(n), fast addition and deletion: o(1)
    • Encapsulates calls to queues and stacks

HashMap 、HashTable、HashSet

  • HashMap (allow key/value to be null)

    • Based on the implementation of arrays and singly linked lists, the array is the main body of the HashMap; the linked list exists to resolve hash conflicts and stores the entity that combines key and value
    • The array index is obtained by key.hashCode (also hashed twice), and indexed by key.equals on the linked list
    • When the hash collision falls in the same bucket, it is directly placed at the head of the linked list (after java1.8, it is placed at the tail)
    • When the number of linked lists in JAVA 8 is greater than 8, it will be converted to red-black tree storage, and the search time will change from O(n) to O(logn)
    • The length of the array is always 2 to the power of n: In this way, the remainder can be achieved through bit operations, so that the index can fall within the range of the array length
    • The load factor (default 0.75) indicates how much fill ratio is added to for expansion. The fill ratio is large: the linked list is longer and the search is slow; the fill ratio is small: the linked list is short and the search is fast
    • When expanding the capacity, directly create twice the length of the original array, and then hash the original object to find the new index, and re-place it
  • HashTable (key/value is not allowed to be null)

    • The data structure is the same as HashMap
    • Thread safe
  • HashSet

    • Based on the HashMap implementation, the element is the key of the HashMap, and Value is passed in a fixed value

ArrayMap、SparseArray

  • ArrayMap

    • Implementation based on two arrays, one to store hash; one to store key-value pairs
    • The array storing the hash is ordered, and the binary search is used when searching
    • When a hash conflict occurs, the key-value pair array is stored continuously, and the search is also indexed by key.equals. When it is not found, the key-value pair array with the same hash value is traversed backwards and then forwards.
    • When expanding capacity, unlike HashMap directly double, the memory utilization is high; there is no need to rebuild the hash table, just call system.arraycopy array copy, which has higher performance
    • Not suitable for storing large amounts of data (below 1000), because binary search is much slower than red-black trees when the amount of data is large
  • SparseArray

    • Based on ArrayMap, the key can only be a specific type

Concurrent collection

  • ConcurrentHashMap
    • The data structure is the same as HashMap, or an array plus a linked list
    • Using segment lock technology, unlike HashTable, which directly synchronizes put and get operations without brain
    • The get operation is not locked, because the value is modified with volatile to ensure visible rows, and the performance is very high
    • After java1.8, the segment lock is removed, and CAS optimistic lock plus synchronized is used to achieve

LRUCache principle

  • Implementation of LinkedHashMap based on the order of access, the most recently accessed will be ranked last

At last

Taking into account the length of the article, I made these questions and answers, as well as the questions I encountered in many years of interviews, and some interview materials into PDF documents. If you need a friend, you can privately mail me [Interview] to receive it for free

Click here to receive a summary of Android interview materials

BC%9F%E5%A6%82%E4%BD%95%E9%9D%A2%E8%AF%95%E6%8B%BF%E9%AB%98%E8%96%AA%EF%BC%81.md)**

[External link pictures are being transferred...(img-5FWI5KPr-1614154915374)]

[External link image is being transferred...(img-OQJb2MiB-1614154915378)]

Friends who like it can follow, forward, and like thank you!

Guess you like

Origin blog.csdn.net/chayel123/article/details/114026567