Saturday, May 29, 2010

About Interface

1. Interface must be declared with the key word 'interface'.
2. All interface methods are implicitly public and abstract. In another words you don't need to actually type the public or abstract modifiers in the method declaration, but method is still always 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.

Monday, May 17, 2010

Difference between 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;

Thursday, May 13, 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 -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
Hello world

Friday, May 7, 2010

Integrating Quartz Job Server with JBoss

I am getting the fallowing error while integrating Quartz job server in the JBoss
javax.naming.CommunicationException: Receive timed out
[Root exception is Receive timed out]

The steps i fallowed to configure the Quarts

1. I removed the quartz.jar from the {JBoss_Home}/deploy/lib and Quartz-ra.rar from {JBoss_Home}/deploy folder.

2. Added the quartz 1.6.5.jar and quartz-jboss-1.6.5.jar into {JBoss_Home}/deploy/lib .

3. Added the quartz-service.xml with fallowing details
<?xml version="1.0" encoding="UTF-8"?>
 <mbean code="" name="user:service=QuartzService,name=QuartzService">  
   <attribute name="JndiName">Quartz</attribute>
   <attribute name="Properties">      
     org.quartz.scheduler.instanceName = DefaultQuartzScheduler
     org.quartz.scheduler.rmi.export = false
     org.quartz.scheduler.rmi.proxy = false
     org.quartz.scheduler.xaTransacted = false
     org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
     org.quartz.threadPool.threadCount = 5
     org.quartz.threadPool.threadPriority = 4
     org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore

4. I have written the Servlet to schedule the job

import java.util.Date;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdScheduler;
import org.quartz.impl.StdSchedulerFactory;

* Servlet implementation class for Servlet: JobSeduleServlet
public class JobSeduleServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
  static final long serialVersionUID = 1L;
   /* (non-Java-doc)
    * @see javax.servlet.http.HttpServlet#HttpServlet()
   public JobSeduleServlet() throws SchedulerException {

   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       System.out.println("under doGet method.................");
   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       System.out.println("under doPost method.................");

   public void sedulingUsingJboss(){
       System.out.println("under...sedulingUsingJboss................. ");
        try {
              InitialContext ctx = new InitialContext();
              System.out.println("Intial Context........."+ctx);
              StdScheduler scheduler = (StdScheduler) ctx.lookup("Quartz");
             JobDetail jd=new JobDetail("myjob",scheduler.DEFAULT_GROUP,TestJob.class);
              CronTrigger ct = new CronTrigger("cronTrigger","group2","0 0/5 * * * ?");
              } catch (Exception exc) {  

5. Above servlet has been configured in web.xml as fallowes

According to console generated by the server Quartz service is loading successfully.
But while calling the JobScheduleServlet it is throwing the exception as fallows
javax.naming.CommunicationException: Receive timed out [Root exception is Receive timed out]