Saturday, 7 May 2022

What happens when you type a URL into your browser?

 What happens when you type a URL into your browser?


The diagram below illustrates the steps.

1. Bob enters a URL into the browser and hits Enter. In this example, the URL is composed of 4 parts:

🔹 scheme - 𝒉𝒕𝒕𝒑://. This tells the browser to send a connection to the server using HTTP.
🔹 domain - 𝒆𝒙𝒂𝒎𝒑𝒍𝒆.𝒄𝒐𝒎. This is the domain name of the site.
🔹 path - 𝒑𝒓𝒐𝒅𝒖𝒄𝒕/𝒆𝒍𝒆𝒄𝒕𝒓𝒊𝒄. It is the path on the server to the requested resource: phone.
🔹 resource - 𝒑𝒉𝒐𝒏𝒆. It is the name of the resource Bob wants to visit.

2. The browser looks up the IP address for the domain with a domain name system (DNS) lookup. To make the lookup process fast, data is cached at different layers: browser cache, OS cache, local network cache, and ISP cache. 

2.1 If the IP address cannot be found at any of the caches, the browser goes to DNS servers to do a recursive DNS lookup until the IP address is found (this will be covered in another post). 

3. Now that we have the IP address of the server, the browser establishes a TCP connection with the server.

4. The browser sends an HTTP request to the server. The request looks like this:

𝘎𝘌𝘛 /𝘱𝘩𝘰𝘯𝘦 𝘏𝘛𝘛𝘗/1.1
𝘏𝘰𝘴𝘵: 𝘦𝘹𝘢𝘮𝘱𝘭𝘦.𝘤𝘰𝘮

5. The server processes the request and sends back the response. For a successful response (the status code is 200). The HTML response might look like this: 

𝘏𝘛𝘛𝘗/1.1 200 𝘖𝘒
𝘋𝘢𝘵𝘦: 𝘚𝘶𝘯, 30 𝘑𝘢𝘯 2022 00:01:01 𝘎𝘔𝘛
𝘚𝘦𝘳𝘷𝘦𝘳: 𝘈𝘱𝘢𝘤𝘩𝘦
𝘊𝘰𝘯𝘵𝘦𝘯𝘵-𝘛𝘺𝘱𝘦: 𝘵𝘦𝘹𝘵/𝘩𝘵𝘮𝘭; 𝘤𝘩𝘢𝘳𝘴𝘦𝘵=𝘶𝘵𝘧-8

<!𝘋𝘖𝘊𝘛𝘠𝘗𝘌 𝘩𝘵𝘮𝘭>
<𝘩𝘵𝘮𝘭 𝘭𝘢𝘯𝘨="𝘦𝘯">
𝘏𝘦𝘭𝘭𝘰 𝘸𝘰𝘳𝘭𝘥
</𝘩𝘵𝘮𝘭>

6. The browser renders the HTML content.



Thursday, 4 June 2020

Different Storage options in Android

Different Storage options in Android




Content Providers



·       Consider the structured data added to the device from application1 is not accessible to another application2 present in the same device but the profile photo added to the device by application1 is available to the application2 running in the same device

·       Consider android device as a city, the applications in it are the houses in the city, people in the houses(application) are the data. Now content provider is like an broker in the city(android device). This broker provide access for the people in the city for finding different houses referring as the content provider in the android device provide access for the data in the device for different applications.


Shared Preferences


·       Consider I have an App say a Face book App which I use to log in to my account.

·       Now the very first time I enter my username and password to get access to my account. Say I log out of the application an hour later again I use the same Face book App to login again to my application.

·       I have to enter username and password again to login to my account and I set a theme to my application and other settings on how my app looks in my current phone

·       This is un-necessary because consider I am using my phone to login to the application. So I will always use my phone to login again and again, thus entering my credentials again and again is more work shows it’s not a user friendly app

·       Shared Preferences is very handy in such scenarios where I can use its feature to share my data in a xml file Which physically exists in the Android app installed in my phone which is not destroyed even if the app is closed. Here we can save user preferences data of the current application.

·       As a result next time I open my app in my phone I can see the data automatically filled in the necessary fields and the settings are


File Storage


·       In Android we can use the device storage space to store the data in it for the applications. The type of data involves things such as a text file, image file, video file, audio file etc.

·       As seen in the figure as we can see that there are two places we can do this. One way is to write the raw files into primary /secondary storage. Another way is to write the cache files into the primary/secondary storage.

·       There is also difference between storing raw data and the cache data, the raw data once stored in memory by user has to be explicitly deleted by the user explicitly otherwise it would exist till then. Cache data stored in memory is not a permanent data because the system automatically deletes it if it feels there is shortage of memory.



Internal Storage:

·       Consider a user in an application has stored data in internal storage, then only that user of that application has access to that data on the mobile and that data is automatically deleted when the user uninstalls the application. Speaking of which internal memory is private.

·       The apps internal storage directory is stored using the name package name in a special place in the android file system.

·       Other apps or users of current app have no access to the file set by a particular user and a particular app unless it is explicitly made available to the user for readable/writable access.




SQLite


·       Sqlite is used to store more structured data locally in a mobile where the android app is running. Structured data involves as of which shown in the figure like a student’s information in the form of rows and columns.

·       Sqlite offers similar functionality like Mysql and oracle but with limited functional features. Some of the things involve performing query operations on tables. There are features though like creating views but also some features are not available like stored procedure.

·       Sqlite is very helpful in storing complex and large data which can be downloaded once and can be used again and again until the application is running. When the application is closed the sqlite database is also destroyed.


Putting all the pieces together



 

Monday, 7 January 2019

Comparable Vs Comparator

https://www.javatpoint.com/difference-between-comparable-and-comparator

Friday, 30 November 2018

Thread Pool executor good explanation

https://www.youtube.com/watch?v=NEZ2ASoP_nY&index=4&list=PLhfHPmPYPPRl0LntrCBnQD5ln6lnqqoms

Saturday, 20 October 2018

IPC using messenger

Service Class Implementation:

https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/app/MessengerService.java

Activity Class Implementation:

https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/app/MessengerServiceActivities.java

Friday, 19 October 2018