Java Archive
Recently I made a post on Language Integrated Query (LINQ) in C#. Since I like that feature very much I did a search for finding some similar libraries for Java. There is one project in sourceforge called JoSQL (http://josql.sourceforge.net/index.html) for querying collections using SQL syntax in Java. I would call JoSQL as LINQ alternative [...]
A J2EE application will be bundled in an EAR (Enterprise Archive) file for the deployment. The EAR file can contain different modules like Web Module, Resource Adapters, Client application modules and EJB modules. The structure of an EAR file is a follows.
EAR file
|
| - META-INF
- application.xml (The deployment descriptor of an EAR file).
| - Resource [...]
How to use a LIKE clause with PreparedStatement object? I had this requirement and all the methods that I tried were not working. Java was not giving me any compile time nor run time errors. However the result was not coming as expected. I did some search on that and finally I got the solution. [...]
There is an easy an elegant way to convert or store an exception stack trace to a string variable. The following method takes an exception object as a parameter and returns the string representation of the stack trace.
public String getStackTrace(Exception ex) {
java.io.StringWriter out = new java.io.StringWriter();
[...]
Defensive copying is used for protecting the field of an object from being changed by all non native class. Sometimes if we do not use defensive copying our object may hold incorrect data. For eg:
import java.util.*;
public class Test {
private Date today;
public void setToday(Date dt) {
this.today = dt;
}
public Date getToday() {
return today;
}
public static void main(String [...]
How to connect to internet from Java program through a proxy? The answer is very simple Just add the following arguments to the virtual machine
java -Dhttp.proxyHost=hostname -Dhttp.proxyPort=port -Dhttp.proxyUser=username -Dhttp.proxyPassword=passowrd
or just put set these System properties using the code.
System.getProperties().put("http.proxyHost", "hostname");
System.getProperties().put("http.proxyPort", "port");
System.getProperties().put("http.proxyUser", "username");
[...]
Polymorphism refers to the ability of an object to behave differently to the same message.
Polymorphism is of two types. static or dynamic. In dynamic polymorphism the response to message is decided on run-time while in static polymorphism it is decided out of run-time (i.e. on compile-time).
The assignment of data types in dynamic polymorphism is known [...]
The following Java code plays a .wav file
import java.io.File;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
public class MusicPlayer {
public static void main(String args[]) {
try {
AudioInputStream stream =
[...]
The first step in parsing an XML String using DOM is to get the org.w3c.dom.Document object from our String object. Here I am going to parse the following XML which is stored in a String variable xmlString
<data>
<address>
<name>Tom</name>
[...]
The StringTokenizer class in java.util package has been deprecated as of Java 1.4. Sun recommends the use of String.split method instead of java.util.StringTokenizer class.
For eg:
StringTokenizer strTokens = new StringTokenizer("Token String");
while (strTokens.hasMoreTokens()) {
System.out.println(strTokens.nextToken());
}
Can be replaces with [...]
