View RSS Feed

My Java Tips

  1. Jsr 75

    by , 11-22-2011 at 05:52 PM (My Java Tips)
    JSR 75 specifies 2 optional packages for mobile devices. I will be talking about these in the next few posts.


    The two provided packages are:
    Java Code:
    javax.microedition.io.file
    javax.microedition.pim
    PIM stands for personal information and it contains following information:
    - contact list
    - todo list
    - events

    If you want to access these from a J2ME application, then javax.microedition.pim is to be used.

    ...
    Tags: j2me, jsr 75, pim Add / Edit Tags
    Categories
    Java ME
  2. Subversion (intro)

    by , 11-22-2011 at 05:45 PM (My Java Tips)
    Subversion is a centralized system for sharing information. It comprises of a repository, which is a central store of data. The repository stores information in the form of a file system. Clients can connect to this repository, and can read or write to these files. When a client writes data, it actually makes the information available to others; and when a client reads the data, it actually receives information from others. Its a typical client server system which uses version model.

    ...
  3. Subclipse

    by , 11-22-2011 at 05:41 PM (My Java Tips)
    Consider that you are working on a large/medium size Java project in teams. This is an ideal scenario for using Subversion to distribute and maintain source code. Good news is that you can use integrate your source code with Subversion within Eclipse environment.


    An Eclipse plugin called Subclipse is to be used for integrating source code with Subversion within Eclipse environment. You may download Subclipse from:
    http://subclipse.tigris.org/download.html

    Once ...
    Categories
    Subversion
  4. Reading/writing files

    by , 11-22-2011 at 05:26 PM (My Java Tips)
    This post is all about reading and writing text files on mobile device.


    In order to write files on the mobile device, you need com.motorola.file.writeaccess. If your application has that permission, you can write files easily using the following code.

    Java Code:
    FileConnection sc = (FileConnection)Connector.open("file:///phone/tmp.txt");
    OutputStream os = sc.openOutputStream();
    os.write(("text to go into the file").getBytes());
    ...
  5. Sending SMS (snippet)

    by , 11-22-2011 at 05:22 PM (My Java Tips)
    This post presents a snippet for sending short text messages from J2Me applications.


    The com.sun.midp.io.j2me.sms package provides an API for the Short Message Service Messaging system and allows MIDlet to access SMS functionality on a GSM mobile device. You need javax.wireless.messaging.sms.send premission to send SMS messages from your J2ME application. The sample code is presented below:

    Java Code:
    sender = (MessageConnection)Connector.open("sms://");
    ...
  6. GPS location / Cell id / Placing a call

    by , 11-22-2011 at 05: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);
    loc.setLocationListener(ll,0,-1,-1);
    Location location = loc.getLocation(60*3);
    String lat = location.getQualifiedCoordinates().getLatitude();
    String lon = location.getQualifiedCoordinates().getLongitude();
    ...
  7. MIDP packages

    by , 11-22-2011 at 04: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
    java.io ...
  8. Ant Paths

    by , 11-21-2011 at 05: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:
        <classpath>
    <pathelement path="${classpath}"></pathelement>
    <pathelement location="lib/helper.jar"></pathelement>
    ...
    Categories
    Ant
  9. Package Explorer - Class Method

    by , 11-21-2011 at 05: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)
    ...
  10. Object references

    by , 11-21-2011 at 04: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) {
    		this.id = id;
    		this.name = name;
    ...
  11. Method signatures

    by , 11-21-2011 at 04: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 ...
  12. Using static and final attributes Ė An example

    by , 11-21-2011 at 04: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 ...
  13. Java Data Object (basics)

    by , 11-21-2011 at 04: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 ...
    Categories
    JDO
  14. JDO Ė Byte Code Enhancement

    by , 11-21-2011 at 04: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 ...
  15. @SuppressWarnings annotation

    by , 11-21-2011 at 04: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 ...
  16. Singleton - Creational Design Pattern

    by , 11-20-2011 at 06: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.


    ...
  17. Adapter design pattern

    by , 11-20-2011 at 06: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 ...
  18. The Facade Design Pattern

    by , 11-20-2011 at 06: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 ...
  19. The Observer Design Pattern

    by , 11-20-2011 at 06: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 ...
  20. Extract superclass

    by , 11-20-2011 at 05: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{
    ...
  21. Extract Interface

    by , 11-20-2011 at 05: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;
    ...
  22. An interface extending an interface

    by , 11-20-2011 at 05: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 ...
  23. The Strategy Design Pattern in Java

    by , 11-20-2011 at 05: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 ...
  24. JSP implicit Session object

    by , 11-20-2011 at 05: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 ...
  25. Enhanced for-loop (Java 5.0)

    by , 11-20-2011 at 05: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:

    ...
    Categories
    Java SE
  26. Handling Cookies in JSP

    by , 11-20-2011 at 05: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:
    response.addCookie(Cookie
    ...
    Categories
    Java EE , JSP
  27. Checking if Session is new

    by , 11-19-2011 at 06: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
    Categories
    Java EE , JSP
  28. Startup time

    by , 11-19-2011 at 06: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 ...
  29. Performance issues related to trigonometric functions , floating point arithmetic and

    by , 11-19-2011 at 06: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 ...
  30. Performance issues related to Look and Feel of GUI

    by , 11-19-2011 at 06: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
    Categories
    Performance
Page 2 of 15 FirstFirst 123412 ... LastLast