Archive

Archive for the ‘java’ Category

Iterators – Fail fast Vs Fail safe

September 22nd, 2009 CertPal No comments

Iterators can be designed so that they are fail fast or fail safe. Depending on the underlying implementation of the Iterator, a ConcurrentModificationException is thrown if the Collection is modified while Iterating over the data structure. It pays to understand how an Iterator will behave under both conditions. Lets try to implement fail fast Vs fail safe iterators of our own.

Our data structure for this example is pretty simple. It defines an interface that abstracts set and get operations on a structure. How the underlying classes handle invalid set operations or the size of the structure is implementation dependent

A data structure interface:

1
2
3
4
5
6
public interface Data<T> extends Iterable<T>
{
    int size();
    T getElement(int position);
    void setElement(int position, T t);
}

An underlying implementation of such an Interface, could be say an array of Integers whose size is fixed. Invalid indexes on bounds are not allowed and the internal structure will not grow or shrink. An implementation is given below

Categories: java Tags: , ,

Response: Are Naming Conventions Still Needed For Abstract Classes?

September 16th, 2009 CertPal 6 comments

I came across a post on the Adam Bien blog recently about using the prefix ‘Abstract‘ to define Abstract classes. The argument was that using the ‘Abstract‘ prefix is superfluous. I do not fully agree with the post. As I read the points he had mentioned on the post, here are some that came to mind

Abstract classes are already distinguishable by the keyword abstract. There is no need to further emphasize it.

A prefix “Abstract” doesn’t provide any additional value to the user – in contrary it blurs the actual intention

The Abstract in the class name helps a developer know that a class is Abstract even before they open it. Of course if some one bucks the convention and names a Concrete class abstract, it creates confusion but that scenario is rare.

Modern IDEs don’t let you instantiate an abstract class, even before saving / compiling.

Categories: java Tags: ,

Eclipse tips and tricks – Part 2

September 5th, 2009 CertPal 7 comments

Eclipse can be used to debug your java applications. Here are a few tips that can help you debug better

Remote debugging:

The eclipse IDE can remote debug your web application. Imagine being able to debug your development server from your local machine. Eclipse can help you do this. First you need to instruct your application / server to listen on a port for debug messages. That can be done using the -Xdebug flag

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8787,suspend=n

This tells the JVM to listen for specific debug messages on port 8787. In eclipse open Bug Icon -> Debug configurations and select “Remote java application”. Mention the port and server address and you should now be able to remote debug the application. Make sure that the classes and source sync with each other. On a network where the bandwidth is poor, this technique will not work.

Remote java application:

Categories: java Tags: , , ,

Eclipse tips and tricks – Part 1

August 30th, 2009 CertPal 5 comments

Eclipse is a pretty good IDE to develop java apps on. However there are some features that you might not be using every day that can save you a lot of time.

Writing your own code templates is one of them. To write your own code template do the following

Go to Window -> Preferences. Select Java -> Editor -> Templates. You can add your own templates here. Templates are nothing but the code that auto completes when you press ctrl+space. For example type syso and ctrl+space. This will automatically fill in System.out.println() into the editor.

Eclipse code templates:
eclipse_code_template
Code template variables:

Eclipse can automatically fill out dynamic code by sniffing out variables in a template. Here are a few you should make yourself aware of

Categories: java Tags: , , ,

Your favorite java IDE

August 27th, 2009 CertPal 41 comments

Which of these tools do you use to code in java ? I use myeclipse for J2EE coding and Netbeans for swing UI (which I would highly recommend.). I have worked with workshop as well.

Which of these is your favorite java IDE ?

  • Eclipse - J2SE / J2EE (48%, 1,405 Votes)
  • Netbeans (44%, 1,293 Votes)
  • IntelliJ (17%, 495 Votes)
  • Plain text editor (4%, 110 Votes)
  • Myeclipse (3%, 74 Votes)
  • JDeveloper (1%, 40 Votes)
  • RAD / WSAD (1%, 35 Votes)
  • Other (1%, 34 Votes)
  • Weblogic workshop (0%, 8 Votes)

Total Voters: 2,926

Loading ... Loading ...





Categories: java Tags: , ,