View RSS Feed

All Blog Entries

  1. Benefits of using Final class

    by , 11-06-2011 at 05:58 PM (My Java Tips)
    Final classes have a lot of benefits if used where required. I will present benefits of final classes in this post.


    Sometimes, you wish that no one can inherit from your class since its functionality is completed and should not be inherited. In that case, you may define your class as final, and then no class can inherit from it. The method of final class are also final. Final methods cannot be overridden in any sub class. There is also performance issues related to final class. A ...
    Categories
    Java SE
  2. Final variables

    by , 11-06-2011 at 05:57 PM (My Java Tips)
    A final variables in Java are can only be assigned once. Once they are assigned some value, they cannot be assigned some other value.


    If you have final class variable, they must be assigned to in the constructor of the class. An interesting thing is that the value of a final variable is not necessarily known at compile time. Consider the following example:

    Java Code:
    public class Sphere {
    
        public static final double PI = 3.141592653589793;
    ...
    Categories
    Java SE
  3. Using a custom task in Ant

    by , 11-06-2011 at 05:53 PM (My Java Tips)
    It is assumed that you have already defined a custom Ant task and wish to use it. In this post, I will show you how to do so.




    You first need to define the task by giving it a name and telling Ant the classfile that implements it and any classpath setting required to locate that classfile. This is done using the taskdef task, like so:

    <taskdef name="fileparser">classname="FileParser"
    classpath="."/&gt; ...
    Categories
    Ant , XML
  4. Defining custom tasks in ANT

    by , 11-06-2011 at 05:49 PM (My Java Tips)
    Ant provides various core and optional tasks which you use to automate the build process. Very seldom, you need to define your own customized tasks.


    To implement a simple custom task, you need to extend the org.apache.tools.ant.Task class and override the execute() method. Follow the sample below:

    Java Code:
    import org.apache.tools.ant.BuildException;
    import org.apache.tools.ant.Task;
    public class FileSorter extends Task {
    // The method executing the
    ...
    Categories
    Ant
  5. JBossWS

    by , 11-06-2011 at 05:47 PM (My Java Tips)
    JBoss used to have JBoss.NET package for web services. Now, there exists JBossWS module which is responsible for providing web services in JBoss 4.0.


    It is based on Apache Axis like JBoss.NET but the difference is that JBossWS provides the complete set of J2EE 1.4 web services technologies like SOAP, SAAJ, JAX-RPC and JAXR. The J2EE web services support exposing EJBs as web services, but only stateless session beans can be used.

    JBossWS is a JAX-WS compliant web service ...
    Categories
    JBoss
  6. JBoss directory structure

    by , 11-06-2011 at 05:45 PM (My Java Tips)
    You should be knowing the directory structure of JBoss server, in order to work efficiently with JBoss. I will target the directory structure in this post.


    The jboss-4.0.2 directory contains following sub-directories:

    Bin
    Contains startup and shutdown scripts.

    Client
    Client folder contains configuration and JAR files that are required by Java client application or an external web container.

    Docs
    The XML DTDs used in ...
    Categories
    JBoss
  7. SVN (Trunk/Branch/Tag)

    by , 11-06-2011 at 05:41 PM (My Java Tips)
    SVN (SubVersion) is being used in software development houses to maintain the source code. Its very effective if used properly. In this post, I will present some basic concepts about SVN.


    Usually, SVN has following directory structure:

    /trunk
    /branches
    /tags

    You may add more directories like archive and some other of you want. I will explain the use of above directories so you know when to use what.

    The trunk directory contains ...
    Categories
    Subversion
  8. Writing System Properties

    by , 11-06-2011 at 05:35 PM (My Java Tips)
    System's setProperties() method can be used to modify existing system's property. It takes a Properties object that has been initialized to contain the key/value pairs for the properties that you want to set.




    This method actually replaces the entire set of system properties with the new set Properties object. Lets review an example that creates a Properties object,initializes it from a file and then uses System.setProperties() to install the new Properties objects ...
    Categories
    Java SE
  9. Environment Variables

    by , 11-06-2011 at 05:31 PM (My Java Tips)
    Environment variables are used by operating systems to pass useful information (configurations) to the applications. Environment variables are key/value pairs very much like properties. The key and the value, both are strings. To set environment variables, please read system documentation as it varies from one operating system to another.




    In our Java applications, we use System.getEnv to retrieve environment variable values. If no argument is passed, getEnv will return ...
    Categories
    Java SE
  10. Java built-in data types (performance issues)

    by , 11-06-2011 at 05:29 PM (My Java Tips)
    Java built in data types provide programmers ease of storing their required data in appropriate data type. But in come cases, it may become a bottleneck. When doing low level related work, the speed is very important. In such case don't use the Java built-in data types.




    Lets take an example. If you are using an Integer class, just think of all the overhead you are creating by using the wrapper class. One rule of thumb is to use the primitives instead of wrapper. This ...
    Categories
    Performance
  11. JBoss – Web Container

    by , 11-06-2011 at 05:27 PM (My Java Tips)
    I assume you are familiar with Tomcat. Normally developers start learning J2EE with Servlet and JSP and deploy them on Tomcat. JBoss now comes with Tomcat 5.5 and is used as default web container.


    The embedded Tomcat service is the expanded SAR jbossweb-tomcat55.sar in the deploy directory. All the required JARs also exist there. The file web.xml provides default configuration set for web applications. server.xml, which contains standard Tomcat format configuration information. This ...
    Categories
    JBoss
  12. Preparing development environment for J2EE dev/JBoss

    by , 11-06-2011 at 05:25 PM (My Java Tips)
    I will show how to prepare development environment for J2EE development using JBoss. Download and install the JBoss. I will be using jboss-4.2.2.GA. Now download the latest Java EE Eclipse from eclipse.org. I have version 3.3.2.


    You should have all the required plugins for J2EE development with JBoss in your Eclipse. Navigate to:

    Help > Software updates > Find and Install > Search for new features to install > New remote site

    You can name ...
    Categories
    Eclipse , EJB , Java EE , JBoss , JSF
  13. Jboss-4.0.2 hibernate bug

    by , 11-06-2011 at 05:21 PM (My Java Tips)
    Hibernate is a popular persistence engine that runs in almost any application server and provides alternative of standard entity beans. With JBoss, you can choose to deploy your application as a Hibernate archive, called a HAR file. This makes using hibernate simpler. JBoss is responsible for managing hibernate session and other configuration details.


    Jboss-4.0.2 does not include Hibernate3 integration module. This requires Apache commons collections JAR. To fix this, use fix-hibernate ...
    Categories
    Hibernate , Java EE , JBoss
  14. Creating a Hibernate archive

    by , 11-06-2011 at 05:20 PM (My Java Tips)
    Consider a simple POJO with no direct coupling to Hibernate. The details of the Hibernate mapping will be specified in the Player.hbm.xml file.




    Player.hbm.xml is shown below.

    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
    <hibernate-mapping>
    <class name="org.jboss.roster.Player" table="PlayerBean">
    <id ...
    Categories
    Hibernate , XML
  15. Using the hibernate objects

    by , 11-06-2011 at 05:18 PM (My Java Tips)
    I assume that you know how to create hibernate archive and you have created a fully configured SessionFactory for use in other parts of your application. I will present an simple JSP which creates a Session from the SessionFactory and issues a query directly.




    It’s a good practice to put the Hibernate access code in a servlet or in a
    session bean, but for example purposes I will use JSP.

    The example shows how to access Hibernate session in the ...
    Categories
    Hibernate
  16. jboss-service.xml

    by , 11-06-2011 at 05:16 PM (My Java Tips)
    JBoss core services are listed in conf/jboss-service.xml file. These services are started first when the server starts up. You may open the file in any test editor or in some XML editor. You will see MBeans for various services including logging, security, JNDI. You may comment any service for example:



    Now if you restart JBoss, you wont see the JNDIView service in the management console listing. In normal practice, you very seldom needs to alter this file. Remember that the ...
    Categories
    Java EE , JBoss
  17. JBoss - Logging Service

    by , 11-06-2011 at 05:13 PM (My Java Tips)
    Jboss uses Apache logging application called log4j for logging. You can find log4j.jar under lib director. The logging service is enabled from jboss.service.xml.


    The file will read like this:

    <!-- ================================================== ================== -->
    <!-- Log4j Initialization -->
    <!-- ================================================== ================== --> ...
    Categories
    JBoss , XML
  18. Using Maven - Unit Tests

    by , 11-05-2011 at 07:00 PM (My Java Tips)
    You want Maven to compile your unit tests. Simply place you unit tests in a directory and mention the director under
    unitTestSourceDirectory´tags.

    src/test




    Once that is done, specify the unit tests which you want to run in unitTest XML element. You may use includes and excludes tags to include or exclude the classes.



    Java Code:
             **/*Test*.java 
           
           
             **/BaseTestCase.java
    ...
    Categories
    Maven
  19. Documenting projects

    by , 11-05-2011 at 06:58 PM (My Java Tips)
    Everyone know how important it is to document the project. I wont be shedding light on this. But the aim of this post is
    to introduce how Maven can help you generate project documentation.




    Maven can actually generate a website for your project. Use following command to generate documentation:
    Run the site:generate goal for your project with this command:

    maven site:generate

    Maven will generate html documentation in the docs ...
    Categories
    Maven
  20. JMS - Publish-Subscribe Messaging

    by , 11-05-2011 at 06:55 PM (My Java Tips)
    Programs can create, send and read messages in distributed enterprise environment using MOM (Message-Oriented-Middleware). The Java Message Service (JMS) provides a standard Java-based interface to the message services of a MOM of some other provider.




    There are few messaging models available which determine which client receives the message.
    Publish-Subscribe Messaging
    Point-To-Point Messaging
    Request-Reply Messaging

    Lets first talk ...
    Categories
    JMS
  21. JMS - Request – Reply Model

    by , 11-05-2011 at 06:51 PM (My Java Tips)
    This model is used when real time response is required. JMS provides two API to implement Request – Reply model which are QueueRequester and TopicRequester.




    QueueRequestor
    You may use this is you wish to use QUEUE. It creates a TemporaryQueue for the responses and provides a request() method that sends the request message and waits for its reply.

    TopicRequestor
    This API uses TOPIC to get responses. It creates a TemporaryTopic for the responses ...
    Categories
    JMS
  22. Entity (Tips/Info)

    by , 11-05-2011 at 06:47 PM (My Java Tips)
    In this post, I will present some useful information about Entities. I hope these will prove useful.




    You may indicate the entity class by annotating it with the Entity annotation or you may denote that class as entity in the XML descriptor. The entity class must have no-arg constructor and it should either be public and protected. The entity class can have other constructors as well.

    Another important thing to note about entity class is that the entity ...
    Categories
    EJB
  23. Sample Entity Bean

    by , 11-05-2011 at 06:45 PM (My Java Tips)
    Creating entity bean is simple. You have to annotate the class to indicate that it’s an entity bean. Also your class should implement Serializable interface. An example entity bean is presented below. Do note that we have defined a no argument constructor which is a must.




    Java Code:
    @Entity
    public class Customer implements Serializable {
    
    private Long id;
    private String name;
    private Address address;
    private Collection
    ...
    Categories
    EJB
  24. Managing dependencies using Maven

    by , 11-05-2011 at 06:42 PM (My Java Tips)
    Maven can manage all jar file dependencies for the build machines. Let me explain how to do this.




    We use dependency element to refer to a jar file which reside in a remote repository. It is said that in near future, the dependencies will extend beyond jar files. Maven places the jar files (fetched from remote repository) on the local repository. The element has three child elements, , , and . Maven looks in the remote repository for a directory with the same name as ...
    Categories
    XML , Maven
  25. Debugging Remote Java Application

    by , 11-05-2011 at 06:38 PM (My Java Tips)
    Debugging is very helpful is following the flow of an application and knowing what happens when. You get list of variables with their values and you can flow what exactly is happening. It really helps is identifying the problem areas. Debugging in Eclipse is really simple and easy. I assume that you have done debugging in Eclipse.




    Debugging a J2EE application is a bit tricky since the application is deployed in web/application container. JBoss provides support for ...
    Categories
    Eclipse , Java EE , JBoss
  26. Eclipse - Show View

    by , 11-05-2011 at 06:35 PM (My Java Tips)
    Java developers working in Eclispe should be aware of the windows that Eclipse provides for assistance. You may turn them on/off when ever required.



    Select Window > Show view from menu bar to see the available views.Name:  eclipse_views.PNG
Views: 269
Size:  34.5 KB

    Once you have a view, you can slide it to the appropriate place you want. I agree that it will take some space and this will reduce your working area. But can always minimize a view. Also, double clicking the view ...
    Categories
    Eclipse
  27. Jboss port numbers

    by , 11-05-2011 at 06:32 PM (My Java Tips)
    While working with JBoss, you must have experienced port-number collision. JBoss is does not tell ports are in use, which services are using those and how you can change them. I will try to provide some useful information in this post.



    In this post, I will talk particularly about JBoss version 4.03. All file references are relative to $JBOSS_HOME/server/default. Do assume that we are working with default configuration.

    File: $JBOSS_HOME/server/default/deploy/jbossweb-tomcat50.sar/server.xml ...
    Categories
    JBoss
  28. Deploying WAR on JBOSS

    by , 11-04-2011 at 06:52 PM (My Java Tips)
    I will present simple steps to create a web application (WAR) and will show how to deploy a WAR on JBOSS.


    Let me start from installing Java.
    http://java.sun.com/javase/downloads/

    Run the installer and install Java at: "C:\Program Files\Java\jdk1.6.0_06\". An important thing to note is that JBoss, requires the full JDK which contains the JRE along with some additional stuff like javac compiler.

    Next step is to install JBoss. Go to the ...
    Categories
    Java EE , JBoss
  29. Debugging - All references of a class/object

    by , 11-04-2011 at 06:48 PM (My Java Tips)
    Consider the following scenario. You have a class and you with to see all the references of it. It’s definitely worth seeing that. Eclipse 3.3 provides this functionality.


    Mark a class (whose references you want to see) in the Java editor and choose All Instanced from the context menu.

    If you want to display references of the specific object, follow the following procedure:

    In the Variable window, right click on the object and choose All References. A ...
    Categories
    Eclipse
  30. Eclipse - Classpath variables

    by , 11-04-2011 at 06:46 PM (My Java Tips)
    A classpath variable can be added to a project’s class path. It can be used to define location of a JAR file that is not the part of workspace. Non modifiable class path variables are set internally like JRE_LIB, JRE_SRC, JRE_JRCROOT.


    To define a class path variable in Eclipse, open preferences by clicking Window > Preferences from the menu bar. You will find class variables under Java > Build Path. There you can define new class variables.

    Name:  eclipse-classpath.PNG
Views: 273
Size:  16.2 KB ...
    Categories
    Eclipse
Page 42 of 48 FirstFirst ... 324041424344 ... LastLast