Reflection example - accessing private data
October 19th, 2008If you think that you cannot access private data members of a class from some other class, then think again. With Reflection, this is possible.
Tags and JavaBeans
October 19th, 2008We 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.
Using reflection QueryRequestTag
October 19th, 2008This 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.
Create SQL File
October 19th, 2008SQL files can be created manually in any existing eclipse project. Its simple and useful. Ill list the required steps.
Detached views
October 19th, 2008Eclipse 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.
costs of unit testing
October 17th, 2008Unit testing brings a lot of benefits but there is some cost for this. Lets talk about this.
Final improves performance
October 17th, 2008Its 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.
Override/Implement methods
October 17th, 2008Eclipse provides an easy way to generate stubs for the parent classes and implemented interfaces.
META-INF and WEB-INF directories
October 14th, 2008If you’re looking at a web application deployed on a tomcat server, then you might notice META-INF and WEB-INF directories.
The JNDI API
October 13th, 2008JNDI API package is called javax.naming package. It is composed of 5 interfaces, 10 classes along with few exceptions. InitialContext is the key class.
JNDI - intro
October 12th, 2008JNDI 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.
java.lang.NoClassDefFoundError: org/apache/log4j/Layout
October 12th, 2008You 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.
apache-log4j-1.2.15
October 12th, 2008You 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.
Running JUnit using Ant
October 10th, 2008You may want to define build script using ant for your application. I will write about how to create ant script to run ant.
Sharing setUp() and tearDown() code for all tests - II
October 10th, 2008This post presents an example that shows how to use @BeforeClass and @AfterClass annotation.
Sharing setUp() and tearDown() code for all tests - I
October 10th, 2008You 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.
Lazy select fetching for collections
October 9th, 2008Hibernate 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.
Remote Debugging
October 9th, 2008Ever 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.
Defining fetch strategy
October 8th, 2008To 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"/>
Hibernate logging
October 8th, 2008Hibernate 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.
SessionFactory Monitoring
October 8th, 2008There 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.
Threads and Monitors
October 7th, 2008When 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.
Hot Code Replace
October 7th, 2008Ever 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.
Mark occurrences
October 7th, 2008Mark occurrences is a nice feature in Eclipse. It simply marks/highlights all the occurrences of a variable, method or a type.
Searching methods with some return type
October 6th, 2008Working 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.
Safe JAR file migration
October 6th, 2008Its 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.
Wrapping Strings
October 6th, 2008Its always useful to wrap strings if they are too long. This provides better readability. Eclipse has support for this.
importing junit.jar
October 5th, 2008Before 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:
Motivation for unit tests
October 5th, 2008Unit 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.
Setting watches
October 5th, 2008Watch point is a special type of break point that suspends execution when specified filed is accessed or modified.
Scrapbook - II
October 5th, 2008Write 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.
Scrapbook - I
October 5th, 2008Consider 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?
Debugger: Code assist
October 5th, 2008You 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.
Running code with compile errors
October 5th, 2008While 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.
Stack traces
October 5th, 2008You 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.
Fetching parms form web.xml - II
October 4th, 2008Now we have defined the parameters in web.xml. This file will reside under WEB-INF. Now lets see how to fetch these values.
Fetching parms form web.xml - I
October 4th, 2008The 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.
Using Java Beans in JSP - III
September 28th, 2008JavaBean’s session scope is used to maintain items such as shopping carts very easily within JSP pages.
Using Java Beans in JSP - II
September 28th, 2008You 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.
Using Java Beans in JSP - I
September 28th, 2008JavaBeans are classes written in the Java programming language conforming to a particular convention.
Reading files from JSP
September 28th, 2008Working in Servlets/JSP, you might have encountered The javax.servlet.ServletContext API. It provides methods to access resources in general.
Writing a file form JSP
September 28th, 2008You 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.
finalize
September 25th, 2008All 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.
ArrayStoreException
September 24th, 2008java.lang.ArrayStoreException is a runtimeException and is thrown when we try to store wrong type of object into an array of objects.
Javap - IV
September 23rd, 2008The output sure is a bit cryptic but things are obvious.
Javap - III
September 23rd, 2008Compile 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.
Javap - II
September 23rd, 2008Time 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.
Javap - I
September 23rd, 2008Javap 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.
XSLT - conditions
September 23rd, 2008Consider 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.
JSP Tag - I
September 19th, 2008JSP tags are like HTML tags and they do not use <%. Instead they use < character.