Android EP3: Network Connection in Android - Interview Question Included
This post will cover 3 semi topics of Network Connection in Android
TCP vs UDP
HTTP vs HTTPS
Some 3rd Libraries: OkHttp, Retrofit2
Related interview questions (2023)
TCP vs UDP
TCP and UDP are 2 primary transport layer protocols that serve different purposes. UDP is a connectionless, unreliable protocol with lower overhead, it’s suitable for real-time applications where speed is more important than reliability. In contrast, TCP is a connection-oriented, reliable protocol with built-in error checking and flow control, TCP is ideal for applications that require guaranteed data delivery and accuracy!
HTTP vs HTTPS
HTTP and HTTPS are protocols used to transmit data over the network.
While HTTP is an unsecured protocol that transmits data in plain text format, it is vulnerable to attack and offers users less trusted privacy.
HTTPS on the other hand, it’s a secured protocol that encrypts data using SSL/TLS, it provides increased protection that against attacks and enhances user privacy. HTTPS also offers users better SEO benefits.
OkHttp, Retrofit2
OkHttp is an Open source provided by Square. OkHttp is designed to be fast, secure, efficient, reliable, and supportive for Android or Java developers. OkHttp is a good solution for Developers if they need an HTTP Client for their apps.
Retrofit2 is an Open source library too, it is built on top of OkHttp. Retrofit2 provides us with a solution to consume RESTful web services. Some advantages of Retrofit2 to use:
Type-safe: You can make sure that the data you’re receiving is in the correct type, this helps to prevent errors, and the code is more readable.
Easy to use: Retrofit2 provides a simple solution to interact with RESTful APIs, the code is very familiar to read and understand.
Wide-range features: Connection Pooling, HTTP/2, Gzip compression, caching, and more to discover.
Related Interview Question (2023)
What is Intercepter in OkHttp, and how does it work internally?
An interceptor in OkHttp is a powerful feature that allows Software Engineers to observe, modify, and retry network requests and responses in their applications. Interceptors are part of the middleware in OkHttp and can be implemented as custom classes that conform to the Interceptor
interface, providing an opportunity to process requests and responses programmatically.
Some use cases of Interceptor
Logging
Caching
Authentication
Error Handling
Rate limit
…
Happy Coding!