Adsense Ad

Monday, 23 October 2017

Oracle: Difference between b-tree and bitmap index


Question:  What is the difference between a btree and a bitmap index?  I need to understand the structural differences between a btree and a bitmap index and understand then to use a b-tree versus a bitmap index on a table column.
Answer:  Internally, a bitmap and a btree indexes are very different, but functionally they are identical in that they serve to assist Oracle in retrieving rows faster than a full-table scan.  The basic differences between b-tree and bitmap indexes include:
1:  Syntax differences:  The bitmap index includes the "bitmap" keyword.  The btree index does not say "bitmap".
2: Cardinality differences:  The bitmap index is generally for columns with lots of duplicate values (low cardinality), while b-tree indexes are best for high cardinality columns.
3: Internal structure differences:  The internal structures are quite different.  A b-tree index has index nodes (based on data block size), it a tree form:


A bitmap index looks like this, a two-dimensional array with zero and one (bit) values:


The Oracle b-tree index
The oldest and most popular type of Oracle indexing is a standard b-tree index, which excels at servicing simple queries. The b-tree index was introduced in the earliest releases of Oracle and remains widely used with Oracle. B-tree indexes are used to avoid large sorting operations. For example, a SQL query requiring 10,000 rows to be presented in sorted order will often use a b-tree index to avoid the very large sort required to deliver the data to the end user.
Oracle offers several options when creating an index using the default b-tree structure. It allows you to index on multiple columns (concatenated indexes) to improve access speeds. Also, it allows for individual columns to be sorted in different orders. For example, we could create a b-tree index on a column called last_name in ascending order and have a second column within the index that displays the salary column in descending order.
create index
    name_salary_idx
on
   person
(
   last_name asc,
   salary desc);
While b-tree indexes are great for simple queries, they are not very good for the following situations:
  • Low-cardinality columns - Columns with less than 200 distinct values do not have the selectivity required in order to benefit from standard b-tree index structures.
  • No support for SQL functions - B-tree indexes are not able to support SQL queries using Oracle's built-in functions. Oracle provides a variety of built-in functions that allow SQL statements to query on a piece of an indexed column or on any one of a number of transformations against the indexed column.
Prior to the introduction of Oracle function-based indexes (FBI), the Oracle cost-based SQL optimizer had to perform time-consuming long-table, full-table scans due to these shortcomings. Consequently, it was no surprise when Oracle introduced more robust types of indexing structures.
Bitmapped indexes
Oracle bitmap indexes are very different from standard b-tree indexes. In bitmap structures, a two-dimensional array is created with one column for every row in the table being indexed. Each column represents a distinct value within the bitmapped index. This two-dimensional array represents each value within the index multiplied by the number of rows in the table. At row retrieval time, Oracle decompresses the bitmap into the RAM data buffers so it can be rapidly scanned for matching values. These matching values are delivered to Oracle in the form of a Row-ID list, and these Row-ID values may directly access the required information.
The real benefit of bitmapped indexing occurs when one table includes multiple bitmapped indexes. Each individual column may have low cardinality. The creation of multiple bitmapped indexes provides a very powerful method for rapidly answering difficult SQL queries.
For example, assume there is a motor vehicle database with numerous low-cardinality columns such as car_color, car_make, car_model, and car_year. Each column contains less than 100 distinct values by themselves, and a b-tree index would be fairly useless in a database of 20 million vehicles. However, combining these indexes together in a query can provide blistering response times a lot faster than the traditional method of reading each one of the 20 million rows in the base table. For example, assume we wanted to find old blue Toyota Corollas manufactured in 1981.
select
   license_plat_nbr
from
   vehicle
and
   make = 'toyota'
and
   year = 1981;
Oracle uses a specialized optimizer method called a bitmapped index merge to service this query. In a bitmapped index merge, each Row-ID, or RID, list is built independently by using the bitmaps, and a special merge routine is used in order to compare the RID lists and find the intersecting values. Using this methodology, Oracle can provide subsecond response time when working against multiple low-cardinality columns.
Summary
  1. B-Tree and Bitmap are two types of indexes used in Oracle.
  2. Bitmap is a method of indexing, offering performance benefits and storage savings.
  3. B-Tree index is an index that is created on columns that contain very unique values.
  4. B-Tree works best with many distinct indexed values.
  5. Bitmap works best with many distinct indexed values.
  6. B-tree indexes are the default index type of the CREATE INDEX statement, but to create a bitmap index you need to specify CREATE BITMAP INDEX.
  7. B-tree indexes are suitable for columns with a high number of distinct values. Bitmap indexes are suitable for columns with a  low number of distinct values.

Thursday, 12 October 2017

Integrate Google AdMob in Android

How to Integrate Google AdMob in your Android App


AdMob is a multi-platform mobile ad network that allows you to monetize your android app. By integrating AdMob you can start earning right away. It is very useful particularly when you are publishing a free app and want to earn some money from it.
Integrating AdMob is such an easy task that it takes not more than 5mins. In this article we’ll build a simple app with two screen to show the different types of ads that AdMob supports.

1. Type of Ads – Banner and Interstitial

AdMob currently support two kinds of ad units. One is Banner ad which occupies a portion of the screen. Other is Interstitial ad which occupies device full screen. Interstitial completely blocks your app UI and places the ad on top it.

2. Creating Ad Units

1. Sign into your AdMob account.
2. Click on Monetize tab.
3Select or Create the app and choose the platform.
4. Select the ad format either Banner or Interstitial and give the ad unit a name.
5. Once the ad unit is created, you can notice the Ad unit ID on the dashboard. An example of ad unit id look like ca-app-pub-066457076332243242/3326342124
Create as many ad units required for your app.

Banner Ad

Banner ads occupies only a portion of the screen. I am adding a banner ad in my main activity aligning to bottom of the screen

Interstitial Ad (Fullscreen Ad)

Interstitial ads occupies full screen of the app. Adding interstitial ad doesn’t require an AdView element to be added in the xml layout. Rather we load the ad programatically from the activity. Normally these ads will be populated when user is moving between activities or moving to next level when playing a game.
We’ll test this ad by creating a second activity and popup the full screen ad when the second activity is launched.
Creating New Project
1. Create a new project in Android Studio from File New Project. When it prompts you to select the default activity, select Empty Activity and proceed.
2. Open build.gradle and add play services dependency as AdMob requires it.
compile ‘com.google.android.gms:play-services-ads:9.0.0’

Open AndroidManifest.xml and add the below mentioned permissions and other properties.
> Add INTERNET permissions.
 <uses-permission android:name="android.permission.INTERNET" />

Add Linear Layout in main activity.
<LinearLayout
   
android:layout_width="fill_parent"
   
android:layout_height="wrap_content"
   
android:id="@+id/ad"
   
android:layout_alignParentBottom="true"
   
android:background="@android:color/transparent"
   
android:orientation="horizontal"
   
/>
Now open and edit main activity java class
public class MainActivity extends AppCompatActivity {



    AdView adView;

    LinearLayout linearLayout;

    InterstitialAd interstitialAd;
@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main);

    linearLayout = (LinearLayout) findViewById(R.id.ad);



    adView = new AdView(this);



    interstitialAd = new InterstitialAd(this);



    initAd();



    new Handler().postDelayed(new Runnable() {

        @Override

        public void run() {

          displayInterstialAd();

        }

    },2000);
}



 public void initAd(){

     adView.setAdUnitId("ca-app-pub-2049596536820731/9402866166");

     adView.setAdSize(AdSize.SMART_BANNER);

     AdRequest adRequest=new AdRequest.Builder().build();

     if(adView.getAdSize()!= null || adView.getAdUnitId()!= null){

         Log.e("","Banner Requested");

         adView.loadAd(adRequest);

     }else{

         Log.e(""," AdSize: "+adView.getAdSize()+" AdUnitID: "+adView.getAdUnitId());

     }





     linearLayout.addView(adView);

 }





    public void showInterstetial(){

        interstitialAd.setAdUnitId("ca-app-pub-2049596536820731/2995926838");

        interstitialAd.setAdListener(new AdListener() {

            @Override

            public void onAdLoaded() {

                super.onAdLoaded();

                displayInterstialAd();

            }

        });

    }



    public void displayInterstialAd(){

        if(interstitialAd.isLoaded()) {

            Toast.makeText(this,"showing ads..",Toast.LENGTH_LONG).show();

            interstitialAd.show();

        }else{

            Log.e("","Ads not loaded");

        }

    }



}




Friday, 22 September 2017

Excel: Convert Scientific Notation To Text

Convert Scientific Notation To Text With Formulas

The following formulas also can help you to convert the list of scientific notation to text.
1. Please enter this formula: =trim(A1) into a blank cell, B1 for instance, see screenshot:
doc-convert-sientific-to-text-7
2. Then drag the fill handle over to the range that you want to apply this formula, and you will get the result as you want:
doc-convert-sientific-to-text-8
Note: This UPPER function: =UPPER(A1) also can help you, please apply any one as you like.

Thursday, 21 September 2017

Android: Shared Preferences

Creating / Using Shared Preferences

Android provides many ways of storing data of an application. One of this way is called Shared Preferences. Shared Preferences allow you to save and retrieve data in the form of key,value pair.

In order to use shared preferences, you have to call a method getSharedPreferences() that returns a SharedPreference instance pointing to the file that contains the values of preferences.

The first parameter is the key and the second parameter is the MODE. Apart from private there are other modes available that are listed below −
Sr.NoMode & description
1
MODE_APPEND
This will append the new preferences with the already existing preferences
2
MODE_ENABLE_WRITE_AHEAD_LOGGING
Database open flag. When it is set , it would enable write ahead logging by default
3
MODE_MULTI_PROCESS
This method will check for modification of preferences even if the sharedpreference instance has already been loaded
4
MODE_PRIVATE
By setting this mode, the file can only be accessed using calling application
5
MODE_WORLD_READABLE
This mode allow other application to read the preferences
6
MODE_WORLD_WRITEABLE
This mode allow other application to write the preferences
You can save something in the sharedpreferences by using SharedPreferences.Editor class. You will call the edit method of SharedPreference instance and will receive it in an editor object. Its syntax is −
Editor editor = sharedpreferences.edit();
editor.putString("key", "value");
editor.commit();
Apart from the putString method , there are methods available in the editor class that allows manipulation of data inside shared preferences. They are listed as follows −
Sr. NOMode & description
1
apply()
It is an abstract method. It will commit your changes back from editor to the sharedPreference object you are calling
2
clear()
It will remove all values from the editor
3
remove(String key)
It will remove the value whose key has been passed as a parameter
4
putLong(String key, long value)
It will save a long value in a preference editor
5
putInt(String key, int value)
It will save a integer value in a preference editor
6
putFloat(String key, float value)
It will save a float value in a preference editor

Create a separate class for shared preferences i.e.

package com.example.user.dailybook;

import android.content.Context;
import android.content.SharedPreferences;

/** * Created by User on 8/26/2017. */public class Config {
    SharedPreferences sp;
    SharedPreferences.Editor spe;

    public Config(Context cnt){
        sp = cnt.getSharedPreferences("MyPref",Context.MODE_PRIVATE);
        spe = sp.edit();
        spe.commit();
    }

    public void setLocal(String key,String val){
        spe.putString(key,val);
        spe.commit();
    }

    public String getLocal(String key){
        String outval = sp.getString(key,null);
        return outval;
    }

    public void removeLocal(){
        spe.clear();
        spe.commit();
    }
}


How to use shared preferences class for storing data.

Declaration

Config cfg;



Initialization

cfg = new Config(this);



Assigning values with key variables
cfg.setLocal("loggedin","Y");
cfg.setLocal("usrid",usrname.getText().toString());


Getting / using values with key variables
if(!cfg.getLocal("loggedin").isEmpty()){
    Intent   i = new Intent(SplashScreen.this,HomeActivity.class);
    startActivity(i);
    finish();
}else{
    Intent   i = new Intent(SplashScreen.this,LoginActivity.class);
    startActivity(i);
    finish();
}

OR Use remove local to clear all data

cfg.removeLocal();


Grid view using drawable images in android

How to create Grid view using drawable images in android

First create a simple app with empty activity
Now create grid view via xml

<GridView
   
android:layout_width="match_parent"
   
android:layout_height="wrap_content"
   
android:numColumns="2"
   
android:id="@+id/gview"
   
/>

Now initialize in java file
GridView gridView;

gridView = (GridView) view.findViewById(R.id.gview);

Create new layout resource .xml file for thumbnails

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical" 
android:layout_width="match_parent"

android:layout_height="match_parent">



    <ImageView

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:adjustViewBounds="true"

        android:id="@+id/thumbimg"/>

    <TextView

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:id="@+id/thumbtxt"

        />

</LinearLayout>



Now Create Grid Adapter Class

package com.example.user.goruntu;



import android.content.Context;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.BaseAdapter;

import android.widget.ImageView;

import android.widget.TextView;

import java.util.ArrayList;

import java.util.HashMap;



public class GridAdapter extends BaseAdapter {

    ArrayList<HashMap<String,String>> data;

    Context cnt;

    public GridAdapter(Context cnt, ArrayList<HashMap<String,String>> data){

        this.data = data;

        this.cnt = cnt;

    }

    @Override

    public int getCount() {

        return data.size();

    }



    @Override

    public Object getItem(int position) {

        return data.get(position);

    }



    @Override

    public long getItemId(int position) {

        return 0;

    }



    @Override

    public View getView(int position, View view, ViewGroup viewGroup) {

        HashMap<String,String> item = data.get(position);

        ViewHolder viewHolder = new ViewHolder();

        LayoutInflater inflater = LayoutInflater.from(cnt);



        view=inflater.inflate(R.layout.griditems,viewGroup,false);

        viewHolder.thumbimg=(ImageView) view.findViewById(R.id.thumbimg);

        viewHolder.thumbtxt=(TextView) view.findViewById(R.id.thumbtxt);

        if(item.get("imgname").equalsIgnoreCase("flw1")){

            viewHolder.thumbimg.setImageResource(R.drawable.flw1);

            viewHolder.thumbtxt.setText(item.get("imgtxt"));

        }else{

            viewHolder.thumbimg.setImageResource(R.drawable.flw2);

            viewHolder.thumbtxt.setText(item.get("imgtxt"));

        }

        return view;

    }



    class ViewHolder{

        ImageView thumbimg;

        TextView  thumbtxt;

    }

}


Go to Main activity class and assign grid view with above adapter
package com.example.user.goruntu;



import android.support.design.widget.TabLayout;

import android.support.v4.view.ViewPager;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.WindowManager;



import java.util.ArrayList;

import java.util.HashMap;



public class MainActivity extends AppCompatActivity {

GridView gridView;

ArrayList<HashMap<String,String>> list;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main);

gridView = (GridView) view.findViewById(R.id.gview);

list = new ArrayList<>();

for(int i=0;i<=10;i++) {



    HashMap<String, String> hashMap = new HashMap<>();

    hashMap.put("imgtxt",Integer.toString(i) + ".) Flowers");

    if(i%2==0) {

        hashMap.put("imgname", "flw1");

        list.add(hashMap);

    }else{

        hashMap.put("imgname", "flw2");

        list.add(hashMap);

    }

}

GridAdapter adp = new GridAdapter(view.getContext(),list);

gridView.setAdapter(adp);

    }
}


Thursday, 14 September 2017

How to use sounds/.mp3 in android

Sounds/.mp3 in Android.

MediaPlayer:

The Android multimedia framework includes support for playing variety of common media types, so that you can easily integrate audio, video and images into your applications. You can play audio or video from media files stored in your application's resources (raw resources), from standalone files in the filesystem, or from a data stream arriving over a network connection, all using MediaPlayer APIs.This document shows you how to write a media-playing application that interacts with the user and the system in order to obtain good performance and a pleasant user experience.

Steps:

First create a project with button or toggle or switch button.

<Switch    
android:layout_width="wrap_content"    
android:layout_height="wrap_content"    
android:id="@+id/sw"    
android:text="Music Off "    
/>


<ImageButton    
android:layout_width="wrap_content"    
android:layout_height="wrap_content"    
android:background="#ffffff"    
android:src="@drawable/on"    
android:layout_centerHorizontal="true"    
android:id="@+id/on"
android:layout_marginTop="30dp"    
/>


Now create a directory in res directory and named it as raw


Now copy paste sound media files in raw directory.

Now go to java class and change in oncreate:

ImageButton off;
Switch aSwitch;
off = (ImageButton) view.findViewById(R.id.off);
aSwitch = (Switch) view.findViewById(R.id.sw);
final MediaPlayer mp = MediaPlayer.create(view.getContext(),R.raw.wholetdogout);

aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(isChecked){
            aSwitch.setText("Music On ");
            if(mp.isPlaying()){
                mp.seekTo(0);
            }else{
                mp.start();
            }


        }else{
            aSwitch.setText("Music Off ");
            mp.pause();
        }
    }
});

final MediaPlayer bb = MediaPlayer.create(view.getContext(),R.raw.shutteraa);

off.setOnClickListener(new View.OnClickListener() {
    @Override    public void onClick(View v) {
        if (hasflash==1){
            parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
            camera.setParameters(parameters);
            camera.stopPreview();
        }else {
            Toast.makeText(getActivity(),"Please Install Camera",Toast.LENGTH_SHORT).show();
        }
        on.setVisibility(View.VISIBLE);
        imgvu.setImageResource(R.drawable.rszoff);
        off.setVisibility(View.GONE);
        if(bb.isPlaying()) {
            bb.seekTo(0);
        }else{
            bb.start();
        }
    }
});