View RSS Feed

My Java Tips

  1. The JNDI API

    by , 05-21-2011 at 10:18 PM (My Java Tips)
    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.

    This is what Sun Java Docs say about InitialContext:
    Java 2 Platform SE v1.3.1: Package javax.naming

    In JNDI, all naming and directory operations are performed relative to a context. There are no absolute roots. Therefore JNDI defines an initial context, InitialContext, which provides a starting point for naming ...
    Tags: jndi Add / Edit Tags
    Categories
    Java EE , JBoss
  2. META-INF and WEB-INF directories

    by , 05-21-2011 at 10:16 PM (My Java Tips)
    If you're looking at a web application deployed on a tomcat server, then you might notice META-INF and WEB-INF directories.

    The META-INF directory is related to .jar files, It contains the manifest file which has list of jars. The WEB-INF directory is a vital component of your web application. Web application won't run without it. It contains a hierarchy in which you'll find the necessary configuration information for your web application, and all the class files for your servlets ...
    Categories
    JBoss
  3. Override/Implement methods

    by , 05-21-2011 at 10:14 PM (My Java Tips)
    Eclipse provides an easy way to generate stubs for the parent classes and implemented interfaces.

    Right click the your class and select Source > Override/Implement methods. You will be presented a window where you can select all the methods that you want to override/implement. This methods will be from the implemented interface or extended class.

    Name:  eclipseoverride.jpg
Views: 244
Size:  20.1 KB

    Really saves time. Do try this.
    Categories
    Eclipse
  4. Final keyword improves performance

    by , 05-21-2011 at 10:10 PM (My Java Tips)
    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.

    Java Code:
    public final void doSomethng()
    {
    ...
    }
    Knowing that a method cannot be overridden, complier inline that method into its derived classes.
    Final variables, especially static final variables, ...
    Tags: final Add / Edit Tags
    Categories
    Performance
  5. Costs of Unit Testing

    by , 05-21-2011 at 10:09 PM (My Java Tips)
    Unit testing brings a lot of benefits but there is some cost for this. Lets talk about this.

    Unit tests require skill and time. Often managers dont appreciate unit tets because they regard it something othere than development. Ofcource client in not interested in unit tests but management needs to understand that these tests will save a lot of debugging effort in future.

    For unit testing to really deliver, all developers need to use it. Mostly due to lack of communicationm ...
    Tags: unit testing Add / Edit Tags
    Categories
    JUnit
  6. Detached Views in Eclipse

    by , 05-21-2011 at 10:07 PM (My Java Tips)
    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.

    This is done as follows:

    • Right-click on the view
    • Select "Detached" from the menu
    • Place the view where you choose


    Name:  detachedview.PNG
Views: 313
Size:  6.3 KB

    Thing to remember is that one can also drag and drop ...
    Categories
    Eclipse
  7. Create SQL File in Eclipse

    by , 05-21-2011 at 10:03 PM (My Java Tips)
    SQL files can be created manually in any existing eclipse project. It's simple and useful. I'll list the required steps.

    • Open Database Development perspective
    • Select File > New > Other, expand SQL Development, select SQL File, and click Next
    • This will open the New SQL File wizard.
    • To create a new project, click "Create Project" and follow the wizard instructions. Now provide the SQL file name.
    • Select a connection profile type from the Connection profile
    ...
    Tags: eclipse, sql Add / Edit Tags
    Categories
    Eclipse
  8. Using reflection QueryRequestTag

    by , 05-21-2011 at 09:51 PM (My Java Tips)
    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.

    Source code for the QueryRequestTag handler is presented below:

    Java Code:
    public class QueryRequestTag extends ExTagSupport {
        static Object []params = new Object[0];
        
        static Hashtable methods = new Hashtable();
        
        static LocalStrings ls =
    ...
  9. Tags and JavaBeans

    by , 05-21-2011 at 09:42 PM (My Java Tips)
    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.

    Bean interaction involves JSP getting the value of some property of a bean and displaying that value to the user. Another role of JavaBean is defining how events are specified. Tags can be concerned with two bean-related issues:

    • Introspecting the beans to find the properties and get the methods that these tags should call
    ...
    Tags: javabean, tag Add / Edit Tags
    Categories
    Java EE
  10. Reflection example - accessing private data

    by , 05-21-2011 at 05:28 PM (My Java Tips)
    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.

    Using reflection, we can see / view / access a private member, private variable, private method. Some people will not like this with argument that this actually means messing up the laws of encapsulation. I use it for unit testing private methods.

    Example follows:


    Java Code:
    import java.lang.reflect.Field;
    ...
    Tags: reflection Add / Edit Tags
    Categories
    Java SE
Page 15 of 15 FirstFirst ... 5131415