Tag Archives: tutorial

Some Basic Java Script

Hi guys, I thought of learning some Java Script as it has become one of the most important aspect of a programer in the present. So I thought of handling some basic default functions for a start. Hope you guys achieve some thing out from this post.

So here we will see how to write JavaScript inside the Basic html inside Body tag. We will see the external Java Script in another Tutorial.

So here we define the Script Tag inside the body and Write all the code explained between the Script Tags.

noscript tag is attached to inform people who are viewing this site in a browser that does not support Java Script.

<html xmlns="http://www.w3.org/1999/xhtml">

<script language="javascript" type="text/javascript">

//Java Scrip Code Goes Here

<noscript><h3>This site needs Javascript Enabled Browser</h3></noscript>


So below are some basic Java Script code you can try yourself

1. A simple Alert

alert("Hi this is amalan");

2. Min and Max number supported by JS

document.write(Number.MAX_VALUE + "<br/>");
document.write(Number.MIN_VALUE + "<br/>");

3. Printing a String

var sampl_str = "Here are some Escape charecters \" \t \' \\ \n";
document.write(sampl_str + "</br>");

4. Combining Strings

var first_String = "First String";
var second_String = "Second String";
var combined_String = first_String + second_String ;
document.write(combined_String + "</br>");

5. Example of using substring function

document.write("Sub String " + combined_String.substring(12, 18) + "</br>");

6. Getting the Last character

document.write("Last Charecter =" + combined_String.charAt(combined_String.length-1) + "</br>");

7.Usage of Indexof function

document.write("Index of " + combined_String.indexOf('t') + "</br>");


var str_var = "5";
var num_var = 10;

var total = num_var + str_var;
var multy = num_var * str_var;

document.write("Total is :" + total+"</br>");
document.write("Multy is :" + multy+"</br>");

9.Force data type conversion

total = num_var + Number(str_var);
document.write("Total is :" + total+"</br>");

total = num_var + num_var;
document.write("Total is :" + total+"</br>");

total = num_var + String(num_var);
document.write("Total is :" + total+"</br>");

10. Float

var float_var = 3.1417376464646464;
var float_str = float_var.toFixed(7);
document.write("Shortened PI value by 7 : "+float_str+"</br>");

document.write("Data type of float_var = "+typeof(float_var)+"</br>");
document.write("Data type of float_str = " + typeof(float_str) + "</br>");


var bool_var = Boolean(23);
document.write("Booloean of 23 is " + bool_var + "</br>");

12. Compare Variables

var rand_num1 = 5;
var rand_num2 = 10;

document.write("5 > 10 = "+(rand_num1 > rand_num2)+"</br>");
document.write("5 >= 10 = "+(rand_num1 >= rand_num2)+"</br>");
document.write("5 == 10 = "+(rand_num1 == rand_num2)+"</br>");
document.write("5 <= 10 = "+(rand_num1 <= rand_num2)+"</br>");
document.write("5 < 10 = "+(rand_num1 < rand_num2)+"</br>");
document.write("5 != 10 = "+(rand_num1 != rand_num2)+"</br>");

13.Logical operators

document.write("Is 5 < 10 and 5 != 10 "+((rand_num1 < rand_num2) && (rand_num1 != rand_num2))+"</br>");
document.write("Is 5 > 10 or 5 != 10 "+((rand_num1 > rand_num2) || (rand_num1 != rand_num2))+"</br>");
document.write("Is 5 < 10"+ !(rand_num1 < rand_num2)+"</br>");



var vehihcals = new Array("Car", "Van","Bus");
document.write("Second Value of the Vehical Array is :" + vehihcals[1]+"</br>");

15.Cycle through Array

for (i in vehihcals) {

document.write("vehical value "+ (Number(i)+1)+" is "+vehihcals[i]+"</br>");


16.Conditional Opperators

var rand_var = (5 < 10) ? "5 is less than 10" : "5 is greater than 10";
document.write(rand_var + "</br>");

17.if Else

if (5 > 5) {
document.write("5 is greater than 10"+"</br>");

else if (5 < 5) {
document.write("5 is less than 10"+"</br>");
else {
document.write("Both are Equal"+"</br>");

18.Switch Case

var state = "Colombo";

switch (state) {
case "Kandy":
document.write("Colder than Me" + "</br>");

case "Colombo":
document.write("Same as Me" + "</br>");

document.write("I dont know what you have entered"+"</br>");


var count = 1;

while (count <= 10) {

20.Continue Statement

var count = 1;

while (count <= 10) {

//try break
//if (count == 6) {
//    break;

if (count % 2) {

document.write(count + "</br>");


var count = 10;

do {
document.write(count + "</br>");
} while (count > 10);


for (var count = 0; count <= 10; count++) {


Get the Code here : Download code

Reference : YouTube Reference

Lets try Android Game Development with AndEngine

Hi Guys, this time I am back with some Android Game Development. I got this idea after, the popular game Flappy Bird. Hope all may have tried that game…!
Ok, so I wanted to develop a game and I did some researches and found out that there are a lot of Game engines out there.  Some of them are COCOS2D, AndEngine, libGDX and many others. In this article I’ll guild you using AndEngine which is a bit easier one. In future I’ll write on libGDX.

Assumption : I assume that you guys know how to install eclipse development environment, configure java path and install Android plugin to eclipse. This post does not cover all those basic steps.

Advise : As this is a kind of a crash course, its advisable to create files the same name as I use(But it is not mandatory).

Expected Outcome : You will be able to create some lines using the AndEngine

Step 1
Download the Source(library) for the AndEngine using this link and extract

Step 2
Create a new project and when creating select ‘Android Project from Existing Code’ and in it select the folder that we extracted in the Step1.
existing code

This is a library project. Actually this library is the ANDENGINE.

You can check it by right clicking on the project we created now and going to the Android tab. You can see the ‘Is Library’ check box ticked.

Step 3
Now create a new Android project and un tick the create activity. Because we are going to create AndEngine activity using the library project we created above.

Step 4
Now you have a project with empty src folder. Right click on that folder and create a new package when naming the package use the package name available in that project ManifestFile

In my case package name is ‘”com.batz.andengsample”‘

Step 4
Now in side the empty package Download or copy the code and create LineEample.java activity using this LineExample Source Code.

You will get some errors, but don’t worry we will fix it in the next step.

Step 5
So now in your project, right click and go to Android tab and there in the below section(library section), click on the add button and select the AndEngine project and press ok. And then press Apply.
add library

Now all the errors may have gone. Some times you will have errors on the package name, if you have used your own name. So for that, click on the package name that shows as error, click ctrl key +1 key , which will bring suggestion to create a package name according to yours, and click on it to create it. And hopefully all the bugs will be fixed.

Step 6
Before going for the app launch, we have to do one more important thing, we have to specify the activity we created now in the manifest file as a launcher

So go to the manifest file and add these lines between the application tags

<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />

LineExample is the name I gave for the activity we created, so in your one don’t forget to change that

Step 7
Now you are ready to run the app. So while you are in the the activity try running the app. it should bring a screen where you will see lots of random lines.

Step 8(For people getting error saying cannot find andengine.apk)
For some people the AndEngine folder is not getting added as library on the time of building the app. So at that point what you can do is copy the andengine.jar file from the AndEngine project libs folder and copy it into your projects’s libs folder. And right click on the newly added andengine.jar file and click on ‘Add to Build Path’ option. This is how the project structure looks after I added the jar to my project from the AndEngine project in the Step8


AndEngine Resources : http://www.andengine.org/

For people who got more time , for people who needs more detailed instruction on the same project guild please watch this tutorial video
Development Reference : http://www.youtube.com/watch?v=Q0kjiIH6u-M

Thank You
Happy Coding…!