Monday, July 29, 2013

Installing the Java Software Development Kit (JDK)

The first software package that you need to install for creating Java EE applications is the JDK, which enables you to compile Java source files into binary class files. In addition to the Java compiler, the JDK includes the Java Runtime Environment (JRE), which provides a Java virtual machine that application servers can run on.

The following steps describe how to install the JDK on your development machine. (We will use a Windows 7 machine in these examples; the procedure may be slightly different for other platforms.)
  1. Go to the Oracle Java Downloads page.
  2. Click on Download Java Platform (JDK).
  3. Accept the license agreement.
  4. Choose your platform and download the installer.
  5. Follow the installation wizard and wait for the installation to complete.
Click on Java Platform (JDK)

When the installation completes, follow these steps to set the JAVA_HOME environment variable:
  1. On the Desktop, right-click on Computer, then select Properties.
  2. Click on Advanced System Settings.
  3. If JAVA_HOME is not listed under User variables, click New
  4. In the Variable Name field, type JAVA_HOME. 
  5. In the Variable Value field, type the installation directory of the JDK; for example: C:\Program Files\Java\jdk1.7.0_25
  6. Then click OK.
The Environment Variables window

Setting the JAVA_HOME environment variable

Now follow these steps to add the JDK bin/ directory to your PATH environment variable:

  1. In the Environment Variables window, select Path under System Variables and click Edit.
  2. In the Edit System Variable window, add the bin/ directory of the JDK installation to the Path variable; for example: C:\Program Files\Java\jdk1.7.0_25\bin
  3. Click OK on the Edit System Variable window.
  4. Click OK on the Environment Variables window.
  5. Click OK on the System Properties window.

Setting the Path environment variable

To test that you have set the environment variables correctly, open a new terminal or command prompt window and type the following commands:

>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.7.0_25
>javac -version
javac 1.7.0_25

Your output shoud be similar to the output shown above.

Sunday, July 28, 2013

Set up your environment to create Java EE applications

You need the following tools to develop and test Java EE applications:

  • The Java Software Development Kit (SDK). The SDK is required to compile any Java program, including classes to be included in Java EE applications.
  • A Java EE application server. The application server installed in your development machine helps you test and debug your applications during the development phase.
  • An Integrated Development Environment (IDE). An IDE helps you create and manage Java EE applications as projects. The sophisticated editors provided by most IDEs increase your productivity and enable you to detect errors earlier in the development phase.
  • An IDE plugin for your application server. Some IDE plugins enable you to start and stop the server from the IDE and to view the server log on the IDE window.

In future posts we will describe in detail how to install and use the Oracle Java SDK, the GlassFish application server, and the NetBeans IDE.

Thursday, July 25, 2013

Java EE and application servers, part five

Java EE is a set of specifications that are implemented by many application servers. The server that you choose to run your applications in a production environment depends on factors such as pricing, familiarity, performance, support options, and so on. If you plan to run your Java EE applications on the cloud, you can choose your cloud service provider based on the application server offered by their cloud platform.

If you develop your applications using standard Java EE APIs, you will have more flexibility when choosing an application server or a cloud platform, since your applications will run in any Java EE-compliant server.

The following list contains links to some of the most popular Java EE application servers:

GlassFish Server - An open-source application server sponsored by Oracle
WebLogic Server - A commercial application server sold by Oracle
WildFly - An open-source application server sponsored by RedHat
JBoss - A commercial application server sold by RedHat
TomEE - An open-source application server sponsored by the Apache Foundation
WebSphere - A commercial application server sold by IBM

We will use mostly the GlassFish server in future posts, but we may cover using some other application servers from time to time.

Wednesday, July 24, 2013

Java EE and application servers, part four

Application servers provide a variety of administration interfaces that enable you to:

  • Submit Java EE applications to run in the application server
  • Configure server parameters
  • Create resources such as connection pools, thread pools, and messaging queues

Each application server provides its own tools to perform these tasks. Most application servers provide a web-based administration console and a set of command-line tools. For example, the following figure shows the web administration console for GlassFish, a Java EE application server:

GlassFish web console

We will use administration interfaces for different application servers in future posts.

Tuesday, July 23, 2013

Java EE and application servers, part three

The application server provides applications with a range of services, as illustrated in the following figure:

Main services provided by an application server

The web server handles HTTP requests and responses from and to clients. Your application only needs to indicate at which URLs its web pages and web services should be made available to clients.

The messaging service enables applications to produce and consume messages to communicate between them.

The thread management service provides and manages new threads for applications to execute work. The application server maintains a pool of threads that can be reused, which increases the scalability of applications by using server resources more efficiently.

The injection service enables applications to obtain resources and dependencies automatically at run time. The application server creates and manages the lifecycle of these dependencies (objects), so the application does not have to.

The transaction management service enables applications to define transactional operations and restores the resources associated with a transaction to their original state automatically if an operation cannot be completed entirely.

The authentication service enables applications to manage users and groups and to grant access to some parts of an application only to some users or groups.

The connection pooling service maintains a pool of active connections to a resource (such as a database or a legacy system) that can be reused by applications. Connection pooling improves the performance of applications that use these connections.

The naming directory service enables administrators and applications to register resources (such as connection pools or message queues) in the application server and to access them by their name.

We will learn how to use these services in future posts.

Monday, July 22, 2013

Java EE and application servers, part two

From the previous post, we now understand that a Java EE application cannot run except inside a Java EE application server, and that the application server is a Java program that provides functionality and services to Java EE applications. This scenario is illustrated in the following figure:

Java EE application server

The system administrator starts the application server. As an application developer, you will run an application server in your development machine for testing your applications. While you need to learn the basics of running and configuring an application server, you do not need to become an expert on it. You can subscribe to a Java EE service on the cloud and submit your applications to it, as we will see in future posts.

You can deploy several Java EE applications to an application server. Deploying a Java EE application is like installing that application into the application server and activating it so that it can respond to requests from clients. The configuration settings included in each application tell the application server at what URLs the application should be accessible to clients, among other things.

Sunday, July 21, 2013

Java EE and application servers, part one

Java EE consists of a set of specifications which define:

- The services and functionality that the platform provides to applications
- The APIs that applications use to access these features
- How application servers must implement these features

The Java EE platform defines services and functionality that most web and enterprise applications need; it would not make sense for each application to reinvent the wheel. For example, a social networking site and an online store both need a web server, an authentication framework, a database connectivity engine, and so on.

An application server is a Java program that implements the services and functionality defined by the Java EE specifications. There are many Java EE application servers on the market, some of them available for free. Although some application servers provide additional proprietary functionality, a Java EE application that uses standard features should run in any application server with minor or no modifications.

An important distinction between a Java SE application and a Java EE application is the following: a Java SE application controls the main loop of execution, while a Java EE application does not

Java EE applications do not have a main() method and can only run within an application server, which controls the main loop of execution and invokes the application as required.