Posts

Java 8: jdeps a command-line static dependency checker tool

jdeps is a command-line Static Dependency Checker introduced in JDK 8.It is a "Java [static] class dependency analyzer" that is useful for quickly identifying "static dependencies of [developers'] applications and libraries. jdeps that takes a look at your non-modular code and tells you about its dependencies. Run it to find out if your application and libraries depend on any JDK's internal APIs.It is a static analysis tool on the given class files and dynamic class dependencies (Class.forName or loading of service providers etc) are not reported. jdeps.exe can be find in your JDK's bin folder. In Windows OS it can be found at location: C:\Program Files\Java\jdk1.8.0_102\bin along with other tools like javac and jps.   It analyzes the immediate dependencies of a specific class in a given classpath. If dependencies are missing from classpath then you will get "not found" message for those artifacts as it is highlighted below in RED. Jdeps Exampl…

Java 9: Jdeprscan tool introduction

Image
Java SE 9 provides a tool jdeprscan that scans a aggregation of class for uses of deprecated API elements from Java SE.  This tool can help you check if your application is Java 9 ready or not. It will be useful for applications that use libraries already been compiled and the user of that library has no idea as to what deprecated APIs he/she is using.jdeprscan is a static analysis tool scans a jar file (or some other aggregation of class files) for uses of deprecated API elements.jdeprscan scans each argument for usages of deprecated APIs. The arguments can be a:
    dir: Directory
    jar: JAR file
    class: Class name or class file
The deprecated APIs identified by the jdeprscan are only those that are defined by Java SE. Deprecated APIs defined by third party libraries aren’t reported. jdeprscan.exe (for e.g. Windows) is available within JDK 9. It can be found in your installed JDK bin (e.g. C:\Program Files\Java\<JDK9-Location>\bin) folder along with other tools like javac.…

Java 9: What does the future hold for sun.misc.Unsafe?

Unsafe provided access to low-level features that aided in the development of many tools:The Oracle position – “Unsafe must die in a fire”Unsafe library was not in fact meant to be accessible to anyone outside the internal development team in the first place.Many developers were fearful that same features don’t have any alternatives outside of the internal JVM library.To address all concerns for now Unsafe is made accessible in JDK 9 under jdk.unsupported module.Possibly getting deprecated in next JDK version.Critical internal APIs for which replacements are introduced in JDK 9 will be deprecated in JDK 9 and either encapsulated or removed in JDK 10. Will removal of sun.misc.Unsafe break Spring, Hibernate in Java 9?The references are not in the core of Spring or Hibernate but some other libraries listed below may break:GuavaGWTNettyJersey-CommonInfinispanJboss-ModulesExample demonstrates how we we can use sun.misc.Unsafe in Java 9:Module declaration for jdk.unsupported:

module jdk.unsu…

Java 8 lambda expression & method reference made easy

Lambda expression facilitates functional programming in Java. 

Lambda expression is a function which can be created without belonging to any class.Lambda expression can be passed around as if it was an object and executed on demand as method reference.Lambda expressions are used primarily to define inline implementation of a functional interface, i.e., an interface with a single method only. Following demonstrates serious ways of using lamda expression.
Method reference:

A method reference is the shorter more concise syntax for a lambda expression that executes just ONE method.

There are four types of method references:
A method reference to a static method.A method reference to an instance method of an object of a particular type.A method reference to an instance method of an existing object.A method reference to a constructor.
Sample program:

// Functional interfaces are heart of lambda expression
@FunctionalInterface
interface FuncIface {
    public void referenceDemo(); //Only one a…

Performance comparison of Executor framework vs Fork/Join framework’s RecursiveTask feature in java or JDK7

I was testing new RecursiveTask feature of ForkJoin framework introduced in JDK7 or Java 1.7.

There are two types of ForkJoinTask specializations:
Instances of RecursiveAction represent executions that do not yield a return value. In contrast, instances of RecursiveTask yield return values. I have already posted an example of RecursiveAction in previous post. To know more about theoretic details and RecursiveAction sample code, you can visit the link: How to use Fork-Join Framework features in JDK7?


In this post I will do comparison of Executor Framework Vs ForkJoin framework's RecursiveTask feature. Following example fills primitive long array of size 100000000 with values from 0 to 10000000.

I use executor framework to calculate the sum of whole array  then I perform same logic using ForkJoin framework's RecursiveTask feature. To setup the example, I will first show the code which uses executor framework and its result then I will show ForkJoin framework's RecursiveTask …

How to use Fork/Join Framework's RecursiveAction feature in JDK7?

JDK 7 has new additions for supporting parallelism using ForkJoinPool executor that is dedicated to running instances implementing ForkJoinTask.

ForkJoinTask objects feature two specific methods:
The fork() method allows a ForkJoinTask to be planned for asynchronous execution. This allows a new ForkJoinTask to be launched from an existing one. fork() only schedules a new task within a ForkJoinPool, but no child Java Virtual Machine is ever created.In turn, the join() method allows a ForkJoinTask to wait for the completion of another one.There are two types of ForkJoinTask specializations:
Instances of RecursiveAction represent executions that do not yield a return value. In contrast, instances of RecursiveTask yield return values. You can checkout RecursiveTask code sample at link: Performance comparison of Executor framework vs ForkJoin framework’s RecursiveTask feature in java or JDK7Following example illustrates how to use RecursiveAction type of ForkJoinTask implementation:

Code Sampl…

How to use node.js?

Introduction:

Node.js is a platform built on Chrome's JavaScript run-time for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Node.js is a server-side version of JavaScript. That means all the things all them cool things about JavaScript apply here.

What makes Node any different from the rest?
Node is evented I/O for V8 JavaScript. V8 is Google’s super fast JavaScript implementation that’s used in their Chrome browser. JavaScript’s ability to pass around closures makes event-based programming dead simple.

Node is not strictly for web development. You can think of Node as a framework for server development of any kind. With Node you can build an IRC server, a chat server, or HTTP server as done in following hello world example. 

You can use node.js to create light weight web server. See the foll…