Saturday, 25 April 2015

Differences between GLES2 and GLES2 Anchor Center

Leave a Comment
In this article, I will try to describe most important differences between two major AndEngine branches, GLES2 and GLES2 Anchor Center, there are some major differences between them.

In  my previous article, I was explaining differences between GLES1 (really old, not active, not recommended) and GLES2.

Currently, there are 3 AndEngine branches, which are:

  • GLES1 - old, abandoned by development, also almost not used by AndEngine developers, which means poor support. 
  • GLES2 - successor of the GLES1 branch, still actively used by developers, but its strongly recommended to move to the latest version of the engine.
  • GLES2 Anchor Center - latest version of the engine, quoting author:

"Rather sooner than later the GLES2-AnchorCenter branch will be merged into the GLES2 branch!
The main, most significant change in the GLES2 Anchor Center is that the coordinate system has changed. The coordinate system in the GLES2 Anchor Center branch has its origin in the lower left, this was changed for multiple reasons:

  • It is the native OpenGL coordinate system. (I can save a few +- calculations here and there.)
  • It is the same coordinate system as cocos2d-iphone and cocos2d-x. (This eases porting efforts in both directions by a whole bunch!)
  • It allowed author of the engine to easily/efficiently write the AndEngineCocosBuilderExtension, which allows reading a format exported by CocosBuilder.
  • It just feels more natural for any side-scrolling game.


Another thing that changed in this branch is that the anchorpoints (rotatincenter, scalecenter, etc…) are now relative, from 0.0 to 1.0, instead of being absolute values. So in general, AndEngine got a little more cocos2d-like on this branch, which is definitely not a bad thing.

To better understand, how does coordinate system works in GLES2 Anchor Center, lets take a look at this sample image:

Okay, lets say its our scene, lets say our camera size is 800x by 480y,

  • bottom left corner is 0x, 0y, top left corner is 0x, 480y
  • bottom right corner is 800x, 0y, top right corner is 800x, 480y
  • we have 3 images: image A, image B, and image C
  • image A is 50 width by 50 height, so to place it in the following position  we needed to place it on the 25x, 25y. 
  • imageB is 200 width by 150 height, I wanted to place it in the middle of the screen, which means its positioned in the 400x, 240y (which is 0.5 * camera width, by 0.5 * camera height)
  • image A and imageB are both attached to the scene.
  • image C is attached to the imageB (on the 0x, 0y - of the imageB)

Following this diagram, you should understand how does it work.
Read More

Comparison between AndEngine GLES1 and GLES2

Leave a Comment
1. What does GLES1 and GLES2 mean?
They are three AndEngine versions (branches), GLES2 and GLES2 Anchor Center which is is latest version of the engine, GLES1 version development  has been stopped. That's why if you are new, its STRONGLY recommended to use latest version of the engine, obviously its always better to work with newest software. Be aware that on my website, in my articles, I am always trying to use latest engine version.



2. Most important differences between those two versions:
Firs of all, GLES2 requires Android version >= 2.2
Some developers says that GLES2 is slower in comparison with GLES1 in some cases.
GLES2 is latest, and currently developed version of the engine.
If you want to know most important improvements in GLES2, please check THIS THREAD.

3. Which one should I select?
For me there are no doubts, you should use latest version of the engine. But if you decided to publish your application for wider android audience, GLES2 might be bad idea, because it requires android version >= 2.2 The good news is the fact, that this version is currently supported by 89% of devices worldwide - according to the official informations - MORE INFO HERE. So what's the conclusion? Basically everything depends on your application needs. Latest engine version, more features, active development!

See also: GLES2 vs GLES2 Anchor Center - differences.
4. Performance differences:

As previously mentioned, some developers says, that GLES2 is slower in some cases in compare to GLES1, also it has been proven by some tests. But even though, I strongly recommend to use latest software version
Read More

Wednesday, 15 April 2015

How to make Clone Object in Java

Leave a Comment
The clone method generates a duplicate copy of the object on which it is called.
The object cloning is a way to create exact copy of an object. For this purpose, clone() method of Object class is used to clone an object.
Only classes that implement the Cloneable interface can be cloned. The Cloneable interface defines no members. It is used to indicate that a class allows a bitwise copy of an object (that is, a clone) to be made.
How to make Clone Object in Java,make Clone Object in Java,Clone Object in Java,Object in Java,

If you try to call clone( ) on a class that does not implement Cloneable, a CloneNotSupportedException is thrown. A clone is simply an exact copy of the original.

Example :
class Data implements Cloneable{
    
    int data1;
    int data2;
    
    public Data cloning()
    {  
        try{
            return (Data)super.clone();  
        }catch (CloneNotSupportedException cns) {
            System.out.println("Cloning Error");
            return this;
        }
    }  
}

public class Javaapp {

    public static void main(String[] args) {
        
        Data d1 = new Data();
        d1.data1 = 50;
        d1.data2 = 100;
        System.out.println("d1.data1 = "+d1.data1);
        System.out.println("d1.data2 = "+d1.data2);
        
        Data d2 = d1.cloning();
        System.out.println("d2.data1 = "+d2.data1);
        System.out.println("d2.data2 = "+d2.data2);
    }
}
Flow of Program :
For see the flow of working click on image

Have any trouble or queries please comment below.
Read More

Tuesday, 14 April 2015

Repeat Task at particular time in Java

Leave a Comment
Sometimes you need to schedule your task and want to repeat them at particular time like check the notification of user after ever 5 sec etc.
For this purpose Java has Timer and TimerTask class but what is it ?
  • java.util.Timer is a utility class that can be used to schedule a thread to be executed at certain time in future. Java Timer class can be used to schedule a task to be run one-time or to be run at regular intervals.
  • java.util.TimerTask is an abstract class that implements Runnable interface and we need to extend this class to create our own TimerTask that can be scheduled using java Timer class.
Repeat Task at particular time in Java,Task at particular time in Java,particular time in Java,time in Java,timer and timer task in java,timer in java,timertask in java,timer example java

package com.blogspot.geekonjava;
 
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
 
public class MyTimerTask extends TimerTask {
 
    @Override
    public void run() {
        System.out.println("Timer task started at:"+new Date());
        completeTask();
        System.out.println("Timer task finished at:"+new Date());
    }
 
    private void completeTask() {
        try {
            //assuming it takes 20 secs to complete the task
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
     
    public static void main(String args[]){
        TimerTask timerTask = new MyTimerTask();
        //running timer task as daemon thread
        Timer timer = new Timer(true);
        timer.scheduleAtFixedRate(timerTask, 0, 10*1000);
        System.out.println("TimerTask started");
        //cancel after sometime
        try {
            Thread.sleep(120000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        timer.cancel();
        System.out.println("TimerTask cancelled");
        try {
            Thread.sleep(30000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
 
}

Result :
Notice that one thread execution will take 20 seconds but Timer object is scheduled to run the task every 10 seconds

Timer class is thread safe and multiple threads can share a single Timer object without need for external synchronization.
Timer class uses java.util.TaskQueue to add tasks at given regular interval and at any time there can be only one thread running the TimerTask, for example if you are creating a Timer to run every 10 seconds but single thread execution takes 20 seconds, then Timer object will keep adding tasks to the queue and as soon as one thread is finished, it will notify the queue and another thread will start executing.
Read More

Monday, 13 April 2015

Why Quartz doesn't remove deleted job from the scheduling

Leave a Comment
Sometimes when we use Quartz for schedule the task in Java and when you want to remove the old task then you would be face some unexpected error.
Your old Quartz task remain running and these type of error got by my friend David :

Question by David 

I'm developing scheduled services.
The application is developed using JDK 1.6, Spring Framework 2.5.6 and Quartz 1.8.4 to schedule jobs.
I've two clustered servers with WebLogic Server 10.3.5.
The behavior that I noticed is that if a job is removed (or renamed) from the application, Quartz keeps trying to launch the old job (which seems to be registered in the database that Quartz uses to synchronize its instances).
Can someone explain the reason for this behavior?
My need is that when I delete a job in the application and I restart WebLogic instances, Quartz does not attempt to boot the old job.
Thanks in advance.
You can fixed these error.
Why Quartz doesn't remove deleted job from the scheduling,Quartz doesn't remove deleted job from the scheduling,doesn't remove deleted job from the scheduling,remove deleted job from the scheduling,deleted job from the scheduling,job from the scheduling,remove quartz in java

You need to remove the job explicitly from the quartz scheduler, have you done that?
For example if you have this scedhuler
private org.quartz.Scheduler myScheduler = null;
you need to invoke:

myScheduler.deleteJob(...
when the job is removed or renamed.

If you do, maybe you're passing incorrect key?

Alternatively, when you build the quartz job, you can use: jobBuilder.storeDurably(false) This will cause your quartz job to be deleted automatically when there are no longer active trigger associated to it.
Read More

Monday, 1 December 2014

What is Synchronized method ?

Leave a Comment
The Java programming language provides two basic synchronization idioms: synchronized methods and synchronized statements. The more complex of the two, synchronized statements, are described in the other post. This section is about synchronized methods.

What is Synchronized method in java,Synchronized method in java,method in java,in java,


To make a method synchronized, simply add the synchronized keyword to its declaration:
public class SynchronizedCounter {
    private int c = 0;
    public synchronized void increment() {
        c++;
    }
    public synchronized void decrement() {
        c--;
    }
    public synchronized int value() {
        return c;
    }
}
If count is an instance of SynchronizedCounter, then making these methods synchronized has two effects:


  • First, it is not possible for two invocations of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.
  • Second, when a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads.
Note: 
Constructors cannot be synchronized — using the synchronized keyword with a constructor is a syntax error. Synchronizing constructors doesn't make sense, because only the thread that creates an object should have access to it while it is being constructed.

Warning:
When constructing an object that will be shared between threads, be very careful that a reference to the object does not "leak" prematurely. For example, suppose you want to maintain a List called instances containing every instance of class. You might be tempted to add the following line to your constructor:
instances.add(this);
But then other threads can use instances to access the object before construction of the object is complete.

Synchronized methods enable a simple strategy for preventing thread interference and memory consistency errors: if an object is visible to more than one thread, all reads or writes to that object's variables are done through synchronized methods.

Important Point:
(An important exception: final fields, which cannot be modified after the object is constructed, can be safely read through non-synchronized methods, once the object is constructed) .
Read More

Friday, 28 November 2014

Two free tools for all Android Developers

Leave a Comment
Hello friends today i am telling you two free tools for android developers by which you android application made easy .
First tool is Android Button Maker and other is Android Asset Studio.

Two free tools for all Android Developers,best free tools for android,android designing tools free



  • Android Buttton Maker

Android Button Maker is online tool to generate buttons code for Android Apps. Android API provide Drawable Resources where XML file defines geometric shape, including colors, border and gradients.

These button is generating based on shape drawable XML code which load faster compare to normal png buttons. You can customize button properties in setting panel and get source code.

View this Tools Site



  • Android Asset Studio

Creating different icon types in several densities, with the right gradient color, shadow, borders, selected/unselected state etc, can be quite time-consuming. This is a great tool for Android Developers that need to build the icons for their application within a few minutes.
The Android Asset Studio has several tools in it including

  1. Launcher icons
  2. Action bar and tab icons
  3. Notification icons
  4. Navigation drawer indicator
  5. Generic icons

It is best to use it in Chrome.

View this Tools Site

Read More