Java: An introduction

Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.

A general-purpose programming language made for developers to write once run anywhere that is compiled Java code can run on all platforms that support Java. Java applications are compiled to byte code that can run on any Java Virtual Machine.

Features of Java

  1. Platform Independent: Compiler converts source code to bytecode and then the JVM executes the bytecode generated by the compiler. This bytecode can run on any platform be it Windows, Linux, macOS which means if we compile a program on Windows, then we can run it on Linux and vice versa. Each operating system has a different JVM, but the output produced by all the OS is the same after the execution of bytecode. That is why we call java a platform-independent language.
  2. Object-Oriented Programming Language: Organizing the program in the terms of collection of objects is a way of object-oriented programming, each of which represents an instance of the class.
  3. Simple: Java is one of the simple languages as it does not have complex features like pointers, operator overloading, multiple inheritances, Explicit memory allocation.
  4. Robust: Java language is robust that means reliable. It is developed in such a way that it puts a lot of effort into checking errors as early as possible, that is why the java compiler is able to detect even those errors that are not easy to detect by another programming language. The main features of java that make it robust are garbage collection, Exception Handling, and memory allocation.
  5. Secure: In java, we don’t have pointers, and so we cannot access out-of-bound arrays i.e it shows ArrayIndexOutOfBoundsException if we try to do so. That’s why several security flaws like stack corruption or buffer overflow are impossible to exploit in Java.
  6. Distributed: We can create distributed applications using the java programming language. Remote Method Invocation and Enterprise Java Beans are used for creating distributed applications in java. The java programs can be easily distributed on one or more systems that are connected to each other through an internet connection.
  7. Multithreading: Java supports multithreading. It is a Java feature that allows concurrent execution of two or more parts of a program for maximum utilization of CPU.
  8. Portable: As we know, java code written on one machine can be run on another machine. The platform-independent feature of java in which its platform-independent bytecode can be taken to any platform for execution makes java portable.

Let’s begin from scratch!

import java.io.*;class intro {public static void main(String[] args){// prints Hello WorldSystem.out.println("Hello World");}}

Executing the program

javac intro.javajava intro

Variables in Java

  • A Variable is a named field containing information that the Java program uses.
  • Variables can also be thought of as the name of the memory location where the value is stored.
  • In Java, a variable has to be declared before it is used in the program. Variables are declared as type variable = value;.
  • Now, depending on the value it takes, we need to mention the type of variable. Which cannot be changed in the program.
  • For example, int x = 10; declares a variable ‘x’ of type ‘int’ and holds a value 10 which can be changed later in the program.

Introduction to types

  • Along with variables we have constants whose values do not change.
  • While we can change the value that a variable stores.
  • Every variable and constant belongs to a certain type.
  • This segregation is necessary so as to define operations that can be performed on them.
  • For example, the division of two bool values(if allowed) would not yield any useful results.

Primitive Datatypes

  • These are pre-built or defined by programming languages.
  • The size of values is fixed.
  • The size of the variable depends on the type.
  • Are handled by actual constant values.
  • Can only be passed by value to methods.

Non-Primitive Datatypes

  • These types are created by programmers and are not defined by java (except for string)
  • The size of values can vary.
  • The size of any variable is the same.
  • Are handled by reference.
  • Can only be passed by reference to
    methods.

Arrays

  • Array in Java is a group of like typed variables.
  • The array can contain primitives as well as to object references of a class depending on the definition.
  • An array is declared as type var_name[ ]; or type[ ] var_name;.
  • The above declaration only signifies that var_name contains an Array of type, but no memory is allocated.
  • To actually link an array of integers, one must allocate using a new keyword. This is done as var_name = new type[size];
  • In Java, all Arrays are dynamically allocated.
  • Array elements can be accessed using the [ ] operator.

Strings

  • The String type is used to declare string variables.
  • You can also declare arrays of strings.
  • A quoted string constant can be assigned to a String variable.
  • A variable of type String can be assigned to another variable of type String.
  • You can use an object of type Strings an argument to println( ).
String str = “This is Group 25”;System.out.println(str);

Type Casting

  • When we assign a variable of type1 a value of type2, the value needs to be converted so as to fit the type1.
  • This is Known as Type-casting.
  • Only numeric data types can be typecast into each other.

Class- Defining custom data types

  • A class is a data type in Java that defines a template or blueprint for an object.
  • A class refers to the category or type of object. A class allows you to declare custom data types.
  • For example, you can define a class cat or car or savings accounts to store objects of specific types.
  • A class has variables defining properties and methods defining the behavior of its objects.

Class Syntax

Interface

An interface in Java is used to specify the contract or capabilities that
implementing classes must implement. An interface has abstract
methods, with only signatures, which are then implemented by some
classes. For example, every corporate department may implement
the Security Interface.

interface Security{boolean accessCheck(String employeeToken);}

Collections in Java

Collections in Java is a framework that provides an architecture to store data. It can be compared with Standard Template Library in C++ and serves similar purpose. Java Collection provides interfaces like Set, List, Queue, Deque. Implements containers like ArrayList, Vector, PriorityQueue, etc. It provides various way to store data and algorithms to manipulate them as per
need. Provides an iterator interface, used to iterate over elements in single direction.

Evolution of Java

JDK 1.0

The first version was released on January 23, 1996. The first stable version, JDK 1.0.2, is called Java 1.

JDK 1.1

Major additions in the release on February 19, 1997 included:

  • An extensive retooling of the AWT event model
  • inner classes added to the language
  • JavaBeans
  • JDBC
  • RMI
  • the reflection which supported Introspection only, no modification at runtime was possible. (The ability to modify objects reflectively was added in J2SE 1.2, by introducing the AccessibleObject class and its subclasses such as the Field class.)
  • JIT (Just In Time) compiler on Microsoft Windows platforms, produced for JavaSoft by Symantec
  • Internationalization and Unicode support originating from Taligent

J2SE 1.2

Codename Playground

The release on December 8, 1998 and subsequent releases through J2SE 5.0 were rebranded retrospectively Java 2 and the version name “J2SE” (Java 2 Platform, Standard Edition) replaced JDK to distinguish the base platform from J2EE (Java 2 Platform, Enterprise Edition) and J2ME (Java 2 Platform, Micro Edition). This was a very significant release of Java as it tripled the size of the Java platform to 1520 classes in 59 packages. Major additions included:

  • strictfp keyword
  • the Swing graphical API was integrated into the core classes
  • Sun’s JVM was equipped with a JIT compiler for the first time
  • Java plug-in
  • Java IDL, an IDL implementation for CORBA interoperability
  • Collections framework

J2SE 1.3

Codename Kestrel

The most notable changes in the May 8, 2000 release were:

  • HotSpot JVM included (the HotSpot JVM was first released in April 1999 for the J2SE 1.2 JVM)
  • RMI was modified to support optional compatibility with CORBA
  • Java Naming and Directory Interface (JNDI) included in core libraries (previously available as an extension)
  • Java Platform Debugger Architecture (JPDA)
  • JavaSound
  • Synthetic proxy classes

J2SE 1.4

Codename Merlin

The February 6, 2002 release was the first release of the Java platform developed under the Java Community Process as JSR 59. Major changes included:

  • Language changes
  • assert keyword (specified in JSR 41)
  • Library improvements
  • Regular expressions modeled after Perl regular expressions
  • Exception chaining allows an exception to encapsulate original lower-level exception
  • Internet Protocol version 6 (IPv6) support
  • Non-blocking I/O (Java) (named NIO) (specified in JSR 51)
  • Logging API (specified in JSR 47)
  • Image I/O API for reading and writing images in formats like JPEG and PNG
  • Integrated XML parser and XSLT processor (JAXP) (specified in JSR 5 and JSR 63)
  • Integrated security and cryptography extensions (JCE, JSSE, JAAS)
  • Java Web Start included (Java Web Start was first released in March 2001 for J2SE 1.3) (specified in JSR 56)
  • Preferences API (java.util.prefs)

J2SE 5.0

Codename Tiger

The release on September 30, 2004 was originally numbered 1.5, which is still used as the internal version number. The number was changed to “better reflect the level of maturity, stability, scalability and security of the J2SE”. This version was developed under JSR 176.

J2SE 5.0 entered its end-of-public-updates period on April 8, 2008; updates are no longer available to the public as of November 3, 2009. Updates were available to paid Oracle customers until May 2015.

Tiger added a number of significant new language features:

  • Generics: provides compile-time (static) type safety for collections and eliminates the need for most typecasts (type conversion) (specified by JSR 14)
  • Metadata: also called annotations; allows language constructs such as classes and methods to be tagged with additional data, which can then be processed by metadata-aware utilities (specified by JSR 175)
  • Autoboxing/unboxing: automatic conversions between primitive types (such as int) and primitive wrapper classes (such as Integer) (specified by JSR 201)
  • Enumerations: the enum keyword creates a typesafe, ordered list of values (such as Day.MONDAY, Day.TUESDAY, etc.); previously this could only be achieved by non-typesafe constant integers or manually constructed classes (typesafe enum pattern) (specified by JSR 201)
  • Varargs: the last parameter of a method can now be declared using a type name followed by three dots (e.g. void drawtext(String... lines)); in the calling code any number of parameters of that type can be used and they are then placed in an array to be passed to the method, or alternatively the calling code can pass an array of that type
  • Enhanced for each loop: the for loop syntax is extended with special syntax for iterating over each member of either an array or any Iterable, such as the standard Collection classes (specified by JSR 201)
  • Improved semantics of execution for multi-threaded Java programs; the new Java memory model addresses issues of complexity, effectiveness, and performance of previous specifications
  • Static imports

There were also the following improvements to the standard libraries:

  • Automatic stub generation for RMI objects
  • Swing: New skinnable look and feel, called synth
  • The concurrency utilities in package java.util.concurrent
  • Scanner class for parsing data from various input streams and buffer.

Java SE 6

Codename Mustang

As of the version released on December 11, 2006, Sun replaced the name “J2SE” with Java SE and dropped the “.0” from the version number. Internal numbering for developers remains 1.6.0.

This version was developed under JSR 270.

During the development phase, new builds including enhancements and bug fixes were released approximately weekly. Beta versions were released in February and June 2006, leading up to a final release that occurred on December 11, 2006.

Major changes included in this version:

  • Support for older Win9x versions dropped; unofficially, Java 6 Update 7 was the last release of Java shown to work on these versions of Windows.[citation needed] This is believed[by whom?] to be due to the major changes in Update 10.
  • Scripting Language Support (JSR 223): Generic API for tight integration with scripting languages, and built-in Mozilla JavaScript Rhino integration.
  • Dramatic performance improvements for the core platform, and Swing.
  • Improved Web Service support through JAX-WS (JSR 224).
  • JDBC 4.0 support (JSR 221).
  • Java Compiler API (JSR 199): an API allowing a Java program to select and invoke a Java Compiler programmatically.
  • Upgrade of JAXB to version 2.0: Including integration of a StAX parser.
  • Support for pluggable annotations (JSR 269).
  • Many GUI improvements, such as integration of SwingWorker in the API, table sorting and filtering, and true Swing double-buffering (eliminating the gray-area effect).
  • JVM improvements include: synchronization and compiler performance optimizations, new algorithms and upgrades to existing garbage collection algorithms, and application start-up performance.

Java SE 7

Java 7 (codename Dolphin) is a major update that was launched on July 7, 2011 and was made available for developers on July 28, 2011. The development period was organized into thirteen milestones; on June 6, 2011, the last of the thirteen milestones was finished. On average, 8 builds (which generally included enhancements and bug fixes) were released per milestone. The feature list at the OpenJDK 7 project lists many of the changes.

Additions in Java 7 include:

  • JVM support for dynamic languages, with the new invokedynamic bytecode under JSR-292, following the prototyping work currently done on the Multi Language Virtual Machine
  • Compressed 64-bit pointers (available in Java 6 with -XX:+UseCompressedOops)
  • These small language changes (grouped under a project named Coin):
  • Strings in switch
  • Automatic resource management in try-statement
  • Improved type inference for generic instance creation, aka the diamond operator <>
  • Simplified varargs method declaration
  • Binary integer literals
  • Allowing underscores in numeric literals
  • Catching multiple exception types and rethrowing exceptions with improved type checking
  • Concurrency utilities under JSR 166
  • New file I/O library (defined by JSR 203) adding support for multiple file systems, file metadata and symbolic links. The new packages are java.nio.file, java.nio.file.attribute and java.nio.file.spi
  • Timsort is used to sort collections and arrays of objects instead of merge sort
  • Library-level support for elliptic curve cryptography algorithms
  • An XRender pipeline for Java 2D, which improves handling of features specific to modern GPUs
  • New platform APIs for the graphics features originally implemented in version 6u10 as unsupported APIs
  • Enhanced library-level support for new network protocols, including SCTP and Sockets Direct Protocol
  • Upstream updates to XML and Unicode
  • Java deployment rule sets

Java SE 8

Java 8 was released on March 18, 2014, and included some features that were planned for Java 7 but later deferred.

Work on features was organized in terms of JDK Enhancement Proposals (JEPs).

  • JSR 335, JEP 126: Language-level support for lambda expressions (officially, lambda expressions; unofficially, closures) under Project Lambda and default methods (virtual extension methods) which allow the addition of methods to interfaces without breaking existing implementations. There was an ongoing debate in the Java community on whether to add support for lambda expressions. Sun later declared that lambda expressions would be included in Java and asked for community input to refine the feature. Supporting lambda expressions also enables functional-style operations on streams of elements, such as MapReduce-inspired transformations on collections. Default methods allow an author of an API to add new methods to an interface without breaking the old code using it. Although it was not their primary intent, default methods also allow multiple inheritance of behavior (but not state).
  • JSR 223, JEP 174: Project Nashorn, a JavaScript runtime which allows developers to embed JavaScript code within applications
  • JSR 308, JEP 104: Annotation on Java types
  • Unsigned integer arithmetic
  • JSR 337, JEP 120: Repeating annotations
  • JSR 310, JEP 150: Date and time API
  • JEP 178: Statically-linked JNI libraries
  • JEP 153: Launch JavaFX applications (direct launching of JavaFX application JARs)
  • JEP 122: Remove the permanent generation

Java SE 9

Java SE 9 was made available on September 21, 2017, due to controversial acceptance of the current implementation of Project Jigsaw by Java Executive Committee, which led Oracle to fix some open issues and concerns, and to refine some critical technical questions. In the last days of June 2017, Java Community Process expressed nearly unanimous consensus on the proposed Module System scheme.

  • JSR 376: Modularization of the JDK under Project Jigsaw (Java Platform Module System)
  • JavaDB was removed from JDK
  • JEP 193: Variable handles : define a standard means to invoke the equivalents of various java.util.concurrent.atomic and sun.misc.Unsafe operations
  • JEP 213: Milling Project Coin : Allow @SafeVarargs on private instance methods; Allow effectively-final variables to be used as resources in the try-with-resources statement; Allow diamond with anonymous classes if the argument type of the inferred type is denotable; Complete the removal, begun in Java SE 8, of underscore from the set of legal identifier names; Support for private methods in interfaces
  • JEP 222: jshell: The Java Shell (Read-Eval-Print Loop) : JShell is a REPL command-line interface for the Java language.
  • JEP 254: Compact Strings
  • JEP 263: HiDPI graphics: automatic scaling and sizing
  • JEP 266: More concurrency updates : It includes a Java implementation of Reactive Streams, including a new Flow class that included the interfaces previously provided by Reactive Streams
  • JEP 268: XML catalogs
  • JEP 282: jlink: The Java Linker : create a tool that can assemble and optimize a set of modules and their dependencies into a custom run-time image. It effectively allows to produce a fully usable executable including the JVM to run it
  • JEP 295: Ahead-of-Time Compilation : Ahead-of-time compilation provided by GraalVM.

Java SE 10

OpenJDK 10 was released on March 20, 2018, with twelve new features confirmed. Among these features were:

  • JEP 286: Local-Variable Type Inference
  • JEP 296: Consolidate the JDK Forest into a Single Repository
  • JEP 304: Garbage-Collector Interface
  • JEP 307: Parallel Full GC for G1
  • JEP 310: Application Class-Data Sharing
  • JEP 312: Thread-Local Handshakes
  • JEP 313: Remove the Native-Header Generation Tool (javah)
  • JEP 314: Additional Unicode Language-Tag Extensions
  • JEP 316: Heap Allocation on Alternative Memory Devices
  • JEP 317: Experimental Java-Based JIT Compiler
  • JEP 319: Root Certificates
  • JEP 322: Time-Based Release Versioning

Java SE 11

JDK 11 was released on September 25, 2018 and the version is currently open for bug fixes. It offers LTS, or Long Term Support. Among others, Java 11 includes a number of new features, such as:

  • JEP 181: Nest-Based Access Control
  • JEP 309: Dynamic Class-File Constants
  • JEP 315: Improve Aarch64 Intrinsics
  • JEP 318: Epsilon: A No-Op Garbage Collector
  • JEP 320: Remove the Java EE and CORBA Modules
  • JEP 321: HTTP Client (Standard)
  • JEP 323: Local-Variable Syntax for Lambda Parameters
  • JEP 324: Key Agreement with Curve25519 and Curve448
  • JEP 327: Unicode 10
  • JEP 328: Flight Recorder
  • JEP 329: ChaCha20 and Poly1305 Cryptographic Algorithms
  • JEP 330: Launch Single-File Source-Code Programs
  • JEP 331: Low-Overhead Heap Profiling
  • JEP 332: Transport Layer Security (TLS) 1.3
  • JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
  • JEP 335: Deprecate the Nashorn JavaScript Engine
  • JEP 336: Deprecate the Pack200 Tools and API

A number of features from previous releases were dropped; in particular, Java applets and Java Web Start are no longer available. JavaFX, Java EE and CORBA modules have been removed from JDK

Java SE 12

JDK 12 was released on March 19, 2019. Among others, Java 12 includes a number of new features, such as:[340]

  • JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
  • JEP 230: Microbenchmark Suite
  • JEP 325: Switch Expressions (Preview)
  • JEP 334: JVM Constants API
  • JEP 340: One AArch64 Port, Not Two
  • JEP 341: Default CDS Archives
  • JEP 344: Abortable Mixed Collections for G1
  • JEP 346: Promptly Return Unused Committed Memory from G1

Thus, we’ve managed to curate a blog on the topic of Datatypes in Java including the version history as well.

Authors: Aniruddha Kulkarni, Nikhilesh Joshi, Aditya Jaiswal, Sarthak Jaiswal, Sanika Jade.