Sunday 30 August 2015

Java 8 - Highlights of new features and enhancements

If you are new to Java, please refer my New to Java - Getting Started Guide post.

Being a java developer, one should start learning new language features and enhancements of Java 8 if not yet!

You can get sample code snippet of Java 8 features from my Learning-Java Repository on Github @ https://github.com/tirthalpatel/Learning-Java/tree/master/Java8 --- Here you would find sample code along with easy to understand comments to learn new language features released in Java 8, and I will be adding more learning code of library enhancements in future.

Executive view of key features introduced in Java 8 --- For more detail, please refer Oracle documentation of New Features and Enhancements in Java 8.

(Right click the image - Open in New Window - Zoom it)

Java 7 - Highlights of new features and enhancements

If you are new to Java, please refer my New to Java - Getting Started Guide post.

Being a java developer, one should be aware of at least new language features (referred as project coin features) of Java 7.

You can get sample code snippet of Java 7 features from my Learning-Java Repository on Github @ https://github.com/tirthalpatel/Learning-Java/tree/master/Java7 --- Here you would find sample code along with easy to understand comments to learn new language features released in Java 7, and I may add more code of library enhancements in future.

Executive view of key features introduced in Java 7 --- For more detail, please refer Oracle documentation of New Features and Enhancements in Java 7.

(Right click the image - Open in New Window - Zoom it)

Java SE 6 - Highlights of new features and enhancements

If you are new to Java, please refer my New to Java - Getting Started Guide post.

Being a java developer, one should know that no new language changes were introduced in Java SE 6. Most importantly, introduction of Scripting in Java Platform (JSR-223) had encouraged acceptance of other popular open-source languages on JVM runtime via scripting engine implementation of a given programming language. This specification also offers interoperability between Java and non-Java JVM languages (i.e. JavaScript, Groovy…).

Executive view of key changes introduced in Java SE 6 --- For more detail, please refer Oracle documentation of New Features and Enhancements in Java SE 6.

(Right click the image - Open in New Window - Zoom it)

Saturday 29 August 2015

Importance of Software Products Interoperability or Compatibility Matrix

Recently I migrated from old to new laptop, which is in majority cases laborious job. After few weeks, I realized I missed to install VMWare vSphere Client software to access ESXi server.

Somehow I could find that I had vSphere client version 5.5 in my previous laptop, and I just installed latest "vSphere client version 5.5 U3". Then when I tried to login, it stuck on "Updating" popup screen which finally failed to do any progress with multiple tries. Well, I could not understand what it tries to do --- The required client support files need to be retrieved from the server "vsphereclient.vmware.com" and installed. Click Run the installer or Save the installer???


I tried to google solution, but could not find anything useful. I tried uninstall and install latest version 6.0, but could not solve it. This way, I wasted my almost 5 hours. Suddenly I realized, I should check version compatibility between ESXi server and vSphere client. So I searched and found this url - http://partnerweb.vmware.com/comp_guide2/sim/interop_matrix.php. Wow, finally I could fix this problem in just few minutes by installing VMWare vSphere client version compatible to ESXi server 5.0 version.


Lesson Learned:

While installing any software products, if we see installation problems or it reacts weirdly, then we should not forget to refer its version compatibility matrix... :-)

Saturday 13 June 2015

Steps to create Scala project using Maven / Sbt and import in Eclipse ScalaIDE

If you are Java developer and accustomed to use Eclipse IDE, you can consider below steps for getting started with creating new Scala project.

Prerequisites

You can create Scala project structure using your choice of build tool - Maven / SBT (scala's simple build tool) - as per below steps. Then import the existing Scala project in Scala IDE for getting started with Scala programming.

Create Scala project with Maven

If you already know Maven, then below are quick steps to get you started with building and running your Scala applications using Maven.

First of all, install "m2eclipse-scala" plugin in Scala IDE. Then go with one of below options.

Option 1: Create project using Scala IDE by following instructions given @ http://scala-ide.org/docs/tutorials/m2eclipse/

Option 2: Create project by executing maven commands as below (Reference @ https://github.com/davidB/scala-archetype-simple).

(1) Generate "scala-mvn-helloworld" project structure using below Mavan command. Ensure to change group id, artifact id and package as per your need. Once you execute this command, it would create directory structure including "pom.xml" file.

D:\Tirthal-LABs\Learning-Scala>mvn archetype:generate -B -DarchetypeGroupId=net.alchim31.maven -DarchetypeArtifactId=scala-archetype-simple -DarchetypeVersion=1.5 -DgroupId=com.tirthal.learning.scala -DartifactId=scala-mvn-helloworld -Dversion=0.1-SNAPSHOT -Dpackage=com.tirthal.learning.scala

(2) Execute maven command to compile scala --- mvn scala:compile

(3) Execute maven command to run and ensure correct package name, which should give "Hello World!" output towards the bottom--- mvn scala:run -DmainClass=com.tirthal.learning.scala.App

(4) Import maven project in Scala IDE using  --- File -> Import -> Maven -> Existing Maven Projects. Then run "App.scala" by right click option--- Run As -> Scala Application.


Create scala project with Sbt (simple build tool)

If you want to try Sbt (interactive build tool which has build-in defaults - compile, test, run and many more…), then below are quick steps to get you started with building and running your Scala applications using Sbt.

First of all, install sbt and add "D:\Softwares\scala\sbt-0.13.7\bin" in path variable of OS. Next,

(1) Create application folder --- D:\Tirthal-LABs\Learning-Scala> mkdir scala-sbt-helloworld

(2) Create necessary sbt files in application folder using below commands  in Windows (or you may create those files manually) --- D:\Tirthal-LABs\Learning-Scala\scala-sbt-helloworld>

(2.1) Run this command and add below three lines in build.sbt file --- touch build.sbt && start build.sbt    

name := "scala-sbt-helloworld"
version := "0.1"
scalaVersion := "2.11.6"

Note:  Here "scala-sbt-helloworld" name will be used for Eclipse project name, while we'll execute "sbt eclipse" command further to create project scaffolding. Also ensure to mention correct Scala version which you have installed.

(2.2) Create "project/build.properties" file by running this command and add below one line in it --- mkdir project && touch project\build.properties && start project\build.properties

sbt.version = 0.13.7

Note: Here folder name must be "project", which you cannot change to different name. Also ensure to mention correct Sbt version which you have installed.

(2.3) Create "project\plugins.sbt" file by running this command and add below line in it --- touch project\plugins.sbt && start project\plugins.sbt

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "3.0.0")

Note: This internally using Apache Ivy - group name % artifact ID % version. Also ensure to mention correct version compatible with your sbt version as given here - https://github.com/typesafehub/sbteclipse/.

(3) Now run this "sbt eclipse" command to create default eclipse project scaffolding ---  D:\Tirthal-LABs\Learning-Scala\scala-sbt-helloworld> sbt eclipse

Note: You should see below lines on command prompt, on successful project creation.
[info] Updating {file: /D:/Tirthal-LABs/Learning-Scala/scala-sbt-helloworld/ }scala-sbt-helloworld...
[info] Resolving org.scala-lang#scala-library;2.11.6 ...
  [info] Resolving org.scala-lang#scala-compiler;2.11.6 ...
  [info] Resolving org.scala-lang#scala-reflect;2.11.6 ...
  [info] Resolving org.scala-lang.modules#scala-xml_2.11;1.0.3 ...
  [info] Resolving org.scala-lang.modules#scala-parser-combinators_2.11;1.0.3 ...
  [info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Successfully created Eclipse project files for project(s):
[info] scala-sbt-helloworld

(4) Finally import maven project in Scala IDE using  --- File -> Import -> General -> Existing Projects into Workspace option. Then, under the folder "src/main/scala" create "App.scala" hello world scala program and run it by right click option--- Run As -> Scala Application.

object App {
  def main(args : Array[String]) {
    println( "Hello World!" ) 
  }
}

(5) Optional extra steps --- As per your project need, you can add more SBT plugins - https://github.com/sbt. For example, to add dependency in project for test add "libraryDependencies" in build.sbt file and run sbt, eclipse commands…

D:\Tirthal-LABs\Learning-Scala\scala-sbt-helloworld> start build.sbt
libraryDependencies ++= Seq("org.scalatest" % "scalatest_2.11" % "2.2.4" %"test", "com.novocode" % "junit-interface" % "0.11" % "test");

> sbt (this will load sbt)

> eclipse (run eclipse task to incorporate dependencies in Eclipse project configuration)

> ~test (this will compile, run the test and show result. it will rerun again, when any change is done in the test source code)
[info] Compiling 1 Scala source to D:\Tirthal-LABs\Learning-Scala\scala-sbt-helloworld\target\scala-2.11\classes...
[info] ScalaTest
[info] Run completed in 151 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.


Sunday 8 March 2015

Tactics to improve Java development productivity

Today I read java development tools/frameworks for a programming boost article by Theodora Fragkouli. This inspired me to publish highlights of the training, I imparted in last month to java developers, on "Tactics to improve productivity in Java" topic.

The scope of this training was stringent to relate Java technical viewpoints, and obviously excluded thoughts of generic ways to boost productivity, i.e. do yoga/meditation regularly, 15 minutes power nap at work, having cup of tea/coffee... :-)

The objective of this training was to make participants familiar with few notable tools, techniques and programming considerations focused to boost java developers productivity. I focused mainly on three areas.
(1) Save time on java app compile, build and redeploy process.
(2) Efficient ways to analyze or review existing/legacy java code.
(3) Less code means more productivity.

I demonstrated following tips practically in the training, which java developers should adopt for being more productive (* as applicable in the given project architecture and development environment).

Before I start, I hope that you have already read "Preface" of my java power tools series.

Tools and Techniques to improve productivity

View Java code changes instantly using JVM HotSwap / class reloading tools
  • Problem = By nature, if we do even single line of code change in java, we must need to wait for few seconds to minutes to test it until application is built and redeployed on server.
  • Solution = JVM Hotswap or class reloading tools can help us to save time at certain extent, i.e. add and update java classes instantly without waiting on java app compile, build and redeploy process.
  • In general, I suggest such tool to use during development. Be cautious to use it in production, until you need to accomplish exceptional use case!

Reverse Engineering technique and tools
  • Useful to improve design documents of legacy systems or efficient way of exploring code from the generated diagrams (e.g. class and sequence).
  • Static reverse engineering using ObjectAid (free for class diagram), i.e. generating diagrams from existing codebase.
  • Runtime reverse engineering using Maintainj (commercial), i.e. firstly perform functional operation in running application and capture corresponding code flow traces, then explore the generated diagrams for the given executed use case and finally from diagrams navigate the exact code.

Static code analysis tools & Dependency analysis technique
  • Generate Dependency graphs using Codepro Analytix (free) or Dependency structure matrix (DSM) using SonarQube (free) from existing or legacy codebase to  detect cyclic dependencies and empower the impact analysis for refactoring / reengineering / modernization, etc. Just google further, you would find many references to understand fundamental of these dependency analysis techniques using the mentioned tools.

Miscellaneous
  • Enrich Eclipse IDE by adding extra Eclipse plugins - Code Recommenders + Snipmatch (code recommendation and a snippet completion engine), InstaSearch (fast text search in the workspace), MouseFeed (helps to form a habit of using keyboard shortcuts), JD-Eclipse (java decompiler), etc.
  • Cronon (commercial) - a DVR for Java, offers to record your entire java program and replay on any machine.
  • Stackifier - A web page to make sense of verbose Java/Scala exception stack trace by translating into the simplified UI.

Less code means more productivity

Less lines of code means more productivity, and also less efforts to unit test and maintain the code. Now the question is - what could be programming considerations for this? Here we go...

Polyglot programming on the JVM
  • Have you ever thought to mix-and-match multiple programming languages in a single application? Well, the phrase polyglot programming on the JVM was coined to describe projects that utilize one or more non-Java JVM (Java Virtual Machine) languages (e.g. Scala, Groovy, Clojure, Jython, Jruby, JavaScript...) alongside a core of Java code. All in all, it is better to use the right programming language to do the right job.
  • Polyglot Programming with respect to Java platform --- Java SE 6: added specification for supporting multiple scripting languages in JSR-223, which encouraged acceptance of many popular open source languages on JVM runtime by just implementing scripting engine of given language. Also it allows java developers to call non-java scripting language (e.g. JavaScript, Groovy…) code from java code and vice versa. Java SE 7: added JSR-292 to enable developers of compilers for dynamically typed languages to generate bytecode that runs extremely fast in the JVM. Java SE 8: replaced default “Mozilla Rhino” JS scripting engine with new highly performant “Oracle Nashorn” engine.
  • The Java specification doesn't talk about how the different languages should be organized in enterprise application architecture! So in general the polyglot programming environment can be categorized in three layers from architectural standpoint, so-called polyglot programming pyramid --- (1) Stable layer - The stable layer is what everything else is built on top of, and should preferably be a thin foundation. Statically typed language (Java, Scala) is suited for this layer, as performance and stability is of the utmost importance. All interfaces to external applications are also defined in this layer, as this will provide type safety and enable other clients to trust it. Example use cases are: Core business functionality, Concurrent code, Application containers… (2) Dynamic layer - The dynamic layer is consisting of most the application code. Languages from all the paradigms can be used, as long as they are dynamic and do not require compilation such as Groovy, Clojure and many more.  Example use cases are: Rapid web development, Prototyping, Flexible development of functionality, Interactive administrative and user consoles, Scripting… (3) Domain layer - The domain layer is tightly coupled to a specific part of the application and should offer to change rules in production. It can be consist of one or more DSLs (domain specific language) to define the actual domain rules. Example use cases are: Enterprise Integration Pattern modeling, Business rules modeling, Build, Continuous integration, Continuous deployment, Dev-ops… For more detail, you should read The Well-Grounded Java Developer - Part 3.

Groovy

Java 5 -> Java 8
  • Java 5 (Released in Sep 2004) – Generics, Autoboxing, Enhanced for loop, Annotations…
  • Java 6 (Released in Dec 2006) – Scripting in the Java Platform…
  • Java 7 (Released in Jul 2011) – Project coin features…

Java EE 7

Spring Data
  • Provides efficient approach to data access – relational, non-relational, map-reduce and beyond. Its most compelling feature is the ability to create repository implementations automatically, at runtime, from a repository interface.

There are many more technological considerations for writing less code. Anyway to make a long story short, Java developers should keep upgrading their skills to harness the power of modern technologies and frameworks for writing code that is more compact, simpler, and easier to maintain.

Final Thoughts

Every project has its own architecture and development environment. So all the above-mentioned technical aspects may not be applicable to each and every project. Anyway here is the crux...



Finally please do share your experience in the comment, if you know any additional tactic applicable to improve java developer productivity.

Disclaimer

I am not biased to particular free or commercial tools and frameworks, rather my objective is about sharing my own experience on the this topic. 

Sunday 25 January 2015

Java power tools series - Extra plugins to enrich Eclipse IDE

I hope, you have already read "Preface" of my java power tools series.

I love using Eclipse, but it is perturbing to upgrade it. Because every time we need to install numerous extra plugins to enrich its standard ability. Besides this, we need to recollect what all plugins to be installed in new Eclipse version. So I thought to publish a post to list Eclipse plugin names which I rely on regularly or occasionally for my own future reference. I hope below Eclipse plugins listing may benefit other java developers too.

Eclipse Plugins


Free
Commercial
Development
Liferay IDE - for building plugins for the Liferay Portal 
for developing Spring applications & GGTS for developing, debugging and executing Groovy and Grails applications
JBoss Tools - like Hibernate Tools provides tooling for JPA and HQL
Plugin for Groovy - provides Eclipse support for Groovy projects
Scala IDE - provides advanced editing and debugging support for the development of pure Scala and mixed Scala-Java applications
AngularJS - Eclipse plugin for AngularJS projects

Unnecessary Code Detector - Dead code analysis
FindSecurityBugs, LAPSE+ - Code security analysis

Unit testing and Code Coverage
Infinitest - Greatly works with TDD. Each time a change is made on the source code, Infinitest runs all the tests that might fail because of these changes.
MoreUnit - Shortcuts to switch between tests and classes under tests, create test stubs, mock support, decoration, refactoring support
EclEmma Java Code Coverage - a Java code coverage tool for Eclipse

Productivity
InstaSearch - fast text search in the workspace
Eclipse Code Recommenders + Snipmatch - code recommendation and a snippet completion engine
MouseFeed - Helps to form a habit of using keyboard shortcuts
JAutodoc - For automatically adding Javadoc and file headers to your source code
JRebel - Live code reload.  Eliminates need to build your app to see changes
Diagramming and Reverse Engineering
Diver, Jive - Runtime sequence diagrams generation
ObjectAid - Reverse engineering for class diagram generation
ModelGoon- Generate various UML diagrams from code
BundleMaker - Dependency analysis
Maintainj - Runtime sequence and class diagrams generation and debugging
Architexa - Generate layered, class and sequence diagrams from code
Performance Analysis
Java Mission Control - A set of plugins designed to help develop, profile and diagnose applications running on the Oracle Java HotSpot VM
VisualVM - for monitoring and profiling of java applications
Lockness - Java thread dumps analysis
MAT - Java head dump analyzer

Miscellaneous
JD-Eclipse - Java decompiler
EasyShell - Offers tight integration of system file manager (Windows Explorer, Gnome Nautilus, KDE Konqueror, Mac Finder, ...) and shell (cmd.exe, Linux/Mac terminal) in Eclipse
Eclipse-fonts - Increase/decrease font-size in editor
AnyEdit Tools - Convert, compare, sort etc.


Updates History
  • 20/May/2017 - Added Infinitest for unit testing


If you know or have experienced any other outstanding Eclipse plugin, please share the name of the plugin in the comment.

Disclaimer
I am not biased to particular free or commercial tools, rather my objective is about sharing my own experience on set of tools.