Unique and Premium information

Over 1000+ working code & snippets, enjoy!

Featured Coupons

Ad (728x90)

Latest Posts

Download Android SDK/ADT

ADT Bundle Download

The Android ADT provides you access to the API libraries and development tools necessary to build, test, and debug any application developed on Android.
If you are new to Android development, and unaware and don't wanna do lengthy setup of android SDK then I will recommend you to download the ADT Bundle to quickly starting the android application developing. It includes the essential Android SDK components and a version of the Eclipse IDE with built-in ADT (Android Developer Tools) to streamline your Android app development.

With a single download of ATD, you will have the access to below tools you will need to begin developing android application:
  1. Eclipse + ADT plugin
  2. Android SDK Tools
  3. Android Platform-tools
  4. A version of the Android platform
  5. A version of the Android system image for the emulator

SDK Download

If you are not willing to work on eclipse and require a sdk for your android application development then use below link to download the SDK and use your own(any other than eclipse) IDE and set the SDK in their preferences.



Android

Setting UP Android Environment

Installing the Android Development kit

Download ADT, which stands for Android Development Kit, ADT Bundle provides everything you need to start developing apps, including the Android SDK tools and a version of the Eclipse IDE with built-in ADT (Android Developer Tools) to streamline your Android app development.

If you didn't yet downloaded the ADT bundle, Please use download the Eclipse ADT bundle, or switch to the Android Studio install or stand-alone SDK Tools install instructions.

To set up the ADT Bundle:
  1. UnZIP the ZIP file named as adt-bundle-<os_platform>.zip as a downloaded ADT bundle and save it to an appropriate location, like "Development" directory.
  2. Open the adt-bundle-<os_platform>/eclipse/ directory and launch Eclipse.
Warning!!!
Please don't change the SDK folder, which may lead to SDK unavailability that can be then manually set through eclipse preferences.
Android

Getting Started with Android Development

Welcome to my blog with which I will try to help you for Android application development. Here you'll find sets of lessons that describe how to accomplish a specific task with some simple and easy to follow samples and you can re-use in your app with out any hesitation. I organised the whose samples and classes into several groups you can find the top-level of the left navigation.
This first article will help you the bare essentials for Android application development. If you're a new Android app developer, you should complete each of these classes in order:
Setting UP Android Environment: After the decision of making and learning the android development/programming this will be the first step to learn that how to setting up the development environment.
What are basics of Android development: This is the first building block of android development, what is activity, intent.
Building your first Android Application: After you've installed the Android SDK, start with this class to learn the basics about Android app development.


    Android

    Custom ClassLoader

    Dynamic Class Loading or Custom Class Loaders are few of the terms which is well known to a Java developer or who is touchbase with Java. now lets learn the term Class Loading and how does it work.

    Class Loading is a term used in Java to load Java classes at the startup, Now we have have different instances wherein we have necessity of loading a class or you can say at below instances a class can be loaded to JVM,

    1. Bootstrap, It is responsible to load java.* packages, typically it is loading rt.jar(Also called runtime jar) and i18n.jar
    2. Extensions, JDK libraries are used to load by here, normally JRE's EXT/LIB are loaded.
    3. System, Loads classes from system classpath or used to load custom classloaders.
    Types of Class Loading?
    Class Loading is a mechanism of loading classes at startup of application and is used widely to support runtime class loading, means if you want to change a class and don't want to start your container again the class loading is best to implement it, now lets learn how many types of a class loading are there in Java,

    Static Class Loading, If we are using "new" operator to create class object, this type of loading or creation of class object is called Static Class loading.
    MySingleton ms = new MySingleton();
    Dynamic Class Loading, Dynamic loading is a technique for programmatically invoking the functions of a
    class loader at run time. Let us look at how to load classes dynamically. 
    Class.forName("com.tekhnologia.classloader.MySingleton");
    Now above code will load your class over JVM and now you can use this class anywhere in you class where you have define above line. Please follow below to create instance from above code,
    Class mysingleClass = Class.forName(com.tekhnologia.classloader.MySingleton");
    MySingleton ms = ()mysingleClass.newInstance();
    ms.runMethod();
    Above code will load class MySingleton and by use of .newInsance() instance will be created then by instance method of class can be use.

    Difference between Static and Dynamic Class Loading?
    Static Class Loading, NoClassDefFoundException will be thrown when class not found.
    Dynamic Class Loading, Will throw ClassNotFoundException.


    Here we will learn how to create our own custom loader class so that we can load as we need the class,
    package com.tekhnologia.classloader;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.util.Hashtable;
    public class SingletonClassloader extends ClassLoader {
    private Hashtable classes = new Hashtable();
    public SingletonClassloader() {
    super(SingletonClassloader.class.getClassLoader());
    }
    public Class loadClass(String className) throws ClassNotFoundException {
            return findClass(className);
        }
    public Class findClass(String className){
            byte classByte[];
            Class result=null;
            result = (Class)classes.get(className);
            if(result != null){
                return result;
            }
         
            try{
                return findSystemClass(className);
            }catch(Exception e){
            }
            try{
            if(!classes.containsKey(className)){
               String classPath =    ((String)ClassLoader.getSystemResource(className.replace('.',File.separatorChar)+".class").getFile()).substring(1);
               classByte = loadClassData(classPath);
                result = defineClass(className,classByte,0,classByte.length,null);
                classes.put(className,result);
                return result;
            }
            else
            return classes.get(className).getClass();
            }catch(Exception e){
                return null;
            }
        }
     
    private byte[] loadClassData(String className) throws IOException{

            File f ;
            f = new File(className);
            int size = (int)f.length();
            byte buff[] = new byte[size];
            FileInputStream fis = new FileInputStream(f);
            DataInputStream dis = new DataInputStream(fis);
            dis.readFully(buff);
            dis.close();
            return buff;
        }
    }
    You can have this tested by below code

    package com.tekhnologia.classloader;

    public class SingletonCLtest {
    public static void main(String[] args) {
    SingletonClassloader scl = new SingletonClassloader();
    String classpath ="com.tekhnologia.classloader.MySingleton";
    try {
    scl.loadClass(classpath);
    MySingleton.seeWhatHappen();
    } catch (ClassNotFoundException e) {
    System.out.println("Class can not be loaded.");
    }
    }
    }

    We frequently update my articles to best of my knowledge, please touch base with us to get maximum.
    If you like reading Please share with others or provide feedback to make it better. 

    Regards,
    Bhanu Pratap
    java

    Needs of Design Patterns in an Application?


    When we talk about design patterns, its seems to be rocket science for some developers and some developer finding it easy to go. Here I will try to make this rocket science design patterns to be a easy to go. Lets answer below questions before going to be a pro in design pattern in java and will try to answer one by one here.
    1. What is Design Patterns?
    2. What is an application?
    3. Why we need Design patterns in application?
    4. How many types of design patterns you now?
    5. How to judge the best scenario for any design pattern to be selected.
    6. How to best implement any pattern?
    If you are not sure about the answers of above asked question then please wait lets describe it one by one here.
    Brief about Design Pattern,
    - Before jumping into answers, lets know something about the design patterns, Design patterns is all about the documentation and implementation of a specific problem which have the common or you can say a well known solution, Concept for Design Pattern was initially started by four guys Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, who was collectively famous as GOF which means Gang of Four, who documented the problem and design pattern concept in the form  of book called Design Patterns: Elements of Reusable Object-Oriented Software. In which they have classified the book in below major criteria so as to understand the concept of design pattern.
    • Pattern Name and Classification: A descriptive and unique name that helps in identifying and referring to the pattern.
    • Intent: A description of the goal behind the pattern and the reason for using it.
    • Also Known As: Other names for the pattern.
    • Motivation (Forces): A scenario consisting of a problem and a context in which this pattern can be used.
    • Applicability: Situations in which this pattern is usable; the context for the pattern.
    • Structure: A graphical representation of the pattern. Class diagrams and Interaction diagrams may be used for this purpose.
    • Participants: A listing of the classes and objects used in the pattern and their roles in the design.
    • Collaboration: A description of how classes and objects used in the pattern interact with each other.
    • Consequences: A description of the results, side effects, and trade offs caused by using the pattern.
    • Implementation: A description of an implementation of the pattern; the solution part of the pattern.
    • Sample Code: An illustration of how the pattern can be used in a programming language.
    • Known Uses: Examples of real usages of the pattern.
    • Related Patterns: Other patterns that have some relationship with the pattern; discussion of the differences between the pattern and similar patterns.
    Now lets back to our discussion, Now how to define design pattern now.
    What is Design Patterns,
    - A Design pattern is a pre-defined solution to a recurring issue, issue may be of java, .net, PHP or any technology/framework, here implementation may vary with technologies/languages or framework but concept to have the problem solved  will  remain same while implementing any design patterns.
    What is an Application?
    - You were be surprised why we have asked this question here why we need to know the application to design pattern and how it can be related to design pattern, Yes its important to know your application before implementing any design pattern in it.
    Ok, Let me ask you one question if you have doubt, If your car has break down , its Tyre pass away, now when you reach to Tyre shop what will you do, what will you ask for. Hmmm…, You have to ask for a specific type which will fit in your specific car, hope you will not ask for any Tyre irrespective to of car specification. yes this is what the difference is. You have to be very precise before implementing the design pattern.
    Anyways Design pattern is dependent on many factor of application and not all design pattern can be implemented in a single Application.
    Why we need Design patterns in an application,
    While developer working on an application, he suddenly face an issue for coding on some functionality/requirement,now he work hard to resolved it  and now after putting an decent amount lets say X hrs he able to solve the problem.
    Till now, there is no issue and if it will be only one time issue, Now what should happen when this developer who work hard and put X hrs to solve the issue resign from company or developer from other company have the same problem and put same effort again, So here is the concern which a design pattern try to resolve here.
    Yes, you got it right, Now we will ask developer to document the problem and its solution too. Now you will wondering, whats the big deal, it is used to happen in every company.
    Yes, Its a big deal, Check out the GoF(Group of Four) for it, its a matter to have all those problem and its solution compile in a document and make some benchmark on acceptance by the user(developer/Architect who gonna use them and feel it beneficiary) this is what GoF try to achieve by their book Design Patterns. 
    How many types of design patterns you now,
    Generally, Design patterns are divided into three category, as follows
    1. Creational Design Patterns, Creational Design pattern is basically focus on creation of object for class.
    2. Behavioral Design Patterns, it help you compose groups of objects into larger structures, such as complex user interfaces or accounting data.
    3. Structural Design Patterns, This helps in communication between objects in system or application and control the flow between objects in a complex application.
    Please share if you like.

    We frequently update my articles to best of my knowledge, please touch base with us to get maximum.
    If you like reading Please share with others or provide feedback to make it better. 
    Design patterns

    Spring first HelloWorld example

    Here I will try to walk through the Spring3.0 first example, which will help you in understanding the spring workflow. and classes and xml required to complete one request process, here we will work on sample java application and not a web application.

    Here we are creating following components to run Spring java application, but before starting please read through the configuration required for Spring3, this will help you setup spring in eclipse.


    Lets create a simple class with sayHello method in it, and put some instructions so that you can see something happening in console here I have put SOP which will print a line Hello from Spring 3.0.


    Spring3HelloWorld.java



    package com.tekhnologia.spring3.example1;
     public class Spring3HelloWorld {
      public void sayHello(){
       System.out.println("Hello from Spring 3.0");
      }
    }



    Spring use IOC(Inversion of Control) to create object of any class, so we have to put entry into xml file called SpringHelloWorld.xml, not required to be same as above class.
    Here we are creating bean tag and putting id as a name which will be used and known to class which will be going to use the object of the above bean class. and class attribute will have full path of class going to be initialized. 


    As IOC is stated for dependeancy injection which means you are not creating dependency but container is doing on behalf of you, here is the example of doing that, here we container is creating runtime  dependency by loading below xml file where ever class object is required.



    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="Spring3HelloWorldBean"
    class="com.tekhnologia.spring3.example1.Spring3HelloWorld" /></beans>



    After creating xml in which dependency is declared, we are going to use above xml to create object of bean class at step 1. We will use XmlBeanFactory to create instance for resource which will take ClassPathResource as parameter which will SpringHelloWorld.xml and now you can use XmlBeanFactory as below to create object of Bean class.


    package com.tekhnologia.spring3.example1;
    import java.util.Map;
    import org.springframework.beans.factory.xml.XmlBeanFactory;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.util.Assert;
    public class Spring3HelloWorldTest {
     public static void main(String[] args) {
     XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource ("SpringHelloWorld.xml"));
     Spring3HelloWorld myBean = (Spring3HelloWorld) beanFactory                      .getBean("Spring3HelloWorldBean");
     myBean.sayHello();
     }
    }       





    Click here to learn spring with example.

    Must Read Articles:
    We frequently update my articles to best of my knowledge, please touch base with us to get maximum.
    If you like reading Please share with others or provide feedback to make it better. 

    Regards,
    Bhanu Pratap
    spring springExample

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

    NoClassDefFoundError is come when some jars or class path is missing from classpath, here commons-logging-1.1.1.jar file is not present in you path. and follow the below steps to resolve this problem: 



    1. Download the common-logging-1.1.1.jar at  http://commons.apache.org/downloads/download_logging.cgi and extract it over your hard drive.
    2. Add the jar to lib folder and then to classpath from java build path by right clicking on project , click properties and select java build path and select the libraries, now click the add jar button, search the above jar from lib and add it to your project.
    3. Build your project again if required, which is mandatory for some cases.
    Now enjoy the issue free application.


    Must Read Articles:
    We frequently update my articles to best of my knowledge, please touch base with us to get maximum.

    If you like reading Please share with others or provide feedback to make it better. 


    Regards,
    Bhanu Pratap
    Exceptions

    Spring first time Configuration and set up IDE

    We have divided Spring Configuration in below steps so please be sure these are available before jumping into Spring Example or Spring Application to work:
    1. JDK 5+
    2. Eclipse Setup.
    3. Spring 3.0 Download
    4. common-logging download
    5. Create Project and add lib in Eclipse

    JDK 5+, Spring 3.0 is based upon JDK 5, so it will require to have JDK 5 or after version to build an Spring Application. if you don't have JDK, please download it from here.
    Check Java Version by java -version


    Eclipse Setup, Download the eclipse at http://www.eclipse.org/downloads/


    Common-logging download, Spring use common logging for making logs so please download it from http://commons.apache.org/downloads/download_logging.cgi, else you will get an error like below:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    So please incorporate this jar in adding to project as below.

    Spring 3.0 Download, Download  spring-framework-3.0.0.RELEASE-with-docs.zip at http://www.springsource.org/download, Extract the zip files as you would like:
    Extracted Spring download /dist folder
     Create Project and add lib in Eclipse, Now create the project in eclipse by right click in Package Explorer and create a Java project;



    Now click on Finish in the popup, Now create folder by right click(Project "tekhnologia") >> New >> Folder;


    Copy and paste all jars, into your lib folder created above:

    1. Common-Logging Jars,
    2. Spring 3.0 jars

    Click Finish. Now again right click(Project "tekhnologia") >> Properties >> Java Build Path >> Libraries >> click on Add JAR button,;




    and after click Ok, screen will look like below;


    Now Click Ok so that all lib files get set as java build path in project and finally screen will look like below;



    Now your Spring is configure and you can use to for developing Spring Application. In case you are try to integrate it with Web Application, please use the project reference of this project in workspace with your web application .project file or you can use JAR architecture. its always a good idea to seperate your java component with web component in your application.

    Please click here to learn spring with example.



    Must Read Articles:
    We frequently update my articles to best of my knowledge, please touch base with us to get maximum.
    If you like reading Please share with others or provide feedback to make it better. 

    Regards,
    Bhanu Pratap
    spring springExample

    Spring Overview

    Spring framework makes developing enterprise application easier and simple to code, now days Spring working in full swing and now each java application demand Spring. Lets discuss the life of developers without the Spring Framework then will jump into Spring so that we can easily understand the difference and benefit of Spring in an application.

    Life without Spring
    - I will take my own example, when I was working on my first application for enterprise application, I have to create a component for my application which will be performing the customer management, at that time EJB was on boom, so I have chosen EJB to create this component, to start I have created several classes like Home interface, local interface and bean, additionally i have to create deployment descriptor for the bean created. Now I was afraid since 20+ number of component were still need to be created, so after analyzing and research I got to know about the XDoclet, which helps me in creating my component's supporting files with some clicks. it would feel like very easy and comfortable to build application.

    Now, I have to look into the component's business logic. After implementing the business logic in component, I was looking to test my logic, I was run the container and verify the test case, but fail to verify due to some issue in code, I change it and again i have to deploy the code and run container again, after so many iterations I felt another problem in our software creation cycle with EJB. Some how I manage to test the all scenarios for the applications and successfully delivered it on time, with so much effort and problems.
    I used to compile all my mistakes and problem  faced during the development of application after application delivered. Please see below what I have written:
    1. Discomfort in creating Component's Multiple supporting files
    2. Testing Slow, Re-starting the Container.
    EJB, why to use EJB, only and only service it provide. Otherwise its really very painful to create multiple files. I was so much afraid that I swear not to use EJB in my future application creation, but I was not alone to decide which technology needs to be used, else I was not gonna use it again.

    How Spring help?
    - Spring helps developer to minimize the effort of creating the an enterprise application, which EJB doesn't provide the service to developer.  So Spring strives to be deliver the best services to developer which makes Spring developers favorite and simplifying the development model of creating an J2EE enterprise application.
    Spring is helping to developer with the given below philosophy:
    1. Designing of an application is more important then underlying technology used.
    2. Loosely coupled design with Interface is a good model.
    3. Code should be easy to test.
    What is Spring?
    - Spring is an open source framework, written by Rod Jhonson and explain the framework in his book
    "Expert One-on-One: J2EE Design and development". According to Jonson, Spring is created to address to handle the complexity of application.

    Spring is a light-weight IOC and AOP container framewok. Now we will check what exactly Spring gonna do to make developer's life easy, Spring can be characterized into 5 as below:
    1. Light-weight
    2. IOC(Inversion of Control)
    3. Aspect Oriented Programming
    4. Container
    5. Framework.
    Light-weight, Spring is a Light-weight framework in both terms either Size or Overhead. an average full application can be consolidated in an single JAR of 1 Mb, Spring has negligible overhead, since it is much loosely coupled with the implementation of IOC concept.

    IOC(Inversion of Control), Spring promotes loos coupling between elements through a well known technique of IOC, by applying IOC in Spring Object passively given their dependency rather than creating dependent objects. It works like reverse-JNDI, instead of an object looking up dependencies through container, container provide the dependency to the objects.

    Aspect Oriented Programming, This is concept introduced in Spring which separate application's Business logic with other system related codes(like Transaction, Exception handling and Audit trails) which was applied with business logic till now.

    Container, Spring handle and control the objects life cycle, which makes it work like container.

    Framework, Spring makes it possible to configure and compose complex application from simpler components. In spring, application objects are composed decoratively, typically in an XML file.

    Now Lets talk about Spring Modules, there are below types of modules in Spring:

    1. AOP
    2. O/R Mapping
    3. JDBC and DAO
    4. Web Context and Utility
    5. Application Context
    6. MVC Framework
    7. Core Container and Supporting Utilities
    Please click here to learn spring with example, before switching to example please know how to configure your Spring 3.0 with eclipse



    Must Read Articles:
    We frequently update my articles to best of my knowledge, please touch base with us to get maximum.
    If you like reading Please share with others or provide feedback to make it better. 

    Regards,
    Bhanu Pratap
    spring

    Java Task Scheduler with Timer.java and TimerTask.java


    Scheduling the task in java is now days getting day by day famous and we have lots of ways to schedule the task in java, below are some of the famous ways to schedule the task:
    1. Quartz
    2. Scheduler.java and SchedulerTask.java
    3. Timer.java and TimerTask.java
    Here we are explaining scheduling task by using Timer.java and TimerTask.java, We can schedule task with below steps:
    1. TimerTask.java is class which used to extend by Class in which run() method needs to be implement, exactly this menthod will be run in case scheduer run.
    2. Main Class is to be use, as we are using TimerExample here which will use Timer class, which will use schedule method which has 2 parameters. first parameter is the object of created of step 1 and second parameter is the long variable which will be a x seconds = x*1000

    Now please find below the example code for the implementation.

    Example Code
    import java.util.Timer;
    /**
    * @author http://www.tekhnologia.com/
    */
     public class TimerExample
     {
        public static void main(String[] args) {
       Timer timer = new Timer();             // Get timer 1
        long delay = 5*1000;                   // 5 seconds delay
        timer.schedule(new Task("Testing"),delay); }
    }



    import java.util.TimerTask;import java.text.SimpleDateFormat;import java.util.Date;
    /**
    * This is a timertask because it extends the class java.util.TimerTask. This class
    * will be given to the timer (java.util.Timer) as the code to be executed.
    *
    * @see java.util.Timer
    * @see java.util.TimerTask
    * @author http://www.tekhnologia.com/
    */
    public class Task extends TimerTask {
    private String _objectName;                 // A string to output
    /**
    * Constructs the object, sets the string to be output in function run()
    * @param str
    */
    Task(String objectName) {
    this._objectName = objectName;
    }
    /**
    * When the timer executes, this code is run.
    */
    public void run() {
    Date date = new Date();
    SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss");
    String current_time = format.format(date);
    System.out.println(_objectName + " - Current time: " + current_time);}
    }
    java

     

    We are featured contributor on entrepreneurship for many trusted business sites:

  1. Copyright © Tekhnologia™ is a registered trademark.
    Designed by Templateism. Hosted on Blogger Templates.