strategy for java jee development

take UI code debug and modification for example. previously, i have been tracing the log, using firebug check the URL address of the link, or better advanced using debug mode. But whatever method it is, i have been making huge effort on making sure, the 100% clear sure flow is made known. click button A —> to ActionA.class —> forward ServiceB.class —> DAOC.class –> JSPD.jsp.

it’s time consuming and effort consuming, yet, still times, there are mistakes. let’s say checking and follow every line, every detail of the code, then i finally modified A.class, D.jsp. Deploy and test, it might still wrong. Might be DAOD, need to be changed.

I just realized, after three years, knowing roughly the usual way of coding, structure, roughly architech, utilizing fiddler, click button A, button B, whatever, then check fiddler record, see what possibly what’s the action, let’s say ActionA.class, then go there, roughly check through, i would quickly decide possible problem occurrence place.

then deploy and test, it probably works.

conclusion is, now since now the “behind” coding (the why, how it works) I have roughly know, so I don’t any more spend so much time effort on tracing so detail, 100%. And utilizing fiddler, httpwatch professional, or debug mode, work is better and faster.


double d=24.5/0;
float f=24.5F/0;
int i=1/0;
System.out.println(“\”d=24.5/0;\” result:” + d);
System.out.println(“\”float f=24.5F/0;\” result:” + f);
System.out.println(“\”int i=1/0;\” result:” + i);

result:Exception in thread “main” java.lang.ArithmeticException: / by zero
at com.IB.test.main(

unlimited !

public class Outer2 {
        private int size;

        public Object makeTheInner(final int localVar) {
                final int finalLocalVar = 6;
                class Inner {
                        public String toString() {
                            return ("#< Inner size=" 
+ size +" localVar=" + localVar 
+" finalLocalVar=" + finalLocalVar + " >");

                return new Inner();

        public class Inner {
                public void doStuff() {


public class TestInner {
        public static void main(String[] args) {
                Outer2 outer = new Outer2();
                Object obj = outer.makeTheInner(1);
                // Must create an Inner object relative to an Outer
                Outer2.Inner inner = Inner();

#< Inner size=1 localVar=1 finalLocalVar=6 >

sonar + findbug + checkstyle +….

this code review tool has cost me much time, due to the poor documentation of sonar, and actually wrong documentaion.

1. the command should be “mvn sonar3:sonar” instead of “mvn sonar:sonar”. the latter would download sonar-maven-plugin-2.0-beta, which would always display the class missing/ class not accessible through classloader exception. the former command would instead download and install sonar-maven-plugin-2.4.1, which is the latest version, using which, the can be utilized locating the needed library jars.
2.there are some checkstyle, pmd null pointer exceptions, this is due to the configuration of each. something like single regexp setting, even though its default value is “^$”, however, specify this explicitly or not, makes a null pointer exception difference. which again proves, sth wrong with the sonar, or the plugin.

3. there are plugins to generate pdf report, sonar-pdfreport-plugin-1.2.jar

4. there are plugins to analyze the jsp, html files, sonar-web-plugin-1.0.2.jar. (however, Please note you can run sonar analysis for an artefact in only one language (SONAR-926). So you cannot run a web analysis and a java analysis on the same maven project. The fix is to make a separate maven pom for the web project with a different name. )

very good articles on Java Memory


“2. Memory

Java handles its memory in two areas. The heap and the stack. We will start with a short overview of memory in general on a computer. Then the Java heap and stack is explained.
2.1. Native Memory

Native memory is the memory which is available to a process, e.g. the Java process. Native memory is controlled by the operating system (OS) and based on physical memory and other physical devices, e.g. disks, flash memory, etc.

The processor (CPU) of the computer computes the instructions to execute and stores its computation results into registers. These registers are fast memory elements which stores the result of the CPU. The processor can access the normal memory over the memory bus. A amount of memory a CPU can access is based on the size of the physical address which the CPU uses to identify physical memory. A 16-bit address can access 2^16 (=65.536) memory locations. A 32-bit address can access 2^32 (=4.294.967.296) memory locations. If each memory area consists of 8 bytes then a 16-bit system can access 64KB of memory and the 32-bit system can access 4GB of memory.

An OS normally uses virtual memory to map the physical memory to memory which each process can see. The OS assigns then memory to each process in a virtual memory space for this process and maps access to this virtual memory to the real physical memory.

Current 32-bit systems uses an extension (Physical Address Extension (PAE)) which extends the physical space to 36-bits of the operation system. This allows the OS to access 64GB. The OS uses then virtual memory to allow the individual process 4 GB of memory. Even with PAE enabled a process can not access more then 4 GB of memory.

Of course with a 64-bit OS this 4GB limitation does not exists any more.
2.2. Memory in Java

Java manages the memory for use. New objects created and placed in the heap. Once your application have no reference anymore to an objects the Java garbage collector is allowed to delete this object and remove the memory so that your application can use this memory again.
2.3. Java Heap

In the heap the Java Virtual Machine (JVM) stores all objects created by the Java application, e.g. by using the “new” operator. The Java garbage collector (gc) can logically separate the heap into different areas, so that the gc can faster identify objects which can get removed

The memory for new objects is allocated on the heap at run time. Instance variables live inside the object in which they are declared.
2.4. Java Stack

Stack is where the method invocations and the the local variables are stored. If a method is called then its stack frame is put onto the top of the call stack. The stack frame holds the state of the method including which line of code is executing and the values of all local variables. The method at the top of the stack is always the current running method for that stack. Threads have their own call stack.
2.5. Escape Analysis

As said earlier in Java objects are created in the heap. The programming language does not offer the possibility to let the programmer decide if an objects should be generated in the stack. But in certain cases it would be desirable to allocate an object on the stack, as the memory allocation on the stack is cheaper then the memory allocation in the heap, deallocation on the stack is free and the stack is efficiently managed by the runtime.

The JVM uses therefore internally escape analysis to check if an object is used only with a thread or method. If the JVM identify this it may decide to create the object on the stack, increasing performance of the Java program.

& from about GC, from Oracle ,


& from


What Is Stack?

Each Java virtual machine thread has a private Java virtual machine stack, created at the same time as the thread. A Java virtual machine stack stores frames. It holds local variables and partial results, and plays a part in method invocation and return. Because the Java virtual machine stack is never manipulated directly except to push and pop frames, frames may be heap allocated. The memory for a Java virtual machine stack does not need to be contiguous.

The Java virtual machine specification permits Java virtual machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation. If the Java virtual machine stacks are of a fixed size, the size of each Java virtual machine stack may be chosen independently when that stack is created. A Java virtual machine implementation may provide the programmer or the user control over the initial size of Java virtual machine stacks, as well as, in the case of dynamically expanding or contracting Java virtual machine stacks, control over the maximum and minimum sizes.

The following exceptional conditions are associated with Java virtual machine stacks:

  • If the computation in a thread requires a larger Java virtual machine stack than is permitted, the Java virtual machine throws a StackOverflowError.
  • If Java virtual machine stacks can be dynamically expanded, and expansion is attempted but insufficient memory can be made available to effect the expansion, or if insufficient memory can be made available to create the initial Java virtual machine stack for a new thread, the Java virtual machine throws an OutOfMemoryError

What Is Heap?

The Java virtual machine has a heap that is shared among all Java virtual machine threads. The heap is the runtime data area from which memory for all class instances and arrays is allocated.

The heap is created on virtual machine start-up. Heap storage for objects is reclaimed by an automatic storage management system (known as a garbage collector); objects are never explicitly deallocated. The Java virtual machine assumes no particular type of automatic storage management system, and the storage management technique may be chosen according to the implementor’s system requirements. The heap may be of a fixed size or may be expanded as required by the computation and may be contracted if a larger heap becomes unnecessary. The memory for the heap does not need to be contiguous.

The heap mainly store objects create using or class level variables.

The following exceptional condition is associated with the heap:

  • If a computation requires more heap than can be made available by the automatic storage management system, the Java virtual machine throws an OutOfMemoryError
  • </em>