Java Tutorial

Intertech Tutorials

Java Tutorial Objective

Overview

Java is currently the most popular programming language. Why? What made it so popular, and why is it used today in a variety of applications? From tiny applications that run on cell phones and embedded devices to huge distributed enterprise applications, Java has had an enormous impact on the software industry. Its presence has forced organizations like Microsoft to adopt a different approach to programming.

In a word, Java’s strength lies in its portability. The mantra by which all Java developers live by is “WORA,” or write once, run anywhere. What makes WORA work in Java?

This chapter introduces you to Java goals and philosophy. After reading this chapter, you will have a much better understanding of the Java platform and why it is so powerful.

You will be introduced to a simple Java application, the ubiquitous ‘Hello World’ application but written in Java. You will also gain an appreciation for how Java applications are built, compiled, and executed.

What Is Java?

Java is two things: a programming language and a platform. As a programming language, Java was designed to be

Java is based on many programming languages (primarily C++) that came before it. Java’s designers attempted to retain the other programming languages’ good qualities. They also tried to remove the complexities found in other languages. Its simplicity and familiarity are owed to its origins. Its extensive compile-time and runtime checking and internal memory management provide for robust and secure applications.

The Java platform allows for a write once, run anywhere (WORA) software development environment. Applications written in Java execute atop the platform-specific Java platform. This allows applications to be platform-neutral, while the Java platform handles hardware and operating system specifics. The interpretive nature of Java results in faster/rapid development, prototyping, and experimentation. It helps avoid the compile, link, and test cycles in older/non-interpreted styles of development.

The Java language and runtime are dynamic in their linking, pulling in code only as needed. New code modules can be linked in on demand from a variety of sources, even from sources across a network. This enables transparent updating of applications. These features, along with Java’s extensive API, have led it to be number one in programming language popularity.

The Java Platform

The Java platform has two components:

JavaPlatform

The Java API is a large collection of ready-made software components that provide many useful capabilities. The API provides input/output, graphical user interface, database access, and more. The Java API is grouped into libraries of related components called packages. Your Java applications call these library components, thereby greatly reducing your development time. The API available to you depends on which version and edition of Java you are using. The Java Virtual Machine (JVM) insulates your application from platform specifics.

In Java, applications are both compiled and interpreted. The Java compiler compiles your application source code to an intermediate language that is interpreted by the JVM. The intermediate language is called bytecode. The bytecode is not machine code that gets executed directly. Instead, the JVM translates (i.e., interprets) the bytecodes into machine code, which gets run by the actual platform. In other words, bytecode is like the “machine code” for the JVM. The bytecode is platform independent and can therefore be interpreted by any JVM. JVMs are built specific to particular platforms (hardware and OS).

JavaP2

More information about the JVM is provided later in this chapter. In order to “run” your Java application, what is needed is both the Java API library used by your application and the JVM. The JVM and Java API required to run Java programs is called the Java Runtime Environment (JRE). The JRE does not include tools to create or develop Java applications. It is strictly the minimum software that must be installed on a machine in order to run Java applications.


Copyright (c) 2008-2013. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.