Wednesday, March 21, 2007

Running more than one instance of Tomcat Server on the same machine

I came across one of the question in one of the Java forum on ITTOOLBOX which was like this:

Can we run more than one instance of the Tomcat server on the same machine?

I was trying this from two days, and finally I was successful in starting three Tomcat instances on the same machine with different port numbers.

I followed the following steps to do the same:
a. Made three different folders of Tomcat directory.

b. Made changes in the environment variables as CATALINA_HOME1, CATALINA_HOME2, and CATALINA_HOME3.

c. Then I reflected the above changes in the "startup.bat", "shutdown.bat" and "catalina.bat" batch files in each Tomcat "bin" folder accordingly.

d. Then I changed the default port numbers 8005, 8080, and 8009 in server.xml & server-minimal.xml files of second and third Tomcat directories.

e. Now first server was running at port 8080, second one at 8090, and the third one at 8095.

Conclusion:
We can either have the instances running on the same machine (different ports), different machines (same ports) or different machines (different ports).

Friday, March 16, 2007

JavaCompilerTool

javax.tools.JavaCompilerTool
It is a JDK 1.6+ interface that lets the Java program fire up the Java compiler, (usually javac.exe) and compile Java source, all under the program's control, in a platform-independent way.

We can use it to compile code that exists only in RAM. We can generate the source code on the fly, compile it, and execute it.

Please find in some interesting pointers related to JavaCompilerTool:

http://www.javalobby.org/java/forums/m91985882.html
http://www.velocityreviews.com/forums/t318697-javacompilertool.html

Thanks.

Tuesday, March 13, 2007

Does Java supports "Operator Overloading"?

This was the question which aroused in my mind when for the first time I saw the use of String concatenation operator "+" to concatenate two or more Strings.
To get to its root, I read many articles on forums and blogs [e.g. Sun's Forum] and finally came to the following conclusion:


> String concatenation operator "+" is an exception and is just given for the simplicity and it's used internally by the compiler.
> We cannot overload any of the operator at the language level, so this means that Java doesn't support operator overloading.

Please feel free to CORRECT me in case I am going wrong, that would be very kind of you :-).

Monday, March 12, 2007

Immutability of the "String" class in Java

Consider the following code snippet:

----------------------------
String a = "First";
System.out.println(a);
----------------------------

The output is: First
Now, I use the string concatenation operator "+" as:

----------------------------
String a = "First";
a = a + " Second"; //Creates a new String object
System.out.println(a);
----------------------------

The output is: First Second

The string concatenation operator "+" implicitly creates a new String object and the reference to the old one is lost, thus the value of String object cannot be changed after it has been created (i.e. it's Immutable).

Friday, March 9, 2007


_________________________________________________________________________________________________________________

"Look at the sky. We are not alone. The whole Universe is friendly to us and conspires only to give the best to those who dream and work."

- Dr. A P J Abdul Kalam
_________________________________________________________________________________________________________________