Wednesday, 23 July 2014

How can include external jar on Netbeans project

Leave a Comment
Hello friends today i am telling you how to include external jar into your Netbeans project.
One of my friend ask me a question :
When I run "clean and build" the .jar file that is being created only runs if the lib folder is at the same folder of the .jar file.
So if I move the jar file to the desktop and leave the lib folder in the dist folder, the jar file will give me an exception.
How can I deal with this problem?
How can include external jar on Netbeans project,include external jar on Netbeans project,external jar on Netbeans project,jar on Netbeans project,Netbeans project,

I solved this by creating just one jar file with all libraries inside, adding the following to my build.xml file in NetBeans:
<target name="-post-jar">
  <jar jarfile="dist/Combined-dist.jar">
    <zipfileset src="${dist.jar}" excludes="META-INF/*" />
    <zipfileset src="lib/commons-io-1.4.jar" excludes="META-INF/*" />
    <zipfileset src="lib/ninja-utils-3.2.jar" excludes="META-INF/*" />
    <zipfileset src="lib/unicorn-1.0.jar" excludes="META-INF/*" />
    <manifest>
        <attribute name="Main-Class" value="com.example.mypackage.Main"/>
    </manifest>
  </jar>
</target>

This creates a jar file (Combined-dist.jar) which is the combination of the dist jar and the specified library jars (in this case, commons-io-1.4.jar,ninja-utils-3.2.jar and unicorn-1.0.jar). You have to be sure to specify your Main Class package for the new jar file or it won't run when you try to open it.
Read More...

Monday, 21 July 2014

AndEngine - Core Terminology

Leave a Comment
In this article, I will try to cover description, of the most important engine concepts. Brief information, such as description of most frequently used classes and their extensions.
AndEngine - Core Terminology,Core Terminology,


  • Engine:

The Engine make the game proceed in small discrete steps of time. The Engine manages to synchronize a periodic drawing and updating of the Scene, which contains all the content that your game is currently handling actively. You can use also subclasses:
LimitedFPSEngine - tries to achieve a specific amount of updates per second.

  • IResolutionPolicy:

An implementation of the IResolutionPolicy interface is part of the EngineOptions. It tells AndEngine how to deal with the different screen-sizes of different devices. I.e. RatioResolutionPolicy will maximize the SurfaceView to the limiting size of the screen, while keeping a specific ratio. That means objects won't be distorted while the SurfaceView has the maximum size possible.

  1. RatioResolutionPolicy - keep everything scaled in in proper ratio (disadvantage - black lines might occur)
  2. FillResolutionPolicy - fill whole resolution (disadvantage - images might be stretched)


  • Camera:

A Camera defines the rectangle of the scene that is drawn on the screen, as not the whole scene is visible all the time. Usually there is one Camera per Scene. There are subclasses with more functions, example:

  1. BoundCamera - you might specify bounds for your scene.
  2. ZoomCamera - you might enable zooming, pinch zoom, and scrolling camera.


  • Scene:

The Scene class is the root container for all objects to be drawn on the screen. A Scene has a specific amount of Layers, which themselves can contain a (fixed or dynamic) amount of Entities. There are subclasses, like the CameraScene/HUD/MenuScene that are drawing themselves to the same position of the Scene no matter where the camera is positioned to.
HUD - usage for example for score (it has to be all the time in the same position, follow camera changes)

  • Entity:

An Entitiy is an object that can be drawn, like Sprites, Rectangles, Text or Lines. An Entity has a position/rotation/scale/color/etc.

  1. Sprite - entity with texture
  2. TiledSprite - entity with tiled texture, you may switch between tiles.
  3. AnimatedSprite - extension of the TiledSprite, you may animate tiles in specified intervals.


  • Texture:

A Texture is a 'image' in the memory of the graphics chip. On Android the width and height of a Texture has to be a power of 2 (in latest GLES2 this rule is not required, so its really useful to reduce memory usage) Therefore AndEngine assembles a Texture from a couple of ITextureSources, so the space can be used better.

  • TextureRegion:

A TextureRegion defines a rectangle on the Texture. A TextureRegion is used by Sprites to let the system know what part of the big Texture the Sprite is showing.
Read More...

How to Setup AndEngine for android game development

Leave a Comment
If you wish to know how to setup the latest AndEngine, please check the video made by RealMayo. It is a detailed tutorial about how to setup Eclipse, Android SDK, download and install the latest AndEngine and how to run the AndEngine examples.
How to Setup AndEngine for android game development,Setup AndEngine for android game development,AndEngine for android game development,android game development,

This videos show how to install the latest version of the engine (which is the GLES2 version).
 You can get it from this github (official from andengine creator) - just make sure to use proper branch - LINK.
Read More...

What is AndEngine android game framework

Leave a Comment
AndEngine is a free open source OpenGL android game engine, developed by  Nicolas Gramlich. It covers the most important OpenGL aspects, which means even if you don't have experience with OpenGL - you can still create great games/applications using this engine, the most important thing obviously is proper Java programming experience.
Introduction to the AndEngine,to the AndEngine,AndEngine,AndEngine, tutorials,AndEngine game development

Most important features of the engine:

  • Scaling across various devices (different resolutions)
  • Multi touch support.
  • Physics extension - Box2D (the one used by for example AngryBirds)
  • TiledMaps in TMX format support.
  • Particle Systems.
  • Live Wallpaper extension.

Benefits from using AndEngine:

  • Free and open source.
  • Most important aspects of every game are covered already by the engine.
  • You don't really need OpenGL experience (but it might be useful, obviously)
  • Fast, well designed and organized engine.
  • Relatively big, active and helpful community.
  • Great engine extensions.
  • Plenty of examples, showing off engine capabilities.

Major drawbacks:

  • There is almost no code documentation.
  • Sometimes slower in comparison to other engines.
  • Lack of documentation is the main difficulty while starting (hard to understand every parameter etc)

But instead of documentation, this engine has great example projects, showing most  every engine capability, it's a great way to check and understand how it work, hopeful while developing your own application. Also as mentioned, the engine community is very helpful, so you can always expect help from different developers. Hopefully this website will also help newcomers (as well as more experienced people) to understand how it works and improve the quality of your games!

Important Links :
Read More...

What is reflection and use in real life

Leave a Comment
Hello java developer today i am telling you what is reflection and use of reflection in real life.
Reflection is one of those things like multi-threading where everyone with experience of it says “Don’t use it unless you absolutely have to
 Above quote is absolutely true for all for us alike. This immediately back-fired me with lots of requests to come up with some real life "good" examples of reflection, and possible scenarios where a developer will be needing it. I promised to come up with my leanings/thoughts on this specific topic, and so here in this post, I will discuss the same i.e. real life practical examples of reflection in java.

What is reflection and use in real life,reflection and use in real life,use in real life, real life practical examples of reflection in java,life practical examples of reflection in java,practical examples of reflection in java,examples of reflection in java,reflection in java,reflection java,reflection in java


Q. When somebody would need Reflection?

Having said that in one sentence, let me elaborate it further. Java is strongly typed language with all the "good" features of OOPs. In practical, if you know the classes you are dealing with in your application, you may never ever come across a situation where you will need reflection. “Never ever”. You can accomplish any task, fulfill any requirement without reflection when you know the classes you are going to use.

But as soon as, you are told to deal with classes which you don’t know at time of writing the code, and you must write code in too general way such that it can handle any class type then you will need reflection to do the job.
For example, you are told to write a code analyzer which is able to look inside any class; and list down it’s all private method then you can do this only by reflection. Generally, It is said that whenever you don’t know, at compile time, the type that should be instantiated or the method that should invoked, you will need reflection.
Some Example which i discussed with you on reflection :

Having talked about need of reflection in real life application programming, it’s time to list down some instances where reflection is used to accomplish certain objectives.

  • Code analyzer tools

Code analyzers tools do lots of different things with your code. They do static analysis of syntax, show optimization tips and even report error conditions, and many more such things. They are written in a way such that they can analyze any class file passed to them to analyze. How can they do it without looking inside the class. Clearly, they use reflection to this analysis.

  • Eclipse (Other IDEs) auto completion of method names

Ever stressed your mind, how eclipse is able to provide you method suggestions whenever you hit CTRL+SPACE, even when you are not finished with writing that class. Reflection does this magic.

I have worked in a team which developed an eclipse plugin for generating REST API sourcecode, for methods defined in some interfaces. It used to create one REST API per interface method, and using wizard you can specify the other REST specific things such as HTTP method (GET, PUT, POST, DELETE), query parameters, path parameters and return values. Return value was a JAXB annotated class which was also generated by plugin. And almost 90% of the logic for code generation was written around reflection only.

In fact, reflection is heavily used in plugins for these kind of IDEs; be it eclipse, or IntelliJ or any other IDE for that matter.
  • Marshalling and unmarshalling
JAXB/Jattison and other marshalling/unmarshaling libraries heavily use reflection for XML (or JSON) to/from java beans code. They look up all annotated attributes in java bean, analyze their overall attributes and generate XML tags for them. The same is valid for unmarshaling as well.
  • Spring Framework for creating the beans
Spring framework uses dependency injection (DI) to populate the dependencies into beans defined in config files. DI framework actually heavily uses reflection for injecting these bean dependencies.

Spring 3 onwards, you can define the dependencies using annotations as well, using autowiring. Annotations are analyzed for dependencies injection using reflection only.
  • Parsing annotations by ORMs like hibernate entity
ORMs like hibernate use the config files (not they use annotations) for defining the relationship between entities and relationship between entity and database schemas. All this information is processed using java reflection capability.
  • Junit Testcases
If you remember the previous versions of Junit, then to run a testcase all you cad to do, was name a method starting with test e.g. testMethod1(), testCode2() etc. Junit processor was using reflection to iterate over all methods in class, and find-out methods starting with test and run this as testcase.

Read More...

Friday, 18 July 2014

Use Notification Tray in Java Application

Leave a Comment
Hello friends we're see the notification tray of software at bottom right side. And at-least one time you'll also think how it work and can i make it for me.
Today i am teaching you how to use notification tray in java application.
Since Java SE 6, we can add an icon for our applications in the system tray area of the operating system.

The following example is a basic implementation of SystemTray class.
import java.awt.*;
import java.awt.TrayIcon.MessageType;
import javax.swing.ImageIcon;
 
public class TrayNotification {
 
    public static void main(String[] args) throws AWTException  {
         
     TrayNotification td = new TrayNotification();
        td.displayTray();
 
    }
 
    public void displayTray() throws AWTException{
        //Obtain only one instance of the SystemTray object
        SystemTray tray = SystemTray.getSystemTray();
        //Creating a tray icon
        ImageIcon icon = new ImageIcon(getClass().getResource("notify.jpg"));
        Image image = icon.getImage();
        //System.out.println(image);
        TrayIcon trayIcon = new TrayIcon(image, "Tray Demo");
        //Let the system resizes the image if needed
        trayIcon.setImageAutoSize(true);
        //Set tooltip text for the tray icon
        trayIcon.setToolTip("System tray icon demo");
        tray.add(trayIcon);
        trayIcon.displayMessage("Hello, World", "This is demo from GeekOnJava", MessageType.INFO);
    }
}
You can use any image which you want to show at bottom. Here notify.jpg is a image file which place at where .class file exist.
Run and enjoy hopefully it work well for you.
Read More...

Wednesday, 25 June 2014

How to Convert String into Calendar Date in Java

Leave a Comment
Hello today i am telling you how to convert string into calendar date and it can be use with
Check : How to get future date from current date in java
and here if we fetch date from database and then we want future date then what we do. How can we convert the date(String ) into calendar date.
How to Convert String into Calendar Date in Java, Convert String into Calendar Date in Java,String into Calendar Date in Java,into Calendar Date in Java,Calendar Date in Java,Date in Java,

Here is the solution :
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;



public class Testing {

  public static void main(String[] args) {
   
   try
   {
   DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
   Date date = formatter.parse("01/29/2002");
   Calendar calendar = Calendar.getInstance();
   calendar.setTime(date);
   
   System.out.println("Changes date : " + (calendar.get(Calendar.MONTH) + 1) + "-"
          + calendar.get(Calendar.DATE) + "-" + calendar.get(Calendar.YEAR));

    
   }
   catch(Exception e)
   {
    System.out.println(e);
   }
    
    
    
  }
}
Thank you....
Read More...