Posts

Debug Java applications remotely with Eclipse

Image
Remote debugging is a way of debugging any process running on some other location from your development machine. Local debugging is the best way in my opinion and should always be preferred over remote debugging but if local debugging is not possible and there is no way to debug your process then remote debugging is the solution. Many of us work on a project which runs on Linux operating system and we do development mostly on Windows. Eclipse provides us most useful feature called " Remote debugging " by using which you can debug your Linux running process from your windows machine. Now let's see how we can setup remote debugging in Eclipse: Just take a example of a simple program that we want to be debugged: package com.tutoial.debugger; /**  * @author abdul  *  */ public class Debug {     public static void main(String args[]) {         for(int i=1; i<=10;i++) {      ...

How to install springsource tool suite on linux

Download the STS self-extracting shell script (*.sh) that matches your OS and machine architecture from the following Url: http://www.springsource.org/eclipse-downloads Please make sure to download and install STS versions that match your JDK installation. Once downloaded, launch the installation by running the following command in a terminal session: $ sh springsource-tool-suite-2.9.0.RELEASE-e3.7.2-linux-gtk-installer.sh Follow the on-screen instructions to finish the installation. See “Running the STS Installer”.

How to find MYSQl Port No and Version ?

mysql> show variables like 'port'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | port | 3306 | +---------------+-------+ 1 row in set (0.02 sec) mysql> show variables like 'version'; +---------------+-------------------+ | Variable_name | Value | +---------------+-------------------+ | version | 5.0.45-community-nt | +---------------+-------------------+ 1 row in set (0.00 sec)

Java JVM Shutdown Hook - tutorial

JVM shutdown hooks provide a clean and simple mechanism for registering application-specific behavior that performs the required cleanup work when a JVM terminates. It is a Java feature that let you have a piece of Java code run whenever the JVM terminates under one of the following conditions:   - The program exits normally, such as when the last non-daemon thread exits or when the                         Runtime.exit() method is invoked.   -  The virtual machine is terminated in response to a user interrupt, such as typing CTRL-C, or a                      system-wide event, such as user logoff or system shutdown (for example, the JVM receives               one of  the interrupt signals SIGHUP (Unix Only), SIGINT, or SIGTERM). A shutdow...

Java HashMap Example

The HashMap class uses a hash table to implement the Map interface. This allows the execution time of basic operations, such as get() and put() , to remain constant even for large sets. The following constructors are defined:   HashMap( ) HashMap(Map m ) HashMap(int capacity ) HashMap(int capacity , float fillRatio )   Hash map does not guarantee the order of its elements. Therefore, the order in which elements are added to a hash map is not necessarily the order in which they are read. Here is the code:   import java.util.HashMap; import java.util.Map; /**  *  * This Java HashMap example describes the basic operations performed on the HashMap  * @author abdul  *  */ public class HashMapExample {     public static void main(String args[]){                 // constructs a new empty HashMap with default initial capacity   ...

How to get free disk space of a drive in java ?

JDK 1.6 provides few new methods  getTotalSpace() , getFreeSpace() , bundled with java.io.File. These methods provides essential information regarding disk space. getFreeSpace() method -   Returns the number of unallocated bytes in the partition named by this abstract path name. getTotalSpace() method - Returns the size of the partition named by this abstract pathname. Here is the code:  import java.io.File; /**  * Program that returns the number of unallocated bytes , total space in the partition.  *  * @author abdul  *  */ public class DiskDetail {     public static void main(String[] args) {         File file = new File("C:");         long totalSpace = file.getTotalSpace(); // total disk space in bytes.         long freeSpace = file.getFreeSpace(); // unallocated / free disk space   ...

JAXB - II (jaxb.index file and ObjectFactory)

I was getting a Exception like, javax.xml.bind.JAXBException: "doesnt contain ObjectFactory.class or jaxb.index" while trying to create a JAXBContext using JAXBContext.newInstance(String contextPath). It took me a while to figure out what went wrong. So now that I've got things working correctly, I thought I'd post this example and solution to hopefully save you some time. When we create a marshaller, we first need to create a JAXBContext via its newInstance() factory method. You can create a context for a specific JAXB class  or you can create a context for a list of packages. There are two ways to resolve this issue :    - By creating ObjectFactory   - By adding jaxb.index file jaxb.index : The jaxb.index file is a text file contains a listing of the classes on the containing package that have JAXB annotations. Note : The name of the clases is their simple name not their classified name.   Rather than creating a ObjectFactory, I guess adding ...