I have found that there is no really good description on how to download and install the FindBugs plug-in for Netbeans 5.5. The plug-in is part of a larger project on java.net called Software Quality Environment (SQE) If you want to use SQE and FindBugs. Do the following:
1. Start Nebeans 5.5 and go to the Tools --> Options --> Advanced Options (located on bottom left corner of Options screen)
2. Navigate to the IDE Configuration --> System --> Autoupdates Types item in the tree. See below
3. Right click on the Autoupdate Types item to bring up the context menu. Select New --> General Update Center. This will bring up the menu below. I named my update center FindBugs and pressed Finish. See Below.
4. Click on the new FindBugs update center in the tree and change the Server URL entry to
5. Close the window and you can now use the update center to install and update FindBugs
Thursday, November 30, 2006
Sunday, November 05, 2006
How to convert an InputStream to a String and Back
There are four methods listed below to convert
InputStream
to String
and String
to an InputStream
.
Labels:
Java
Subversion 1.4.0 Build Configuration (Solaris 10) (SPARC)
Set the library path using crle
crle -c /var/ld/ld.config -l /lib:/usr/lib:/usr/local/lib:/usr/sfw/lib
***You may need to unset the LD_LIBRARY_PATH
unset LD_LIBRARY_PATH
set make to gmake
export MAKE=/opt/sfw/bin/gmake
Add additional directories to the path
export PATH=$PATH:/usr/ccs/bin:/usr/sfw/sparc-sun-solaris2.10/bin
CONFIGURE SCRIPT
./configure --enable-maintainer-mode --enable-javahl --with-zlib --with-apxs=/usr/apache2/bin/apxs --with-jikes=no --with-jdk=/usr/jdk/jdk1.5.0_07 --without-berkeley-db --with-apr=/usr/apache2/bin/apr-config --with-apr-util=/usr/apache2/bin/apu-config --with-editor=/opt/sfw/bin/pico
crle -c /var/ld/ld.config -l /lib:/usr/lib:/usr/local/lib:/usr/sfw/lib
***You may need to unset the LD_LIBRARY_PATH
unset LD_LIBRARY_PATH
set make to gmake
export MAKE=/opt/sfw/bin/gmake
Add additional directories to the path
export PATH=$PATH:/usr/ccs/bin:/usr/sfw/sparc-sun-solaris2.10/bin
CONFIGURE SCRIPT
./configure --enable-maintainer-mode --enable-javahl --with-zlib --with-apxs=/usr/apache2/bin/apxs --with-jikes=no --with-jdk=/usr/jdk/jdk1.5.0_07 --without-berkeley-db --with-apr=/usr/apache2/bin/apr-config --with-apr-util=/usr/apache2/bin/apu-config --with-editor=/opt/sfw/bin/pico
Labels:
Solaris 10
,
Subversion
Friday, November 03, 2006
Coding for Performance
Here are some performance tips gathered from various sources and personal experience. I have sorted them by category (General, J5SE, J5EE)
General
- Always use the simplest classes possible to get the Job Done.
- Never code your own frameworks unless the performance is lacking. Reuse code and frameworks.
- Use open source frameworks which are established and tested.
- "Never do today what can be put off till tomorrow. " - Aaron Burr
- If a class proves difficult to code, put it off until you have a rest. You can then look at it with a fresh set of eyes
- Delegate the hard parts to code to another class
- Do not attempt to resolve all scenarios while coding, i.e., Wait to do locale specific encodings until after the initial code is complete.
- Place design notes in your code. Explain the performance requirements in your comments. If there are specific SRS requirements, note the number, date, and revision of the SRS document.
- Avoid object creation and destruction except as necessary. Reuse existing objects.
- Learn Collections and use them correctly. Use "lightweight" collections and avoid "heavyweight" collections where synchronization is not required.
- Initialize objects using a constructor with the least amount of requirements. If you need to use a number of parameters other than the default values, consider using the inverse of the object. In other words, if the object contains an int which is initialized to zero (0), then use the object with the default value and treat initialization parameters as the exception.
- Use findbugs to find common errors and performance problems.
- Reduce the distance between objects during operation. It is better to perform complex operations locally.
- Use System.currentTimeMillis() for performance measurements to determine execution time
- Use the -verbose:gc flag on the JVM to determine if the heap size is too small.
- Use constants where possible by using static final in the variable declaration.
- Use Enum instead of integer constants. Enums are more flexible and are typesafe.
- Avoid casting and using instanceof
- Use synchronized methods instead of code blocks.
- Avoid synchronized calls within a synchronized method or code block.
- Avoid using synchronization over IO operations except as required to maintain correct operation. For example: JPA inside a servlet.
- Turn off auto-commit and use transactions to improve throughput.
- Use -Xms and -Xmx flags to set the minimum and maximum heap sizes. Try to size appropriately to prevent wasting resources.
J5SE
Looping
- Do not recalculate constants inside a loop.
- "Fast Fail" - If a method fails, or throws an exception have it exit the loop quickly. Break loops early.
- Use local variables in loops. javac can assign an exact location of a local variable for a method at compile time.
Strings
- Avoid using Strings when you are modifying them. Strings are immutable. Therefore to "modify" a String, object creation and destruction must occur. Use StringBuilder and StringBuffer when Strings must be modified.
- Create Strings using the short form syntax to avoid creating additional objects.For example use: String s1 = "ABC";instead of: String s1 = new String("ABC");
- Never use String or StringBuffer for parsing characters. Use a character array.
- Try to set the StringBuilder or StringBuffer to the size required, or maximum size required during initialization to prevent a performance penalty while resizing.
- Avoid using StringTokenizer if there is a performance requirement. Use a more specific (custom) tokenizer to split Strings. StringTokenizer is a generic utility that is synchronized internally.
- Use StringBuilder instead of StringBuffer unless synchronization is required.
Collections
- Avoid using generic object collections. Use generics with collections to avoid having to cast objects.
- Use a LinkedList over an ArrayList if there a large number of insertions and deletions.
- Use a HashMap instead of a TreeMap unless there is a requirement to maintain a sort order.
- Use a HashSet over a TreeSet unless there is a requirement to maintain a sort order.
- When using Vector, try to set the initial size to the expected maximum size to prevent having to grow the Vector. If you must grow a Vector use a reasonable value to increase the size.
- It is extremely important to try to appropriately size a HashTable to prevent reorganization.
J5EE
- Reduce the number of network operations by returning complete results rather than smaller intermediate results.
- If database design constraints impose a specific database, use the advantages of the database where possible.
- If operations are performed on the database, consider using stored procedures and making JDBC calls.
- Do not use Entity Beans unless you must, use Java Persistence API (JPA) instead.
- Do not use Java Persistence API (JPA) unless you need it, or want to use some of its advanced capabilities.
- Limit the subset of data required to the minimum required for your program. Do not pull a whole row of data from table when you require only a few fields.
- When given a choice use local interfaces and local method calls on EJBs
- Shorten the distance between servers. Try to maintain dependent servers as close as possible. In clustered environments, try to keep remote communications on a separate private network interface.
- It is generally better to use a coarser stateless session bean to avoid JNDI lookups for fine grained operations.
- Avoid stateful session beans except as necessary.
- Set timers for non-activity on stateful session beans as low as possible to prevent "dead" connections waiting to timeout.
- Use Data Transfer Objects (DTO) to maintain granularity. DTOs must be Serializable.
Labels:
Java
,
JEE5
,
JSE5
,
Programming
Thursday, November 02, 2006
Subversion 1.3.2 Build Configuration (OS X)
Here are the parameters I used to install subversion on OS X.
./configure --with-ssl --with-libs=/usr/include/ssl --enable-maintainer-mode --enable-javahl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr --with-zlib --with-editor=/usr/bin/pico --with-apxs=/usr/local/apache2/bin/apxs --with-jikes=no --with-junit=/Users/jyeary/Library/Java/PrivateExtensions/junit-4.1 --with-jdk=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
Please note that I have the junit libraries stored in an alternate location.
./configure --with-ssl --with-libs=/usr/include/ssl --enable-maintainer-mode --enable-javahl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr --with-zlib --with-editor=/usr/bin/pico --with-apxs=/usr/local/apache2/bin/apxs --with-jikes=no --with-junit=/Users/jyeary/Library/Java/PrivateExtensions/junit-4.1 --with-jdk=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
Please note that I have the junit libraries stored in an alternate location.
Labels:
OS X
,
Subversion
Subscribe to:
Posts
(
Atom
)
Popular Posts
-
Introduction This article is not another diatribe to tell you the importance of unit testing. I think we can all agree that it is important...
-
A friend of mine asked me if there was a list of reserved words in EL and JSF. He had previously looked for it, and after some Google search...
-
I saw a question posed on stackoverflow called Trouble with Primefaces 3.0.M2 SelectOneMenu Ajax behavior and I had just done an example a...
-
I was working on a couple of SSL based issues when I made a couple of observations. The default self-signed key generation in Java does not ...
-
This is an example on how to make a system call to the local operating system to execute external programs. This example was written to work...
-
We have been doing a lot of work lately with PrimeFaces. A common set of questions comes up about displaying <p:dialog/> boxes on a pa...
-
I was asked earlier today how to reset fields in a JSF application, if the validation fails. In his case, he had a Richfaces table which had...
-
Image by quasarkitten via Flickr The basics for creating a Maven archetype can be found in the Maven - Guide to Creating Archetypes . The ...
-
Previously, I posted an example of how to use JSF 1.2 with form based authentication (j_security_check). In this example, I use JSF 2.x to...
-
Abstract A common use case is to iterate over a collection of elements, and display them on a page. In the world of JSP, we would use a Ja...