Day 4 — Let’s write Null free Java code

Every Java developer whether beginner, novice, or seasoned has in his/her lifetime experienced NullPointerException. This is a true fact that no Java developer can deny. We all have wasted or spent many hours trying to fix bugs caused by NullPointerException. According to NullPointerException JavaDoc, NullPointerException is thrown when an application attempts to use null in a case where an object is required.. This means if we invoke a method or try to access a property on null reference then our code will explode and NullPointerException is thrown. You can follow the 7 Days with Java 8 series at http://shekhargulati.com/7-days-with-java-8/ Continue reading Day 4 — Let’s write Null free Java code

Day 3: Let’s collect data using Stream API

On day 2, you learned that Stream API can help you work with collections in a declarative manner. We looked at the collect method, which is a terminal operation that collects the result set of a stream pipeline in a List. The collect method is a reduction operation that reduces a stream to a collection. The collect method takes a Collector which let us implement functionalities like group by, partitioning, very easily. Continue reading Day 3: Let’s collect data using Stream API

Day 2 — Let’s learn about Streams

On day 1, we learnt how lambdas can help us write clean concise code by allowing us to pass behavior without the need to create a class. Lambdas is a very simple language construct that helps developer express their intent on the fly by using functional interfaces. The real power of lambdas can be experienced when an API is designed keeping lambdas in mind i.e. a fluent API that makes use of Functional interfaces(we discussed them on day 1). Continue reading Day 2 — Let’s learn about Streams

Day 1 — Let’s learn about lambdas

From today, I am kicking off 7 Days with Java 8 blog series with first blog on Lambdas. One of the most important features in Java 8 is the introduction of Lambda expressions. They make your code concise and allows you to pass behaviour around. For some time now, Java is criticised for being verbose and for lacking functional programming capabilities. With functional programming becoming more popular and relevant, Java is forced to embrace the functional style of programming. Else, Java would become irrelevant.

Java 8 is a big step forward in making the world’s most popular language adopt the functional style of programming. To support functional programming style, a language needs to support functions as first class citizen. Prior to Java 8, writing a clean functional style code was not possible without the use of an anonymous inner class boilerplate. With the introduction of Lambda expressions, functions have become first class citizen and they can be passed around just like any other variable. Continue reading Day 1 — Let’s learn about lambdas

Android Studio Mac OSX Installation Error — NoClassDefFoundError: Could not initialize class javax.crypto.SunJCE_b

Today I decided to play with Android and build a simple app. I downloaded the latest version of Android Studio for Mac from the official website http://developer.android.com/sdk/index.html. As soon as I tried to install the Android Studio on my Mac book (OSX YoseMite 10.10.2) I was greeted with a weird error message as shown below.

Internal error. Please report to https://code.google.com/p/android/issues

java.lang.NoClassDefFoundError: Could not initialize class javax.crypto.SunJCE_b
at javax.crypto.KeyGenerator.a(DashoA13*..)
at javax.crypto.KeyGenerator.(DashoA13*..)
at javax.crypto.KeyGenerator.getInstance(DashoA13*..)

You get this error because you need to have Java 6 installed on your Mac. To get rid of this error, just download the Java from this link https://support.apple.com/kb/DL1572?locale=en_US. Once Java 6 is installed, open the Android Studio app again and you will be able to work with Android Studio :)

How to resize a Virtual Box virtual machine hard disk size

Today while working on a project I had to resize hard disk size of one of the virtual machines. The Windows virtual machine was created using veewee. To resize a VM hard disk size, you have to perform couple of steps:

1. Run the $ VBoxManage modifyhd ~/VirtualBox\ VMs/windows2008/windows20081.vdi –resize 20480 command.

2. Follow the steps mentioned in this post http://derekmolloy.ie/resize-a-virtualbox-disk/ to understand how you can use the gparted to allocate the unallocated space.

Writing Test Automation Framework for Installers

Last few weeks I have spent considerable time writing integration test suite for one of our product installers. The goal of this test suite is to automatically test functionality of the product on various operating systems. Currently, we are running our automated test suite on Windows 2008, Windows 7, and Windows 8 systems. In this blog, I will first talk about the technology stack that we used to build our automation framework and then I explain  how you can write such test suite using Java installer as an example. Continue reading Writing Test Automation Framework for Installers