What Java is?

Understanding Java as a technology

    Sun Microsystems developed the original specifications for the language in the mid 1990s. Patrick Naughton, Mike Sheridan, and James Gosling were the original inventors of Java and the language was called Oak at the beginning.

   Java is a full-fledged object-oriented programming language. It is platform independent and is normally interpreted rather than compiled like C/C++. It is syntactically and structurally modeled after C/C++ and performs various compile-time and run-time checking operations. Java performs automatic memory management that helps to greatly reduce the problem of memory leaks found in other languages and libraries that dynamically allocate memory.

   Java supports many features that, at its time of conception, were not found directly in other languages. These features include threading, networking, security, and Graphical User Interface (GUI) development. Other languages could be used to support these capabilities, but they were not integrated in the language to the extent that it was done with Java.

   Java uses an independent bytecode that is architecture neutral. That is, it is designed to be machine independent. The byte codes are interpreted and executed by a  Java Virtual Machine (JVM). All of its primitive data types are fully specified, as we will see in Chapter 3, Decision Constructs. The various releases of the Java Development Kit (JDK) and other significant moments are depicted in the following timeline diagram:

1

Object-oriented software development

   Let’s digress for a moment and consider why we are using Java at all. One of the most significant aspects of Java is that it is an object-oriented (OO) language. OO technologies are a popular paradigm for developing applications. This approach models an application around a series of real world objects, such as an employee or a ship. In order to solve a problem, it is useful to think of the real world objects that make up the problem domain.

The OO approach is based on three distinct activities:
    • Object Oriented Analysis (OOA): This is concerned with determining the functionality of the system, that is, what should the application do
    • Object Oriented Design (OOD): This is concerned with how the architecture supports the functionality of the application
    • Object Oriented Programming (OOP): This is concerned with the actual implementation of the application

   The products of the analysis and design steps are often referred to as analysis and design artifacts. While there may be several different types produced, the one of most interest to the OOP step is called the class diagram. The following diagram shows a partial class UML diagram depicting two classes:  Customer and CustomerDriver . In the A simple Java application section, we will examine the code for these classes. The Unified Modeling Language (UML) is a widely used OO technique used to design and document an application. A class diagram is one of the end products of the technique and is used by programmers to create the application:

2

Each box represents a class and is divided into three sections:

    • The first section at the top of the box is the name of the class
    • The second section lists the variables that make up the class
    • The last section lists the class methods

The symbols preceding the variable and method names specify the visibility of these class members. The following are the class diagram symbols used:

    • – : Private
    • + : Public
    • # : Protected (used with inheritance)

Normally, a class diagram consists of many classes and is interconnected with annotated lines showing the relationship between the classes.

The class diagram is intended to clearly show what objects make up the system and how they interact. Once a class diagram is complete it can be implemented using an OOP language such as Java.

The object-oriented approach is typically used for medium-scale to large-scale projects, where many developers must communicate, and work together, to create an application. For smaller projects involving only a few programmers, such as the one dealt with in most programming classes, the object-oriented approach is not normally used.

OPP principles

   While there is some disagreement in what actually makes a programming language an OOP programming language, there are generally three underlying principles that must be supported by an OOP language:

    • Data encapsulation
    • Inheritance
    • Polymorphism

   Data encapsulation is concerned with hiding irrelevant information from the users of a class and exposing the relevant. The primary purpose of data encapsulation is to reduce the level of software development complexity. By hiding the details of what is needed to perform an operation, the use of that operation is simpler. How to achieve data encapsulation in Java is explained in the Access modifiers section, later in this chapter.

   Data encapsulation is also used to protect the internal state of an object. By hiding the variables that represent the state of an object, modifications to the object are controlled through the methods. Any changes to the state are verified by the code in the methods. Also, by hiding variables, sharing of information between classes is eliminated. This reduces the amount of coupling possible in an application.

   Inheritance describes the relationship between two classes such that one class reuses the capabilities of another class. This enables the re-use of software resulting in a more productive developer. Inheritance is covered in detail in Chapter 7, Inheritance and Polymorphism.

   The third principle is polymorphism and its primary concern is to make the application more maintainable and extendable polymorphism behavior is where the behavior of one or identical methods is dependent upon the object it is executing against. For example, a person object and a square object can both have a draw method. What it draws depends on the object the method is executed against. Polymorphism is discussed in Chapter 7, Inheritance and Polymorphism.

   These principles are summarized in the following table:

3

   The implements keyword is used in support of polymorphic behavior as is
explained in Chapter 7, Inheritance and Polymorphism.


Chapter 1: Getting Started with Java
Chapter 2: Java Data Types and Their Usage.
Chapter 3: Decision Constructs
Chapter 4: Using Arrays and Collections
Chapter 5: Looping Constructs
Chapter 6: Classes, Constructors, and Methods
Chapter 7, Inheritance and Polymorphism
Chapter 8: Handling Exceptions in an Application
Chapter 9: The Java Application

Leave a comment