Friday, May 4, 2012

Java PageCheck

I've been doing some Java programming on my own. I am working on smaller programs to get back in the groove. Made a Factorial program and an assignment I found called FizzBuzz as well as other small programs.

I wanted to do something more but didn't know what to do or where to start. So, I decided to go back to the beginning and redo one of my first programming assignments, PageCheck. PageCheck is a program that takes an URL and a time interval and returns true if the corresponding page has been modified within the time interval, and false otherwise. This is the basic version.

The program below seems to be correct. For some webpages, it returns the correct vales. For other webpages, the values are not correct. These webpages don't seem to have a last modified date. There last modified date is 'Wed Dec 31 14:00:00 HST 1969.' These are webpages like Amazon, YouTube, and ics.hawaii.edu. getLastModified() Returns the value of the last-modified header field. The result is the number of milliseconds since January 1, 1970 GMT. The 1969 date is making last modified return 0.

I DON'T GET IT?


1:  import java.io.IOException; 
2:  import java.net.URL; 
3:  import java.net.URLConnection; 
4:  import java.util.Calendar; 
5:  import java.util.Date; 
6:   
7:   
8:  /** 
9:   * The CheckPage class implements a system to notify the user  
10:   * when a webpage has been modified within the past 24 hours. 
11:   *  
12:   * @author Keola Ng 
13:   * @version $Id$ 
14:   */ 
15:  public class CheckPage { 
16:    
17:   /** The url connection object that connects to the web page to check. */ 
18:   private URLConnection urlConnection; 
19:    
20:   /** The time interval to check the web page. */ 
21:   private int timeInterval; 
22:   
23:   /** 
24:    * Constructs a valid PageCheck object otherwise throws an exception. 
25:    *  
26:    * @param urlString The url of the web page to check. 
27:    * @param timeInterval The time interval to check the web page. 
28:    * @throws IOException problem connecting to the url in urlString. 
29:    */ 
30:   public CheckPage(String urlString, int timeInterval) throws IOException { 
31:    URL openUrl = new URL(urlString); 
32:    this.urlConnection = openUrl.openConnection(); 
33:    this.urlConnection.connect(); 
34:    this.timeInterval = timeInterval; 
35:   } 
36:    
37:   /** 
38:    * Determines when the web page was last modified. 
39:    *  
40:    * @return The long value of last modified date. 
41:    */ 
42:   public long getLastModified() { 
43:    return this.urlConnection.getLastModified(); 
44:   } 
45:    
46:   /** 
47:    * Checks if the URL has been modified within a specified time. 
48:    *  
49:    * @return URL has been modified before or after the timeInterval. 
50:    */ 
51:   public boolean isModified() { 
52:    Calendar currentCalendar = Calendar.getInstance(); 
53:    int intervalUnit = 3600000; 
54:    int lastModified = (int) (getLastModified() / intervalUnit); 
55:    int currentTime = (int) (currentCalendar.getTimeInMillis() / intervalUnit); 
56:     
57:    int num = currentTime - lastModified; 
58:    System.out.println("Date: " + new Date(currentCalendar.getTimeInMillis())); 
59:    System.out.println("Last modified: " + new Date(getLastModified())); 
60:    System.out.println(getLastModified() + " / " + intervalUnit  
61:                + " = " + lastModified); 
62:    System.out.println(currentCalendar.getTimeInMillis() + " / "  
63:                + intervalUnit + " = " + currentTime); 
64:    System.out.println(currentTime + " - " + lastModified + " = "  
65:                + num + " < " + this.timeInterval); 
66:     
67:    return ((currentTime - lastModified) < this.timeInterval); 
68:   } 
69:   
70:   /** 
71:    *  
72:    * @param args 
73:    * @throws IOException  
74:    */ 
75:   public static void main(String[] args) throws IOException { 
76:     
77:    CheckPage cp = new CheckPage("http://www.ics.hawaii.edu/", 24); 
78:    if (cp.isModified()) { 
79:     System.out.println("True"); 
80:    } else { 
81:     System.out.println("False"); 
82:    } 
83:   } 
84:  } 

Thursday, October 27, 2011

Blog Purpose

My blogging has been erratic and without purpose. There has been no reason behind any of the blog posts I've written. I want there to be a purpose and a future goal for my blogging. I've decided to work on my online presence. My goal is to create a professional persona to help me asses my strength and weaknesses of my programming capabilities.

The purpose of my blog is to showcase my learning. I will start detailing everything I'm working on.
  • Demonstrate my willingness and curiosity to continue increasing my programming knowledge.
  • Demonstrate I understand content related to programming.
  • Demonstrate my researching ability.
  • Demonstrate my writing ability.
  • Demonstrate my critical thinking ability.
  • Demonstrate my creativity.
  • Through my writing, develop and demonstrate my unique professional personality and character.
  • Develop and demonstrate my social media skills.
  • Begin developing my professional brand, not as a job-seeker in my field, but as a thought leader in my field.

My writing to this point has not clearly demonstrated any of these standards. One of my goals is to be able to clearly articulate in my writing what I'm working on so that everyone can understand. When I write what I'm working on, I want the newbie to the professional to understand what I'm explaining. I always hacking on something, whether it's Java or Rails or CSS and XHTML, I will have something to write about. It will take a lot of deliberate practice to get my writing to this point.

Wednesday, October 26, 2011

Apache Ivy

In researching Apache Ant and how to create a build.xml file, I discovered Apache Ivy. Apache Ivy is a dependency manager that can easily be integrated with Apache Ant.

The main and most frequent way to use ivy is from an ant build file. However, ivy can also be called as a standalone application. If you use ant version 1.6.0 or superior, you just have to add ivy namespace to your project (xmlns:ivy="antlib:org.apache.ivy.ant") attribute of your project tag, and you can call ivy tasks.
 <project name="sample" default="compile" xmlns:ivy="antlib:org.apache.ivy.ant"> 
The build will use Apache Ivy to download, install, and manage third party libraries of the different tools needed for the project. The retrieve task copies resolved dependencies anywhere you want in your file system. Below is an example of adding checkstyle to the project.
1:  <target name="install-checkstyle" description="Install checkstyle."> 
2: <ivy:retrieve module="checkstyle" organisation="com.puppycrawl" revision="5.4" pattern="${basedir}/lib/checkstyle/[artifact].[ext]" sync="true" conf="bundled" type="jar,report"/>
3: </target>

Tuesday, October 18, 2011

Build System

The build system is extremely important. It provides a standardized way for anyone to build the system. Users can build and test the system without an IDE. Developers can build and test the system using their IDE of choice. This automated build is helpful in preventing errors, testing, and deployment. Developing a robust build system can ease the process when maintaining a large and/or complex software system.

My build system will need to become a template. As a template, I can adapt it to any project I create. The build system will be modular and extensible to become as big or as small as needed. It will integrate any third party build tools. It will handle junit, checkstyle, and any other third party build tools that the build system requires. It will be able to download, install, and manage all third party libraries needed. It will support web application development.

Below is the beginnings of a build file. It contains two targets, clean and compile. It's very simple in what its doing. I am studying the Ant manual to learn how to integrate the third party build tools and libraries into the build system.

1:  <project default="default">
2: <description>
3: The build file.
4: $Id$
5: </description>
6:
7:
8: <property name="src.dir" location="${basedir}/src"/>
9: <property name="build.dir" location="${basedir}/build"/>
10:
11:
12: <target name="clean"
13: description="Delete build/ directory.">
14: <delete dir="${build.dir}"/>
15: </target>
16:
17: <target name="compile"
18: description="Compiles the code.">
19: <!-- Ensure that the build output dir exists. -->
20: <mkdir dir="${build.dir}/classes"/>
21: <!-- Now compile the system. -->
22: <javac srcdir="${src.dir}"
23: destdir="${build.dir}/classes">
24: </javac>
25: </target>
26: </project>

Thursday, October 13, 2011

Configuring My Java Build Environment

In my efforts to improve my programming skills, I have decided to get back into Java programming and building large projects. My previous involvement with a large Java project was seven years ago as a university of Hawaii student with the CLEW system. The Collaborative Educational Website (CLEW) was a web application development framework for collegiate department websites.

Environment Configuration

The current laptop I will be working on is a Toshiba Satellite A505 running on Windows 7 64-bit. It has a 1.60 GHz processor, 4 GB RAM, and over 100 GB of free space. My first step is to create a high quality Java software development environment. I downloaded and installed the Java 7 JDK and JavaDoc documentation. I added %java%/bin to my computers PATH variable. I downloaded and installed the Eclipse 3.6.2 IDE. I chose "Eclipse IDE for Java EE Developers" to work on the Java projects. To improve the performance of Eclipse, I modified some runtime options. Increase the heap space for Eclipse. I have at least 2GB RAM. In the eclipse.ini file, I changed -Xms=40m to -Xms=512m and -Xmx=512m to -Xmx=1024m.

To verify my configuration was working, I wrote a couple of basic programs in my eclipse IDE. I wrote the generic HelloWorld program that worked fine. I wanted to try something else so I searched online and found a simple program to implement called FizzBuzz. FizzBuzz is a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". I was able to implement a working FizzBuzz program. My initial configuration was working.

Build System

This is the point in my configuration where I am stuck. The build system I used for CLEW included apache ant, jakarta tomcat, junit, checkstyle, and other tools. Are these tools still relevant?

In my research for build tools, the top two I came across were Ant and Maven. Ant is open source, Java-based, extensible, and uses XML configuration files. Maven is project management technology that uses convention over configuration. Ant is still very popular and I am familiar with the Ant concepts. Every project requires an Ant build file, build.xml. Each build file is composed of targets. Each target is composed of tasks. And targets can have dependencies.

I downloaded and installed Apache Ant 1.8.1. I added %ant%/bin to my computers PATH variable.

Now What?

Next in configuring my Java build environment will be to include the different tools to help build a working project. I will look into junit, checkstyle, and other tools currently being adopted. When I get a build environment up and running, I will begin my Java programming.

Thursday, January 13, 2011

Learning by Doing

After graduating from the University of Hawaii, I fell into a programming funk. I didn't know what to do, how to get started, or where to get help. I felt like none of the courses I took prepared me to take a project from development through to distribution. I missed not having access to Professors, TA's, classmates, and friends. I finally took action and contacted my mentor for guidance.

His advice was to just start hacking. Do anything. Think of an idea and try to implement the program. Work by trial and error. If you encounter an error, try to figure it out with research and fix the problem. There is no better way to learn then to just do it.

I found the following on a website the echoes this sentiment.
Program. The best kind of learning is learning by doing. To put it more technically, "the maximal level of performance for individuals in a given domain is not attained automatically as a function of extended experience, but the level of performance can be increased even by highly experienced individuals as a result of deliberate efforts to improve." (p. 366) and "the most effective learning requires a well-defined task with an appropriate difficultly level for the particular individual, informative feedback, and opportunities for repetition and correction of errors." (p. 20-21) The book Cognition in Practice: Mind, Mathematics, and Culture in Everyday Life is an interesting reference for this viewpoint.
This concept of learning by doing would have been nice to have done while at UH. Looking back I feel my focus was more on completing assignments before the due date to get the best grade to pass the class to get to graduation. I didn't immerse myself into the subject to fully understand it and relate it to a real world problem. Because of this, I didn't have the right mindset or ask the right questions. I would've liked to learn by doing with the class, during class, with the professor giving feedback and correcting errors as he instructs. My ideal situation would've allowed more natural learning and less lecturing.

I've been thinking a lot about my student self. I feel I approached learning all wrong. I put more effort into getting through my courses then being in the moment and participating. I've come to realize my goals were geared towards doing what I needed to do to move up instead of understanding the material. It would've been amazing to be given a difficult task and allowed to fail without the consequence. My failure would have been an opportunity to teach me where I went wrong and how to correct the mistake for next time instead of failing me with no idea or explanation why my work was unsatisfactory and forced to retake the course.

It wasn't all bad. I had a few courses that allowed me to learn by doing. We worked on real world projects. I was able to receive informative feedback and correction on errors. In one of these classes I was introduced to pair-programming. Pair-programming is a great concept.

Over the past year of I've been learning a new programming language and hacking away implementing a variety of programs. I am gaining a deeper knowledge of Ruby on Rails, CSS, and XHTML. In this process I'm learning more about utilizing the MySQL database, how the MVC paradigm works, how to work with plugins and gems, authentication, uploading images and videos, dynamic select menus, and many more things. I am coming to the conclusion that a year of learning by doing has given me a better understanding then the majority of Computer Science courses I took at UH. Out of the 15 or more ICS courses I took during my time at UH, only two were helpful, ICS 413 and ICS 414.

I will be continuing my learning by doing. My current project is a web application using Rails. My ultimate goal is to get my webapp online. I also plan on getting back into Java development. My last foray with Java was using the Struts web application framework, eclipse, ant, tomcat, mysql, and cvs. I will be looking into what I need to develop with Java and if any of the preceding tools are still relevant.

Thursday, December 16, 2010

Whatcha Been Doin? A Conversation

It's the holiday season and we are visiting with family and friends. We are out gathering with people at parties or games or whatever. While hanging out with everyone we talk to each other.

One of the early questions asked to begin a conversation is "what you been up to lately" or "what do you do." I've participated in and listened to some conversations that began this way. Over the past month I have engaged in a dozen or so conversations and listened to a bunch more that began this way. I will note that I am not the best conversationalist.

When family, friends, or strangers came up to me and ask me that question, I fill them in on the hacking and trading I've been doing. I get two responses to my answer, "that's great" and they walk away or "that's great" and they change the subject. I did not get one person to pursue further into what I'm doing or exhibit any interest in what I've said. I've come to the conclusion that it could be one of two things, 1) hacking and trading are not interesting for the people I talked with or 2) my delivery in explaining what I'm doing was not clear and understandable for anyone to continue with that conversation topic. I believe the problem is with the latter.

In listening to other similar conversations, the response was much different. The questioner was engaged with the answers and continued with follow up questions to gain a deeper knowledge of the subject. I too became fascinated with what people are doing.

So, I've been trying to figure out why my delivery failed. As I noted earlier, I am not the best conversationalist. I don't participate in many conversations because I have a weak and soft voice and many people have a difficult time hearing me, especially in loud areas. I wing it every time I tell people what I'm doing so its probably not succinct and a little confusing. I need to practice.

I'm looking to improve in this area. In my research I've come across the concept of Branding. I will be working on Brand Me. I want to be able to articulate what I'm doing better. Maybe then I will get people interested in learning more.