Java Numeric Promotion

When we use conditional operator with different data types then the result value will be converted to higher data type value. Due to this we will get unexpected results.

Example:

When we use conditional operator with different data types then the result value will be converted to higher data type value. Due to this we will get unexpected results.

Example:

package com.gudla.numericpromotion;

public class NumericPromotion {
    boolean f = true;
    void test(){
        Object s = true ? new Integer(20) : new Float(4.0);
        System.out.println("Unexpected results: "+s);
        if(f){
            s = new Integer(20);
            System.out.println(s);
        } else{
            s = new Float(4.0);
            System.out.println(s);
        }
    }
}

Output:

Unexpected results: 20.0
20

Intent and Intent Filters

Intent: Intent is a messaging object, it is a data structure containing a description of to-be-performed operation. Using intents we can send messages asynchronously to other component.

Intents are 2 types.

  1. Explicit Intent: In explicit intent we will specify the component name which we want to start. In our application we mostly use explicit intent because we know which component(Activity, Service or Broadcast Receiver).

Example:

Intent intent = new Intent(MainActivity.this, AboutTgActivity.class); 
                startActivity(intent);

      2. Implicit Intent: For implicit intent we just specify the action then the android framework will take care of launching the specified action component. If more than one component is found for specified action then it will prompt all available components then user can select any of one.

Example:

        Uri articleURL = Uri.parse(articleUrlString);
        Intent i = new Intent(Intent.ACTION_VIEW, articleURL);
        startActivity(i);

 

Intent Filters:

Using intent filter we can specify which actions can be performed in a specific component. Intent filters we normally specify in the manifest.xml.  In intent filter we can specify only one action and multiple categories which can handle the given action also we can specify the data type.