<?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>Java Archives &#8211; Beer &amp; Skittles</title>
	<atom:link href="https://nelson.ph/archives/programming/java/feed/" rel="self" type="application/rss+xml" />
	<link>https://nelson.ph/archives/programming/java/</link>
	<description>Life is not all beer and skittles</description>
	<lastBuildDate>Sun, 08 Mar 2020 18:44:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
<site xmlns="com-wordpress:feed-additions:1">177521838</site>	<item>
		<title>Renaming Photos by Timestamp</title>
		<link>https://nelson.ph/2016/10/renaming-photos-by-timestamp/</link>
					<comments>https://nelson.ph/2016/10/renaming-photos-by-timestamp/#respond</comments>
		
		<dc:creator><![CDATA[Nelson]]></dc:creator>
		<pubDate>Tue, 18 Oct 2016 08:15:55 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<guid isPermaLink="false">http://nelson.ph/?p=1649</guid>

					<description><![CDATA[<p>Including my cellphone, I used to have three cameras (used because my waterproof one died on me right after my recent trip to Palawan). Most smartphones already save photos with timestamps as the filenames but as for digital cameras, as far as I know, it&#8217;s not really the case. In general, the file naming convention [&#8230;]</p>
<p>The post <a href="https://nelson.ph/2016/10/renaming-photos-by-timestamp/">Renaming Photos by Timestamp</a> appeared first on <a href="https://nelson.ph">Beer &amp; Skittles</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Including my cellphone, I used to have three cameras (<em>used</em> because my waterproof one died on me right after my recent trip to Palawan). Most smartphones already save photos with timestamps as the filenames but as for digital cameras, as far as I know, it&#8217;s not really the case. In general, the file naming convention varies from one device to another. The lines in Java that follow are not really anything special; it just reads the <strong>Last Modified</strong> metadata and uses it as the filename. I&#8217;ve been using this for quite some time now just because I want to be able to view photos chronologically once I consolidate them from multiple devices. That simple. Okay, and a bit of an OCD, too.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="java">String dirName = "C:/Photos/Maldives"; //in my dreams
String fileNameExt = ".jpg"; //JPEG format
String fileNamePref = "RIMG"; //just blank to rename all photos
String fileNameFmt = "yyyyMMdd_HHmmss"; //e.g. 20161018_161534 for October 18, 2016 4:15:34 PM (should be unique enough!)

File directory = new File(dirName);
File[] photos = directory.listFiles();

for(File photo : photos) {
   String filename = photo.getName();

   if(filename.toLowerCase().endsWith(fileNameExt) &amp;&amp; filename.startsWith(fileNamePref)) {
      SimpleDateFormat sdf = new SimpleDateFormat(fileNameFmt);
      String newFilename = sdf.format(photo.lastModified()) + fileNameExt;
      File renamedPhoto = new File(photo.getParent() + "/" + newFilename);

      if(!photo.renameTo(renamedPhoto)) {
         System.out.println("Failed to rename: " + photo.getAbsolutePath());
      }
   } else {
      System.out.println("Not a " + fileNamePref + "*" + fileNameExt + ": " + photo.getAbsolutePath());
   }
}
</pre>
<p>This is under the assumption that the date and time in your devices have been set correctly. Different time zones are no longer within the scope of this post but is accommodated in—apparently someone already thought of the same—<a href="http://www.angelfire.com/id/robpurvis/devnotes/renaming-jpeg-files-with-date-time-stamp.html" target="_blank" rel="noopener noreferrer nofollow" class="broken_link">Renaming jpeg files with date+time stamp</a>. Ideally, all photos should be renamed successfully since no two photos can be taken at exactly the same time (burst shots are another story). But with multiple cameras, there can simply be conflict sometimes. Lastly, you should be careful when copying or moving photos because sometimes the <strong>Last Modified</strong> data are changed to the date you copied or moved them. Should that be the case, the given source code no longer holds any value.</p>
<p>The post <a href="https://nelson.ph/2016/10/renaming-photos-by-timestamp/">Renaming Photos by Timestamp</a> appeared first on <a href="https://nelson.ph">Beer &amp; Skittles</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nelson.ph/2016/10/renaming-photos-by-timestamp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1649</post-id>	</item>
		<item>
		<title>Printing XYZ in Java using Asterisks</title>
		<link>https://nelson.ph/2014/03/printing-xyz-in-java-using-asterisks/</link>
					<comments>https://nelson.ph/2014/03/printing-xyz-in-java-using-asterisks/#respond</comments>
		
		<dc:creator><![CDATA[Nelson]]></dc:creator>
		<pubDate>Tue, 25 Mar 2014 15:23:12 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<guid isPermaLink="false">http://log.flirt-wind.net/?p=1527</guid>

					<description><![CDATA[<p>Assumption is that dimension should always be an odd number (you have to be able to have immediately understood why, else please stop reading this this instant). It&#8217;s accomplished using brute force, because I just wanted to see it working and prove to myself that I haven&#8217;t gone totally rusty yet. package letter; public class [&#8230;]</p>
<p>The post <a href="https://nelson.ph/2014/03/printing-xyz-in-java-using-asterisks/">Printing XYZ in Java using Asterisks</a> appeared first on <a href="https://nelson.ph">Beer &amp; Skittles</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Assumption is that dimension should always be an odd number (you have to be able to have immediately understood why, else please stop reading this this instant). It&#8217;s accomplished using brute force, because I just wanted to see it working and prove to myself that I haven&#8217;t gone totally rusty yet.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="java">package letter;

public class LetterGenerator {
   public static void main(String[] args) {
      int dim = 7;

      for(int i = 0; i &lt; dim; i++) {
         for(int j = 0; j &lt; dim; j++) {
            if(i == j || i + j == dim - 1) {
               System.out.print("*");
            } else {
               System.out.print(" ");
            }
         }

         System.out.println();
      }

      System.out.println();

      for(int i = 0; i &lt; dim; i++) {
         for(int j = 0; j &lt; dim; j++) {
            if(((i == j || i + j == dim - 1) &amp;&amp; i &lt; dim / 2 + 1) || (i &gt; dim / 2 &amp;&amp; j == dim / 2)) {
               System.out.print("*");
            } else {
               System.out.print(" ");
            }
         }

         System.out.println();
      }

      System.out.println();

      for(int i = 0; i &lt; dim; i++) {
         for(int j = 0; j &lt; dim; j++) {
            if(i == 0 || i + j == dim - 1 || i == dim - 1) {
               System.out.print("*");
            } else {
               System.out.print(" ");
            }
         }

         System.out.println();
      }
   }
}
</pre>
<p>The post <a href="https://nelson.ph/2014/03/printing-xyz-in-java-using-asterisks/">Printing XYZ in Java using Asterisks</a> appeared first on <a href="https://nelson.ph">Beer &amp; Skittles</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nelson.ph/2014/03/printing-xyz-in-java-using-asterisks/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1527</post-id>	</item>
		<item>
		<title>Generating Dates Between Start and End in Java</title>
		<link>https://nelson.ph/2012/08/generating-dates-between-start-and-end-in-java/</link>
					<comments>https://nelson.ph/2012/08/generating-dates-between-start-and-end-in-java/#respond</comments>
		
		<dc:creator><![CDATA[Nelson]]></dc:creator>
		<pubDate>Sat, 11 Aug 2012 05:14:42 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<guid isPermaLink="false">http://log.flirt-wind.net/?p=1421</guid>

					<description><![CDATA[<p>Yesterday I had to generate a list of dates given two inputs. Having no Internet connection yet, I eagerly searched for help through my Android phone. Stack Overflow would&#8217;ve instantly helped me if I didn&#8217;t leave immediately after reading &#8220;Joda Time&#8221;. The thought of not needing some library for such an ideally simple task was [&#8230;]</p>
<p>The post <a href="https://nelson.ph/2012/08/generating-dates-between-start-and-end-in-java/">Generating Dates Between Start and End in Java</a> appeared first on <a href="https://nelson.ph">Beer &amp; Skittles</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Yesterday I had to generate a list of dates given two inputs. Having no Internet connection yet, I eagerly searched for help through my Android phone. <a href="http://stackoverflow.com/questions/4534924/how-to-iterate-through-range-of-dates-in-java" target="_blank" rel="noopener noreferrer">Stack Overflow</a> would&#8217;ve instantly helped me if I didn&#8217;t leave immediately after reading &#8220;Joda Time&#8221;. The thought of not needing some library for such an ideally simple task was simply there. Then there was <a href="http://helpdesk.objects.com.au/java/how-can-i-iterate-through-all-dates-in-a-range" target="_blank" rel="noopener noreferrer">this</a>, which compiled but never ran. :faint:</p>
<p>In my case, the checking that the end date should be greater than the start date was already handled somewhere else so I already skipped it. Also, instead of actual Dates, I only needed Strings (but I do intend to convert this into a generic utility class). So, yeah, here you go:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="java">final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd");
Calendar startDate = Calendar.getInstance();
Calendar endDate = Calendar.getInstance();

try {
   startDate.setTime(DATE_FORMAT.parse("2012/08/01"));
   endDate.setTime(DATE_FORMAT.parse("2012/08/10"));

   ArrayList&lt;String&gt; includedDates = new ArrayList&lt;String&gt;();

   while(!startDate.equals(endDate)) {
      String date = DATE_FORMAT.format(startDate.getTime());
      includedDates.add(date);
      startDate.add(Calendar.DATE, 1);
   } includedDates.add(DATE_FORMAT.format(endDate.getTime()));

   for(String date : includedDates) {
      System.out.println(date);
   }
} catch(Exception e) {}
</pre>
<p>Today I checked back on the supposedly second working solution I cited above, copy-pasted the code, and successfully ran it. :wtf:</p>
<p>The post <a href="https://nelson.ph/2012/08/generating-dates-between-start-and-end-in-java/">Generating Dates Between Start and End in Java</a> appeared first on <a href="https://nelson.ph">Beer &amp; Skittles</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nelson.ph/2012/08/generating-dates-between-start-and-end-in-java/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1421</post-id>	</item>
		<item>
		<title>Vigenere Cipher in Java</title>
		<link>https://nelson.ph/2010/08/vigenere-cipher-in-java/</link>
					<comments>https://nelson.ph/2010/08/vigenere-cipher-in-java/#comments</comments>
		
		<dc:creator><![CDATA[Nelson]]></dc:creator>
		<pubDate>Fri, 27 Aug 2010 10:31:38 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<guid isPermaLink="false">http://log.flirt-wind.net/?p=660</guid>

					<description><![CDATA[<p>By stumbling upon this page, I presume knowledge on the encryption is already at hand. Otherwise, take a walk first. The program is under the following assumptions: User only inputs characters (and spaces!) included in the given alphanumeric set. Numeric characters result in uppercase plain/cipher characters. Encryption/decryption key cannot have a space. VigenereCipher.java private static [&#8230;]</p>
<p>The post <a href="https://nelson.ph/2010/08/vigenere-cipher-in-java/">Vigenere Cipher in Java</a> appeared first on <a href="https://nelson.ph">Beer &amp; Skittles</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>By stumbling upon this page, I presume knowledge on the encryption is already at hand. Otherwise, <a href="http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher" target="_blank" rel="noopener noreferrer">take a walk</a> first. The program is under the following assumptions:</p>
<ul>
<li>User only inputs characters (and spaces!) included in the given alphanumeric set.</li>
<li>Numeric characters result in uppercase plain/cipher characters.</li>
<li>Encryption/decryption key cannot have a space.</li>
</ul>
<blockquote><p>
<strong><a href="https://nelsoft.org/files/code/VigenereCipher.java">VigenereCipher.java</a></strong></p></blockquote>
<pre class="EnlighterJSRAW" data-enlighter-language="java">private static final char[] alphnum = {
   'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
   'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
   'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
};
</pre>
<p>The post <a href="https://nelson.ph/2010/08/vigenere-cipher-in-java/">Vigenere Cipher in Java</a> appeared first on <a href="https://nelson.ph">Beer &amp; Skittles</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nelson.ph/2010/08/vigenere-cipher-in-java/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">660</post-id>	</item>
		<item>
		<title>Java Implementation of &#8220;Inception&#8221;</title>
		<link>https://nelson.ph/2010/08/java-implementation-of-inception/</link>
					<comments>https://nelson.ph/2010/08/java-implementation-of-inception/#comments</comments>
		
		<dc:creator><![CDATA[Nelson]]></dc:creator>
		<pubDate>Sat, 14 Aug 2010 13:14:52 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<guid isPermaLink="false">http://log.flirt-wind.net/?p=496</guid>

					<description><![CDATA[<p>Feedback from friends, positively spoken and written (statuses), kept me wondering what the movie really was all about. I never set my eyes on it because the trailer didn&#8217;t intrigue nor enlighten me as a layman. But as it turns out, it&#8217;s way more nerve-wracking than you can think of. After seeing a pseudocode post [&#8230;]</p>
<p>The post <a href="https://nelson.ph/2010/08/java-implementation-of-inception/">Java Implementation of &#8220;Inception&#8221;</a> appeared first on <a href="https://nelson.ph">Beer &amp; Skittles</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://i0.wp.com/nelsoft.org/files/flirt-wind/return-to-innocence/inception_ver4.jpg?ssl=1"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/nelsoft.org/files/flirt-wind/return-to-innocence/inception_ver4-1.png?resize=100%2C148&#038;ssl=1" alt="Inception" class="floatright" width="100" height="148"/></a></p>
<p>Feedback from friends, positively spoken and written (statuses), kept me wondering what the movie really was all about. I never set my eyes on it because the trailer didn&#8217;t intrigue nor enlighten me as a layman. But as it turns out, it&#8217;s way more nerve-wracking than you can think of.</p>
<p>After seeing a pseudocode post from my adviser and visiting the big screen, I knew I just had to make my own — a  recursive one. To experience euphoria, I dug an implementation. What the program does is very simple. It asks for the levels of dream <em>you</em> wish to experience, and then prints out the time spent on each level. You&#8217;ll see&#8230;</p>
<blockquote><p>
<strong><a href="https://nelsoft.org/files/code/Inception.java">Inception.java</a></strong></p></blockquote>
<pre class="EnlighterJSRAW" data-enlighter-language="java">void dream(int level) {
   if(level &lt;= 0) {
      return;
   }

   try {
      System.out.print("Level " + level + ": ");
      long startTime = System.currentTimeMillis();
      Thread.sleep(1000*level);
      long endTime = System.currentTimeMillis();
      System.out.println((endTime-startTime) + " ms");
   } catch(InterruptedException ie) {}

   dream(level-1);
}
</pre>
<p>The post <a href="https://nelson.ph/2010/08/java-implementation-of-inception/">Java Implementation of &#8220;Inception&#8221;</a> appeared first on <a href="https://nelson.ph">Beer &amp; Skittles</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nelson.ph/2010/08/java-implementation-of-inception/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">496</post-id>	</item>
	</channel>
</rss>
