Thursday, July 13, 2017

How Maps work in Java

Maps are the indispensable part of Java, and you can't think of any application without its use.

When it comes to the background of the Maps the first thing that comes to the mind is that a Map is like a dictionary or in other words you can say its a key value pair, where you assign a key with a data, so that you can get the data from the structure just by passing the Key.

Logically the accessing of the data happens in O(1) order but in case if there is a collision(will talk about it soon) it might take 2 or 3 hops but again that is negligible when we talk about memory and high end processors our systems have.

As a coder or a computer enthusiast you should have the basic understanding of how hashing works, but in case if you don't have let me give you the basic idea of the same.

What is hashing?

Hashing, in layman language means getting the data on the basis of the value of the data.

In other words, consider having the data of the students. Now each student is assigned with a roll number, now just consider if for a particular roll number we want to get the details of the students, we have following choices:
  1. We should keep on searching for the roll number sequentially one by one and matching the roll number with the one we are looking for.
  2. Or in normal case(not in prod level or high end apps), if we create an Array of the Student Details and save the student details at the position of the roll number in the array itself.
Now coming to the point (1) this approach is overhead and is not acceptable since for every search this will going to search over whole data. Also if you consider the worst case this approach might end up in O(N) order, since the data you are actually searching would be at last of the storage.

Coming to point (2) suppose you have a total of 10 students whose roll number ranges from 1 to 10 sequentially. And if every student data is stored at the position of the roll number in the Array itself we can just write a simple function to get the data of the student by following:

       //We have ARRAY_WITH_DATA_OF_STUDENTS
       function giveMeStudentWithRollNumber(N){ =====> (A)

             //since array starts from 0
            ARRAY_WITH_DATA_OF_STUDENTS[N-1]; ====> (B)
       }

Here in this code, the N-1 is basically a hash function which is giving me the information where the data is residing in my data structure, this data structure for me is Array.

Now  if we refine this code a little bit we can rewrite the same code as follows:

        //ARRAY_WITH_DATA_OF_STUDENTS
       function giveMeStudentWithRollNumber(N){ =====> (A)

             ARRAY_WITH_DATA_OF_STUDENTS[addressWhereDataIsStoredFor(N)]; ====> (B)
       }


        function addressWhereDataIsStoredFor(N){ ====> (C)
            return N-1;
       }

Now we have made a function named addressWhereDataIsStoredFor that will return me the value of the address where my data is stored in the data structure. This function is termed as the hashFunction and the value it returns is hashValue where the actual data is stored. In our case the hash function is pretty simple, that is  f(x) = X-1; but in reality the hash function does some calculations with prime number to guarantee no hash collision. Now Hash collision is a situation where 2 different data generate the same hashValue, thus resulting in a hash collision.

How hash map works in Java?

Some of the important points of Map in Java:

  1. Maps in Java is an interface available at java.util
  2. There are many classes that implemented the Map and HashMap is one of them which is widely used in many applications. 
  3. By far now you might have guessed it that the Map stores the data against a key which is same as N.
  4. Now for storing the data against a key it also needs a function that will tell the Java where to store the data so that the same can be retrieved back when asked for.
  5. Since the key is meant to be unique, the is of Set type in nature which means that it can not be duplicated.
Here is the basic example of Map with HashMap.

      import java.util.*;
      class MapUse{
            public static void main(String args[]){
                        Map test = new HashMap();
                        test.put(1, "one");
                        test.put(2, "two");
                        System.out.println(test.get(1)); // ===> one
                        test.put(1,"one again");
                        System.out.println(test.get(1)); // ===> one again
           }
      }

Now Map only accepts the Object of that class as a key, which overrides the hashCode() and uses the equals() of the same object to check when the Hash value collided and internally the Linked List is created for the same scenario.

In a nutshell, when an Object of Map is created it internally creates an Array, Node[], where each element is capable of storing the Start of the Linked List. The default size of this Array is 16 and it grows when the limit(based on, if you configured or default) met. In case of Maps the element of the Arrays are termed as Buckets. So basically we would have 16 buckets, where each bucket is capable of keeping a Linked List. 

The element of Node[] is having the following members:

    Node{
        int hash;
        K key,
        V value;
        Node next;
    }

You might be thinking why the key itself is being stored since we have the value, just return it, but there is a scenario where we have a collision, and in that case we need to return the value related to the Key we sent.

Let me explain you this by example.

Lets suppose my hashCode() function is this:

    function int hashCode(){
        //do the code and return n
        int size = size_of_hashmap;
        return n>(size) ? n%size : n; // =====> Please give attention to this.
    }

This 'n' for some reason  (because of the poor formula of calculation of hashcode) gave the repeated value, i.e hash Collision at that time this key comes to a rescue, since at that time you have a linked list and that linked list nodes will be checked on the basis of equals() with the key, with all the nodes of the linked list.

So for summary:

  1. The Maps is basically an Array of Linked Lists and each element is termed as Bucket.
  2. Each node is having the 4 things: hashCode, key, value, next.
  3. In case of collision the key comes as rescue to return the actual intended result.
  4. The index where the value is stored is basically calculated on the basis of the size of the hash map or in other words size of the array.









Thursday, December 22, 2016

Yay, consolidated links for free movies, shows & songs and live tv and more.

Hey guys, I have found many apps and sites/apps that provides access to free movies, series, songs and live tv and frankly speaking, I am done writing about each app one by one, so all in all I am writing this post with the links as well as apps that you can install in your Android to get going, so without further due lets gets started.

Android Apps:
  1. Terrarium TV 
  2. CartoonHd
  3. Showbox
  4. Showitme
  5. Popcorntime
  6. cinemaboxhd
  7. newestmovieshd
  8. aphim app
Websites for movies
  1. xmovies8.tv
  2. fmovies.me
  3. 123movies.is
  4. vumoo.li
  5. watchfree.to
  6. yesmovies.to
  7. projectwatchseries.com
  8. cmovieshd.com
Websites/Apps for songs
  1. freehindisongs.in(hindi)(Website)
  2. 123music.co(English)(Website)
  3. xtunes (English/Hindi)(App)
  4. fildo(English)(App)
Live TV Streaming Apps
Websites/Apps to download free apps
  1. Aptoide (Website/App)
  2. AppVn (Website/App)
  3. mob.org(Website)
  4. blackmart(App)
The list above is just a set of some of the sites/apps that provides you the free content. The installation of all the apps are possible only if you enable the installation from Unknown Sources under Security tab in your Android Phone. So make sure that you enable the same before doing the installation of any of the apps. 

Going forward I will tell you one more interesting stuff of downloading the videos from the above websites just by installing one app and that app will give you the link of all the videos that runs inside itself. So here we go.

The apps are AdBlocker Browser that can be found here and ADM that can be found here. Adblocker is important to surf the net without advs and ADM is like an IDM (Internet Download Manager) for Android. After installing these apps open any website with the video in Adblocker, and once the video starts playing, keep a finger over the video it will show you the popup to save/share the video. Now here is the hook, other apps like chrome browser/opera browser also supports the downloading of videos from the app, but they starts downloading in the default downloader that comes with Android. But that downloader is a bit slower in terms of download speed. So for that speed only we have installed ADM. Now once you get the popup click share button and share it via ADM. At this step ADM will get the link and you can start the download with quite a high speed just like IDM in PC

Attached the snapshots of AdBlocker and ADM collaboration. Please check them out and as always Happy Coding.
:)




DISCLAIMER: This post is for informational purposes and I don't owe or is related with any of the above apps. Also I don't promote these apps. So its your personal decision of installing or using these apps.

Tuesday, December 20, 2016

CartoonHd, another app to get free movies and series

Hey guys, I am back with one more app that gives you chance to download and watch free movies and series in HD format and the name is CartoonHd.

CartoonHd has the website as well as an android app. The website can be found here and the app can be found here.

As usual you can't find this app in the play store for obvious reasons and so you have to enable Installation From Unknown Sources before installing the apk.

Now once the apk is installed you can open the app and search for any movie/series of your choice and it will return you the link which can either be streamed or downloaded in different resolutions.

Here are the screens of the app and it is pretty easy to use.

First screen is the home page of the app, second is the search screen and third is the screen that will give you the links to view the episodes of the searched series. I searched for flash and I found the episodes of the series.




This app is a descent app if you want to view the series and movies directly from the internet, or in-fact you can download the same if you want to view them afterwards.

I hope you guys have might have enjoyed the review of the app, so give a thumbs up, and Happy coding :)


Monday, December 19, 2016

FileChef, Download anything for free

Filechef, downloading anything for free. This program is not a program that hosts anything rather it creates a google query and that query itself is good enough to go deep in to servers of Google to return you best possible searches to get the direct links to the files.

DESCRIPTION

FileChef is basically a program that gives you direct links to the files that are available on the net. Although the searches are not to be 100% working but gives pretty descent links and since they are direct links you need not to worry about torrents illegality or anything like that. There is a website and an app named Filechef. The website is available here and the app can be downloaded from the play store here.

DOWNLOAD

Coming to downloading of the app, since the app is available in the play store so you can download it directly from the playstore and installs it in the mobile.

INSTALLATION & APP SCREENS

Installation is straight forward and one opening of the app, there is a section available that lets you choose the type of the file you want to download like software, movie, app, book etc and a text box to give your search query. After that press the search icon and boom it will open a web page with the query formed on the basis of options you gave and the page will have the google search. You can open any link the same way you search something else in the google.

Place your search query and enjoy.

I hope you guys might have liked the app. So enjoy it and Happy Coding :)

Aptoide, playstore to have free apps

Hey Guys, today we will talk about an app named Aptoide. This app is actually a play store to give you access to many of the paid apps for free. And again you guessed it right, you can't find this on play store due to obvious reasons.

Lets break this post in following:

  1. Description
  2. Download
  3. Installation
  4. App Screens
DESCRIPTION

    As I already told you all that this app is basically a play store that offers many paid apps of Google Play Store for free. Now you may ask what about the authenticity of the app that will be downloaded then I can tell you that Aptoide servers have the inbuilt security to scan all the apps that are posted by any user and the app should go through from a number of tests to make sure that app is clean and is ready to be used.

The app itself comes as an APK as well as have the website.

DOWNLOAD & INSTALLATION

    You can find the website here  and find the android app here

Create a free account in Aptoide and after installing the apk in the phone, login with the same credentials you have created an account with. The installation is straight forward after you enable the installation from Unknown Sources.

Now after login you can search for any app and checks for the authenticity of the app by looking at the top right corner in both android app and website. If the sign says INSTALL with GREEN color, you are good to go. (Please see the app screens for more info.)

APP SCREENS


For Zooper Widget pro, you are seeing that TRUSTED (Green) icon so, that means this app can be installed without a worry. Now since it is already installed in my mobile that's why it is saying OPEN. But for you it will show INSTALL in case you don't have the app installed.

If you have the rooted phone then you might give the app SU access and by giving that it is able to install the apps automatically without you being clicking on INSTALL for every app, same as normal APK you downloads and INSTALLS .

Also if you see this same app in Play store here you will see that the app costs Rs. 185.00 /-. So enjoy the app and install some apps free for your testing.

Note: I don't support this app, this post is just for the informational purposes.

Enjoy the app and Happy Coding, :).



Sunday, December 18, 2016

Mobdro, free live channel streaming

Hey Guys I am back with a new App named Mobdro.

Lets break out this post in following parameters:

  1. Description
  2. Download
  3. Installation
  4. App Screens

DESCRIPTION

    This app is very useful for bachelors, who don't want to spend the money on Tata Sky, Airtel DTH and like that to view the channels, whether it is a match or whether it is a reality show. Now coming to this there is still a chance of viewing the series after they are broad-casted (by the channels) by searching the recorded cast. Now for those who want to view the series or anything live and that too without spending the penny on DTH services, there is a hope for them named Mobdro. This app lets you stream many channels(National as well international) live and that too with pretty descent quality which mainly depends on the speed of the internet.

DOWNLOAD

    As you guys have already guessed it, that this app can't be founded in the play store due to pretty obvious reasons and that is sharing a live content for free. You know play store is like a great enemy of free content (:P). So coming to the downloading of the apk, then the app can be downloaded from the direct lik here, and the site for the same can be found here.

Also since the app is not there in the play store you have to enable Unknown Sources, in the 
Security And Installation tab in Settings.

INSTALLATION

    Installation is pretty straight forward and you just have to follow the on screens instructions to get the app installed, and when it comes to the permission access the app asks for 3 permissions (by the time I was writing the post) named Contact, Storage and Location. And out of these 3 I had given only storage and denied other 2. And even after the denial of those 2 services the app is running perfectly fine.

SCREENSHOTS

    This app is really simple and useful in the things it offers. There are different categories of channels and depending on your choice you can choose the category respectively. There is a section of showing the recent channels you viewed as well. As soon as you click your choice, the chosen Channels starts streaming after which you can either start casting it on the TV if your TV supports or you can just keep seeing the channels in Mobile itself. Here is the simple screenshot for the app.


Enjoy the live streaming of the Channels and let me know in case of any discrepancy. Thanks all guys and keep smiling

Monday, December 12, 2016

Fildo, get me and get all the songs free

Yeah yeah, I know, I am pretty late, infact too much late in writing this, but since since we can't change that so lets get started with the new app named Fildo.

Lets break out this app in following parameters:

  1. Description
  2. Download
  3. Installation
  4. App Screens

DESCRIPTION

    This app is useful if you are a musical guy, if you want to get the mp3's of English songs and don't want to spend your bandwidth again and again in listening those songs from online music services like Gaana, Saavna and many more. This app lets you download the English songs and that too in MP3 version so that you can listen them in any player of your choice


DOWNLOAD

     This app can be downloaded from the site given above or apk version directly from here. Since this app is rejected by the Google play store for the pretty obvious reason of giving the songs as free, so you can't get it there. Also because this app is not getting downloaded from the play store you need to enable a special setting in the Settings of your phone to let install the Apk from untrusted sources as this one.
 Note: Enabling the installation unknown sources is a risky step, so be very careful in installing the apps that are trustworthy or is coming from trusted sources, but yeah the step is required to install these type of programs which are good enough but are removed from the play store due to very obvious reasons.


INSTALLATION

    Installation of this app is pretty straight forward like other apps, but needs an extra step of enabling installation from unknown sources. For enabling that follow :
  • Go to settings -> Security & Fingerprint and enable Unknown sources by saying yes when asks for confirmation 
  • Now go to folder where the Apk, is downloaded (mostly in Downloaded folder) and open the apk
  • Follow the wizard and install the app
  • Now go to Settings  - Apps - Fildo - Permissions - Give only storage 
  • Now come to Home Screen and open Fildo and wait for some time to till the waiting bar is rotating 
  • Once the app shows you some of the albums drag the screen from left hand side and that screen contains the Search bar, type the name of the song or else name of the Album or name of the star and press enter in your keyboard
  • Let it search for sometime and boom you have the song that can be downloaded
  • Choose a file to get downloaded by the 3 dots visible in front of the songs

APP SCREENS

Settings screen with app screens.


 Also you can change the directory structure under which your mp3's will gets downloaded, That is available under the Configurations menu of the app,  So tweak that according to your own understandings of the folder structure and and comes back making it save the changes.

I hope you guys have enjoyed the overall explanation of the App so please let me know, by comments like, share and every damn thing available to share.

Thanks all,
Happy Coding.

:)