What is a monad?: A monad is a design pattern concept used in mostly functional programming languages like lisp or in the modern world clojure or scala. (I would in fact copy a few things from scala.) Now why is it becoming important in java? Because java has got its new lambda feature from version 8. Lambda or closure is a functional programming feature. It allowes you to use code blocks as variables and lets you pass it around as such. I have discussed about Java's 'Project Lambda' in my previous article What's Cooking in Java 8 - Project Lambda. You can now try it out on JDK 8 preview release available in here. Now could we do monads before Java 8? Sure, after all Java's lambda is semantically just another way of implementing an interface (Its not actually that because the compiler knows where its being used), but it would be a lot messier code which would pretty much kill its utility.
Saturday, February 22, 2014
Sunday, April 1, 2012
What's Cooking in Java 8 - Project Jigsaw
What is Project Jigsaw: Project Jigsaw is the project to make the java compiler module aware. For years java API has been monolithic, i.e. the whole API was seen from any part of the code equally. There has also not been any way to declare a code's dependency on any other user libraries. Project Jigsaw attempts to solve these problems along with others in a very eligant way. In this article, I will highlight the basic concepts of Jigsaw module systems and also explain how it would work with the commands so as to provide a real feel of it. Currently, Jigsaw is targetted to be included in the release of Java 8. In my opinion, this is a change bigger than generics that came with verion 5 of java platform.
Wednesday, January 25, 2012
What's Cooking in Java 8 - Project Lambda
What is project lambda: Project lambda is the project to enable lambda expressions in java
language syntax. Lambda expressions are major syntax in functional programming languages like lisp. Groovy would be the closest relative
of java that has support for lambda expressions, also known as closures.
Sunday, November 20, 2011
Java Generics Capture Conversion
Introduction: Earlier in my article Java Compile Time Method Binding
I had promised to explain how type arguments are inferred during invocation of a generic method. However, that would not be of that use without
learning how capture conversion works first. So what is capture conversion. Capture conversion is the type conversion when a reference of
a generic type is created by passing the type parameters. Its not really that complicated. But it still does require some attention. Note that
capture conversion is only required for compile time type checking, nothing is there in the compiled code and nothing happens at runtime.
Saturday, October 22, 2011
Java Compile Time Method Binding
Introduction: It appears to be a simple process to determine which method a particular
method invocation refers to, but it still needs pages of documentation in the java language specification to address this, especially
to take care of auto-boxing/auto-unboxing and variable arguments. In this article, I will highlight how an actual method is bound at compile
time to a particular method invocation.
Thursday, October 13, 2011
Manipulating Java Class Files with ASM 4 - Part Two: Tree API
What is ASM tree API: ASM Tree API is the part of ASM that lets you
create/modify the class in memory. The class is viewed as a tree of information. Like the whole
class is an instance of ClassNode, which contain a list of FieldNode objects, a list of MethodNode objects etc.
This article assumes that the reader has already read the first part here.
Thursday, October 6, 2011
Manipulating Java Class Files with ASM 4 - Part One : Hello World!
What is ASM: ASM is an open source java library for manipulating java byte code. So it has the same purpose as Apache BCEL. As
this article assumes that the reader has some knowledge of java class file format, it is advisable to read about it in
here. So how is it different from
BCEL? Well firstly it allows for an event driven way to manipulate byte code eliminating the need to load the whole class in the memory
just to make a small addition. Secondly, it does not have a separate class for every single instruction. Instead, it handles opcodes directly
and only has constants representing each. This reduces the size of the library to a great extent. So, ASM is simply lighter and smarter.
However, ASM also has a mechanism to deal with class files by loading the whole class into the memory just in case the operation is too
complex to be handled through event based processing.
The current stable version of ASM is 3.3. However version 4.0 RC2 is out. So, I am going to discuss that version here.
The current stable version of ASM is 3.3. However version 4.0 RC2 is out. So, I am going to discuss that version here.
Thursday, September 15, 2011
Implementing Aspect Oriented Programming Framework - Java Instrumentation
What is Aspect Oriented Programing: Aspect Orented Programing or AOP is a design pattern or programming
practice, in which the code for cross cutting concern is separated out from the main program logic, thus effectively reducing the program
complexity. Now what is a cross cutting concern? They are application non-functional requirements that apply to multiple functionalities. A
simple example would be logging. Logging is done whenever some predefined things happen (for example a method is invoked). Normally, every method
that is invoked would have to contain the code for logging. In AOP, we write the logging code in a separate method may be in a separate class
and then configure our AOP framework to do logging whenever a method is invoked. There are so many good tutorials available on
AOP, one of which is here. However, in Java SE environment, it certainly requires a change
in the method's byte code made by the AOP framework. I will demonstrate how an AOP framework performs load time weaving (changes byte code during
runtime).
Thursday, August 25, 2011
Manipulating Java Class Files with BCEL - Part Three: More About BCEL
This is the third article in the BCEL series. You can read all here.
Since I have covered the basics, I will accumulate the points left now. I will discuss about local variables, fields, methods and
jump instructions.
Thursday, August 18, 2011
Manipulating Java Class Files with BCEL - Part Two: Expressions
This is the second article in the series of articles on Apache BCEL. If you have not read part 1, read it here.
Expression Processing: Expressions are key part of a language. In this article, I will discuss how expressions are compiled into java byte code. I will also cover a little bit about compilation process. At the end, I will go through the steps and create a compiler for numerical expression.
Expression Processing: Expressions are key part of a language. In this article, I will discuss how expressions are compiled into java byte code. I will also cover a little bit about compilation process. At the end, I will go through the steps and create a compiler for numerical expression.
Thursday, August 11, 2011
Manipulating Java Class Files with BCEL - Part One : Hello World!
What is BCEL: Apache BCEL or Byte Code Engineering Library is a library that enables simpler manipulation of java byte code. Now the question is, why manipulate byte code? There can be a million of reasons. For example, you might want to insert some profiling code in the class file. Or you might want to write your own language that compiles to java byte code. You can also provide some attractive extension to some framework you are creating. Or you can even be more creative than I am and do something that I cannot think of. But for that, you must first understand how java class files work.
Manipulating java byte code directly is not trivial in nature, so I decided to break the tutorial into a series. This one is the first - the hello world. Keep in touch to learn more.
Since it is a BCEL tutorial, get the BCEL library first from here
Manipulating java byte code directly is not trivial in nature, so I decided to break the tutorial into a series. This one is the first - the hello world. Keep in touch to learn more.
Thursday, August 4, 2011
Java Threads - How They Work
What is Thread: A thread is a single sequence of instructions being executed in a java virtual machine. The instructions in two different threads have no mutual ordering, they can execute independent of each other.
How to create a thread: In java, the only way to create a thread is by creating an object of class java.lang.Thread. In reality, we can either extend the Thread class and override the method run(), or we can implement java.lang.Runnable in a separate class and pass it to Thread's constructor. This article is meant for people who have some experience with Thread programming in java. If you do not know how to do thread programming in java, there is a very good tutorial in here.
How to create a thread: In java, the only way to create a thread is by creating an object of class java.lang.Thread. In reality, we can either extend the Thread class and override the method run(), or we can implement java.lang.Runnable in a separate class and pass it to Thread's constructor. This article is meant for people who have some experience with Thread programming in java. If you do not know how to do thread programming in java, there is a very good tutorial in here.
Saturday, July 30, 2011
An Anatomy of Java Generics
1. What is Generics: Generics is a feature in java language to create parameterized types. A parameterized type is a type with parameters passed to it, mostly to enable compiler to check for errors which otherwise would have been a runtime exception.
For example, let us consider programs below. In the first one, generics is not used. We are using java collection API to store and retrieve objects. In this program, it is impossible for the compiler to know what actually is stored in the collection. It is the programmer's job to take care that the objects stored are of expected type and that they are not cast to a wrong type in the time of retrieval. Not only this takes a lot of nasty boiler plate code, it also obfuscates the purpose of the collection all together. Generics attempts to solve this by passing parameters to type to specify what the types are related to. As we will see.
For example, let us consider programs below. In the first one, generics is not used. We are using java collection API to store and retrieve objects. In this program, it is impossible for the compiler to know what actually is stored in the collection. It is the programmer's job to take care that the objects stored are of expected type and that they are not cast to a wrong type in the time of retrieval. Not only this takes a lot of nasty boiler plate code, it also obfuscates the purpose of the collection all together. Generics attempts to solve this by passing parameters to type to specify what the types are related to. As we will see.
Saturday, July 23, 2011
Java enterprise framework developers' tools
Wanna develop your own framework? Developing your own framework is sure geeky. Fortunately, in Java, doing so is not as difficult as it seems. But, why develop a framework when there are too many of them already available there? Well, firstly its fun, but more importantly, the existing frameworks might not right away give you all you need. In that case, it might be a good idea to at least extend those frameworks to meet your needs.
Please note that there are so many things you can use and my list is definitely not exhaustive. It just gives idea about a few good ones that come bundled with Java SE.
Please note that there are so many things you can use and my list is definitely not exhaustive. It just gives idea about a few good ones that come bundled with Java SE.
Saturday, July 16, 2011
What's new in Java 7 - Project Coin
What's new in Java 7: Well, its a major version upgrade, there needs to be a lot of things coming up. Of course the most noticeable feature set for a java programmer would be the language level change, i.e. Project Coin. Although the changes are not as major as generics (that came with version 5, which was the time they dropped the "1." from the version number.) or annotations (also came with the same version). But, I guess they are at least as good as auto-boxing.
What is Project Coin: Project Coin or JSR334 is the common JSR that embraces all language level changes that comes in Java 7. I will talk about its features one by one.
What is Project Coin: Project Coin or JSR334 is the common JSR that embraces all language level changes that comes in Java 7. I will talk about its features one by one.
Subscribe to:
Posts (Atom)