Networking based Android interview questions and answers

Which method to open Http connection to an Uri?

A) url.openConnection()

To get data from Webserver to Android application, which of the following class you need to use to establish connection?

A) HttpURLConnection

02 Android JSON Parsing

What is JSON?

A) JSON is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML

What is the name of Android class do we need to use to build up an JSON object?

A) JSONObject

Assume that we have an Android object named stored in reader variable, and inside it has a child object named?

A) JSONObject mainObj = reader.getJSONObject("main");

What is JsonParsing?

Ans: JSON stands for Javascript object notation, a format for data exchange from the server. In Android, when we work with the online database, we need to convert table data into JSON data, and to manipulate those data Android provides a different way for JSON Parsing.

HTTP Url connection, Retrofit, Volly etc.

Write code for fetching JSON array in Android?

Ans: JSONArray array = new JSONArray(result);

for(int i=0;i<array.length;i++)

{

JSONObject object = array.getJSONObject(i);

}

03 GSON :

What is GSON in Android?

Ans: GSON is converter library, which converts JSON array and objects when we work with a retrofit.

Difference between Rest and Soap?

Answer:

Rest:

  1. Uses XML, text, HTML and Jason format to send and receive data.
  2. Security is less than soap
  3. Transfers data through HTTP only.
  4. Performance is better than Soap since it uses less CPU
  5. It doesn’t need much bandwidth
  6. Rest can make use of Soap

Soap:

  1. Uses XML only for sending and receiving data.
  2. It is more secure than rest.
  3. Transfers data through HTTP ,SMTP,FTP etc.
  4. Performance is not better than rest.
  5. It needs more bandwidth for users.
  6. Soap cannot use Rest.

What’s Volley and what’s positive and negative with it?

A) An HTTP library that makes networking for the app easier.
Very good at handling multiplie network connections.
Not god for large download or streaming operations.

Advantage of Retrofit over Volley?

A) Retrofit is type-safe. Type safety means that the compiler will validate types while compiling, and throw an error if you try to assign the wrong type to a variable.

Advantage of Volley over Retrofit?

A) Android Volley has a very elaborate and flexible cache mechanism. When a request is made through Volley, first the cache is checked for Response. If it is found, then it is fetched and parsed, else, it will hit Network to fetch the data. Retrofit does not support cache by default.

What is the advantage of using Retrofit over AsyncTask?
A) Retrofit reduces boiler plate code by internally using GSON library which helps parsing the json file automatically. Retrofit is a type safe library. This means - it checks if wrong data type is assigned to variables at compilation time itself. More use-cases at: https://stackoverflow.com/a/16903205/3424919

How to handle multiple network calls using Retrofit?
A) In Retrofit, we can call the operations asynchronously by using enqueue() method where as to call operations synchronously, we can use execute() method. In addition, we can use zip() operator from RxJava to perform multiple network calls using Retrofit library.

HOW WOULD YOU UPLOAD MULTIPLE FILES TO AN HTTP SERVER IN AN SINGLEHTTP REQUEST?

Use MIME Multipart. It was thought to send different fragments of information in a Single request and is integrated with most of the native HTTP clients.

Aaaaaaat


Comments

Popular posts from this blog

Jetpack Compose based Android interview and questions

Null safety based Kotlin interview questions and answers

CustomView based Android interview questions and answers