• Explore the strengths of the Java programming language
• Understand what Java is
• Learn about the different versions and editions of Java
• Cover the history of Java
• See the purpose of the Java Virtual Machine
• Create a simple starter program in Java
• Compile, correct errors, and test a program
• Become familiar with one way to get answers about Java
• Understand object-oriented programming concepts
• Learn how to use objects already provided in the Java API
• Create objects using “new”
• Explore the use of the . (dot) operator to access data and invoke methods
• Learn how to create your own object types called classes
• Examine the role of class constructors and the default constructor
• Study the difference between class and object
• Learn the uses of the static keyword
• Examine how and why data can be associated with a class
• Learn what class or static methods are and where they are used
• Investigate the “this” keyword in Java and how it is used
• Survey the various scopes in Java
• Understand the purpose of garbage collection in Java and how it is managed
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
• simple, object-oriented, and familiar
• robust and secure
• architecturally neutral and portable (i.e., platform independent)
• interpreted, threaded, and dynamic
• high performing
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
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:
• The Java Virtual Machine (JVM)
• The Java Application Programming Interface (API)
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
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).
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.
Table of Contents
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.