Monday, June 13, 2022

Java SE overview

The JVM is the great platform on which our Clojure programs are run. In order to have a thorough familarity with Clojure, it is necessary to also have expertise with the Java platform. The Java virtual machine (JVM) and the Java programming language are quite simple, so expertise with Java comes from understanding the Java libraries. In order to make sense of the vast Java SE API, Oracle distinguishes between three classes of libraries in its documentation:
  • Base libraries
  • Integration libraries
  • Desktop libraries
The tripartite division of Java SE is then typically expanded in a conceptual diagram, updated below to deal with the modularisation of the JDK. This conceptual diagram is our first overview of Java SE.

Swing Java 2D AWT
Image I/O Sound Print service
JDBC RMI JDNI Scripting
XML HTTP XML Cryptography Security
JMX Instrumentation Compiler Networking
Preferences Logging I/O Compression
Lang Util Reflection Concurrency

In order to get an overview of Java SE and its vast functionality, we will consider a number of conceptual approaches to organizing knowledge about its API. In doing so, we can make better sense of the functionality made available to JVM languages.

Hardware overview

Computer science is about transforming reality. The objects of transformation are hardware devices. Hardware is the foundation of computer science, so that is a good place to start. The Java SE API contains means of interacting with a wide variety of hardware devices: CPUs, hard disks, networking devices, sound cards, speakers, monitors, MIDI devices, keyboards, mouses, printers, etc. In short, it contains the means of interacting with all standard hardware devices.

Processors

To begin with a program needs to interact with its processor. Historically, each program was written in the native assembly language of the computer it run on and compilers weren't that good. Of course, such programs weren't portable because CPUs have minor technical differences which prevent you from porting a program from one machine architecture to another.

At the same time, processors were not designed with developers in mind. Most processors have a low level architecture which is not suitably friendly to developers. Processors are low level devices with minor technical differences to one another. The Java virtual machine (JVM) solves this problem by introducing a universal high level abstraction layer over the CPU.

This wouldn't have been possible with the technology of the past. The JVM relies on the most advanced and modern advancements in compiler technology for its implementation. The JVM has the most advanced optimisations and a compiler architecture. The JVM is now the most perfectly engineered software in the world, with countless hours put into perfecting every line of its code.

Storage devices:

The distinction between RAM and hard drives in most modern computing devices means that we need special mechanisms for dealing with storage devices. In Java this is handled by the I/O classes, which can actually be used to handle a wide variety of different types of external hardware. Towards that end, Java I/O defines input stream and output stream classes.

The input stream and output stream define the sequential access to bytes. These general purpose classes can be used to handle interaction with all kinds of external devices. In addition to this, Java provides the Serializable mechanism which helps you handle storage devices by taking objects in RAM and converting them to a form they can be stored in.

Storage devices are typically organized by file systems. In order to interact with them, you need to be able to interact with the file system. The Java IO package provides the File class in order to handle such files in the file system. Given a File you can form a FileInputStream or a FileOutputStream to read or write from it. With this it becomes rather easy to transfer memory stored in RAM to a storage device.

Networking devices

The Java platform was designed from the start to handle networking applications. This support is embodied by the classes of the java.net package. With this builtin networking API you can communicate via TCP/IP sockets or UDP sockets over the internet. UDP is distinguished by the fact that it is connectionless, which means that you have no guarantee that the data will alive. A connectionless protocol is going for example for live feeds.

The Java networking API handles communication between machines with sockets. A socket is an endpoint for communication between two machines. Sockets are handled by using the same I/O routine streams used on local storage devices, which can be acquired by the getInputStream and getOutputStream methods. These methods let you communicate streams of bytes over a network.

The Java SE API also includes support for distributed computing, as provided by the RMI (remote method invocation) module. The RMI module builds on the Java networking API and sockets in order to allow for you to communicate with external machines. Separately, the Java SE API provides support for HTTP, the hypertext transfer protocol. Finally, Java enables distributed computing with the JDNI API for handling naming and directory services.

Sound devices

The Java SE API contains separate packages for sampled audio and MIDI devices. The sampled audio API is centered on the AudioSystem class. Using this you can get an audio input stream for a sound file (WAV, AIFF, or AU) and a Clip that can play it. By associating a Clip with an audio input stream, you can play that audio either once or on repeat.

On the other hand, Java SE provides support for MIDI (musical instrument device interface). You can use this package to generate the sounds of a piano for example. It is generally easier to generate music with MIDI then using sampled audio. Interaction with MIDI goes through the MidiSystem class. Combined with the sampled audio package, this provides everything you need to write code for audio devices.

Printers

The Java SE API includes a number of packages specifically for handling printing devices. The first, java.awt.print was created with the Java 2D API. It lets you handle printing devices by using the Java 2D API. The Printable interface provides a print method, which takes in a Graphics object, this way you can handle the printer using the graphics API.

In addition, this the Java Print service is defined by a number of packages including javax.print. This API includes an extensible print attribute set based upon the internet printing protocol. This allows you to discover and select printers in the network based upon their capabilities. In addition, the Java Print service event API lets you register for events in the process of running a print job.

Graphical devices

The Java SE API comes equipped with a full set of 2D graphics programming functionality: it contains geometry, compositing, painting and stroking, fonts, colors, text layouts, clipping, rendering hints, transformations, image processing, and so on. These functionalities can be accessed by using the Graphics2D class. Further, the GraphicsDevice class lets you directly model one or model graphics devices in your environment.

One of the more advanced uses of graphics in Java SE is its support for graphical user interfaces (GUIs), which is defined by Swing. Using the Java 2D API and Swing you can define your own JComponents that have their own custom graphics, which enables you to create rich graphical applications using Java SE. In addition, Swing comes with a wide variety of premade widgets. All this is to enable you to create rich graphics applications using Java SE.

Modules overview

As Java SE evolved over time it got so vast, that it certainly required modularisation to make its vast API more handlable. The modularisation of the JDK was achieved with Java SE 9. With this we have an alternative perspective on the structure of Java SE API. The APIs of Java SE are grouped into a partially ordered set of modules: This produces an alternative overall perspective on the Java SE API then the earlier conceptual diagrams. The following observations can be made:
  • The desktop module depends upon XML. The reason for this is the Java beans package of the desktop module which includes the XMLEncoder and XMLDecoder classes. These classes let you encode Swing applications as XML trees. It also depends upon data transfer, which was originally part of the AWT and considered a desktop library but it was moved to its own module so other modules could use it without bringing in the entire desktop module.
  • The XML cryptography module depends upon the XML module. Basically, XML cryptography is a direct extension of the functionality provided by the XML module, but its moved to its own module because the XML module is already big enough as it is.
  • The management RMI module depends upon both management and RMI. It is a direct combination of Java's management and RMI facilities.
  • SQL depends upon XML, logging, and the Java transaction API. The SQL rowset API also depends upon naming. The SQL APIs depend upon on a lot of other things.
  • Everything depends upon the base module, which contains the lang package and the indispensible APIs of the Java platform.
Aside from these basic observations, the Java SE module graph is basically flat. Most modules only depend upon the base module, and the other cases we have explained above. While it takes more to understand the Java SE API, this module graph is another way to get a good perspective on it.

Classes overview

While modules provide a high level overview of the Java SE platform, classes provide a much more direct overview. We will therefore consider Java SE from a class based perspective.

Class based programming

The central concept of the Java platform is the idea of a class. Everything in Java is a class. An interface, for example, is simply a class with a flag set to declare that it is meant to be treated as an interface. All classes are encoded in the class file format of the Java virtual machine. So Java SE can be considered to be a vast set of classes.

Classes provide the best means of modeling concepts and creating programs. In particular, classes provide the best means of interacting with hardware devices. Given some hardware device, you can always create a class to represent it like the GraphicsDevice of the Java SE API. The class based approach is key to the success of the Java platform.

Classes in the Java SE API

With this perspective in mind, the Java SE API can be considered to be a vast array of thousands of different classes dealing with all kinds of different types of programming purposes and modeling a wide array of concepts from server sockets to currencies. The Java SE API has a class for everything.

The classes in Java SE form all together vast partial order based upon implementation and inheritance. Classes provide single inheritance while interfaces define multiple inheritances. So if you include interfaces, then the class system is a general partial order and not a tree. As Java SE contains thousands of classes, this contains many more relations then the modules.

Conceptual overview

The conceptual overview of Java divides the platform into three different basic types of modules: integration libraries, desktop libraries, and base libraries.
  • Base libraries
    • Base
    • Compiler API
    • Instrumentation
    • Management
    • Logging
    • Preferences
    • Networking
      • HTTP
    • Security
      • SASL
      • GSS
    • XML libraries
      • XML
      • XML cryptography
  • Integration libraries
    • Scripting
    • Databases
      • SQL
      • Distributed transactions
      • Row sets
    • Distributed computing
      • RMI
      • Management RMI
      • JDNI
  • User interface libraries
    • Desktop
    • Data transfer
Conceptualy, many modules like SQL and XML have specialized purposes that are not necessary in all applications. With the modularisation of the JDK, you can now specify only the parts of the Java SE API that you need. With all this functionality built in, there is a lot for you that is readily available.

Previously
Java base libraries

Java integration libraries

Java desktop libraries

No comments:

Post a Comment