View RSS Feed

All Blog Entries

  1. GPS location / Cell id / Placing a call

    by , 11-22-2011 at 06:16 PM (My Java Tips)
    This post presents miscellaneous tasks that you can do in your J2ME application.

    Firstly, how to get GPS location. javax.microedition.location.Location provides support for this. Review the snippet below:

    Java Code:
    LocationProvider loc = LocationProvider.getInstance(null);
    Location location = loc.getLocation(60*3);
    String lat = location.getQualifiedCoordinates().getLatitude();
    String lon = location.getQualifiedCoordinates().getLongitude();
  2. MIDP packages

    by , 11-22-2011 at 05:53 PM (My Java Tips)
    MIDP provides a standard run-time environment that allows new applications and services to be deployed dynamically on end-user devices like cellular phones and pagers. The MIDP is built upon CLDC (Connected Limited Device Configuration).

    MIDP is an industry-standard profile for mobile devices and it is not dependent on a specific vendor. It is a provides foundation for mobile application development. MIDP contains following 3 core CLDC packages:

    java.lang ...
  3. Ant Paths

    by , 11-21-2011 at 06:05 PM (My Java Tips)
    If you specify the PATH and the CLASSPATH type references using any of this, that is ":" and ";" as a separator characters, Ant can convert the separator to the correct character of the operating system in the use.

    A nested element can be used wherever path like values need to be specified. See the example below.
    Java Code:
    <pathelement path="${classpath}"></pathelement>
    <pathelement location="lib/helper.jar"></pathelement>
  4. Package Explorer - Class Method

    by , 11-21-2011 at 06:01 PM (My Java Tips)
    In this post, I will write about Eclipse feature that shows the artifacts of a class method.

    Eclipse package explorer is a very useful explorer that gives the developer a birds eye view of the package, class and methods. Review the class below:

    Java Code:
    public class Student {
    	private int id;
    	private String name;
    	private static int counter;
    	private static final int MAXCOUNT=10;
    	public Student(int id, String name)
  5. Object references

    by , 11-21-2011 at 05:58 PM (My Java Tips)
    In this post, I will be talking about how to refer to an object. I will present a simple example to make things obvious.

    We have a class called Student. It had 2 attributes, getter setter methods and a method named showAll() to show the contents of both the attributes.

    Java Code:
    public class Student {
    	private int id;
    	private String name;
    	public Student(int id, String name) { = id; = name;
  6. Method signatures

    by , 11-21-2011 at 05:52 PM (My Java Tips)
    In this post, I will present an interesting example related to method signature.

    Method signature comprise of the following:

    - method name
    - return type
    - input parameters
    - access modifier

    For example:

    Java Code:
    public Vector processText(String test, int id)
    Two methods in a class can have same name provided then have different parameters. Different parameters means different no of parameters and ...
  7. Using static and final attributes Ė An example

    by , 11-21-2011 at 05:47 PM (My Java Tips)
    In this post, I will present an example which used static and final keywords with attributes in meaningful way. I hope after going through this, you will develop good understanding of these.

    As may know, that we may access static member of class without using any object of that class. Final field/attribute means that you cannot change its value. If you try to change the value of final attribute, you will get an error Ė some this like this:

    Exception in thread ...
  8. Java Data Object (basics)

    by , 11-21-2011 at 05:42 PM (My Java Tips)
    Java Data Object (JDO) can be used to build an application that creates, reads, updates, and deletes persistent instances of Java classes. These objects can be persisted on to relation database, object oriented database or on to XML files. This depends on the implementation of JDO you are using.

    One needs to get the basics before starting working with JDO. Once you have the basics, you can map java objects to the data source transparently.

    JDO allows you to map your ...
  9. JDO Ė Byte Code Enhancement

    by , 11-21-2011 at 05:39 PM (My Java Tips)
    In order to store instances of a class into data store, a class has to be persistence capable. There are different ways to make a class persistence capable. One of the way is Byte Code Enhancement.

    When a Java class is compiled, a class file is generated. It contains the byte code. To make a class persistence capable, some extra code will surely be added to our source. In order to make the process transparent, byte code modification can be done. So this works even, if you donít have ...
  10. @SuppressWarnings annotation

    by , 11-21-2011 at 05:34 PM (My Java Tips)
    In this post, I will be talking briefly about SuppressWarnings annotation.

    Java compiler gives you warnings to assure that you know what is happening. Sometimes, you want donít want the warnings. Java 5.0 provides a way for this.

    One had to use SuppressWarnings annotation to ignore the warnings. Annotations are followed by @.

    For example: consider the following code:
    Java Code:
    int a;
    Object object = new Object();
    I declared two variables ...
  11. Singleton - Creational Design Pattern

    by , 11-20-2011 at 07:14 PM (My Java Tips)
    The Singleton Design Pattern is the most commonly used design pattern in Java. The Singleton Design Pattern is a Creational Design Pattern. It governs the instantiation process. Sometimes in programming only one object is required across the system. The Singleton Design Pattern is used to achieve exactly that, that is to restrict instantiation of a class to one object. The Singleton Design Pattern ensures a class has only one instance, and provides a global point of access to it.

  12. Adapter design pattern

    by , 11-20-2011 at 07:10 PM (My Java Tips)
    A Adapter design pattern is Structural design pattern. It is also called as wrapper pattern or just a wrapper. Some classes could not work together because of incompatible interfaces. An adapter allows classes to work together by wrapping its own interface around that of an already existing class. The adapter also handles the logic necessary to transform data into an appropriate form.

    The adapter design pattern is useful in circumstances where an already existing class provides some ...
  13. The Facade Design Pattern

    by , 11-20-2011 at 07:05 PM (My Java Tips)
    The Facade Design Pattern is a structural design pattern amongst the design patterns. A facade is actually an object. It provides an uncomplicated interface to a larger body of code, for example a class library.

    As a facade has simple and tailored methods for common tasks. A facade can make a software library easier to use and understand. A facade also makes the code that uses the library more readable. A facade assists in developing a more flexible system. It reduces dependencies ...
  14. The Observer Design Pattern

    by , 11-20-2011 at 07:00 PM (My Java Tips)
    The Observer design pattern is a Behavioral design pattern. It is used to observe the state of an object in the program. In Observer pattern object(s) are registered to observe an event that may be raised by the observed object. Simply put the Observer pattern allows one object called the observer to watch another object called the subject.

    The observer pattern can listen to an external event, for example a user action. The observer pattern is also used to create a loose coupling ...
  15. Extract superclass

    by , 11-20-2011 at 06:49 PM (My Java Tips)
    Inheritance is a very useful feature that object oriented languages provide. Normally you write parent class first and then the child class. When the design of the application is not final, you tend to put more code in a class than required. At some instance, you realize, that you may make a super class and put some methods in it. Eclipse provide an easy way to do this.

    Lets take an example. We have following class:

    Java Code:
    public class CSVFile{
  16. Extract Interface

    by , 11-20-2011 at 06:43 PM (My Java Tips)
    Eclipse provides the possibility to extract interface from a class. You may call it reverse engineering since rule of thumb is to write the interface first and then write the classes implementing it. But sometimes, itís the other way around. You write a class and then you want to generate the appropriate interface for it. Lets see how to do this.

    I wrote a class that has to do with text extraction from CSV files. I named it CSVFile.

    Java Code:
    import java.util.ArrayList;
  17. An interface extending an interface

    by , 11-20-2011 at 06:37 PM (My Java Tips)
    The subject topic is very interesting and I decided to write something on it. I hope it will be useful.

    You know about the interfaces. They do not contain the implementation details, rather they contain the method signatures. The class implementing an interface, has to provide the implementation for each interface method. An interface in implemented using the keyword implements.

    Java Code:
    Class Room implements IOffice
    The keyword extends ...
  18. The Strategy Design Pattern in Java

    by , 11-20-2011 at 06:25 PM (My Java Tips)
    The strategy design pattern is one of the most fundamental design pattern. The strategy pattern is a design pattern with the help which algorithms can be selected in a real time. The Strategy pattern is behavioral design pattern. The strategy pattern is very useful when it is needed to swap the algorithms used in an application at runtime.

    The strategy pattern is used to define a family of algorithms, encapsulate each one, and make them interchangeable. The strategy design pattern ...
  19. JSP implicit Session object

    by , 11-20-2011 at 06:19 PM (My Java Tips)
    Session Object is another implicit JSP object that denotes the data associated with a specific session of a user. It is associated to Javax.servlet.http.httpsession.

    The connection between client and the server is provided by the session object. It maintains states when there are multiple page requests. If the user is navigating between multiple pages, and you need to store some data associated with that user, then session object helps you in this.

    Some useful session ...
  20. Enhanced for-loop (Java 5.0)

    by , 11-20-2011 at 06:14 PM (My Java Tips)
    Java 5.0 introduced an enhanced for-loop. In this post, I'll write about it.

    The enhanced for loop provides a simple structure allows one to simplify code by presenting for-loops that visit each element of an array/collection without explicitly expressing how one goes from element to element.

    The new for loop makes programming simpler. For example, if you want to print each element for an array, you used to do that with a for loop in the following way:

    Java SE
  21. Handling Cookies in JSP

    by , 11-20-2011 at 06:04 PM (My Java Tips)
    Cookies are text files that are downloaded onto a visitor's hard drive to store the visitor's actions in order to better
    customize their following visits. We may handle cookies in JSP and I will show you how to do that.

    JSP provides an implicit response object which is used to add cookies. To add a cookie to the response, addCookie method is used.
    We may store useful information in cookies for later use and this method is perfect for our needs.
    Java Code:
    Java EE , JSP
  22. Checking if Session is new

    by , 11-19-2011 at 07:26 PM (My Java Tips)
    Sessions are used to keep track of the user in applications. Specifically talking about web applications (JSP), we may store objects in the session as well for using them later. Sometimes we wish to know if the session is new or not. This post will show how to do that.

    If a session is new, then isNew method of session object will return true otherwise false. When a server creates a session and client has not yet acknowledged the session, the server marks it with new. When the client ...
    Tags: isnew, sessions Add / Edit Tags
    Java EE , JSP
  23. Startup time

    by , 11-19-2011 at 07:22 PM (My Java Tips)
    Java programming language is undoubtedly one of the leading programming languages amongst new breed of programming languages. Though it is considered to be the best in the industry, it too has its own limitations, flaws due to certain unavoidable programming constraints which Java follows.

    Execution of Java program is said to be slow and it requires more memory when compared with programming languages such as C, C++ etc. Programs written in C, C++ are natively compiled, where as Java ...
  24. Performance issues related to trigonometric functions , floating point arithmetic and

    by , 11-19-2011 at 07:19 PM (My Java Tips)
    I have briefly listed the performance issues related to trigonometric functions, floating point arithmetic functions and Java Native Interface. I hope these will be helpful.

    Trigonometric functions

    In Java, results got from trigonometric functions and calculations may not be as accurate as that of results got from trigonometric functions and calculations of C language. This is because because Java has strict specifications for the results of mathematical operations.This ...
  25. Performance issues related to Look and Feel of GUI

    by , 11-19-2011 at 07:15 PM (My Java Tips)
    When you use Java Swing or Java Foundation Classes (JFC) for your GUI application development the look and feel of GUI application is not the same as the look and feel of your operating system as JFC or Java Swing has its own built in look and feel. Although, if you want you can achieve the same look and feel as of your operating system's by using Java's Abstract Window Toolkit (AWT), the AWT toolkit is unable to meet advanced GUI programming requirement.

    The Java Foundation Classes ...
    Tags: awt, java swing, jfc, swt Add / Edit Tags
  26. Handling ASCII character set in Java

    by , 11-19-2011 at 07:11 PM (My Java Tips)
    In this post, I will talk about ASCII character set and how to deal with ASCII codes in Java.

    ASCII character uses 7 bits for character representation. This means that there are total of 128 characters supported by ASCII set. Point to note is that there are only 93 printable characters in ASCII whose ASCII codes are from 33 till 126.

    Java supports all popular character including UTF. But sometimes you only want the input to comprise of ASCII printable characters. This ...
  27. IDL Plugin for Eclipse

    by , 11-19-2011 at 07:06 PM (My Java Tips)
    Developers working on CORBA often complains that writing IDL takes time. If you are new to it, you are bound to make a lot of mistakes. You need something to assist you in writing IDL. Fortunately, Eclipse has a plugin for this.

    Eclipse CORBA plugin can be downloaded from:

    You need Eclipse 3.2 or higher to use this plugin.

  28. Design Patterns - Basics

    by , 11-19-2011 at 07:01 PM (My Java Tips)
    A design pattern is an abstraction at a very high level. It is to create common and reusable solutions to the recurring problems. Design Patterns provide solutions to design problems which arise again and again in a certain design situations. As a result design patterns have become immensely popular and are very useful to known design issues and problems.

    There are several ways to use and implement these design patterns. These implementation details are called strategies.
  29. The Five Tiers in Java EE

    by , 11-19-2011 at 06:57 PM (My Java Tips)
    This post briefly explains the 5 tiers in Java Enterprise Edition.


    A web browser, a hand held device or an application which remotely accesses the services of an enterprise application are examples of a Client tier. In other words a Client tier can consists of all the types of components that are clients of an enterprise application.


    Filters, Java Servlets, JavaServer Pages, JavaBeans and other utility classes ...
  30. Creating and visualizing graphs - JGraphT

    by , 11-19-2011 at 06:54 PM (My Java Tips)
    Graphs are used to represent knowledge in a visual form. There are many types and forms of graphs. Java provides support for graphical structures. In this post, I will talk about JGraphT which is a free Java graph library.

    You may download the library from:

    Creating and visualizing the graph is very easy:
    Java Code:
    // create a JGraphT graph
    ListenableGraph g = new ListenableDirectedGraph(
Page 4 of 17 FirstFirst ... 2345614 ... LastLast