Singleton Design pattern in JAVA


Below class depicts the Singleton design pattern.

SingletonDesignPattern.java

package in.javatutorials;

/**
* @author JavaTutorials
* @version 1.0
*
*/
public final class SingletonDesignPattern {

/**
* make the class object as private as it is
* not used directly out side the class
*/
private static SingletonDesignPattern singletonObj = null;

/**
* make the constructor as private.
* Object cannot be created using the constructor outside of this class.
*/
private SingletonDesignPattern(){

}

/**
* Create the class object if it is null and
*
* @return singletonObj SingletonDesignPattern
*/
public static SingletonDesignPattern getInstance(){
if(singletonObj == null){
singletonObj = new SingletonDesignPattern();
}
return singletonObj;
}

/**
* Take the user name as parameter and return the welcome message
*
* @param userName String
* @return message String
*/
public String getWelcomeInfo(String userName){
String message = null;
//make method access to synchronized to make thread safe
synchronized (SingletonDesignPattern.class) {
System.out.println(“User Name is : ” + userName);
message = “Hello ” + userName + “!!!”;
}
return message;
}
}

 

TestSingleton.java

The main() method of below class will get the single ton object and access the other methods using the same.

package in.javatutorials;

public class TestSingleton {

public static void main(String[] args) {
//Get the singleton object
SingletonDesignPattern singletonObj = SingletonDesignPattern.getInstance();

System.out.println(singletonObj.getWelcomeInfo(“Mallik”));
}

}

JBoss Areo Gear – Build Cross-Platform Mobile Apps with Ease


When building mobile web apps, it is important to have lightweight, performant code that gives a great experience to your users no matter what device they might be using. That is where AeroGear.js comes in. This library provides everything from a simple persistence layer to a security API and everything in between.

 

To know more : http://aerogear.org/

JBoss Errai – makes rich client easy.


Errai’s mission is to make building rich client applications not just easier, but more scalable and manageable. App grow over time, features get added, and code bases balloon into an albatross for developers. By applying good practices, and leveraging frameworks which promote modularity and decoupling, many of these pain points can be avoided. Errai is such a framework.

Errai provides a comprehensive framework and tools for building rich web applications, leveraging the GWT compiler. With standard server-side APIs, such as CDI, in the browser, managing large web applications was never so easy.

http://www.jboss.org/errai?sc_cid=701600000006b8nAAA

Convert Array to Vector in Java


package com.test;

import java.util.Arrays;
import java.util.Vector;

public class ArrayTest {

public static void main(String[] args) {
ArrayTest arrayTest = new ArrayTest();
arrayTest.arrayToVector();
}
public void arrayToVector() {

String[] arrayToConvert = { “jhony”, “peter”, “don” };

Vector<String> convertedVector = new Vector<String> Arrays.asList(arrayToConvert));

System.out.println(“11111 ” + convertedVector.get(0));

System.out.println(“3” + convertedVector.size());
}
}