Master any programming language fast

The Java Programming Language

Share
Like SyntaxCorect.com on Facebook
Be the first to rate this article

With billions of devices running software written in Java according to Oracle (its current owner), Java is a mature, well established and industry widely accepted technology that ranks between the most widely adopted computer programming languages of the world

Introduction

Note: While this article is about the Java programming language, often the Information Technology world designates with Java a set of specifications, software applications and development tools used to design, develop, deploy and run cross-platform software solutions, which means software applications that do not need to be recompiled for the specific computer system/architecture they run on.

The Java programming language is a computer programing language first appeared on the scene 24 years ago (on May 23, 1995). It is an high-level, general-purpose, statically typed, object-oriented, structured, imperative, generic, reflective, concurrent programming language with automatic memory management whose main purpose is to let developers write software programs only once and have them to be used/run everywhere without requiring neither modifications nor recompilation of the source codes. This concept is emphasized by the slogan "write once, run anywhere" (WORA) created by Sun Microsystems when the language invented by James Gosling (at the time working for the company) was deployed to the market.

The means by which software written in Java can run on many different hardware/software platforms are mainly two:

  1. both the language and the extensive buil-in libraries of the Java eco-system are specifically designed to have as few dependencies as possible on the hardwares and operating systems that host the Java applications.
  2. Java source code files are compiled to a virtual machine (Java Virtual Machine or JVM) istruction set (Java Bytecode) instead of the hosting hardware CPU instruction set, and the Java programs are executed by the virtual machine instead of the physical CPU, or can be recompiled to native CPU machine code on the fly by the JVM built-in Just-in-time (JIT) compiler for performance improvement while the program is already executing.

First glance at the code

Example: The classic "Hello world" program written in Java:

Main features of Java

Technical features

Statically typed

Java has a type system that is checked at compile time, which means that every variable has an explicit pre-assigned type and comes at run-time with the guarantee that the type of the values that can be assigned to that variable cannot be incompatible with the original type it has been pre-assigned. Object is the only type that can be used to obfuscate the effective type of a non primitive variable.

Java type system consists of primitives, classes, interfaces and enumerations and supports a compile-time-only version of generics.

For performance reason Java implements primitives the C/C++ way, meaning that variables of primitive types just store values. At the same time an automatic boxing/unboxing mechanism for primitive types is provided offering the programer the ability to use classes counterparts versions of the primitive types when desired.

Contrary to C/C++, Java primitive types have the same bits size on every platform, and they are:

Name Type Default value bits size
boolean true/false false 1 bit
byte twos complement integer 0 8 bits
char Unicode character \u0000 16 bits
short twos complement integer 0 16 bits
int twos complement integer 0 32 bits
long twos complement integer 0L 64 bits
float IEEE 754 floating point 0.0 32 bits
double IEEE 754 floating point 0.0 64 bits

Object-oriented

Java is object-oriented. A class can inherit characteristics and features from a single class, Object being the most basic class. Inheritance from multiple classes and from primitive types is not allowed. Classes can implement more than one interface.

Concurrent

The Java language has complete support and offers libraries and language costructs to allow the concurrent execution of multiple threads within the same application.

Memory management

Memory management in Java is automatic. A garbage collector at run-time provides to free the memory resources allocated for the object instances that become not reachable any more by any part of the running application.

Security

The Java language and its built-in libraries allows for the complete configuration of many security aspects of a running application. It's even possibile to run applications in sandboxed mode or to load classes with different classloaders in the same application. All these features have decreted the success of Java technologies on the server-side with a proliferation of server-side container-platforms most of which are also open source.

Performance

While in the beginning Java has usually been criticized for its sub-optimal run-time performance if compared to languages that compiles the source directly to machine code and run applications without virtual machines in between the code and the CPU, nowaday JVM implementations have reached an unparalled level of sofistication which results in very good run-time performance, finally comparable to those tipically achievable with applications written in C/C++.

Run-time support

Java software is tipically compiled to the Java Bytecode for the JVM to execute it. While this allows Java programas to run on any platform without the needing to compile the source code for every platform, it also means that the hosting platform can execute Java software only if a JVM is available for the platform.

Other features

Free and open source

In 2006 Sun Microsystems, the original Java creator, started the process to release Java as an open source platform. Java has been fully open source for many years now, and the reference implementation of any new standard version fo the whole platform is provided by OpenJDK. While not open source, Oracle specific JDK binaries are also available and usable most of the time for free both for commercial or open source projects.

Not only Java is open source, it also offers to developers the Java Community Process (JCP) for the development of standard technical specifications for Java technology. With the JCP any developer can review and provide feedback for all the hundreds of different Java specification requests. JCP membership requires an annual fee for organizations and commercial entities but is free for individuals.

Java huge community/ecosystem

As one of the most adopted programming language of the world Java has a strong and constantly growing community with a huge amount of libraries both proprietary and open source for almost anything that can be imagined, expecially for server side development. The wealth of tooling and IDEs is very good and the best products of this category are usually open source too like the Eclipse, NetBeans or IntelliJ IDEA Community Edition IDEs. Many server-side container platforms, database implementations or interfaces to databases are also available and open source.

Higher salary for Java programmers

According to the challengerocket.com ranking of projected earnings in 2017 by programming language, Java is at the very top of the list with an estimated annual salary for a Java programmer of $ 130,000 (USD). Other sources like codingdojo.com, techrepublic.com, infoworld.com and many others also rank Java programmers among the highest payed IT jobs.

Notable softwares/platforms/products written in Java

  • LinkedIn is primarily written in Java
  • Ebay architecture is implemented in Java
  • Amazon architecture is mainly written in Java
  • AliExpress is written in Java
  • Android, the most popular mobile OS of the world, is for the most part written in Java. Even if it's compiled to a different bytecode the language is Java
  • Google, Facebook, PayPal, Walmart and many other big companies adopt Java for many parts of their IT infrastructure

Conclusion

More than 20 years after its first release, Java still tops the TIOBE index as the most popular programming language of the world together with C. It's wide adoption is due to many of its features but two, as we see it, have been, and are still today, key: 1) Java is easy, very readable, and it's automatic memory management, while not new at the time of Java first release, became very popular exactly thanks to Java, all this without sacrificing the power of the language; 2) while the initial "write once, run anywhere" slogan from Sun Microsystems was for sure the classic marketing exaggeration, Java strong portability is one of its key strengths. Java software runs on everything from laptops to data center servers, from phones, game consoles and IoT devices to scientific supercomputers, all with almost no modification to the source code programmers write. If around 2000 it was already clear that Java was here to stay, today (2018) this is even more clear than ever.