Tuesday, July 27, 2010

Enabling JMX port in Tomcat

By default JMX port is not enable in the Tomcat.
If you want to enable the JMX port, add the fallowing properties
in catalina.bat file which located in bin directory of the %CATALINA_HOME%.
Add the fallowing properties as starting line of catalina.bat
set JAVA_OPTS= %JAVA_OPTS% -Dcom.sun.management.jmxremote.port=7009

Enabling JMX port in JBOSS

By default JMX port is not enabled in the JBOSS. If you want enable the JMX port, add the falowing properties
in run.bat file which located in bin directory of the %CATALINA_HOME%.
set JAVA_OPTS = %JAVA_OPTS% -Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl
-Djboss.platform.mbeanserver -Dcom.sun.management.jmxremote.port=8007
To add the above propertis in run.bat fallow the steps
1. Find for the fallowing code:
set JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx512m
2. Replace the above code with :
set JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx512m -Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl -Djboss.platform.mbeanserver -Dcom.sun.management.jmxremote.port=8007 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false

Monday, July 26, 2010

Enable JMX Remote port in Websphere

By default Websphere is not JMX enabled ,  so we have to enable the JMX remote port after installation.
Below I am trying to explain the steps to enable the JMX remote port in Websphere.  These are the steps I have fallowed to enable the JMX remote port in Websphere 7.0.
Login to Admin console of the web sphere any profile(server). You can find the shortcut in the Windows menu after installation.
Step 2:
Deploy the PerfServletApp.ear application if not deployed already:  Go to "Applications" left pane of admin console, click on  WebSphere Enterpise Applications. Check PerfServletApp.ear is deployed or not, if its not deployed – fallow the below steps
New Application underApplications. Browse from WebSphere directory -> AppServer -> InstallableApps.
Click on next button to  deploy Pref Application. Fallow the next steps to complete the installation
 Enable the PMI Data and set all the statistics enabled:
Go to "Monitoring and Tuning" in left pane of Admin Console, Click on Performance Monitoring Infrastructure(PMI) in "Configuration" tab, enable the "PMI and set the All Statistics. Also set the All Statistics in Run time Tab. 
Step 4:  Don’t forget to save all changes……….. J
    Set the generic jvm argument =
-Djavax.management.builder.initial= -Dcom.sun.management.jmxremote
In Severs --> Server Types --> WebSphere Application Servers  shows the servers list. Click on the server you want.
In the right pane --> Server Infrastructure --> Java and Process Management  click on Process definition, again in Additional Properties of Configuration tab

Click on Java Virtual Machine and put the -Djavax.management.builder.initial= -Dcom.sun.management.jmxremote in Generic Jvm Argument field.
STEP 6:   
    To enable the JMX remote port open the below properties file and add the code below.
    Note : The properties file can be available in :
WebSphere_Home directory  \AppServer\java\jre\lib\management\management.properties

Save all the changes and stop and start the server.   
After doing all this you can connect the Websphere using your JConsole Appplication.

Friday, July 2, 2010

Jar file Vs Executable Jar file

Jar file is the combination of compiled java classes.
Executable jar file is also be combination of compiled java classes with Main class.
Normal jar file can be created as
C:\> jar -cvf TestNew.jar .
But while creating executable jar file we have to specify the Main-Class in a manifest file. Following are the steps to fallow while creating the executable jar file. Here its explained with a simple class in a test package.
Step1: create a java class TestNew under package test
package test;
public class TestNew{
public static void main(String a[]){
System.out.println(“Hello world”);
Step 2: compile the class with fallowing command
C:\>javac TestNew.java -d .
Note: Once you run the TestNew class you have to get “HelloWorld” in the console. To run use fallowing command
C:\>java test.TestNew
Step 3: Create a “mainClass” file in the directory where your test folder is located . This file contains a single line specifying where the main Class is to be found in the jar file. Note that I use the package specification. Here is the single line:
Main-Class: test.TestNew
Note: specify the single line only don't specify anything
Step 4: create the jar using fallowing command
C:\>jar cmf mainClass test.jar test
Where “c” represents the create that you are going to “create”, “m” specifies the manifest file mainClass (which adds information to the jar file on where the main class will be found) and “f ” refers to “file”.
Note: The file has to be created in your folder with the name test.jar
To view the content of the jar file you can use the fallowing command
C:\>jar tf test.jar
It displays as:
To execute the jar file you can use the following commond
C:\>java -jar test.jar

What is the difference bet ween object and instance

There is a lot of discussions on this topic over the internet. Some of the people says both are same and some of other says both are different. Here I am planning to share my overall view on this topic. As per my knowledge both are looks same but different. Here are the some useful points:
  • Instance is Logical but object is Physical means occupies some memory.
  • We can create an instance for abstract class as well as for interface, but we cannot create an object for those.
  • Object is instance of class and instance means representative of class i.e object.
  • Instance refers to Reference of an object.
  • Object is actually pointing to memory address of that instance.
  • You can’t pass instance over the layers but you can pass the object over the layers
  • You can’t store an instance but you can store an object
  • A single object can have more than one instance.
  • Instance will have the both class definition and the object definition where as in object it will have only the object definition.
Syntax of Object:
classname var=new classname();
But for instance creation it returns only a pointer refering to an object, syntax is :
classname varname;

The basic Properties of Interface

1. Interface must be declared with the key word ‘interface’.
2. All interface methods are implicitly public and abstract. In another words you dont need to atually type the public or abstract modifiers in the metod declaration, but method is still allways public and abstract.
3. All variables defined in an interface is public, static, and final. In another words, interfaces can declare only constants , not instance variables.
4. Interface methods must not be static.
5. Because interface methods are abstract, they cannot be marked final, strictfp, or native.
6. An interfaces can extend one or more other interfaces.
7. An interface cannot implement another interface or class.
8. interface types can be used polymorphically.

Difference between Abstract Class and Interface

1. Abstract class has the constructor, but interface doesn’t.

2. Abstract classes can have implementations for some of its members (Methods), but the interface can’t have implementation for any of its members.

3. Abstract classes should have subclasses else that will be useless..

4. Interfaces must have implementations by other classes else that will be useless

5. Only an interface can extend another interface, but any class can extend an abstract class..

6. All variable in interfaces are final by default

7. Interfaces provide a form of multiple inheritance. A class can extend only one other class.

8. Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.

9. A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.

10. Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast.

11. Accessibility modifier(Public/Private/internal) is allowed for abstract class. Interface doesn’t allow accessibility modifier

12. An abstract class may contain complete or incomplete methods. Interfaces can contain only the signature of a method but no body. Thus an abstract class can implement methods but an interface can not implement methods.

13. An abstract class can contain fields, constructors, or destructors and implement properties. An interface can not contain fields, constructors, or destructors and it has only the property’s signature but no implementation.

14. Various access modifiers such as abstract, protected, internal, public, virtual, etc. are useful in abstract Classes but not in interfaces.

15. Abstract scope is upto derived class.

16. Interface scope is upto any level of its inheritance chain.