Posts

Manipulating String intelligently

Image
Performance and Optimizations are the key features desired in Java Programming. So here are some examples, how to make improvement in your String manipulation.. String is the most encountered Objects in Java Programming. Till Tiger, we have 3 Classes to manipulate Strings. These are String, StringBuilder, StringBuffer. String is immutable whereas StringBuffer and StringBuilder can change their values. StringBuilder was introduced in J2SE5 or Tiger.The only difference between StringBuffer and StringBuilder is that StringBuilder is unsynchronized whereas StringBuffer is synchronized. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer. Here are some examples given by Mr. Heinz Kabutz about how to perform String Manipulation intelligently. We start with a basic concatenation based on +=: public static String concat1(String s1, String s2, String s3, String ...

Calendar class - Better Way to Manipulate Dates.

Java’s Calendar class offers a set of methods for converting and manipulating temporal information. In addition to retrieving the current date and time, the Calendar class also provides an API for date arithmetic. Calendar’s built-in date/time arithmetic API is extremely useful. This tutorial examines the Calendar class API and presents examples of how you can use Calendar objects to add and subtract time spans to and from dates and times, as well as how to evaluate whether one date precedes or follows another. Adding time spans Let’s say you want to add a time span to a starting date and print the result. Consider the following example, which initializes a Calendar to 16 July 2007 and then adds two months and three days to it to obtain a new value: import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; public class CalenderDemo{ public static void main(String[] args) { CalenderDemo tdt = new CalenderDemo(); tdt.calculateDa...

Reflection APIs - A way to inspect classes at runtime

Java Reflection is a technology that looks inside a Java object at runtime and sees basically everything about the object that you would know at compile time. Java Reflection is a technology that looks inside a Java object at runtime and sees what variables it contains, what methods it supports, what interfaces it implements, what classes it extends—basically everything about the object that you would know at compile time. The Reflection API is located in the java.lang.reflect package and is included in any J2SE installation. Primarily it is intended for very generic programs such as database browsers or visual code editors, but it can be used in any other applications. Reflection is for Basic techniques There are two basic techniques involved in Reflection: discovery and use by name. Here are descriptions of both: Discovery involves taking an object or class and discovering the members, superclasses, implemented interfaces, and then possibly using the discovered e...

Java Singleton Pattern : Potential Problems and Solutions

The Java Singleton pattern belongs to the family of design patterns that governs the instantiation process. This design pattern suggests that at any time there can only be one instance of a Singleton (object) created by the JVM. You implement the pattern by creating a class with a method that creates a new instance of the class if one does not exist. If an instance of the class exists, it simply returns a reference to that object. How the Singleton pattern works: Here’s a typical example of Singleton: public class Singleton { private final static Singleton INSTANCE = new Singleton(); // Private constructor suppresses generation of // a (public) default constructor private Singleton() {} public static Singleton getInstance() { return INSTANCE; } } The classic Singleton does not use direct instantiation of a static variable with declaration — it instantiates a static instance variable in the constructor without checking to see if it already ex...

Struts Are the Really Very Beautiful..................

Three Days Before Struts started in Training program. I Heard that Struts are very difficult to understand. But After three days, I found how beautifully they are designed by the Craig R. McClanahan. I also learned Here in current company that learning the concepts is very neccessary rather than just gulping the APIS. I really thank our instructor for this. Hey I m not going to write about the struts, since web is just full of such kind of material. The spirit is to force urself to learn the basics of anything. Technology may change not the basic concepts. Time to Take a Break.

Exams Season of Tension, Isn't It?

Exams are going on, Tension is also there. But Exams should be there to test us, otherwise we''l become Lazy..... Isn't IT?

Hey Proud to be an Indian.

Hi day before yesterday, it was 59th Independance Day. We seen the as usual 15th august parade & just enjoyed another holiday. But we r forgetting the meaning of the day. On this day, i remembered what our President said in 'Ignited Minds'. His mission of transforming India into a developed country. Youth like us need to think abt it seriously. We can do this simply by performing our duties like not paying bribes, oppose the curruption, just switching the electric equipments, by keeping our environment clean, etc. By making people aware abt their fundamental duties & rights. Everyone need to do his share of work in transforming India into a developed. Lets make a commitment to ourself that we'll do these small things & help our country. In this way only, we'll find true meaning of these days like 15th August, 26 Janauary, etc. Ok bye for now, i m coming back soon... Ashish