Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Monday, January 25, 2016

Reading Parse.com docs

I got less time to do my things today. Most of the day went by playing with my son as maid took leave today.
Most part of the remaining time i read parse docs. Learnt a lots of new things about parse and also got some ideas out of it for my app.
When i turned on my system to work I managed to get the comment thing sorted out.
Actually i never mentioned it before here. So here it goes.
In MySQL i was using id for the content that were integers and they were getting incremented automatically on every new row added. I was using this id in the comments table to label which content this comment belongs to. Easy stuff that is.
But here in parse they use NoSQL database that doesn't give auto incrementing integers as id rather they give a alphanumeric objectId. So if i add a new row to content it will not generate same type of integer id so i will have to use objectId in comment table to link comments to newer content.
Now the problem arises how to write the query because old content will not have new objectId in comments and new on will not have the old content id.
To sort this out i needed to add objectId of the content to all the respective comments. I couldn't do it manually because there were 22,000 comments in all.
I needed an automated approach.
I had two options:
1. I use the cloud code facility that parse provide. To use it i needed to write a JavaScript function and run it on the data.
2. I extend my existing android code and update the ids using the app.
First option was little difficult for me as i have never done any of that stuff before. I mean i never used parse cloud code or the tools required to write cloud code. And also i never wrote such a JavaScript function before. But it could have been a nice learning experience.
I chose second option because it required very less time in comparison to first one and also i could track the changes i was introducing with android logcat, so i would not corrupt the data. Although i backed up all data before hand.
I wrote a java method that pulled all the comments attached to old content id and then update each of them by inserting new content objectId in it. I could have done it to all the data at once but i chose to go with one at a time approach. I tapped on the content and all the comment rows related to that content got updated and i tracked it in the parse interface and logcat window.
Took time but finally managed to update all.
Finally i updated the query to use the objectId rather than old content id in the android app to pull the comments. Working nicely.
Yesterday i updated the android app to send objectId for new comments so nothing was required to change in that method. 
Reading through the parse documents i learnt about the caching the data in device so i won't have to query it every time i needed more data. Nice function. Would use it. It will make things faster. Tomorrow will try to implement this caching thing.
One thing that went unexpectedly nice as i switched to parse is that when i was using JSON to get and sent data to and from app i was not getting the emoji working. They were changing into question marks. But now i can use all the emoji in content as well as in comments 🙌.
Later.

Thursday, January 21, 2016

Lazy day

Today was cold and lazy day.
I wanted to just lay down and not do anything, but you know.. 😔.
So i managed to import the api data to app engine datastore by pulling and parsing JSON from my current api. Actually i have imported 1 table and 1 more yet to be imported but that is not important. Even if i don't import it, it won't effect a thing but i will try to do that just for the sake of learning.
I tested the new api with my app and its working flawlessly.
I imported the data in local datastore, but the script will import it well in production server when i upload the project to app engine. Tomorrow i will be making a new app engine project and upload the api files to test it again.
I also learnt how to use memcache on app engine. Although it was just few line of code but it makes a huge difference in performance and server costs. What you do here is that you check if the data you looking for is saved in the memcache or not. If its there you serve it right away from memcache. If not you pull it from the datastore and save a copy in  memcache and also serve a copy to user. When next time that data is needed you pull it from the memcache and serve it without doing the roundtrip to the datastore. Memcache, as the name suggest is space in system memory(RAM) that is very fast compared to the disk or datastore so performance improvement is very good. And also app engine gives you restricted queries to datastore in free plan so you save that too by using memcache. If you Move to paid plan you will save cost by using memcache effectively.
I think i need to again read the app engine docs. I read it long back and now i have to look up every time i plan to do anything. This looking into is taking too much time and slowing me down considerably. 
Parsing JSON with python was new experience to me. I used simplejson to parse it. That doesn't mean i have learnt it. I found a sample code and adapted it to work by trial and error but afterward when i looked into the code it looked just like java code i wrote in my android app to parse the same JSON. Just a little syntax difference. Will read little more about simplejson. It will come very handy in long run.
As i have never learnt python in the way i should have, i feel little under confident writing the code but as i write it more i find it far more easier to write and way cleaner than either PHP or java. And writing app engine apps using webapp2 is a bliss compared to writing a vanilla PHP code.
In other news ,for some strange reason i am finding that my system is not loading few websites. It just keep on loading and doesn't show anything. If i try same pages from my phone using the same WiFi connection it loads in a jiffy. Don't know what's the problem. Will try to fix it. May be the problem is in the DNS. If it is then its a quick fix. If not then its going to be headache for me. Just chimed in that the problem may be in the host file i edited recently. Will look into it tomorrow.
What more..
Yes I updated more softwares.
Enough typing on phone on this cold and lazy day.
See ya..

Tuesday, January 19, 2016

App engine java python and more..

As i wrote in last post i am planning to use google app engine to host json api for my android apps so today time went into it.
I was using PHP to generate JSON from MySQL database. PHP makes it a breeze to generate JSON. Only few line of code and you are all set. App engine also support PHP but SQL is paid so i am not using it. Not because of the cost but if it can be done with app engine datastore using python or java then why not do it.
I am not fluent in either python or java but have workable knowledge and also know how to find the answers if stuck.
Today i managed to figure how to generate JSON from datastore using  python. Done it with help of django simplejson module.
Reading through the app engine docs i also found it interesting to build a backend using java. Android studio makes it real easy to go through the process but my internet speed killed all the fun. I could have built the whole api with java today but my system spent hours downloading the app engine java SDK and i think that too isn't perfectly working. I tested 2 modules one cloud endpoint and other java servlet. Endpoint one was not running perfectly. The time it took to download java SDK i managed to generate json using python.
Also my Mac(actually hackintosh) was refusing to load the page using "localhost:8080", which is default, as address. So i edited the host file and still nothing worked. When i changed the default port from 8080 to 8888 it started working.
Also genymotion refused to take "10.0.2.2:8888" as address to local api. I had to turn on the android emulator to get it working.
I hope tomorrow i will complete the api and also build the basic app to work with that api. Later i will polish the app.

Wednesday, August 31, 2011

Getting on with android

I started learning java and android app building a while back. Everywhere I looked they said 
Learn java first and then start learning to make android application. 
I suggest a different approach. 
Don't learn java completely before jumping into android development. You just need to know only java basics to get started with android. 
Select a java video tutorial on YouTube. See how it works. Then jump straight into android. Learn what you need to know about java along with android. This way you will save a lot of time and learn both things to the extent where you will find you have wasted far lesser time. 
Suggested books to learn Java for android development and android app development.

Hope this will help a few.

Monday, August 29, 2011

Android Development

This time I am sticking to this.
If you have read few post on this blog you have noticed that I jump again and again and never stick to something.
This time I am sticking to something here. I have started to learn Java a while ago and now I am going to learn android app development this time and make some nice applications for android.

Tuesday, June 28, 2011

My first love in tech : Mobile Phones

I try to learn many things but my brain always returns to mobile phones. I tried to learn developing mobile phone apps when I got my first Symbian mobile but failed as I never had even an introduction of programming at that time. Now as I can write few small scripts in PHP I again want to write applications for mobile phones.
Yes I can write application for mobile web with PHP but I want to write native mobile apps. Not Symbian for sure now.
I have an android phone and I am learning java as android apps are written in java. I have tried appinventor but it lacks functions seriously. 
I again got back to my favorite programming books Head first series to learn java
Here is the link to the book: Head First Java, 2nd Edition

Sunday, April 24, 2011

Finishing PHP

I started learning PHP a while ago and left it incomplete. In my last post I wrote about the pot of gold. Before starting to make money with medical affiliate programs I thought if finishing php training.

After I finish PHP I will be learning Java too. Already started with the basics.

This time I am going to finish things properly.