Introducing Java
Estimated time to read: 4 minutes
Overview of the benefits of Java¶
- Write once, run anywhere (WORA)
- Develop object-oriented solutions
- C/C++ based syntax
- Rich library support
- Security
- Internationalisation
- High Performance
Key Benefits¶
WORA (Write once, run anywhere)¶
The benefit of WORA means that an application can be written on one type of platform, but then can be run on any other platform.The code is compiled into an 'intermediate format' called architecture-neutral byte-code. A Java application is run on a Java Virtual Machine, this processes the byte-code of the application into machine code through the use of a JIT (Just-in-time) compiler.
Packages¶
Classes are organised into packages. Packages are like standard directories, however, they are Java's platform-neutral version. They contain files and folders.
Just as Windows directories are separated by a backslash, the 'nodes' of a Java package structure are separated by a dot, eg
Windows: C:\learnquest\calculator\util
Java: package com.learnquest.calculator.util:
Each part of the 'node' is classed as a child directory.
Java programmes often use dozens, even hundreds, of individual files. Packages can be used to meaningfully group these files together, whilst also avoiding name collisions.
The standard is to use your domain name, revered, the start the package directory name.
io.entityfour.app.name
com.google.app.name
C/C++ Syntax¶
Developed by Sun in the early 90's Java intestinally borrowed the syntax and data types from C/C++ as it was developed to enable familiarity within the language.
Int, Float, Doubles are known as primitives, as they are acquired from C. Non-Object data types are call primitives or built-in types.
Java includes a data type wrapper for many C/C++ primitives. Exception handling is borrowed from C++ Many statements, keywords and operators are taken from C
Rich Library Support¶
Java provides a comprehensive set of libraries as part of the standard distribution.
These offerings are enhanced with a huge selection of reliable and supported open source libraries.
This is akin to PIP (Python), nuget (C#), etc
Library Standards¶
The Java Community Process (JCP) defined the specification of the API; Interfaces and required behaviours.
Designed to enhance portability by promoting vendor independence.
Standards-compliant vendors are expected to support this required behaviour but the standard will generally not specify how it should be implemented.
A 'TCK' will be released alongside standards to enable testing and thus compliance with standards.
Extensive Documentation¶
There is extensive documentation for Java.
This can be produced following the 'javadoc' standard, which standardises how classes are documented.
Database Connectivity¶
One of the major areas that Java has support for is database connectivity through the JDBC (Java DataBase Connectivity) suite of packages. This is included in the java.sql package, which is part of the standard distribution and java.x within the EE distribution.
The package facilitates database-neutral interaction with a relational database. JDBC brings the WORA approach to SQL database development. The JDBC package includes a driver which interfaces with the relevant database.
SQL strings and queries, however, must still support the backend that is being connected to.
The application only cares about the Java SQL connection, the Vendor provides an implementation of the interface. Above, MySQL provides the implementation so that the application can talk to the database.
Security¶
There are many layers of security built in to Java. Primarily, the byte-code verifier ensures that that byte-code in the compiler and that is about to be executed by the JRE, has no violations and is valid.
Java programs now run with client-specified security settings that give them specified degrees of access to local resources.
Internationalsation¶
Java uses Unicode. It stores all character data in the 16-bit Unicode standard. (This covers both the phonetic and ideographic character sets of the entire world.)
It also includes, in the standard library, the ability to store via key/value pairs in files; the identifier for a message and the locale specific value of that message.
This means that translations are easy to do.
Identifiers can be used to reference strings within the application, so that the correct locale can be applied by Java.
Performance¶
Initial releases of Java were originally slow. However, enhancing Java performance has been a key feature of the later JRE releases.
As of 2020, thanks to many performance gains, Java is now equitable in speed to native code and potentially exceeded it! As the JIT and JVM can apply tricks whilst the application is running to ensure best performance.
Licensing¶
Java, itself, is not open source but private. It has commercial licensing available and is based on a royalty-free basis.
There are however open source implementations of Java which adhere to the JCP standards and are released under the GPL. Alternatives to Java include, but are not limited to, OpenJDK.
"Java was originally developed by James Gosling at Sun Microsystems and released in May 1995 as a core component of Sun Microsystems' Java platform. The original and reference implementation Java compilers, virtual machines, and class libraries were originally released by Sun under proprietary licenses. As of May 2007, in compliance with the specifications of the Java Community Process, Sun had relicensed most of its Java technologies under the GPL-2.0-only license. Oracle offers its own HotSpot Java Virtual Machine, however the official reference implementation is the OpenJDK JVM which is free open-source software and used by most developers and is the default JVM for almost all Linux distributions."