Read Large JSON Files Using Gson

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.

JSON exists everywhere and used mainly in REST APIs, There are many ways to read JSON files but here I will cover the two ways that are supported by Gson library.

  • Object Model

Load the whole file in memory and translate each JavaScript object to a Java object containing all the properties, array objects, etc. It is similar to the DOM way to read XML files.

  • Stream Model

Operate on a JSON document as a sequence of tokens that are traversed in depth-first order. Because stream mode reads one token at a time it requires less memory. It is similar to Pull Parsers way to read XML files.

When to use each model depends on your needs, If your JSON file is small then using object model to load the whole file into memory at once will be best choice, But if your JSON file it too large then using stream model will be the best.

I was having a large JSON file (≈ 30 MB) that I wanted to read. I couldn’t read the whole file at once using object model because loading all this data into memory made the system crash, So here I will describe how to use GSON library to read this file using stream model.

Firstly, Let’s take a look how the JSON file formed


City and Coord model classes



Now we will read the JSON file from assets folder using stream model


With this approach we are loading objects one by one, and each time we convert the object that has been read to City model object.



What Is Android Intent ?

I was reading about Android Intents and I found this explanation very simple.

​An Intent is an “intention” to perform an action; in other words,

a messaging object you can use to request an action from another app component

An Intent is basically a message to say you did or want something to happen. Depending on the intent, apps or the OS might be listening for it and will react accordingly. Think of it as a blast email to a bunch of friends, in which you tell your friend John to do something, or to friends who can do X (“intent filters”), to do X. The other folks will ignore the email, but John (or friends who can do X) will react to it.

To listen for an broadcast intent (like the phone ringing, or an SMS is received), you implement a broadcast receiver, which will be passed the intent. To declare that you can handle another’s app intent like “take picture”, you declare an intent filter in your app’s manifest file.

If you want to fire off an intent to do something, like pop up the dialer, you fire off an intent saying you will.


Android Developer Path

Udacity has launched an Android Developer Path Guide. If you are newbie or have some experience with Android, take a look to that map to know the skills that you lack.

There are 3 levels in Udacity for Android developers:

  1. Beginner
    1. Android Basics: User Interface
    2. User Input
    3. Multi-Screen Apps
    4. Networking
    5. Data Storage
  2. Intermediate
    1. Developing Android Apps
  3. Advanced
    1. Advanced Android App Development



Now I am 22

mmm … Today 14 – 8 – 2013, I am 22 years old .. Yes I hear some people over there say Happy Birthday To You, But no I am not writing this post for celebrating with my Birthday.

I have some weird thoughts, Why people celebrate with their Birthday even they know that another year passes from their life Which means your life on earth decreases by one year .. And that is not a happy thing to celebrate with !!

There is a hidden conversation between Me and Myself .. I am asking Myself >_>

1) What do you spend your life in ?

2) What do you spend your youth in ?

3) What do you spend your money in ?

4) Do you increase your knowledge in Religion and Science ?

5) Are you Useful for someone ? Helpful for someone ?

6) What do you offer for your Religion ?

7) What do you offer for helping your country and your Islamic Ummah ?

8) Do you know that Allah is keeping an eye “يراقب” on you in all your actions ?

9) What is the changes that you want to make in your life ? and in others life ?

10) What books you plan to read ?

11) When you will improve your behaviours and morals to gain Allah’s Satisfaction and Mercy ?

12) Will you be an effective human ? Will you participate in any charity organization (Resala, Life Makers, … etc.)

A lot of other questions in my mind for you ‘Myself’ .. Because I know that

نفسك إن لم تشغلها بالحق شغلتك بالباطل — ابن تيمية

So the last thing I want to say to Myself .. ” I hope to see you better in all life sides in the next years 🙂 and don’t forget there is another year that passes from your life, you are growing and life doesn’t wait for anyone and always remember Allah is watching you, Keep Moving Forward To Your Goals 😀 ”


Willpower & Determination

Today, I will talk about the meaning of Willpowerقوة الإرادة” and Determinationالعزيمة” and how they could change our life and i will use a real life example to prove my point of view.

The Willpower قوة الإرادة” and Determination “العزيمة” are inner power that enable us to face the challenges and to continue in achieving our GOALS 🙂

“If you think you can do a thing or think you can’t do a thing, you’re right.” – Henry Ford

So, It is all about what you believe and think .. If you have a strong motiveدافع“, You can do it 😀

Try to always motivate and encourage yourself … Set Your GOAL, and Go On You Can Achieve It .. You Can Do It — Ask Allah To Help You, And Trust That He Will — 🙂


And the last thing I want to talk about is the real life examples that I watched and they Motivate, and Inspire me. Here you are this great two videos 🙂

The first example was about Khaldoon Sinjab a Software Engineer that has an accident and he give all of us a lesson in life. A lesson about Never Give Up and Yes You Can whatever obstacles you face.

The second example was about Nick who was born with no arms and no legs. See him when he say ‘I Love Living Life .. I am Happy’ 🙂

I hope that we all change our mind and our life, Stay positive, have faith in Allah and thank him for his graces 🙂


How To Read A Book ?!

When we are kids, a lot of us doesn’t have family that encourages reading. So when we go to study we are always bored and thinking of high marks only and didn’t care about understanding the subject.

Boy studying

Reading is important in our life, with reading we can gain knowledge and success. Many of us(including me :D) doesn’t read in a regular way, Sometimes we read a hole book in a small time .. and other times we don’t read for several months maybe years :(. We need to change our life in this point, We need to care more about Reading … We need to make “Reading A Way Of Life” — “القراءة منهج حياة“.

Today, I am going to talk about How To Read A Book ?! and Can We Really Have A Time For Reading In Our Busy Life ?!

Steps To Read A Book :-

  1. Divide the book to sections or chapters.
  2. When you read, you need to stabilize yourself. (Make yourself comfortable :))
  3. Read the book chapter by chapter or section by section.
  4. Make thing that you want to read portable (Like to have a hard copy of the book, or have it on your own phone or tablet) to read it when you have some free time.
  5. Pay attention to what you read and get rid of distractions “الملهيات” like (phone, TV, Music, … etc).
  6. Get a pencil on your hand while reading to take notes.
  7. Don’t judge a book from the first 1 or 2 chapters (because in most of books they are introduction).
  8. Use your time efficiently, and read in any small chunks of time (Like when you are waiting someone, or in the transportation or anything else).

We need also to implant the love of Reading in children’s life .. If they are used to read, They will never have our problem with reading and maybe they become a great researchers or scientists 😀


By the end of this topic, I will let you watch a great video about How To Read A Book That You Don’t Want To Read It …