Friday, February 17, 2017

Tes Koran Privacy policy

Tes Koran needs you to login to google in order to submit your score since it uses Google Play Games Services API. Your user ID will be displayed on leaderboards for comparation with other players. It does not collect your information outside the google server.






Contact Us,

contact.ceurapelab@gmail.com

Monday, October 17, 2016

What is java try catch

In a running java program an error could occurs at unexpected time. For example, when you are browsing to internet, you post a status or a message, at that time the internet connection is off. The piece of code that running that post task should be aware of this. So, how do the code handle this unexpected error in a running program?. The answer is they use try catch statement in their program.
When this error occurs the code execute the piece of code in catch statement rather than force close the entire running app that will make user annoyed. let's see a piece of code containing a try
catch statement.
package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;

public class MainActivity extends Activity {
    private Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
            button = (Button) findViewById(R.id.btnLogin);
        }
        catch (Exception e) {
            e.printStackTrace();
            Log.e("Exception raised", e.toString());
        }
        

    }
}

Look at the line 14 to line 20, we have put a try-catch statement here. The purpose of this statement is to anticipate if an exception will be raised inside the try statement, in this example at line 15. This exception will be raised for example if findViewById(R.id.btnLogin) return object not a Button type.
So what happened then if it is not Button type?. The code will immidiately jump to catch statement at line 18. If the exception is not raised, the code at line 18 to 19 will never be executed. Now at line 18 you can put a debug breakpoint to see what makes the cast exception appears. By knowing the cause of the exception, you can fix the code later and minimize the bug in your code.


Thank you for visiting our website. Just comment below if you have any question to ask.

What is java type casting

In android programming with java you will frequently encounter type casting. Since java class can extends another class, this another class can also be casted to its subclass.
Let's see the example code :
package com.example.myapplication.alert;

/**
 * Created by SONY on 17/10/2016.
 */
public class Child extends Father {
    
}

From the code above Child is called a subclass and Father is called a superclass. There is time you need to cast a superclass to its subclass, let's see one example :
 public void createPeople() {
        ArrayList<Father> list = new ArrayList<Father>();
        Father father = new Father();
        Child child = new Child();
        list.add(father);
        list.add(child);
        int size = list.size();
        for(int i = 0; i < size ; i++) {
            Father father1 = list.get(i);
            if(father1 instanceof Child){
                Child child1 = (Child) father1;
            }
        }
    }

Look at line 11, here father1 is type casted to Child, at line 10 we have checked wether father1 is an object instance of Child. so at line 11 now it is safe to cast to its subclass. If we remove line 10, we will not be sure wether father1 is a Child, if not of type Child,  a TypeCastException will be raised. Let's see type casting example in android programming. Look at the activity class code below :
 package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
    private Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.btnLogin);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

    }
}
In android code above, at line 14, findViewById(R.id.btnLogin); return value is a type of View (look at reference here ), but then is casted to type Button. Since Button extends View , see reference  here , this return value of findViewById could be a Button type. But you should make sure that the id R.id.btnLogin  is referring to is the right Button widget in layout xml file. If it does not correctly refer to Button widget in xml layout, a ClassCastException will be raised that will make your app force close.

Thank you for visiting our website. Just comment below if you have any question to ask.

Java Interface and Multiple Inheritance

Interface in java is to support multiple inheritance. What is multiple inheritance? a good question to ask. Multiple inheritance means you inherit property from many individuals. Take yourself as an example, you inherit properties from your mother and your father. A java class also need to inherit properties from other classes. We do this inheritance by extends keyword, it means we extends the class from super class. But extends keyword only valid for one class. for example :
package com.example.myapplication.alert;

/**
 * Created by SONY on 17/10/2016.
 */
public class Child extends Father {
}

It is not valid to extends from two classes like below :
package com.example.myapplication.alert;

/**
 * Created by SONY on 17/10/2016.
 */
public class Child extends Father, Mother {
}

And it is not valid also to write extends two times like below :
package com.example.myapplication.alert;

/**
 * Created by SONY on 17/10/2016.
 */
public class Child extends Father extends Mother {
}

But like in the real world, you need the child inherit properties from mother and father (not just from mother only or father only). Now, I want a child has white skin like his mother and black hair like his father. Okay, that is why we have interface. Let's do that.

Below we define an interface IMother with setSkinWhite() method:
package com.example.myapplication.alert;

/**
 * Created by SONY on 17/10/2016.
 */
public interface IMother {
    public void setSkinWhite();
}


And below we define interface IFather with setHairBlack() method:
package com.example.myapplication.alert;

/**
 * Created by SONY on 17/10/2016.
 */
public interface IFather {
    public void setHairBlack();
}

Now let's make  Child that inherit both IMother and IFather properties.

package com.example.myapplication.alert;

/**
 * Created by SONY on 17/10/2016.
 */
public class Child implements IMother, IFather {
    @Override
    public void setHairBlack() {
        
    }

    @Override
    public void setSkinWhite() {

    }
}


From the above code you see that Child implements both IMother and IFather. So now that child inherits property from his mother and his father. That's it. That is multiple inheritance in java.

Thank you for visiting our website. Just comment below if you have any question to ask.

What is NullPointerException

If you are new to android programming you will frequently encounter with NullPointerException when running your app. NullPointerException will make your running app crash. You will be warned with a dialog app force close.

What is NullPointerException?. From its name we know that it is one of java exception. This exception is raised by Java when you refer to a variable that is null. It means that your variable is not yet initialized, so when you call a method to that variable it does not know where that method is, because that variable itself points to nothing.

Below is an example of NullPointerException in android programming :

package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
    private Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                
            }
        });


That piece of code above will raise a NullPointerException at line 14, because the variable button is not yet initialized and the method call to button.setOnClickListener does not point to any object at all.
Try to debug at that line by putting a breakpoint at line 14, tutorial to debuggin is here. Point your mouse arrow on button variable, you will see that button variable is still null, then click resume the app will crash.

You can fix that code by initializing button like in the example below :

package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
    private Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.btnLogin);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

    }
}

In the code above button variable has been initialized by findViewById(R.id.btnLogin); and it is safe now to call button.setOnClickListener, no NullPointerException will be raised.

Thank you for visiting our website. Just comment below if you have any question to ask.

What is a java class

A class is a blueprint of object. In java, class is a keyword, you can not use this keyword to name a variable because it is reserved to represent a class.  In  a class you can create other classes, you can create methods, create global variables and etc. Below is an example of a class Student.

package com.example.myapplication.alert;

/**
 * Created by SONY on 17/10/2016.
 */
public class Student {
    private String name;
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}


You can use that class by creating the object class first like in the example below :
 Student student = new Student();
        student.setName("Robert");
        String name = student.getName();


Thank you for visiting our website. Just comment below if you have any question to ask.

Sunday, October 16, 2016

I want to learn android programming from zero

You never do any programming before and you don't study computer science either. But you really want to make an android app. Maybe you are inspired by young people there in the world who have gained a lot of money and become millionaire in their country by making apps or games that luckily becomes so popular. Don't worried. You are in the right place here.

Learning android programming to make apps does not difficult at all. It does not require high math skills unless if you want to invent a new algorithm for search engine. To make you comfort with android programming you just have to change your mindset that everything is object. Yes, Android uses Java and it is one of Object Oriented Programming (OOP). Everything you see or not see in android app is an object. That object also contains other objects. When you click a button, that button is an object. When you see a  page screen that screen is also an object and it contains other objects like button. When you send a message it also create an http object where you can not see.  Even the application itself is an object. So right now look at java codes in android and view it as object. Okay, I think it is clear now and you want to rush to coding.

To start writing code you need to open Android Studio and launch a new project. see :make my first app. After you click next next next and so on, then you finish. Click run button in Android Studio menu and your app will be built, a "hello word" text is shown to you. That is android application. You still don't write any code yet. But the app is there has been created for you by Android Studio. Well well,  At this time you are not supposed to write  any code yet, but you need to understand what has been written to you by android studio. 

When you launch a new project and then click finish at the end the android studio creates some folders and files for the app. The most important file you need to understand is AndroidManifest.xml. 

Below is the example of AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="com.example.myapplication.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


This manifest file tells you a lot information about the application. All of your activity should be registered in this manifest otherwise will not work. The highest hierarchy in manifest is <application> tag. That is your application, it contains activity as the children. When you first install your application from google play store or from apk file or you build from android studio the android system create your application object. Now start thinking that you app is an object. Now click the app icon in home menu screen then it will display a page (page is activity), which activity is displayed first?. Allright,  this manifest will tell you. That the activity that has been declared with intent-filter
as android.intent.category.LAUNCHER will displayed first. Okay now clear to you that why I should see that page. Now let's go back to object thinking. Now when it lauch that activity it creates that activity object, well activity is an object now. Let's see an example of activity code :
package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
    }
}

See that MainActivity extends Activity, Activity is a class from Android Library SDK, you don't write it, the google team write it for you, you just extends it. That activity calls onCreate method and set content to your page in  line setContentView(R.layout.activity_main); That is why you see layout activity_main.xml is shown to you. You put activity_main.xml in layout folder under res folder separated from java files, to make easier for you to manage source code. see : explore android studio folders and files. If you have understand this basic concept you are ready for next lessons. keep in mind that everything is object.


Thank you for visiting our website. Just comment below if you have any question to ask.