Permalink
Browse files

New post added, new series started!

  • Loading branch information...
1 parent 45cb45c commit 46020b03c43c9534bb6acee6c32eccc44effbf96 @credmp committed Jan 6, 2013
@@ -3,7 +3,18 @@
<p>
<small>
- <a href="/about">Credmp</a>, aka Arjen Wiersma, has been active in the software development game for over 18 years, working for companies like Personify, Tiscali, eBuddy and Infomedics. I am passionate about GNU Emacs, Java and all other geeky things in this world.
+ <a href="/about.html">I</a> have been active in the software
+ development game for over 18 years, working for companies like
+ Personify, Tiscali, eBuddy and Infomedics. I am passionate about
+ GNU Emacs, Java and all other geeky things in this world.
+ </small>
+ </p>
+
+ <p>
+ <small>
+ I hope you enjoy the articles I write for this blog as much as I
+ do writing them. For me it has become a way to empty my head and
+ relax.
</small>
</p>
@@ -0,0 +1,296 @@
+---
+tags: [Java]
+title: "Java; starting at nothing"
+series: developing a Java application
+image: /assets/post_images/java_from_nothing/1.class-diagram.png
+layout: post
+---
+{% include JB/setup %}
+{% include series.html %}
+
+# Start at nothing
+
+This is the first article in a series about developing in Java. In
+this series we will be creating a full-fledged Java application from
+scratch.
+
+The goal is to understand what it takes to create a complete Java
+application from the absolute beginnings to the spit and polish of an
+user interface.
+
+## Learn something along the way
+
+Along the way we will be discussing several very interesting topics.
+Starting with, in this article, the basics of an Java application with
+a build environment, [Maven](http://maven.apache.org). During the rest
+of the articles we will be creating a complete application with at
+least, I can of course still change my mind on several topics, the
+following technical components:
+
+ - JUnit unit testing
+ - Mockito
+ - Hibernate
+ - Hibernate Search
+ - Spring Batch
+ - Spring MVC
+ - Spring Security using OpenId
+ - REST Webservices
+
+## End up with something
+
+So, what is it that we will be building you ask? We will be building
+our own interface on the data of the [IMDB](http://www.imdb.com). The
+IMDB has made, some of, their databases available for the public
+[here](http://www.imdb.com/interfaces).
+
+We will create an entity model that will reflect a subset of the data
+from these databases. This entity model will be stored in a database
+using **[Hibernate](http://www.hibernate.org)** and will be searchable
+using **[Hibernate Search](http://www.hibernate.org/subprojects/search.html)**.
+
+**[Spring Batch](http://static.springsource.org/spring-batch/)** we
+will use to automate the retrieval of the databases and the insert of
+modified data in our tables.
+
+Of course we will need an interface on top of this wonderful data. For
+this we will utilize
+**[Spring MVC](http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html)**.
+Perhaps we will also use
+**[Spring WebFlow](http://www.springsource.org/spring-web-flow)**, but
+I am uncertain of that at the moment.
+
+Security is key and for this we will add
+**[OpenID](http://openid.net)** authentication to our interface using
+**[Spring Security](http://static.springsource.org/spring-security/site/)**.
+And just to top it all off we will create a nice REST interface as
+part of our application as well. The webservices use
+**[OAuth2](http://oauth.net/2/)** for their authorisation.
+
+A whole lot of work lays ahead of us, so lets get started!
+
+# Getting started
+
+**Note**:There is a special branch for this post on [Github](https://github.com/credmp/java-from-nothing/tree/01_getting_started).
+
+So, lets quit wasting time and get started! As you might've noticed I
+do not refer to any IDE or editor by name. I am assuming you can pick
+something to work with yourselves, as there are so many choices.
+Popular in the Java community are: [Eclipse](http://www.eclipse.org)
+and [Netbeans](http://www.netbeans.org). I use [GNU Emacs](http://www.gnu.org/software/emacs/).
+
+## A word about version control
+
+I am an avid believer in the use of version control (VC). I highly
+recommend using [Git](http://git-scm.com) as a VC system.
+
+Adding files early and often to your VC system allows you to rollback
+any mistakes you might make. We are all human, so it will happen!
+
+You can follow along with these blog posts by cloning the repository
+for this post as follows:
+
+ $ git clone https://github.com/credmp/java-from-nothing.git
+ $ git checkout 01_getting_started
+
+You will end up with the current version of the project in your
+current directory.
+
+## Maven
+
+The most important thing to start with is to create a good environment
+in which you can build your project.
+
+Download the latest [Maven](http://maven.apache.org) version and
+create a file called **pom.xml**. The one I made for this project is
+available on [Github](https://github.com/credmp/java-from-nothing/blob/01_getting_started/pom.xml).
+
+The file itself is about 80 lines long, so lets take a look at the
+highlights.
+
+In order to have a concise overview of the versions of dependencies
+used in the build file I use properties. These allow you to define a
+variable with a piece of text and it then lets you use that throughout
+the document. This is specifically usefull when we will include the
+**Spring** binaries, as they have many dependencies which should be
+the same version.
+
+{% highlight xml %}
+ <properties>
+ <junit.version>4.10</junit.version>
+ </properties>
+{% endhighlight %}
+
+Per default we create our **pom.xml** file with a dependency on the
+unit testing framework JUnit. We will use this dependency extensively
+lateron.
+
+{% highlight xml %}
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+{% endhighlight %}
+
+Maven, by default, assumes the Java 1.4 language when generating
+project files for Eclipse. This is quite outdated and in order to use
+many of the new feature we will instruct maven to use language level
+1.6. You can now run **mvn eclipse:eclipse** and import it into
+eclipse if you are so inclined.
+
+We will also enable the generation of a **site**. This is a website
+that maven can generate for you with lots of information on your
+project. Most interesting here is the dependency list which tells you
+what binaries are included by what dependency you defined.
+
+{% highlight xml %}
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>3.2</version>
+ ...
+ </plugin>
+
+ </plugins>
+ </build>
+{% endhighlight %}
+
+Although the standard website has many interesting bits of
+information, I also like to know what the state of code coverage is.
+Code coverage is a metric which tells you how well you unit tested
+your code. Properly tested code will safe you a lot of time lateron
+when you have to make changes to your project.
+
+As an added bonus we will also ask maven to generate the Javadoc
+documentation for our project as part of the website.
+
+{% highlight xml %}
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>2.6</version>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ ...
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ ...
+ </plugin>
+ </plugins>
+ </reporting>
+{% endhighlight %}
+
+## The Model
+
+Sketching our our project I created a simple, not at all totally
+correct, model for our application.
+
+![The model](/assets/post_images/java_from_nothing/1.class-diagram.png)
+
+From all the data available on the internet we will focus on these:
+
+ * Actors (also Actresses) who plays a role in a movie
+ * Trivia we know about them
+ * A basic biography
+ * Movies
+ * Quotes from these movies
+ * The relationship between the movie and the actor
+
+Lets create the Java source files for these objects. I will not post
+the full Java sources here, you can find those in the
+[Github](https://github.com/credmp/java-from-nothing/blob/01_getting_started/pom.xml) repository.
+
+{% highlight java %}
+public class Actor {
+ private long id;
+ private String firstName;
+ private String lastName;
+ private String nickName;
+ private Date birthDate;
+ private Date dateOfDeath;
+ private String credit;
+
+public class Trivia {
+ private long id;
+ private Actor actor;
+ private String text;
+
+public class Biography {
+ private long id;
+ private Actor actor;
+ private String text;
+
+public class Movie {
+ private long id;
+ private Integer year;
+ private String title;
+ private String subtitle;
+ private Double rating;
+
+public class MovieCredits {
+ private long id;
+ private Actor actor;
+ private Movie movie;
+
+public class Quote {
+ private long id;
+ private Movie movie;
+ private String text;
+{% endhighlight %}
+
+So that is it for today, you now have a working build environment and
+several model entities that we will build upon.
+
+When you now run the following command:
+
+ $ mvn site:site
+
+Everything will build correctly and you will be left with a beautiful
+website in the **target/site** directory of your project.
+
+# What next?
+
+In the following blog post we will add persistence using Hibernate to
+the project. We will also introduce some unit tests en integration
+tests to make sure everything works correctly.
+
+# References
+
+This entire series is published to Github so you can follow along and
+see the code that is used.
+
+ * [The Repository](https://github.com/credmp/java-from-nothing)
+ * [Maven homepage](http://maven.apache.org)
+
+# Feedback
+
+If you have feedback about this post please feel free to comment
+below.
+
+If you have feedback on the code or have some great idea on how to
+make it better, please open an
+[Github Issue](https://github.com/credmp/java-from-nothing/issues).
+Thanks!
+
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,18 @@
+---
+tags: [Java]
+title: "Java; starting at nothing"
+image:
+layout: page_with_sidebar
+---
+{% include JB/setup %}
+
+
+Roadmap:
+
+ - Maven
+ - Spring
+ - Spring Batch
+ - Hibernate
+ - Hibernate Search
+ - Spring MVC
+ - Vaadin

0 comments on commit 46020b0

Please sign in to comment.