Recently, I have been reviewing the knowledge of Android, hoping to have a certain ability to protect myself in the cold winter. Now only a part of the summary, the follow-up will be updated, I hope my summary can bring you some help. I hope we can correct the wrong points and make progress together, so that we can stay together in the cold winter.
This article refers to Android advanced light Android development art exploration brain Academy VIP course
JAVA based
Java basic data types
The Java language provides eight basic data types. Six numeric types (four integers (default: int), two floating-point (default: double)), one character type, and one Boolean.
The data type | The size of a | The number of bytes | The default value |
---|---|---|---|
Byte (bytes) | 8 | 1 | 0 |
Short (short) | 16 | 2 | 0 |
Int (integer) | 32 | 4 | 0 |
Long (long shaping) | 64 | 8 | 0 |
Float (single precision) | 32 | 4 | 0.0 |
Double (double) | 64 | 8 | 0.0 |
Char (character) | 16 | 2 | \u000 |
Boolean (Boolean) | – | – | flase |
Meaning of interfaces
- Importance:
Abstract class and Interface are two mechanisms in the Java language that support abstract class definitions. It is these two mechanisms that give Java its powerful object-oriented capabilities.
- Simple normative:
If a project is large, you need an architect who can understand all the business to define the main interfaces that not only tell developers what business needs to be implemented, but also restrict the page naming conventions (into BaseActivity initView(); InitData ())
- Maintain scalability:
Let’s say you’re going to make a sketchpad program, and there’s a sketchpad class that’s going to draw, and you define that class like this. But in the near future, you suddenly find that the class does not satisfy you, and then you have to redesign the class, or worse, you may have to abandon the class, and then there may be references to it somewhere else, which is very troublesome to modify. If you first define an interface, put the drawing function in the interface, and then implement the interface when defining the class, then you just use the interface to reference the class that implements it, and then you just refer to another class, so that you can achieve easy maintenance and extension.
- Security and tightness:
Interfaces are an important means to achieve loose coupling of software, and she describes all the external services of the system without any concrete implementation details. It makes it a little more secure.
The meaning of abstract classes
Abstract classes are often used to represent the abstract concepts derived from the analysis and design of the problem domain. They are the abstractions of a series of concrete concepts that look different but have the same essence
- Because an abstract class cannot instantiate an object, it must have a subclass to implement it before it can be used. In this way, components with the same properties and methods can be abstracting, which is beneficial for code and program maintenance
- When a similar component is created, the properties and methods of the abstract class can be obtained by implementing the abstract class.
The role of inner classes
- Definition: A class placed inside a class is called an inner class
- Function:
- Inner classes do a good job of hiding. Normally, non-inner classes are not allowed to have private protected permissions, but inner classes can.
- The inner class has all the element access rights of the outer class
- Multiple inheritance can be implemented through inner classes
- You can implement calls to two methods of the same name in the same class without modifying the interface
Can a static method of a parent class be overridden by a subclass? Why?
A static method of a parent class cannot be overridden by a subclass. Overrides only use instance methods, not static methods. Methods with the same method name for a subclass and a parent class are called hidden
Java static methods can be overridden in form, but they are not overridden in nature. Because static methods are class-specific, they are not implementation-specific. What class refers to the static method of the corresponding class (static does not need to be declared, can be directly referenced). And the static method is not post-bound; it does so at compile time. In other words. This method does not make polymorphic judgments, only declarations
Inheritance relationships of Java collections
- Collection
- Set: unordered and not repeated
- HashSet: disorderly
- LinkedHashSet: Keep the order
- TreeSet: It needs to be sorted
- HashSet: disorderly
- List: ordered and repeatable
- ArrayList: look up to
- LinkedList: add or delete
- Set: unordered and not repeated
- Map
- A HashMap: disorderly
- LinkedMap: Maintain the order
- TreeMap: Sort is required
- A HashMap: disorderly
HashMap principle, Hash collision, concurrent collection, thread-safe collection and implementation principle
HashMap is different from HashTable
How do I override the HashCode method
ArrayList is different from LinkList
Under what circumstances objects are disposed of by the garbage collection mechanism
- When an object is out of its reference field, the object becomes garbage
- There is no reference beyond the scope of the object, and when the reference is assigned a null value, the referenced object becomes garbage.
- When you create anonymous objects, they become garbage when you run out of them
The difference between processes and threads
Process is the basis of the operating system, is the process that the program runs on a data set, is the basic unit of the system for resource allocation and scheduling. Processes can be thought of as the entities of programs, as well as containers for threads —- advanced light
- A program must have at least one process, and a process must have at least one thread, so the relationship between threads and processes is contained and contained
- The scale of thread partition is smaller than that of process, which makes the concurrency of multithreaded program high.
- The process has independent memory during execution, and multiple threads share the memory, which greatly improves the running efficiency of the program
- Threads are different from processes in their execution. Each individual thread has an entry point through which the program runs. Sequential execution of sequence and program exits. However, threads cannot execute independently and must depend on the application, which provides multiple thread execution control
- From a logical point of view, the meaning of multithreading is that multiple executing parts of a program can be executed simultaneously. However, the operating system does not regard multiple threads as multiple independent applications to achieve process scheduling and management and resource allocation. This is an important difference between a process and a thread
The difference between equals and equals in Java
- The == operator is used to compare primitive data type variables by value, and reference type variables by address
- Equals equals equals equals equals equals equals equals equals equals equals equals equals equals equals equals equals equals equals equals equals equals equals equals
Java Object class method
The GC mechanism
Java reflection mechanism, Java proxy pattern
Java generics
Principle of Synchronized
How Volatile works
The meaning and difference of method lock, object lock and class lock
Methods of thread synchronization: Synchronized, Lock, reentrantLock analysis
Types of Java locks: fair locks, optimistic locks, mutex locks, segmented locks, biased locks, spin locks, etc
Principles and usage of ThreadLocal
Usage and examples of ThreadPool
The difference between wait() and sleep()
- Sleep belongs to Thread and wait belongs to Object
- The sleep method causes the program to suspend execution for a specified time to release the other CPU thread, but its monitoring state remains, and it automatically resumes when the specified time is up. It does not release the object lock
- When the wait method is called, the program waivers the object lock and enters the wait lock pool for the object. The thread enters the wait lock pool only after notify() is called for the object
2 senior JAVA
Java Virtual Machine, Java Runtime, Java GC mechanism (reachability analysis, reference counting)
The full life cycle of a Java object
JVM memory model
Interprocess communication, interthread communication
JVM class loading mechanism
Java reference types
Design patterns: in addition to the usual design patterns, in particular, reflection mechanisms, proxy patterns
HTTP and HTTPS
The Socket protocol implements long connections
TCP and UDP protocols
- TCP connection-oriented (for example, dial up to establish a connection before making a phone call); UDP connectionless. There is no need to establish a connection before sending data
- TCP provides reliable services. That is to say, data transmitted through the TCP connection is error-free, not lost, not repeated, and in order to arrive; UDP does its best to deliver and neither guarantees reliable delivery
- TCP byte stream oriented, in fact TCP treats data as a genetic connectionless byte stream; UDP does not have congestion control. Therefore, congestion on the network does not reduce the sending frequency of hosts (useful for real-time applications, such as inbound IP calls and real-time video conferences).
- Each TCP connection can be point-to-point only. UDP supports 1-to-1, one-to-many, many-to-one, one-to-many, and many-to-many interactive communications
- TCP header cost 20 bytes; The header of UDP has a small overhead of only 8 bytes
- TCP is a reliable channel for logical communication, while UDP is an unreliable channel
HTTP protocol GET and POST concrete implementation
Serialization and deserialization
Implementation principle of thread pool
Database basics: multi-table queries, indexes, database transactions
3 the Android primary
Application Life Cycle
Android Activity lifecycle
The activity lifecycle includes onCreate() onStart () onResume() onPuase() onStop()onDestroy() and onRestart()
- The onCreate ()→ onStart()→onResume () method is called when the Activity is created
User switch to desktop onPause()→ onStop()
The onStop method is not called if the Activity has a transparent theme
- The user returns to Activity onRestart()→onStart()→onResume()
- Jump from Activity A to Activity B
Call A onPuase() B onCreate ()→ onStart()→onResume () A onStop()
- Called by B returning A
Call B onPause() A onRestart()→onStart()→onResume() BonStop() onDestroy()
OnStart onStop and onResume onPause (√)
- OnStart and onStop are called back from whether the Activity is visible
- OnResume and onPause are called back from the perspective of whether the Activity is in the foreground
Activity Start mode
There are currently four launch modes for an activity standard singleTop singleTask singleInstance
- Each time an Activity is started, a new instance is created, and onCreate, onStart, onResume is called and who started the acelasticity The Activity runs on the same stack that started it. (We get an error when we use ApplicationContext to start an Activity in Standard mode because a non-activity Context does not have a task stack So there’s a problem.)
- In this mode, if a new Activity is already at the top of the task stack, the Activity is not recreated and its onNewIntent method is called back. Using this method, we can retrieve the information currently requested (Application scenario Video e-commerce directly returns to the list when the same interface is opened for several times).
- This is a singleTask in which the Activity is not recreated as long as it exists in a stack as many times as it is started. Just like singleTop, the system calls back to its onNewIntent method
- This is a singleTask mode in which an Activity is not recreated as long as it exists in a stack as many times as it is started. Like singleTop, the system calls back to its onNewIntent method
Android interprocess communication
Bundle, file sharing, Messnger, ContentProvider, Socket, etc.
Android Service, IntentService, Service and component communication
The Activity of onNewIntent
Fragment lazy loading implementation, parameter passing and saving
ContentProvider example explanation
BroadcastReceiver uses summaries
What are the operation types of the database and how to import the external database?
- How to use the database
- openOrCreatrDatabase(String path)
- Inherit the SqliteOpenHelp class to manage the database and its older versions (onCreate,onUpgrade). The database is only opened when the program calls the getWritableDatabase() or getReadableDatabase() methods of this class. If no database file is available, the system automatically generates a database.
- Operation type of database: add, delete, change, check CRED
Android messaging
Binder mechanism, shared memory implementation principle
Android event distribution mechanism
Android multithreading implementation: Thread, HandlerThread, AsyncTask, IntentService, RxJava
How ActivityThread works
Nesting sliding implementation principle
RecyclerView and ListView(cache principle, difference, advantages and disadvantages)
View rendering principle, custom View, custom ViewGroup
View, SurfaceView and TextureView
Why does the main thread Looper. Loop not cause an infinite loop
Cache implementation of ViewPager
RequestLayout, Invalidate, postInvalidate
AndroidP new features
Android two types of VMS
ADB common commands
Differences between the Asset directory and the RES directory
Introduction to Android SQLite
4 Android will be
Four major components
Handler principle
View Event Distribution
View Drawing process
multithreading
AsyncTask
Image to load
Network request
Memory optimization
1. A memory leak is a memory that is out of the GC’s control. A memory leak occurs when an object is not needed for collection and another object that is being used holds a reference to it
- The amount of memory available reduces the stress on heap memory
- Degrading application performance such as frequent GC triggering
- A severe fit can cause memory overflow