Skip to main content

Posts

Singleton Pattern revisited

As the name suggest, Singleton Pattern restricts to the creation of one and only one object of a class. This is very useful whenever we want to restrict the creation of an object to single instance . This is very small and sweet type pattern that is used in many cases. Let's take an example and see how it is used in the code public class SingleObject { private static SingleObject singleObject; private SingleObject() { } public static SingleObject createInstance() { if (singleObject == null) { singleObject = new SingleObject(); } return singleObject; } } Line by line explanation Line 2 : creates private instance of the class Line 4 : constructor is private, so that no outer class can create object of this class Line 7 : creating a static method to get an instance of the class. We have defined method as static so that we don't need to create a object to call this method. Since it is static we can call this method by name of the class i.e. SingleO...

Chandigarh Java User Group

Its a long time I have written about any new things in Java. But few days back I had started working on starting a JUG in my local city Chandigarh. I had seen people in Chandigarh specially freshers not able to grasp a good knowledge of the Java and related technologies. They even don't know about the latest technologies and what is happening in the world of Java. So I finally thought of starting a JUG namely Chandigarh Java User Group. I want to organize a JUG meet as soon as possible in the city. So anyone can join and start working on that side. I am very much influenced by @HarshakOak who is a Java Champion and organizes many Java events like the indicThreads. I had gone to attend those meetups some time. There you will get a lot of knowledge about what is happening around the world in the field of Java Some of you wanted know about the procedure of joining the JUG. its pretty simple. Join java.net and then go to Chandigarh Java User Group and join it. There is also a...

How to handle autocomplete in browsers

Sometimes we face a problem while opening forms. There are some fields in the form that are always pre-filled whenever that form is opened. This is because of the auto-fill feature of the browser. To solve that simple put the autocomplete="off" in form tag like below: <form name="frmUser" method="post" action="test" autocomplete="off"> Name : <input type="text" name="name" /> </form> According to the mozilla https://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion  this happens because we are using the the two fileds in our form i.e. NAME and ADDRESS.  Like in the above form we have used the label Name . To resolve this issue we can do the following: Simply include the name using span as below <form name="frmUser" method="post" action="test" autocomplete="off"> < Name : <input type="text" name="abc" ...

IndicThreads Java Conference 2010

This is my second consecutive Java conference from IndicThreads. Here are some of the topics and the speakers who had share their valuable information. The conference is great and I recommend all to visit it once and see the difference Harshad Oak Harshad is the man of few words. He is the organizer and owner of the indicthreads conference. He is the Java Champion and Oracle Ace. He started conference with the topic Java: Riding the Change where he discusses the changing the nature of the Java. What is around the corner and what Java guys need to be in mind in the coming time. He discusses the language changes and the Oracle view on the Java. He had given his experienced thought on the many of the scripting languages like groovy, jython etc. He clarifies that the place of Java is more superior to any of the other languages. Java superiority will be continued. He had also told about the 5 - 95 rule which says that 5% of the people think java will be lost in the near ...

Struts 2 - result type input error Resolved

Some times when coding through Struts 2 we get a input error specifying that result type input missing. But we haven't applied any validation on it. That some times creates a havoc among developers and they start complaining about the error as Struts 2 doesn't give the proper error. Struts 2 in Action I was also facing the same problem until I found the hole in my coding. As we all know that input type result is required when validate framework is applied. This is obvious as it will return to the input page defined in the input type result if some validation fails. But when we haven't applied any validation and this error is displayed what can be the problem. The problem can be: You have created a field on the jsp let it be hidden field and you are implementing the ModelDriven interface. But you forgot to add the jsp hidden field variable in the pojo class . This will surely generate this error. The solution to this problem is to declare a variable in the pojo ...

Unclean shutdown of previous Apache run - Resolved

Today I am having a problem with Apache restart. It is continuously giving me the Unclean shutdown of previous Apache run error. After googling for two hours I got a answer to it. Actually I had installed a Skype on my system which uses port 80 for its some connection purpose and Apache also uses it. So simple un-check the Use port 80 option in the Advanced -- Connection tab from Skype options. Then restart the apache it works well. Hope it works for you as well. What a stupid mistake.

Getting height and width of image in Java

Yesterday I was working on something that requires manipulation of image for getting its properties. After searching over the internet I found a very intersting class on Java i.e ImageIO and BufferedImage class. These classes are good enough to manipulate images. there are many other claases also. But what I need i got it from these. I found many developers searching over internet for getting properties of image and there is no good small example for that. Thats why I thought why not creating a simple code to manipulate the image and help the developers. Here is the small code that helps to get the height and width of the image. Enjoy it!! import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class GetImage { public static void main(String[] args) { try { File f = new File("E:/Vinod/Docs/Pics/krishna_01.jpg"); BufferedImage image = ImageIO.read(f); int height = image.getHeight(); in...