Java

Creating a Temporary File

Dec 22nd, 2009 | By admin | Category: Java

We use temporary file in our day to day applications. This post would talk on how to create a temporary file using Java Programming language. Java gives us a direct API to create a temporary file with some options.

A temporary file can be created depending on certain condition and can be closed and deleted depending on some condition. For an example, lets assume we can upload and install a plug-in(a file) on an application.



Story behind start() and run() methods of Java Thread

Nov 27th, 2009 | By admin | Category: Java

The basic concept of creating a java thread is to extend the class java.lang.Thread or to implement java.lang.Runnable interface. In both the cases , implementation of run() method is mandatory for your thread to be a meaningful Thread.

The run() method is the most important method in the thread classes, it is also the only method that we need to implement in both cases. Why it’s only proper to call the start() method to start the thread instead of calling the run() method directly? What are the problems if we do so ?

Click below to have a look at the detail explanation.



Version Control in Java Serialization – serialVersionUID

Aug 6th, 2009 | By admin | Category: Java

In my last post on java object serialization , I have explained how to write an object to an object stream and how to read the object state under a different java virtual machine. Lets assume, we have created a class and instantiated it and serialized(Written the state to the file system) it too. Now [...]



Simple way to Write to XML using Java

Jul 30th, 2009 | By admin | Category: Java

Often it becomes necessary for application programmer to read from or write to XML pragmatically. There are many different ways to deal with XML using Java programming language. I am going to share one of them. Let me start this post with an use case. While reading through the use case , we should learn how to use Java to write to XML file. Lets Start . . .



Java Object Serialization – Developer’s Guide

Jul 16th, 2009 | By admin | Category: Java

Class is the heart of Java programming and object is a representative of the class. In day to day java programming , we create object and use that in different way.But the life span of an object is till the JVM(Java Virtual Machine) is up. Once JVM is down , there is no existence of the object you have created.But Java has a mechanism which allows you to store(save) your object ( let me say, object state) and you can use the stored object under a different JVM , in a different application or after restarting your own JVM. Isn’t it cool ? Read this post to start with Java Serialization API.



Java Reflection Mechanism

May 27th, 2009 | By admin | Category: Java

Can you ever think of writing a Java program without a class ? I know the answer is ‘NO’. As a class is the heart of the java program , it is always good to know about the in and out of the class. Java provides a very ordinary(but strong enough) API to know more about java classes , methods and fields. This API is known as Java Reflection API. Don’t you wonder how Eclipse IDE gives you the Auto complete feature ? How web application deployment descriptor (web.xml for tomcat) works ? The basic answer is REFLECTION. Have a look.



Custom Exception in Java

May 26th, 2009 | By admin | Category: Java

When a program violates the constraints of Java programing language , Java virtual machine(JVM) throws an error signal to the program. These signals are known as Exception in Java programing language. Excpetions are of two types. Checked (Compile-time) exception and un-checked(run-time) exception. JVM has a collection of exceptions that will be thrown at compile time with the exception message and the print stack trace. A developer can create their own exception which is closely related to the application he or she is developing. A Custom exception can be used to form a better customized message to the user of your application. Have a look.



Reading a Manifest file from Jar file

May 13th, 2009 | By admin | Category: Java

When a JAR file is created, it automatically bundles a default manifest file. There can be only one manifest file in a jar archive, and it always has the path name META-INF/MANIFEST.MF. This post describes , how to read the Manifest.MF file from a Jar file. Have a look at it.



Java Static Import

Apr 30th, 2009 | By admin | Category: Java

Java 5 introduces a feature of importing static member of other class without qualifying by the class name. We should not keep any static member in an interface and then inherit from that rather it is a better idea to import them to a new class.This post illustrates the step-by-step procedure to achieve it.



Singleton – What it is and why is Singleton ?

Apr 24th, 2009 | By admin | Category: Java

Sometimes it’s the requirement of the application to maintain only one instance of a class . This instance will be accessed throughout the a software life cycle of the application.This type of classes are called Singleton class.
Typical examples could be ,Logger,Print spoolers,Connection pool etc.
Singleton is ideal if an application developer wants to make sure only [...]