Pointer in C/C++ denotes to the variables saving the reference, In Java there is only call by reference. But here the pointer refers to an object which itself has another reference within it.
Java classes can have instance variables. If an instance variable is of class type, then it can hold instance of the class in it. This is called pointer to the object.
In some cases, we need an object that contains an instance variable that can refer to another object of the same
Collections in Java include so many interesting features. As the number of features increase there arise the possibility of incorrect usage. Here we discuss such an issue while removing an object from a Collection. Exception throw is "Concurrentmodificationexception" .
Code: Java Code: package test;import java.util.ArrayList;
public class ListExample
package test;import java.util.ArrayList;
public class ListExample
"Whether to implement 'service' method or 'doGet/doPost' in Http Servlet ?" ,Is question often heard at least in the beginners columns.
Actually the answer depends on the requirement.
First we should know that the purpose of servlet is to accept an HTTP request from a Web browser, and return an HTTP response. This is done by "service", "doGet\ doPost" methods. Each of these include request object (HttpServletRequest) to receive data from
Mostly new Java programmers get confused when comparing strings. You can check the equality of strings either by using "==" or "equals()". But one should know when to use each of these in order to get the required results.
First, lets talk about "equals() " method. Method "equals()" is included in the class java.lang.Object which every Java class inherit. "equals()" method actually compares the characters that make up String object.
UDP stands for User Datagram Protocol.
UDP does not ensure reliable delivery of all the packets, the order in which the packets would be received and it is connectionless too.
Despite all these UDP provides quick transfer of packets through low-overhead because of an minimal error-checking and correction.
Java supports UDP through two classes.
contains a wrapper for an array of
Method "clone"creates and returns a copy of the object. It makes another object of the class in memory. Suppose, We are creating a clone of the object x then x.clone() != x will return true but it is not necessary that x.clone().equals(x) will return true. It depends upon the implementation of class.
Class should implement "Cloneable" interface in order to make clone of its objects. Otherwise "CloneNotSupportedException" will be thrown. Array,HashMap are considered
Good Java programmers use "instanceof" operator since it is a must to escape from "Class Cast Exceptions".
Following are the key points to be remembered while using instanceof operator
Instanceof operator is used to restore full functionality of an object.
While programming many times heterogeneous collection are used and then to invoke full functionality of an object casting is required then to check the type of instance, "instanceof"
Though it is very simple to override "equals" method for a class. But people usually make mistakes in overriding this method. It is very important for a Java developer to know about this method.
Some Important points to remember
Always remember to override "hashCode" method if you are overriding "equals" method otherwise you may face problem while using your class with HashTable, HashMap like classes as they uses "hashCode"
Hibernate is a popular OR (Object Relational) mapping framework. To access database, we have to use Hibernate Query language. I will present the basics in this post that will help you starting query database tables using HQL.
Hibernate queries can be roughly divided into 3 categories:
The queries we general use can be divided up into three main categories :
- Queries using one class
- Queries which several classes so join operation is required
It is right to say that a typical application programmer won't need to define annotations in normal routine. But still, one should know how to define annotations.
Annotation type declarations are very much like normal interface declarations. An at-sign (@) comes before the interface keyword and each method declaration defines an element of the annotation type. Method declarations should not have any parameters or a throws clause. Also note that the return type should be amoung the
Methods called on the asynchronous proxy will be executed asynchronously, and the results can be obtained later on.
To execute methods asynchronously in EJB 3.0, one can use asynchronous proxy. This allows calling methods at an instance, and collecting the results later. Good thing is that there exist a JBoss extension to EJB 3.0, which allows obtaining asynchronous proxy from the remote or local interface of a stateful session bean, stateless session bean or service bean.
To create an implementation of SyncML protocol, you may use sync4j. I will introduce you to sync4j in this post.
You may download it from: http://sync4j.sourceforge.net.
Sync4j possesses layered architecture and the layers are:
Core layer - The actual SyncML handling is done by the core layer. Its responsibilities include XML parsing and conversion of the SyncML markup to an internal object representation. Sync4j can also convert internal
I have found may people asking the difference between ClassPath and path. They tend to mix these and find this confusing. I will address this issue in this post.
Path is simply a system wide variable that tells where to find your commands. Like you can run directory command (dir) from an path. This is so because Windows path is set in the path variable. To see the contents of path variable, use following command on command prompt:
The aim is to iterate through a collection of data using a common interface and more importantly, underlying implementation should not be known. We have a behavioral design pattern called ‘Iterator Pattern’ for this. I will introduce you to it in this post.
Iterator should be implemented as an interface. This allows the user to implement it anyway its easier for him/her to return data.
I will take an example of daily life and will show how to use iterator pattern in that. You
Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value. Thing to remember is that it I s not any encryption technique. It’s simply hashing. Same message will always generate the same hash code and a slight change in the message will generate completely different hash code. In the next few posts, I will talk about how we can generate message digests in our Java programs.
The popular message digest algorithms are MD5 and
In the next few posts, I will write about how to perform an XSLT transformation using StAX APIs: Cursor API and Event Iterator API.
TrAX (Transformations API for XML) is a Java API for performing XSLT transformations. In J2SE 1.5, there are three different ways to represent the source and the result of an XSLT transformation and they are: by XML stream source/result, by SAX events source/result, and by DOM tree source/result. In J2SE 1.6 an XSLT transformation is performed using a
ANT makes building complex Java applications easier. But many people argue that managing ANT scripts is itself a cumbersome task and involves a lot of effort. In the next few posts, I will talk about how one can adopt best practices for creating and managing ANT scripts that will make the life of developers and configuration managers easier.
First thing is, one should follow a consistent style while writing XML for ANT files. If you format your ANT script, it will be visually appealing
A lot of J2ME developers face problems when running multiple instance of Nokia Wireless Toolkit emulators. Some of the problems are linked with in.use file. This post is all about that.
When your run the emulator, a file named in.use is created in the emulator’s root directory with will be something like:
This file is removed when the emulator shuts down.
This emulator’s default directory will also
I will use several examples to show how to use RecordStrore in J2ME applications.
Creating record store is simple. We use a static method to create or open an existing record store. Java Code: public static RecordStore openRecordStore(String recordStoreName,
public static RecordStore openRecordStore(String recordStoreName,
Eclipse provides a window called ‘Open Resource’ window to locate the required files in no time.
You can find it under the Navigate. Its shortcut is Ctrl+Shift+R. ‘Open Resource’ window allows you to type a search for any file that exists in your workspace. You are free to use wildcards like ? to replace a single character or * to replace an entire string. It is amazingly fast and useful.
Let me present a use case.
To make your Java applications flexible, you might want to give properties that keep on changing in properties file. A property file is simply a text file that has key-value pairs relation.
If you are thinking of writing your parser to read the property files, then think again. Java provides java.util.Properties class, that will help you deal with propery files. Property files comprise of key-value pairs in a file, where the key and value are separated by an equal
Maven uses an XML project descriptor to generate the object model for project. This file is POM.XML and should be located at the top level directory of the project.
The XML file contains all the needed information for the project. Apart from core information, it also contains groupid, version, name and all the libraries needed for the project.
In this post, I will present how to read properties from XML files.
We have following XML file with the required properties:
<!--?xml version="1.0" encoding="UTF-8"?-->
DTD for the XML file
This post is all about an ANT example. I will present an ANT build script that will compile a project, and will generate a JAR file.
I will name the project as Project X and will provide some useful description.
<project default="dist" name="Project X">
Now is the time to define the properties.
A project object model (POM.xml) contains all necessary information about a project like configurations of plugins involved. You might be thinking about Ant build file. You may embed ant tasks inside the POM. A build.xml tells Ant precisely what to do when it is run, a POM states its configuration.
A POM in simplest form is given below:
To execute a system command from Ant, exec is used. Since different operating systems have different commands, therefore OS commands (if used), will restrict the build script to a particular operating system.
One cannot interact with the forked program and if any attempt to read input in the forked program is made, an EOF (-1) will be thrown.
The task delegates to Runtime.exec which in turn apparently calls ::CreateProcess. Generally, batch files (.bat) cannot by executed
SMPP is a communication protocol designed for transfer of short messages between short message centre and SMS application.
Some useful points about SMPP are listed below:
- Binary encoded protocol data units are exchanged in request and response.
- Transceiver support is added in version 2.4, which allows a single connection to send and receive messages.
- Data exchange can be synchronous or a synchronous.
External Short Message Entities
Subclipse is a very popular Eclipse plugin which provides SVN repository supports within Eclipse. It serves the purpose but there is no real way to change the SVN user for a repository if credentials are saved. I will try to address this problem in this post.
First of all, why you would need to change the svn user credentials? Person A is working on your machine and he checks out a project from a SVN repository using his credentials. He saves his SVN credentials in your Eclipse environment.
There is a very useful Eclipse feature that is normally not used by the developers. Its called ‘Link with Editor’. I'll write about it.
In complex projects, lot of files are involved. To search a rile, you may use Open Resource window – which is really very useful. Then you may click the file and can see/modify the contents. You might want to see where the file lies in the project. Obviously lots of folders are involved and its not easy to manually search for the file. You can simple
Updated 11-07-2011 at 06:09 PM by Java Tip
Each contact entry in a PIM Contact database is represented by Contact. This post is all about retrieving contact fields from PIM.
The supported field list for a Contact depends on vCard specification from the Internet Mail Consortium. These set of fields included in this Contact class provides relevant information about a contact. ContactList restricts what fields a Contact can retain. This reflects that some native Contact databases do not support all o the fields available in a