Reflection example - accessing private data

October 19th, 2008

If you think that you cannot access private data members of a class from some other class, then think again. With Reflection, this is possible.

Read the rest of this entry »


Tags and JavaBeans

October 19th, 2008

We use tags and beans to fetch data from the bean and present it. If you have some knowledge about these, then you will love working with these.

Read the rest of this entry »


Using reflection QueryRequestTag

October 19th, 2008

This post presents an example that show use of reflection in creating a tag. The created tag will call some methods of the request (HttpServletRequest) object using reflection.

Read the rest of this entry »


Create SQL File

October 19th, 2008

SQL files can be created manually in any existing eclipse project. Its simple and useful. Ill list the required steps.

Read the rest of this entry »


Detached views

October 19th, 2008

Eclipse provides an option to detach a view so that it can be moved to the desired place. Detached views are used if you are not comfortable with the placing of a view and want it to be move to someplace that is more feasible.

Read the rest of this entry »


costs of unit testing

October 17th, 2008

Unit testing brings a lot of benefits but there is some cost for this. Lets talk about this.

Read the rest of this entry »


Final improves performance

October 17th, 2008

Its right to say that Final keyword improves performance. For example, if you declare a method as final, then you cannot override it in derived classes. When this is told to compiler in advance using final keyword, it improves performance.

Read the rest of this entry »


Override/Implement methods

October 17th, 2008

Eclipse provides an easy way to generate stubs for the parent classes and implemented interfaces.

Read the rest of this entry »


META-INF and WEB-INF directories

October 14th, 2008

If you’re looking at a web application deployed on a tomcat server, then you might notice META-INF and WEB-INF directories.

Read the rest of this entry »


The JNDI API

October 13th, 2008

JNDI API package is called javax.naming package. It is composed of 5 interfaces, 10 classes along with few exceptions. InitialContext is the key class.

Read the rest of this entry »


JNDI - intro

October 12th, 2008

JNDI is a standard Java API that comes with JDK 1.3 and higher. It provides a common interface to a variety of existing naming services for example DNS, LDAP, Active Directory, RMI registry, COS registry, NIS, and file systems.

Read the rest of this entry »


java.lang.NoClassDefFoundError: org/apache/log4j/Layout

October 12th, 2008

You might have seen the following exception:

java.lang.NoClassDefFoundError: org/apache/log4j/*

It may mean that log4j is not in your class path or you are using some outdated version of log4j.

Read the rest of this entry »


apache-log4j-1.2.15

October 12th, 2008

You will surely have heard and used log4j in your applications. Its worth using it believe me. Its really east to log using apache’s logging framework. Sometimes, while working on some legacy application, you may find problems with the versioning for log4j framework.

Read the rest of this entry »


Running JUnit using Ant

October 10th, 2008

You may want to define build script using ant for your application. I will write about how to create ant script to run ant.

Read the rest of this entry »


Sharing setUp() and tearDown() code for all tests - II

October 10th, 2008

This post presents an example that shows how to use @BeforeClass and @AfterClass annotation.

Read the rest of this entry »


Sharing setUp() and tearDown() code for all tests - I

October 10th, 2008

You may wish to share the code written in setUp() and tearDown() methods of your JUnit tests. This clearly will indicate that you have excessive coupling in your design. Coupling is not bad always but if more tests share the same test fixture state, then this indicates that the classes under test have some undesirable dependencies.

Read the rest of this entry »


Lazy select fetching for collections

October 9th, 2008

Hibernate uses lazy select fetching for collections by default. This behavior makes sense and is used as it is unless you really want to do something different for some reason.

Read the rest of this entry »


Remote Debugging

October 9th, 2008

Ever wanted to launch a Java program from a network computer and debug it from the workstation running the Java platform? Example scenario is that you have an a J2EE application deployed on a dedicated server and you need to do debugging on you machine. This can be done if Java VM that supports this feature.

Read the rest of this entry »


Defining fetch strategy

October 8th, 2008

To tune fetch strategy, you have various options. Which to choose depends on the scenario. You may define the fetch strategy in the mapping document. For instance:

<set name="permissions" 
            fetch="join">
    <key column="userId"/>
    <one-to-many class="Permission"/>
</set
<many-to-one name="mother" class="Cat" fetch="join"/>

Read the rest of this entry »


Hibernate logging

October 8th, 2008

Hibernate logs various events using Apache commons-logging. Hibernate logs are very interesting to read if you want to do some troubleshooting or performance improvement. Hibernate uses commons-logging service for logging. It actually sends the log to either Log4j or to JDK1.4 logging.

Read the rest of this entry »


SessionFactory Monitoring

October 8th, 2008

There are few ways of accessing SessionFactory metrics. One of them is to use JMX to publish metrics. For that you need to enable the StatisticsService MBean. A single MBean can be enabled for your SessionFactory or one per factory.

Read the rest of this entry »


Threads and Monitors

October 7th, 2008

When you are working with multi threading where resources are locked and released, deadlock prevention becomes very important. To prevent starvation, proper lock and release mechanism has to be defined/implemented.

Read the rest of this entry »


Hot Code Replace

October 7th, 2008

Ever heard of hot code replace in reference to debugging in Eclipse? Well, its sure is a powerful and useful feature. It enables you to change code while debugging. It simply means that you may change the code in debug mode and see its affect.

Read the rest of this entry »


Mark occurrences

October 7th, 2008

Mark occurrences is a nice feature in Eclipse. It simply marks/highlights all the occurrences of a variable, method or a type.

Read the rest of this entry »


Searching methods with some return type

October 6th, 2008

Working on a project, I need to search all the methods defined in my workspace or in a package or in a class with a specific return type. Eclipse search feature (ctrl + h) provides support for this. We all have used eclipse search window a lot of times but many of us don’t know how to really use it to great affect.

Read the rest of this entry »


Safe JAR file migration

October 6th, 2008

Its always a good idea to include refactoring information into the JAR file when you are exporting it from Eclipse. Eclipse’s JAR Export Wizard offers this option.

Read the rest of this entry »


Wrapping Strings

October 6th, 2008

Its always useful to wrap strings if they are too long. This provides better readability. Eclipse has support for this.

Read the rest of this entry »


importing junit.jar

October 5th, 2008

Before you start writing unit tests, you must import junit.jar, so we have access to the testing framework. Follow these steps to import the require jar:

Read the rest of this entry »


Motivation for unit tests

October 5th, 2008

Unit tests are essential part of software development especially. In complex and large softwares, introducing new changes in very tricky as it can break some other part. If you have clearly defined test cases, then you can check the working of newly introduced change and make sure it works as expected.

Read the rest of this entry »


Setting watches

October 5th, 2008

Watch point is a special type of break point that suspends execution when specified filed is accessed or modified.

Read the rest of this entry »


Scrapbook - II

October 5th, 2008

Write Java code in scrapbook page. Code assistant is also available. Use it if required. To execute the code, highlight the code, right click it and select execute.

Read the rest of this entry »


Scrapbook - I

October 5th, 2008

Consider the following scenario: you are working on a project with client specific APIs .You need to test some API methods before you put them in your real code. For that, you might consider a separate test workspace or defining a new test class in your running workspace. What about scrapbook page? Ever heard of it?

Read the rest of this entry »


Debugger: Code assist

October 5th, 2008

You might have used code assistant while coding in Eclipse. Its really useful and saves time for trivial stuff. Most of us think that code assistant is only available in code writing context. That’s not right.

Read the rest of this entry »


Running code with compile errors

October 5th, 2008

While coding in Java using Eclipse, you might have experienced situations where your Java class has some compile errors but stilly you want to run it. The reason might be that the problematic area might be invoked in your execution. What ever is the reason, Ill briefly explain how to execute code with compile errors.

Read the rest of this entry »


Stack traces

October 5th, 2008

You must have seen stack traces in console window of your Eclipse. Good this is that Java stack traces in the console appear with hyperlinks. This means you can click these to go to the referred place in the code. This helps in problem identification.

Read the rest of this entry »


Fetching parms form web.xml - II

October 4th, 2008

Now we have defined the parameters in web.xml. This file will reside under WEB-INF. Now lets see how to fetch these values.

Read the rest of this entry »


Fetching parms form web.xml - I

October 4th, 2008

The file named web.xml is part of your web applications. You may use it for different purpose. Sometimes you wish to define some parameters for your web application in it. Obviously, you need to use this in your application. I will briefly tell you how to do this.

Read the rest of this entry »


Using Java Beans in JSP - III

September 28th, 2008

JavaBean’s session scope is used to maintain items such as shopping carts very easily within JSP pages.

Read the rest of this entry »


Using Java Beans in JSP - II

September 28th, 2008

You may access JavaBean’s value through a set of properties, which provides access to the JavaBean’s settings. For instance: Student is a JavaBean and student id, name, age, majors are properties.

Read the rest of this entry »


Using Java Beans in JSP - I

September 28th, 2008

JavaBeans are classes written in the Java programming language conforming to a particular convention.

Read the rest of this entry »


Reading files from JSP

September 28th, 2008

Working in Servlets/JSP, you might have encountered The javax.servlet.ServletContext API. It provides methods to access resources in general.

Read the rest of this entry »


Writing a file form JSP

September 28th, 2008

You may want to write a file from JSP page. For example, user fills a form and you want to persist the details on a text file on server. Now you need to know how to write text file from JSP.

Read the rest of this entry »


finalize

September 25th, 2008

All Java classes inherits the finalize() method from java.lang.Object and this method is called by the garbage collector when it determines no more references to the object exist.

Read the rest of this entry »


ArrayStoreException

September 24th, 2008

java.lang.ArrayStoreException is a runtimeException and is thrown when we try to store wrong type of object into an array of objects.

Read the rest of this entry »


Javap - IV

September 23rd, 2008

The output sure is a bit cryptic but things are obvious.

Read the rest of this entry »


Javap - III

September 23rd, 2008

Compile the class presented in last post and you will get class file. Lets see what javap outputs when it’s run against the class with the -c option.

Read the rest of this entry »


Javap - II

September 23rd, 2008

Time for an example. StringBuffer vs. String scenario is a well known thing to developers. You know that using String for concatenation is an expensive operation since compiler uses StringBuffer internally. Lets validate this fact.

Read the rest of this entry »


Javap - I

September 23rd, 2008

Javap is shiped with JDK and it really very useful when you want to see what your compiler is doing to your code. It generates source code from a compiled class file.

Read the rest of this entry »


XSLT - conditions

September 23rd, 2008

Consider the scenario: You have xml data and you need to filter some data out. You may do that in Java but its open a good idea to keep the logic separate in XSLT filters.

Read the rest of this entry »


JSP Tag - I

September 19th, 2008

JSP tags are like HTML tags and they do not use <%. Instead they use < character.

Read the rest of this entry »


Next Page »