In this blog, I am going to write a code which will print all the sub-arrays of an array in linear time, i.e O(n). First, we should to try to understand the problem we are trying to solve here. We have an array of integers. {1, 2, 3, 4, 5} and we need to print […]
Watchout for NullPointerException while using method reference in Java, and Learn how you can fix it.
As a Java developer, I love to use method reference whenever I get an opportunity to do it. But, most of us don’t know that we can get NullPointerException , if we are not careful. Let us see an example. I have a function, which takes a supplier, and it prints the value supplied by the supplier. static […]
Use object oriented and functional programming to write a branch-less code for fizz-buzz test
Fizz-Buzz is a some kind of test used in interviews, which I have heard. But, I was never asked this question. In Fizz-Buzz test, what you have to do is to write a code, to print Fizz, Buzz, FizzBuzz or a number. To go in detail, you have to loop over some number or test […]
Let user handle null case, using functional programming in modern java
When pass an object to a function, then there is a scenario which always arises. That, the passed object could be null. And, we have to write logic to react to that null-condition. And, generally that logic is hard-coded in the function. And, there are times as a user I feel that, instead of throwing an exception […]
How to create basic java plugin using Plugin interface, and run it is using -Xplugin command line argument
We can use Plugin interface to create a plugin that runs during compilation of java files. You can watch me code this plugin on youtube. We use com.sun.source.util.Plugin from the jdk. We will have to provide an implementation for init-function of this interface. And, another thing that is important is to provide implementation for […]
Java Data Structure Binary Tree : Print The Nth Level
Printing Nth Level in a binary tree is the same as doing level order traversal. Logic : We loop through all the levels. And, we maintain the current level count. If the level count is the same as the level requested by the user then print the level information. You can watch me code the […]
FUNCTIONAL PROGRAMMING : Currying In Java, How to curry a hashmap
Currying is just a name for a function, which does not have all the arguments passed to it. So, if have a function which takes 4 arguments, we will provide only 3 and we will provide 1 later on. This stage of function, where it does not have all the arguments is called curried stage, […]
Java Module System – How to create a module, compile it and run the modular java application from a command line.
In this post, I am going to tell you how to create a module. How you can compile that module and use modular architecture to run java application. you can watch me code the module-system mentioned in this post on youtube. I am using java 16 and ubuntu 18.04. You can run commands which are […]
Stack datastructure implementation in C programming Language.
Stack is an abstract data-structure. This data-structure allows user to access the contents in Last In First Out order. This means, the latest element which was put in the data-structure, will be the first one to be removed on remove operation. You can watch my video, where I code this implementation. The operation, where we […]
Use IntUnaryOperator to calculate sum and cube of an int using modern java : java functional programming
There are different ways to implement IntUnaryOperator . You can watch my video, where I am implementing IntUnaryOperator. Utility Class with square and cube static functions. private static class Utility{ private static final int square(final int intValue) { return (int) intValue * intValue; } private static final int cube(final int intValue) { return (int) intValue * […]