Pages

12 February, 2013

Date and Time Difference in Java


Classes Which are used in the Program for calculating the time difference...


java.text 
Class SimpleDateFormat

java.lang.Object
  extended byjava.text.Format
      extended byjava.text.DateFormat
          extended byjava.text.SimpleDateFormat
All Implemented Interfaces:
Cloneable, Serializable
 

java.util 
Class Date

java.lang.Object
  extended by java.util.Date
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Date>
Direct Known Subclasses:
Date, Time, Timestamp
 
 

Here the sample code for getting the time difference HH:MM:SS Format...

 
package com.sana.test.date;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeDiffTest {

    public static void main(String[] args) {

        String startDate = "01/23/2013 06:34:44";
        String endDate= "01/24/2013 08:22:57";

        //HH converts hour in 24 hours format (0-23), day calculation

        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

        Date d1 = null;
        Date d2 = null;

        try {
            d1 = format.parse(startDate );
            d2 = format.parse(endDate);

            //in milliseconds
            long diff = d2.getTime() - d1.getTime();

            long diffSeconds = diff / 1000 % 60;
            long diffMinutes = diff / (60 * 1000) % 60;
            long diffHours = diff / (60 * 60 * 1000) % 24;
            long diffDays = diff / (24 * 60 * 60 * 1000);

            System.out.print(diffDays + " days, ");
            System.out.print(diffHours + " hours, ");
            System.out.print(diffMinutes + " minutes, ");
            System.out.print(diffSeconds + " seconds.");

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
 
 

THANKS 

SANA



 
 

Java Decompiler (Jad) Set Up with Eclipse


Please follow the steps to configure Java Decompiler with Eclipse:

Step 1:

Download the Jad executable file (jad.exe ).


Step 2:

Download the Jad Eclipse Plugin named   net.sf.jadclipse_vesion.jar

http://sourceforge.net/projects/jadclipse/



Step 3:

Copy the downloaded Jad Eclipse plugin net.sf.jadclipse_vesion.jar  to Eclipse plugin folder.
For example,

Note: No need to extract the Jar Simply paste the jar file 

 in C:\eclipse\plugins\net.sf.jadclipse_3.3.0  Location.



Step 4: 

ReStart the Eclipse to  change the Plugin Effect in Eclipse.


Step 5:

In Eclipse, Click Window –> Preference –> Java –> Jadclipse , Key in Jad’s path in “Path to Decompiler” field










Step 6:


Now open any .class file  Jad will decompile it automatically.

Example Given Below For the same...

 

  I hope this will helpful for you.... Further any  clarifications you can reach me at shekarsana@gmail.com

 Your Suggestions and feedback help me to improve my technical and written skills.


Thanks

SANA

Debugging SetUp In Eclipse

 
Please follow the steps to configure the Dedugging mode Eclipse:

TOMCAT :

 
1) Open the catalina.bat file in edit mode which is available in "{tomcat home}\bin\catalina.bat" path

2) Add the below two lines in catalina.bat after the "rem --------------------------------------" line

set JPDA_ADDRESS=8000
set JPDA_TRANSPORT="dt_socket"


 
  


3) Create a shortcut for catalina.bat and paste it in desktop

4) Right click the shortcut and select 'properties' option.

5) Select the 'Shortcut' tab in properties window.

6) Add the { " } at the begining and ending of the path in target.

7) Append the below text at the end of the path.

jpda start




  1. Open the debug configuration window

  1. Add a debug config under “Remote Java Application



  2. Configure the project which has to be debugged.

  1. Select “source” tab in Debug configuration


  1. add the project in the source list.
  2. Apply the settings and close the window.
  3. Start the catalina shortcut which is in desktop.
  4. Start the configured debug in eclipse.


    JBOSS:


    This is really useful – only recently found out how to do this and the benefit is enormous. Basically by a small configuration on JBoss’s startup configuration and a setting...

    This is really useful – only recently found out how to do this and the benefit is enormous. Basically by a small configuration on JBoss’s startup configuration and a setting in Eclipse we can toggle breakpoints in our java code so that we can see where our code gets stuck and the JBoss processes that it goes through.

    Start with JBoss, you’ll need to edit its run file (/jboss/bin/run.sh or run.bat) and un-comment line
    JBoss-Debug-RunFile
    This tells JBoss which port to use to listen to for debug commands and it enables the JBoss’s remote debugging functionality.
    JBoss-Debug-Eclipse-Debug
    Next we need to go to Eclipse and configure the debugger in there. If you go to the Window menu at the top and then go to Open Perspective and look for Debug (you may need to choose it from the Other menu). Once you’re in this perspective you can then setup an application profile for your debugger – look for the bug symbol on the top tool bar and select the Debug Configurations menu.
    JBoss-Debug-Eclipse-Debug-Config
    In here we choose to create a new Remote Java Application giving it a name and connection details for your JBoss server – so in my case its localhost. The port MUST be the same as the port expected in your JBoss run file, in this case by default its port 8787.
    JBoss-Debug-Eclipse-Debug-New-Config
    Ok thats it – debug should be setup. When you start JBoss it’ll pause waiting for you to start the debugger in Eclipse – just go back to the bug symbol and select your configuration you just made. JBoss will continue to load after this point and Eclipse should start showing you JBoss’s processes that it’s running.
    JBoss-Debug-Startup
    Now we can add in breakpoints to our code allowing us to step through the code when its activated on JBoss – so if a user submits a form that calls in a bean which does x, y, z then we can see the logic that happens and if any issues occur – this is really useful for things like payment pipelines.
    JBoss-Debug-Eclipse-Debug-Breakpoint
    To toggle a breakpoint or to enable/ disable an existing one, just click in the left margin of your code window at the line you want to begin to step through. When this line gets processed JBoss will stop and you can then use the step through commands on the debug menu.
    JBoss-Debug-Eclipse-Debug-Step-Through
    If you’re using the startDynamoOnJboss and run-in-place methods for your server then you can debug and fix your code theoretically very quickly and easily.

    BY

    SANA