Java Language Specification

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

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

Interface Declarations in Java

Introduction The previous post introduced Class Declarations in Java and it is the obvious next step to understand the Interface Declarations in Java after that. So, here is an insight to Interfaces in Java. Interfaces are considered as the way to achieve multiple inheritance in Java. We will certainly talk about that part in the coming sections. This post will introduce you to Interfaces and will also mention about the Annotations, which are different categories of interfaces and an important feature of the language. Multiple Inheritance Multiple Inheritance is a language construct w...
Read More

Class Declarations in Java

Introduction As promised here is the continuation of Understanding Java Classes. We will mostly discuss about the production rule for Class Declarations in Java. If you recall, in the previous post I mentioned about the below rule: NormalClassDeclaration: ClassModifiersopt class Identifier TypeParametersopt Superopt Interfacesopt ClassBody Do not worry, if you have no idea about what production rules of a grammar are. I will define them below and we do not need to know that as I will explain things in simple words. :) Dissecting the Production If you look at the above definition, we have...
Read More

Understanding Classes in Java

Introduction After gathering some insight into Java Reference Types in the previous posts, now understanding classes in Java has become easier. We need to understand how a Reference Type comes to existence and more. Apart from that we must also learn about Interfaces and Enums which are the building blocks of any written program. A Class in Java A class declaration defines a new reference type and describes its implementation. A class contains members which are enclosed in the body of the class. Members may also be inherited from a Super Class or Interfaces. A member can be a field, a...
Read More