Java Language Specification

This category is to learn and describe the concepts mentioned in the Java Language Specification.

Java 8 Date Time API Usage

Introduction Every effort we put in to showcase the extent of Java 8 Date Time API usage leaves us only scratching the surface of it. This post walks through a couple of examples and some standard methods that can be helpful in daily use. Timezone aspects are not covered in this post. Refer to this post to for an introduction to Java 8 Date Time API. Old And The New Let us see how date formatting code changes with the new Java 8 Date Time API. If you landed directly on this post, we recommend reading this introductory post first. [crayon-58ad0d0227730612519371/] Goodbye ThreadLocals and c...
Read More

Java 8 Date Time API

What ailed Date and Time handling in Java? The existing java.util.Date and SimpleDateFormat are mutable and not thread-safe, more often than not, leading to concurrency issues for users. Having to deal with this overhead is not welcoming for novice developers. Inconsistent API (months starting at 1 while days start at 0), no ability to handle Time alone, no utilities like plus/minus dates lead to popularity of libraries like joda-time. Many enterprise products use joda-time, when date/time usage and manipulation should have been provided by the language which was in it's 7th iteration (person...
Read More

Try With Resources in Java 7 and Above

Introduction Try with Resources in Java 7 and above allows for automatic closing of resources that implement java.lang.AutoCloseable or the more familiar java.io.Closeable (which extends AutoCloseable) Anyone through a basic Java course will be familiar with this block of code. Open a text file to write data and close it when done. [crayon-58ad0d02299d4058975318/] The method attempts to write to a file and throws any exception that hinders in achieving this. The finally block ensures that no file handle is left open by this method. But close() can throw an exception if closing the file f...
Read More

Introduction to Lambda Expressions – Java8

What are Lambda Expressions? Lambda expressions are another way of writing inline unnamed code block which performs a simple function. Not a direct analogy but if you recall anonymous classes in Java they are a way of writing inline classes. On similar lines Lambda expressions are a way to write method body inline. They can be considered as anonymous methods, there is no need to formally define these methods but the code in the lambda expression is the body of the method. Lambda Expression Example If I want to write a print method which prints the content of a List of strings which is pa...
Read More

Details of Class Loading in JVM

Have you ever seen a ClassNotFoundException or a NoClassDefFoundError? Did you ever face a situation where you are trying to cast and assign it to a compatible reference but it throws a ClassCastException ? Or did you face issues where you never understood where to put the jars in your application? Ever did any hot deployment on a running Application Server and wondered how the new changes get reflected without a server restart? Ever got confused with the process of Class Loading in JVM? If you didn't face any of these, then you are extremely lucky or you are yet to start development :)...
Read More

Java Virtual Machine Startup

In the last post we had a brief idea about the memory model of the Java Virtual Machine. We also came across certain terms like the Creation, Linking, Loading and Initialization of classes. In this post we will try to improve our understanding of all these terms. At the Java Virtual Machine Startup The JVM starts up by creating an initial class and loads it using the bootstrap class loader (we will learn about the class loader in another post). Some implementation of the JVM allow us to pass the name of the initial class using the command line. The JVM then links this initial class. L...
Read More

Memory Model of Java Virtual Machine

The Java Virtual Machine is an abstract computing machine. It is responsible for most of the features which made Java a great technology. Few of the major selling points of Java was: Platform Independence Hardware Independence Operating System Independence Security from malicious programs It is said to be abstract computing machine because it offers all the specification which if implemented properly can act as a machine to execute instructions. Sun Microsystems (now acquired by Oracle) offers an implementation of the JVM. The JVM understands a particular binary format wh...
Read More