<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Java on Evan Hoffman</title><link>https://evan.wtf/tags/java/</link><description>Recent content in Java on Evan Hoffman</description><generator>Hugo</generator><language>en-US</language><copyright>Evan Hoffman</copyright><lastBuildDate>Tue, 13 Aug 2013 08:58:41 +0000</lastBuildDate><atom:link href="https://evan.wtf/tags/java/index.xml" rel="self" type="application/rss+xml"/><item><title>Java Wrapper does whatever it wants</title><link>https://evan.wtf/2013/08/13/java-wrapper-does-whatever-it-wants/</link><pubDate>Tue, 13 Aug 2013 08:58:41 +0000</pubDate><guid>https://evan.wtf/2013/08/13/java-wrapper-does-whatever-it-wants/</guid><description>&lt;p&gt;Yesterday I set out to increase the memory settings for a bunch of our ActiveMQ machines. Most of the time these queues work pretty efficiently and their steady-state memory usage is just a few MB, but with some upcoming maintenance we expect these queues to get considerably fuller, so I was growing them preemptively. Anyway, our ActiveMQ installation gets bootstrapped using &lt;a href="http://activemq.apache.org/java-service-wrapper.html"&gt;Java Service Wrapper&lt;/a&gt; and the JVM settings for ActiveMQ are managed in some wrapper.conf file. What I wanted to do was pretty straightforward: I increased the VM&amp;rsquo;s &amp;lsquo;physical&amp;rsquo; memory to 16 GB and intended to increase Java&amp;rsquo;s MaxHeap from its current setting (1536MB aka 1.5GB) to 8192MB (8 GB). In wrapper.conf, I found the &amp;ldquo;wrapper.java.maxmemory&amp;rdquo; setting (which was set to 1536), set it to 8192, and restarted ActiveMQ. Here&amp;rsquo;s where it got weird.&lt;/p&gt;</description></item><item><title>Installing Sun (Oracle) JDK 1.5 on an EC2 instance</title><link>https://evan.wtf/2011/11/16/installing-sun-oracle-jdk-1-5-on-an-ec2-instance/</link><pubDate>Wed, 16 Nov 2011 11:52:55 +0000</pubDate><guid>https://evan.wtf/2011/11/16/installing-sun-oracle-jdk-1-5-on-an-ec2-instance/</guid><description>&lt;p&gt;I&amp;rsquo;m currently working on moving a Tomcat-based application into EC2. The code was written for Java 5.0. While Java 6 would probably work, I&amp;rsquo;d like to keep everything as &amp;ldquo;same&amp;rdquo; as possible, since EC2 presents its own challenges. I spun up a couple of t1.micro instances and copied everything over, including the Java 5 JDK, &lt;a href="http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase5-419410.html#jdk-1.5.0_22-oth-JPR"&gt;jdk-1_5_0_22-linux-amd64.rpm&lt;/a&gt;. Installing from RPM was easy, but the EC2 instance defaults to using OpenJDK 1.6:&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;[root@ec2 ~]# java -version&#10;java version &amp;#34;1.6.0_20&amp;#34;&#10;OpenJDK Runtime Environment (IcedTea6 1.9.10) (amazon-52.1.9.10.40.amzn1-x86_64)&#10;OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)&#10;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There were a couple of things I had to do to get the system to accept the Sun JDK as its &amp;ldquo;real&amp;rdquo; java.&lt;/p&gt;</description></item><item><title>Benchmarking DNS servers with Java</title><link>https://evan.wtf/2011/09/26/benchmarking-dns-servers-with-java/</link><pubDate>Mon, 26 Sep 2011 12:33:28 +0000</pubDate><guid>https://evan.wtf/2011/09/26/benchmarking-dns-servers-with-java/</guid><description>&lt;p&gt;I&amp;rsquo;m currently in the process of moving our DNS over to another provider and I was curious as to whether the old or new provider offers faster lookups. &lt;code&gt;dig&lt;/code&gt; shows query times, but I didn&amp;rsquo;t want to just run that over and over. I decided to write something to do this, in Java since I like Java. I found &lt;a href="http://mowyourlawn.com/blog/?p=8"&gt;this post,&lt;/a&gt; which has the meat of the work done already. I also read some of Sun&amp;rsquo;s &lt;a href="http://download.oracle.com/javase/1,5.0/docs/guide/jndi/jndi-dns.html"&gt;JNDI/DNS&lt;/a&gt; lookup info, which was pretty dense. All I want to do is specify the name server&amp;rsquo;s IP and do the lookup. I don&amp;rsquo;t even really care about the result, just how long the query takes.&lt;/p&gt;</description></item><item><title>Calculating SHA-1 sums in Java</title><link>https://evan.wtf/2011/05/25/calculating-sha-1-sums-in-java/</link><pubDate>Wed, 25 May 2011 18:19:27 +0000</pubDate><guid>https://evan.wtf/2011/05/25/calculating-sha-1-sums-in-java/</guid><description>Java code for calculating SHA-1 sums from arbitrary InputStreams, files, or Strings and printing them as strings.</description></item><item><title>Java Code: searching a Binary Search Tree for the largest value strictly less than X</title><link>https://evan.wtf/2010/05/09/java-code-searching-a-binary-search-tree-for-the-largest-value-strictly-less-than-x/</link><pubDate>Sun, 09 May 2010 13:43:17 +0000</pubDate><guid>https://evan.wtf/2010/05/09/java-code-searching-a-binary-search-tree-for-the-largest-value-strictly-less-than-x/</guid><description>Java code for creating and searching a Binary Search Tree of any element implementing the Comparable interface.</description></item><item><title>Code to flatten a list in Java, with and without recursion</title><link>https://evan.wtf/2010/04/17/code-to-flatten-a-list-in-java-with-and-without-recursion/</link><pubDate>Sat, 17 Apr 2010 23:42:16 +0000</pubDate><guid>https://evan.wtf/2010/04/17/code-to-flatten-a-list-in-java-with-and-without-recursion/</guid><description>&lt;p&gt;Recently had someone ask me to solve this problem: assume you have a list of objects, some of which may be lists of arbitrary depths. Write a function to return the list &amp;ldquo;flattened,&amp;rdquo; so sublists are all in the &amp;ldquo;main&amp;rdquo; list. I solved it recursively pretty easily, but it took some thought to do it without recursion. My solutions are below.&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;package com.evanhoffman.listflattener;&#10;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;import java.util.LinkedList;&#10;import java.util.List;&#10;import java.util.ListIterator;&lt;/p&gt;&#10;&lt;p&gt;import org.apache.log4j.BasicConfigurator;&#10;import org.apache.log4j.Logger;&lt;/p&gt;</description></item><item><title>How to install the 64-bit Sun Java plugin on 64-bit firefox on 64-bit Fedora Core 11 Linux (which happens to use 64 bits)</title><link>https://evan.wtf/2009/10/21/how-to-install-the-64-bit-sun-java-plugin-on-64-bit-firefox-on-64-bit-fedora-which-happens-to-use-64-bits/</link><pubDate>Wed, 21 Oct 2009 17:45:09 +0000</pubDate><guid>https://evan.wtf/2009/10/21/how-to-install-the-64-bit-sun-java-plugin-on-64-bit-firefox-on-64-bit-fedora-which-happens-to-use-64-bits/</guid><description>&lt;p&gt;I&amp;rsquo;m giddy! I found &lt;a href="http://plugindoc.mozdev.org/linux-amd64.html"&gt;this post&lt;/a&gt; on mozdev.org which was magical.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;[evan@ehoffman ~]$ java -version&#10;java version &amp;#34;1.6.0_17&amp;#34;&#10;Java(TM) SE Runtime Environment (build 1.6.0_17-b04)&#10;Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)&#10;&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;[root@ehoffman plugins]# uname -a&#10;Linux ehoffman 2.6.30.8-64.fc11.x86_64 #1 SMP Fri Sep 25 04:43:32 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux&#10;[root@ehoffman plugins]# pwd&#10;/usr/lib64/mozilla/plugins&#10;[root@ehoffman plugins]# ln -s /usr/java/jdk1.6.0_16/jre/lib/amd64/libnpjp2.so&#10;&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;&#10;&lt;p&gt;The main thing I was missing was that the plugin isn&amp;rsquo;t libpluginjava_oji.so, or whatever I thought it was, but libnpjp2.so. Once I created the symlink into /usr/lib64/mozilla/plugins it worked (as verified on &lt;a href="http://www.java.com/en/download/help/testvm.xml"&gt;http://www.java.com/en/download/help/testvm.xml&lt;/a&gt; and &lt;a href="http://www.java.com/en/download/installed.jsp"&gt;http://www.java.com/en/download/installed.jsp&lt;/a&gt;).&lt;/p&gt;</description></item><item><title>Java compound interest calculator</title><link>https://evan.wtf/2008/01/10/java-compound-interest-calculator/</link><pubDate>Thu, 10 Jan 2008 00:00:08 +0000</pubDate><guid>https://evan.wtf/2008/01/10/java-compound-interest-calculator/</guid><description>&lt;p&gt;I wrote a thing to calculate compound interest and print out how much you&amp;rsquo;ve accrued after each period. It&amp;rsquo;s pretty basic but I was bored and didn&amp;rsquo;t want to do it via calculator. The code is in &lt;a href="https://evan.wtf/InterestCalculator.java"&gt;InterestCalculator.java&lt;/a&gt;, sample output is below:&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;Initial principal: 5000.00&#10;Interest rate: 0.05 (4.93%)&#10;# of ann. periods: 4&#10;Total years: 5&#10;Annual Addition: 500.0&#10;Starting year 1 with $5000.00&#10;Year 1, period 1, accrued $61.62, value is now: $5061.62&#10;Year 1, period 2, accrued $62.38, value is now: $5124.01&#10;Year 1, period 3, accrued $63.15, value is now: $5187.16&#10;Year 1, period 4, accrued $63.93, value is now: $5251.09&#10;Added $500.00 for the end of year 1, total is now: 5751.09&#10;Starting year 2 with $5751.09&#10;Year 2, period 1, accrued $70.88, value is now: $5821.98&#10;Year 2, period 2, accrued $71.76, value is now: $5893.73&#10;Year 2, period 3, accrued $72.64, value is now: $5966.37&#10;Year 2, period 4, accrued $73.54, value is now: $6039.91&#10;Added $500.00 for the end of year 2, total is now: 6539.91&#10;Starting year 3 with $6539.91&#10;Year 3, period 1, accrued $80.60, value is now: $6620.51&#10;Year 3, period 2, accrued $81.60, value is now: $6702.11&#10;Year 3, period 3, accrued $82.60, value is now: $6784.71&#10;Year 3, period 4, accrued $83.62, value is now: $6868.34&#10;Added $500.00 for the end of year 3, total is now: 7368.34&#10;Starting year 4 with $7368.34&#10;Year 4, period 1, accrued $90.81, value is now: $7459.15&#10;Year 4, period 2, accrued $91.93, value is now: $7551.08&#10;Year 4, period 3, accrued $93.07, value is now: $7644.15&#10;Year 4, period 4, accrued $94.21, value is now: $7738.37&#10;Added $500.00 for the end of year 4, total is now: 8238.37&#10;Starting year 5 with $8238.37&#10;Year 5, period 1, accrued $101.54, value is now: $8339.90&#10;Year 5, period 2, accrued $102.79, value is now: $8442.69&#10;Year 5, period 3, accrued $104.06, value is now: $8546.75&#10;Year 5, period 4, accrued $105.34, value is now: $8652.09&#10;Added $500.00 for the end of year 5, total is now: 9152.09&#10;Final value: $9152.09&#10;&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Java utility to reorganize photos by date taken (via EXIF metadata)</title><link>https://evan.wtf/2007/03/28/java-utility-to-reorganize-photos-by-date-taken-via-exif-metadata/</link><pubDate>Wed, 28 Mar 2007 00:00:37 +0000</pubDate><guid>https://evan.wtf/2007/03/28/java-utility-to-reorganize-photos-by-date-taken-via-exif-metadata/</guid><description>&lt;p&gt;I wrote a little utility to reorganize my digital camera pics based on the EXIF date-taken data stored in the pic. It&amp;rsquo;s pretty simple, I hacked it together in about an hour,&#10;but I thought it might be worth sharing for anyone else looking to do something similar. My camera organizes stuff as it sees fit sometimes, I am particular about my directory structure. This is probably a job best left to perl, but I don&amp;rsquo;t feel like getting Perl running on my Windows box where all the pics are. Now I can finally burn all my images to DVD.&lt;/p&gt;</description></item></channel></rss>