Friday, September 23, 2011

How to share and access propeties file using singleton and java properties

In this example I have given a Idea to share properties file(configuration file) using Singleton class and Java Properties

first we have our properties file say for example

name = Rajkumar Singh
course = java

now create a singleton class as fallows

package example;
import java.util.Properties;

public class DataSingleton {
static  private DataSingleton instance = null;
public String name;
public String course;
static public DataSingleton getDataSingleton(){
if(instance == null){
instance = new DataSingleton();
return instance;

private DataSingleton(){
BufferedReader br = new BufferedReader(new FileReader(new File("data.txt")));
Properties prop = new Properties();
name = prop.getProperty("name");
course = prop.getProperty("course");
}catch(IOException e){

now we have our tester class like this

public class TesterClass {
public static void main(String[] args) {
DataSingleton ds = DataSingleton.getDataSingleton();

Rajumar Singh

the example is self explementory.......hope u enjoy the code segment
looking forward to your reply

Sunday, September 4, 2011

New in Java 7

You'll be able to use String values in switch-case statements! It'll support A COMPLETELY NEW BYTE CODE -- Invoke Dynamic -- which might be used, maybe, by some other languages on the platform, some years from now after Java 7 is widely adopted. You'll be able to put UNDERSCORES in numeric literals -- like 1_345_892!!! Excitement is at an all-time-high!!!!! Java 7 has a known runtime optimization bug that is known to do crazy things, including corrupting files. Use the '-XX:-UseLoopPredicate' command line option to disable that feature/bug. Actually, this bug was present in Java 6. But it's disabled by default in Java 6, so hardly anyone used it. But Java 7 enables it by default, so *everyone* has been testing/using it, and it corrupted lots of files