<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eTechTips &#187; Java</title>
	<atom:link href="http://www.etechtips.com/articles/programming/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.etechtips.com</link>
	<description>Your Technical resource</description>
	<lastBuildDate>Wed, 01 Feb 2012 21:38:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>JAVA: XMLGregorianCalendar Dates</title>
		<link>http://www.etechtips.com/2011/11/20/java-xmlgregoriancalendar-dates/</link>
		<comments>http://www.etechtips.com/2011/11/20/java-xmlgregoriancalendar-dates/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 13:07:27 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=536</guid>
		<description><![CDATA[I was updating some plugins for a project and came to a query for an e-mail program I was writing, I had to send out recently introduced defects to their respective owners and insure that they would only get the defects from the a given offset. It turned out that my API had a XMLGregorianCalendar [...]]]></description>
			<content:encoded><![CDATA[<p>I was updating some plugins for a project and came to a query for an e-mail program I was writing,  I had to send out recently introduced defects to their respective owners and insure that they would only get the defects from the a given offset.  It turned out that my API had a XMLGregorianCalendar argument.  So I went out to look for a way to offset the date object so I could retrieve the correct information.  </p>
<p>I used the following to convert my date:</p>
<pre>
package com.etechtips;

import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class UpdateDate {

	public static void main(String[] args) {
		XMLGregorianCalendar xgcstart;
		GregorianCalendar gc;
		int daycount = 0;
		if (args.length != 1)
		{
			System.out.println("Need to specify offset");
			System.exit(1);
		}

		daycount = Integer.parseInt(args[0]);

		// This will get the current date based on System time of an object
		gc = new GregorianCalendar();
		System.out.println("CURRENT:" + gc.toString());

		// This will offset the date by daycount days
		gc.add(Calendar.DATE, daycount);
		System.out.println("OFFSET: "+ gc.toString());

		try
		{
			// Now the XMLGregorianCalendar object has an
                        instance that is based on the time set in the gc object
			xgcstart = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
		}
		catch(DatatypeConfigurationException dce)
		{
			dce.printStackTrace();
			System.exit(1);
		}

		// Code omitted
	}
}
</pre>
<p>Output:</p>
<pre>
CURRENT:java.util.GregorianCalendar[time=1321793315934,areFieldsSet=true,areAllFieldsSet=true,\
lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Chicago",offset=-21600000,\
dstSavings=3600000,useDaylight=true,transitions=235,\
lastRule=java.util.SimpleTimeZone[id=America/Chicago,offset=-21600000,dstSavings=3600000,\
useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,\
startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,\
endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=10,\
WEEK_OF_YEAR=48,WEEK_OF_MONTH=4,<strong>DAY_OF_MONTH=20</strong>,DAY_OF_YEAR=324,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=3,\
AM_PM=0,HOUR=6,HOUR_OF_DAY=6,MINUTE=48,SECOND=35,MILLISECOND=934,ZONE_OFFSET=-21600000,\
DST_OFFSET=0]
OFFSET: java.util.GregorianCalendar[time=1321706915934,areFieldsSet=true,areAllFieldsSet=true,\
lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Chicago",offset=-21600000,\
dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/Chicago,\
offset=-21600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,\
startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,\
endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,\
YEAR=2011,MONTH=10,WEEK_OF_YEAR=47,WEEK_OF_MONTH=3,<strong>DAY_OF_MONTH=19</strong>,DAY_OF_YEAR=323,\
DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=6,HOUR_OF_DAY=6,MINUTE=48,SECOND=35,\
MILLISECOND=934,ZONE_OFFSET=-21600000,DST_OFFSET=0]
</pre>
<p>The printouts above show the current date and the new date based on the offset.  I made the day of the month bold in the printouts to show what the offset has updated the date.  You could put a much larger offset than 1 and Calendar object will take care of updating the day of week, week of year and more. You will not need to deal with checking for leap year or dealing with updating all the month and years, this is all taken care of for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/11/20/java-xmlgregoriancalendar-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java: Command line argument processing</title>
		<link>http://www.etechtips.com/2011/11/06/java-command-line-argument-processing/</link>
		<comments>http://www.etechtips.com/2011/11/06/java-command-line-argument-processing/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 04:44:15 +0000</pubDate>
		<dc:creator>techtipse</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=71</guid>
		<description><![CDATA[In each language that I have learned I have found it useful to know how to process command line arguments and here is a simple framework that I use for Java. I usually wrap the java command line in a bat or shell file to make it easier to run so that the user does [...]]]></description>
			<content:encoded><![CDATA[<p>In each language that I have learned I have found it useful to know how to process command line arguments and here is a simple framework that I use for Java.  I usually wrap the java command line in a bat or shell file to make it easier to run so that the user does not have to worry about classpath or path issues.</p>
<p>The following is the basic code to handle the command line arguments.</p>
<pre>
class CmdArgs
{

  public static void main(String[] args)
  {
      int argsize = args.length;
      String curarg;

      if (argsize > 0 )
      {

      }

      for(int i = 0; i < argsize; i++)
      {
          if (args[i].equals("--host")
          {
             args++;
             host = args[i];
           }
          else if (args[i].equals("--debug")
          {
               debug = 1;
          }
          else
          {
              System.out.println("Unknown option: " + args[i]);
              System.exit(1);
          }
       }

   }
}
</pre>
<p>The bat file for Dos/Windows might look like this:</p>
<pre>
@echo off

java -cp c:\javabin;somejar.jar  com.etechtips.CmdArgs %*
</pre>
<p>The shell based file might look like:</p>
<pre>

java -cp /home/ecdown/javabin:somejar.jar com.etechtips.CmdArgs $*
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/11/06/java-command-line-argument-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gallery of Hello World!</title>
		<link>http://www.etechtips.com/2011/08/04/gallery-of-hello-world/</link>
		<comments>http://www.etechtips.com/2011/08/04/gallery-of-hello-world/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 15:14:39 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=324</guid>
		<description><![CDATA[Here is a list of the Hello World Programs for different languages: C #include int main() { printf("Hello World!"); } C++ #include int main() { cout &#60;&#60; "Hello World!" &#60;&#60; endl; } C# public class HelloWorld public static void Main() { System.Console.WriteLine("Hello World!"); } Java class HelloWorld { static void main(String[] args) { System.out.println("Hello World!"); [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a list of the Hello World Programs for different languages:</p>
<p>C</p>
<pre>#include
int main()
{
printf("Hello World!");
}</pre>
<p>C++</p>
<pre>#include
int main()
{
cout &lt;&lt; "Hello World!" &lt;&lt; endl;
}</pre>
<p>C#</p>
<pre>public class HelloWorld
  public static void Main()
  {
    System.Console.WriteLine("Hello World!");
  }</pre>
<p>Java</p>
<pre>class HelloWorld {
static void main(String[] args)
{
System.out.println("Hello World!");
}</pre>
<p>SHELL</p>
<pre>echo "Hello World"</pre>
<p>Python</p>
<pre>print "Hello World!\n"</pre>
<p>Ruby</p>
<pre>puts "Hello World!"</pre>
<p>Perl</p>
<pre>print "Hello World!\n";</pre>
<p>PHP</p>
<pre>  &lt;?php
    print "Hello World!";
  ?&gt;</pre>
<p>This is the simplest form of Hello World for most of these languages.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/08/04/gallery-of-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ant unable to find tools.jar</title>
		<link>http://www.etechtips.com/2011/01/29/ant-unable-to-find-tools-jar/</link>
		<comments>http://www.etechtips.com/2011/01/29/ant-unable-to-find-tools-jar/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 12:30:53 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[ant]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=196</guid>
		<description><![CDATA[When attempting to run ant I get the following message: &#8220;Unable to locate tools.jar. Expected to find it in C:\Program Files (x86)\Java\jre6\lib\tools.jar&#8221; This had to do with my JAVA_HOME not pointing to a Java JDK. So if you download a JDK and update your JAVA_HOME environment variable to point to that directory, ant should run [...]]]></description>
			<content:encoded><![CDATA[<p>When attempting to run ant I get the following message: &#8220;Unable to locate tools.jar. Expected to find it in C:\Program Files (x86)\Java\jre6\lib\tools.jar&#8221;</p>
<p>This had to do with my JAVA_HOME not pointing to a Java JDK.  </p>
<p>So if you download a JDK and update your JAVA_HOME environment variable to point to that directory, ant should run happily.</p>
<p>In BASH:<br />
export JAVA_HOME=/path/to/jdk</p>
<p>IN DOS:<br />
set JAVA_HOME=c:\PATH\to\jdk</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/01/29/ant-unable-to-find-tools-jar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Exception java.lang.NoClassDefFoundError and how to resolve it</title>
		<link>http://www.etechtips.com/2011/01/26/java-exception-java-lang-noclassdeffounderror-and-how-to-resolve-it/</link>
		<comments>http://www.etechtips.com/2011/01/26/java-exception-java-lang-noclassdeffounderror-and-how-to-resolve-it/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 21:23:20 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=142</guid>
		<description><![CDATA[I had recently reinstalled my system and was trying to run a simple class that consisted of a &#8220;Hello World&#8221; program in Java. I received the following: Compile: $&#62; javac LottoMain.java Run: $&#62; java LottoMain Exception in thread &#8220;main&#8221; java.lang.NoClassDefFoundError: LottoMain Caused by: java.lang.ClassNotFoundException: LottoMain at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:319) at [...]]]></description>
			<content:encoded><![CDATA[<p>I had recently reinstalled my system and was trying to run a simple class that consisted<br />
of a &#8220;Hello World&#8221; program in Java.  I received the following:</p>
<p>Compile:</p>
<pre>$&gt; javac LottoMain.java</pre>
<p>Run:</p>
<pre>$&gt; java LottoMain</pre>
<p>Exception in thread &#8220;main&#8221; java.lang.NoClassDefFoundError: LottoMain<br />
Caused by: java.lang.ClassNotFoundException: LottoMain<br />
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)<br />
at java.security.AccessController.doPrivileged(Native Method)<br />
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)<br />
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)<br />
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)<br />
at java.lang.ClassLoader.loadClass(ClassLoader.java:264)<br />
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)<br />
Could not find the main class: LottoMain. Program will exit.</p>
<p>The compile line completed without errrors and the LottoMain.class file was there, but<br />
what I didn&#8217;t know was that I no longer had the current directory &#8220;.&#8221; in my CLASSPATH variable.</p>
<p>After adding &#8220;.&#8221; to my CLASSPATH variable the run command gave me what I was expecting.</p>
<p>Run:</p>
<pre>$&gt; java LottoMain</pre>
<p>Hello Eric!</p>
<p>Updating the CLASSPATH variable in Bash:<br />
in my home directory/.bashrc file</p>
<pre>export CLASSPATH=$CLASSPATH:.</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/01/26/java-exception-java-lang-noclassdeffounderror-and-how-to-resolve-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java: Great link to Swing Examples</title>
		<link>http://www.etechtips.com/2011/01/21/java-great-link-to-swing-examples/</link>
		<comments>http://www.etechtips.com/2011/01/21/java-great-link-to-swing-examples/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 17:03:29 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=220</guid>
		<description><![CDATA[Starting on my road to creating a Java based GUI I stumbled upon the following link within the &#8220;Creating a GUI with JFC/Swing&#8221; Train in the Java Tutorials from Oracle. Using Swing Components: Examples It has code examples and can really get you started on the road to a Java GUI interface.]]></description>
			<content:encoded><![CDATA[<p>Starting on my road to creating a Java based GUI I stumbled upon the following link within the &#8220;Creating a GUI with JFC/Swing&#8221; Train in the Java Tutorials from Oracle.</p>
<p>  <a href="http://download.oracle.com/javase/tutorial/uiswing/examples/components/index.html">Using Swing Components: Examples</a></p>
<p>It has code examples and can really get you started on the road to a Java GUI interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/01/21/java-great-link-to-swing-examples/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java: Creating a Window</title>
		<link>http://www.etechtips.com/2011/01/20/java-creating-a-window/</link>
		<comments>http://www.etechtips.com/2011/01/20/java-creating-a-window/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 19:22:17 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=217</guid>
		<description><![CDATA[This is the First of some basic articles about creating a GUI in Java. The following code is the basis of the following series of articles. I am using the Java Swing window toolkit. import java.awt.*; import java.swing.*; class FirstWindow { public static void main(String[] args) { //Create Window object and set title bar text [...]]]></description>
			<content:encoded><![CDATA[<p>This is the First of some basic articles about creating a GUI in Java. The following code is the basis of the following series of articles.  I am using the Java Swing window toolkit.</p>
<pre>
import java.awt.*;
import java.swing.*;

class FirstWindow
{

  public static void main(String[] args)
  {
      //Create Window object and set title bar text
      JFrame frame = new frame("First Window");

      // Set the Default operation when you close the window
      // This exits the program on closing the window
      // The default behavior is to HIDE_ON_CLOSE
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      // Now we need to Display the window
      // The null argument will place the element in the center of the screen.
      frame.setLocationRelativeTo(null);
      frame.pack();
      frame.setVisible(true);
   }
}
</pre>
<p>This is enough to display a simple window, but it will probably not have any useful size associated with it and it does not do anything.</p>
<p>The next step will be to add some useful widgets and eventually functionality to make the window useful.</p>
<p>Helpful info:<br />
<a href="http://www.etechtips.com/?p=220">Java: Great link to Swing Examples</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/01/20/java-creating-a-window/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passing JVM options to Maven</title>
		<link>http://www.etechtips.com/2010/06/30/passing-jvm-options-to-maven/</link>
		<comments>http://www.etechtips.com/2010/06/30/passing-jvm-options-to-maven/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 15:55:05 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=120</guid>
		<description><![CDATA[If you are using maven to build your projects , then you might have found an out of memory condition in your tests.  Well, setting the MAVEN_OPTS variable with JVM specific options will help with this. Example: MAVEN_OPTS=-Xmx1024 Depending on what environment you are in, you will need to set this variable. This will give [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using maven to build your projects , then you might have found an out of memory condition in your tests.  Well, setting the MAVEN_OPTS variable with JVM specific options will help with this.</p>
<p>Example:</p>
<p>MAVEN_OPTS=-Xmx1024</p>
<p>Depending on what environment you are in, you will need to set this variable.</p>
<p>This will give the JVM more 1024 megs to work with and you can customize the number to fit your needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2010/06/30/passing-jvm-options-to-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java formatting a number with leading zeroes</title>
		<link>http://www.etechtips.com/2009/07/17/java-formatting-a-number-with-leading-zeroes/</link>
		<comments>http://www.etechtips.com/2009/07/17/java-formatting-a-number-with-leading-zeroes/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 05:10:56 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[formatting]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=53</guid>
		<description><![CDATA[Recently, I had a Java project that needed to encode a set of numbers and I needed a fixed number of digits used for each number. I found the DecimalFormat class a good solution for my needs. Here is a snippet of code to show a simple way to format a number with a fixed [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I had a Java project that needed to encode a set of numbers and I needed a fixed number of digits used for each number.  I found the DecimalFormat class a good solution for my needs.</p>
<p>Here is a snippet of code to show a simple way to format a number with a fixed number of digits.</p>
<pre><code>import java.text.DecimalFormat;

class TestEncoder
{
        public static void main(String[] args)
        {
                // This program expects one integer
                // argument and places it in the num1
                // variable. This program is not very
                // robust as to watch for no arguments
                // or to check if the argument is not
                // an integer.
                String num1 = args[0];
                String output;

                // This creates the Decimal Format instance
                // and assigns the formatting that we want
                // to use, in this case three characters .
                DecimalFormat dfmt =
                             new DecimalFormat(&quot;000&quot;);

                // This does the work of formatting the number
                // passed in on the command line to be at least
                // three digits.
                output = dfmt.format(new Integer(num1));

                // This just displays the results of the
                // dfmt.format(new Integer(num1)) command.
                System.out.println(&quot;Output: &quot; + output);
}
}
</code></pre>
<p>The Decimal format allows for many more formatting options for numbers.</p>
<p>Make sure to look a the API docs for the version of Java that you are using:</p>
<p>http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2009/07/17/java-formatting-a-number-with-leading-zeroes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

