1

Is JSON language?

  • TRUE
  • FALSE
  • We can't really call it as a language. It is light weight text-based format used to exchange data between two systems connected in the network. It is an alternative to xml way of transferring data between systems.
  • None are correct

Answer: C We can't really call it as a language. It is light weight text-based format used to exchange data between two systems connected in the network. It is an alternative to xml way of transferring data between systems.
Description: Its full form is JavaScript Object Notion.

2

What are the JSON elements?

  • Number, String, Boolean, null, Array, Object.
  • Number, String, Boolean, Array, Object.
  • String, Array, Object.
  • Number, String, null, Array, Object.

Answer: A Number, String, Boolean, null, Array, Object.
Description:

3

How to communicate the data with an internet server from an android application?

  • If data is less - use name spaces, if data is heavy use - xml.xml is faster than json. so parsing and loading will be fast.
  • If data is less - use name spaces, if data is heavy use - json. json is faster than xml. so parsing and loading will be fast.
  • Option 1 is true, and many web sites and services have more support to xml compared to json.
  • option 2 is true, and many of the web sites and services including twitter, facebook, google, linkedin uses json than xml.

Answer: D option 2 is true, and many of the web sites and services including twitter, facebook, google, linkedin uses json than xml.
Description: for small data - use name spaces, for heavy structured data - use json. json is faster than xml. json has advantage over xml with java script which is sued to update client side web page fastly.

4

HTTP : What is true about HTTP response status code coming from server to android application?

  • i. Status code is available in status line, which contains the result status of server response.
  • ii. If status code is > 400, then it means success from server side.
  • iii. If status code is <= 400, then it means success from server side.
  • i
  • i & iii
  • i & iii
  • none of the above.

Answer: C i & iii
Description: Response status code >=400 means error, else success.

Note : as a simple example, status code 404 is an error "page not found". So error codes are always > 400.

5

What will happen if HTTP Connection code is written in activity's Main thread?

  • i. It may lead to ANR.
  • ii. It wont give any error, but may lead to ANR till 2.3 version. but from 3.0 it is mandatory that all network connections has to happen in separate worker thread. else it will crash at run time with NetworkOnMainThreadException
  • iii. It works fine. No error will come.
  • iv. If we don't use separate background thread from 3.0 version on wards, system will throw run time exception.
  • i
  • ii
  • ii & iii
  • ii & iv

Answer: D ii & iv
Description: The purpose of Main UI thread is to take care of all UI events coming to the screen from the user. All UI is under control of Main thread.
Connecting to internet is a heavy functionality. Basic android rule says don't do more than 1 heavy functionality in Main UI thread. Because it affects UI responsiveness and it may lead to ANR (Application Not Responding) error at run time.
Connecting to internet in main thread, wont give any error till 2.3 version but may lead to ANR at run time.
From 3.0 it is mandatory that all network connections has to happen in separate worker thread else it throws run time exception.
Exception name is : NetworkOnMainThreadException

6

To connect to network from android application which of the blow options I have to use?

  • DefaultHTTPClient
  • HTTPUrlConnection. it is light weight compared to option 1 and 3. so use this one always.
  • DefaultHTTPClient or AndroidHttpClient
  • till before Froyo better to use option DefaultHTTPClient or AndroidHttpClient, but from then on wards better to use HTTPUrlConnection as it has the size advantage over later.

Answer: D till before Froyo better to use option DefaultHTTPClient or AndroidHttpClient, but from then on wards better to use HTTPUrlConnection as it has the size advantage over later.
Description: To connect to internet, till before Froyo better to use DefaultHttpClient or AndroidHttpClient, but from then on wards better to use HTTPUrlConnection as it has the size advantage over later.

7

How to log in to gmail account from android application using HTTP request?

  • DefaultHttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://mail.google.com/");

    List <NameValuePair> params = new ArrayList <NameValuePair> (3);
    params.add(new BasicNameValuePair("Email", "username@gmail.com"));
    params.add(new BasicNameValuePair("Passwd", "password here"));
    params.add(new BasicNameValuePair("signIn", "Sign in"));
    post.setEntity(new UrlEncodedFormEntity(params));
    HttpResponse res = client.execute(post);

    if(res.getStatusLine().getStatusCode() < 400)
    //success
    else
    //fail
  • DefaultHttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://mail.google.com/");

    List <NameValuePair> params = new ArrayList <NameValuePair> (3);
    params.add(new BasicNameValuePair("Email", "username@gmail.com"));
    params.add(new BasicNameValuePair("Passwd", "password here"));
    post.setEntity(new UrlEncodedFormEntity(params));
    HttpResponse res = client.execute(post);

    if(res.getStatusLine().getStatusCode() < 400)
    //success
    else
    //fail
  • DefaultHttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://mail.google.com/");

    List <NameValuePair> params = new ArrayList <NameValuePair> (3);
    params.add(new BasicNameValuePair("Email", "username@gmail.com"));
    params.add(new BasicNameValuePair("Passwd", "password here"));
    post.setEntity(new UrlEncodedFormEntity(params));
    HttpResponse res = client.execute(post);

    if(res.getStatusLine().getStatusCode() >= 400)
    //success
    else
    //fail
  • DefaultHttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://mail.google.com/");

    List <NameValuePair> params = new ArrayList <NameValuePair> (3);
    params.add(new BasicNameValuePair("Email", "username@gmail.com"));
    params.add(new BasicNameValuePair("Passwd", "password here"));
    params.add(new BasicNameValuePair("signIn", "Sign in"));
    post.setEntity(new UrlEncodedFormEntity(params));
    HttpResponse res = client.execute(post);

    if(res.getStatusLine().getStatusCode() >= 400)
    //success
    else
    //fail

Answer: A DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://mail.google.com/");

List<NameValuePair> params = new ArrayList<NameValuePair>(3);
params.add(new BasicNameValuePair("Email", "username@gmail.com"));
params.add(new BasicNameValuePair("Passwd", "password here"));
params.add(new BasicNameValuePair("signIn", "Sign in"));
post.setEntity(new UrlEncodedFormEntity(params));
HttpResponse res = client.execute(post);

if(res.getStatusLine().getStatusCode() < 400)
//success
else
//fail
Description: DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://mail.google.com/");

List<NameValuePair> params = new ArrayList<NameValuePair>(3);
params.add(new BasicNameValuePair("Email", "username@gmail.com"));
params.add(new BasicNameValuePair("Passwd", "password here"));
params.add(new BasicNameValuePair("signIn", "Sign in"));
post.setEntity(new UrlEncodedFormEntity(params));
HttpResponse res = client.execute(post);

if(res.getStatusLine().getStatusCode() < 400)
//success
else
//fail

8

How to send or receive data between android application and a remote server? Which of the below mechanisms are fast to send the data ?

  • i. If the data is very small, then use NameValuePairs.
  • ii. if the data is heavy structured data, then use JSON. Because JSON is lighter than xml. So transferring speed will be fast.
  • iii. if the data is heavy structured data, then use XML. Because XML is lighter than JSON.
  • iv. XML & JSON don't have any difference in terms of transferring speed. So you can use any of them.
  • i
  • i & ii
  • i & iii
  • i & iv

Answer: B i & ii

Description: If the data is very small, then use NameValuePairs. And if the data is heavy structured data, then use JSON. Because JSON is lighter than xml so transferring speed will be fast. JSON can be easily transferred to javascript object compared to XML, so its preferred to use json.
Note : JSON will get lot of advantage over xml especially when used with AJAX kind of technology which refreshes page content dynamically with out reloading entire page.

9

Which technology suites best to send data across network to a server from an android application?

  • SOAP is faster than REST to transfer the data.
  • JSON is faster than XML, XML is faster than SOAP.
  • JSON is faster than XML, XML is faster than SOAP. But if we want to SOAP in mobiles, we can go with KSOAP designed for embedded devices which is faster.
  • none of the above.

Answer: C JSON is faster than XML, XML is faster than SOAP. But if we want to SOAP in mobiles, we can go with KSOAP designed for embedded devices which is faster.
Description: JSON is faster than XML, XML is faster than SOAP. But if we want to SOAP in mobiles, we can go with KSOAP designed for embedded devices which is faster than SOAP.

10

What kind of exceptions can be thrown while parsing JSON response from server, in an android application?

  • IOException
  • JSONException
  • JSONParsingException
  • IOError

Answer: B JSONException
Description:

11

Android JSON : Which of the below terms will be used while parsing a json file.

  • i. JSONObject
  • ii. JSONArray
  • iii. JSONString
  • iv. JSONUnion
  • i
  • i & ii
  • i, ii, & iii
  • i, ii, iii, & iv

Answer: B i & ii
Description: JSONObject & JSONArray.

12

How to know the number of elements in a JSONArray?

  • use length() function
  • use length variable which will hold no of elements in that array
  • put infinite loop to read JSONArray, JSON library will automatically detect end of array.
  • none of the above.

Answer: A use length() function
Description: use length() function on JSONArray object to find number of elements in it.

13

Which of the below web sites uses JSON technique heavily to send and receive data on over the network.

  • facebook, google drive, twitter
  • facebook, google drive, twitter, linkedin
  • google drive
  • facebook

Answer: B facebook, google drive, twitter, linkedin
Description: Now a days almost all famous social networking sites and search engines uses JSON as the mechanism to send and receive data. JSON is lightweight and faster compared to other ways of data transmission.

14

What is GCM?

  • 1. Google Cloud Messaging is a service that allows a mobile device to send text messages to other mobile devices.
  • 2. Google Cloud Messaging for chrome (GCM) is a service for signed-in Chrome users that helps developers send message data from servers to their Chrome apps and extensions. The service is intended to wake up an app or extension, and/or alert a user. For example, calendar updates could be pushed to users even when their calendaring app isn't open.
  • 3. Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device, and also to receive messages from devices on the same connection.
  • 1,2
  • 1,3
  • 2,3
  • None are correct

Answer: C 2,3
Description: GCM is a faster mechanism to push data (light weight) from your web server to all your client mobile devices at a time with free of cost. It is a framework deisgned by Google to support faster and free data transimission between server to mobile deives that is powerd by android. This is a 2 way communication channel that allows even android devices to send the data to the web server via GCM framework. This is really useful to the start up companies who can't afford high bandwidth communication rates to the mobile clients to communicate.

15

While connecting to Google server from an android application, what are the checked exception that needs to handle in this scenario?

  • ClientProtocolException, IOException, UnsupportedEncodingException, XmlPullParserException
  • ClientException, IOException, UnsupportedEncodingException, XmlPullParserException
  • ClientProtocolException, IOError, UnsupportedEncodingException, XmlPullParserException
  • ClientProtocolException, IOError, UnsupportedEncodingException

Answer: A ClientProtocolException, IOException, UnsupportedEncodingException, XmlPullParserException
Description: ClientProtocolException - if httpget or post protocol is not proper, IOException - if network connection could not be established with server, UnsupportedEncodingException - while encoding the data to be send if encoding format is not supported, XmlPullParserException - while parsing xml data that we got from server.