Introduction to Java web applications
I used the following material to give a one-hour overview of Java and web applications to a group of developers experienced in the Microsoft ecosystem.
The basic Hello World: Java source in .java file compiles to JVM bytecode in .class file
See the following sections of this useful Introduction to Java Programming:
- 1. Introduction
- 2. Classpath
- 3. Your first Java program
Section 13 provides an overview of JAR (Java ARchive) files. More details at the Java Tutorial Lesson: Packaging Programs in JAR Files.
Using Java for Financial Applications
Dates and Times
The standard Java library has two classes for dates and times: java.util.Date and java.util.Calendar. Both are mutable and difficult to use for common date arithmetic. A much better replacement is Joda-Time. In particular, the LocalDate class is an “immutable datetime class representing a date without a time zone”. Most of the time, this is exactly what you need.
Monetary Values
Java does not have a built-in decimal data type. Instead, you need to use the BigDecimal class in the standard library for immutable, arbitrary-precision signed decimal numbers with complete control over rounding behavior.
Do not use either of the binary floating-point types (float or double). It is impossible to represent 0.1 (or any other negative power of ten) as a float or double exactly. The representation errors and rounding errors will bite you. See http://floating-point-gui.de/ for more details on “what every programmer should know about floating-point arithmetic (or why don’t my numbers add up?)”.
I recommend carrying the currency with every monetary value, as documented in the Money pattern (Patterns of Enterprise Application Architecture, Martin Fowler). The Currency class in the standard Java library represents currencies using their ISO 4217 currency codes.
Programming Guidance: Effective Java and Collections
The book Effective Java, Second Edition by Joshua Bloch gives much useful programming guidance in bite-sized articles.
The Java Collections framework in java.util is very useful. See the overview and annotated outline.
Google have written an extension collection framework in the Guava Google Core Libraries for Java.
Structure of Java Web Applications
The most basic component of a Java web application is the servlet: a Java class that responds to HTTP requests.
Start with the overview page Getting Started with Web Applications, then read the following sections of the J2EE 1.4 tutorial:
- Chapter 1: Overview
- Chapter 3: Getting Started with Web Applications
- Chapter 11: Java Servlet Technology
After that, you'll find the other 32 chapters describe many other technology components that you can add to Java web applications, including Web services.
A Hello World Web Application using Eclipse, Ant and Tomcat
The following pages give detailed instructions on how to build a Hello World web application. Along the way, they introduce the Eclipse IDE, the Ant build tool, and the Tomcat servlet container.
- Hello World Java Web Application in Eclipse (Part 1)
- Hello World Java Web Application in Eclipse (Part 2)
- Hello World Java Web Application in Eclipse (Part 3)
The copyright notice on these pages is rather amusing.
Web Application Security Issues
A public-facing web application has particular security issues. See the Open Web Application Security Project (OWASP) Top Ten for a general overview, and then see the Enterprise Security API for Java EE, which provides a security framework for Java web applications.
Tags: java
Comments
You can email me at geeks#stephen.viles.geek.nz (change # to @).