12 CHAPTER 1: Introducing Java Web Development
Setting Up the Development Environment
The Java software is available in two distributions.
The Java Runtime Environment (JRE)
The Java Development Kit (JDK)
The JRE includes a JVM and the core libraries; it is essentially just an environment for running
bytecode. The JDK includes the JRE, a Java compiler (javac), and other tools—the basic software
you need to write and compile Java programs.
Before you can start compiling and running Java programs, you need to download and install the
JDK and configure some system environment variables.
Most of the code in this book requires Java 7, but some of the code is based on Java 8, so you
should install Java 8. To get the latest version of the JDK)), follow these steps:
- Open http://www.oracle.com/technetwork/java/javase/downloads/index.html in a
web browser. - Click the Download JDK button.
- Follow the instructions provided by the web site.
- Run the installer and accept any defaults.
To confirm you have installed the JDK correctly, type javac on the command line from any directory
on your machine. If you see instructions on how to run javac correctly, then you have installed it
successfully.
Creating and Running Your First Java Application
This section demonstrates how to create, compile, and execute a simple Java application on
Windows. Every Java application has one class that is the program’s starting point (often called an
entry point). Listing 1-1 illustrates a HelloWorld entry-point class.
Listing 1-1. A HelloWorld Java Application
- public class HelloWorld {
- public static void main(String[] args) {
- System.out.println("Hello World.");
- }
- }
Line 2: The main method in line 2 makes this class an entry-point class. This
method accepts inputs and starts the program.
The name of the Java application should be the name of the entry-point class, and the file that holds
a Java class must have the same name as the class. Therefore, the HelloWorld class in Listing 1-
must be stored in a file named HelloWorld.java.