Sunday 28 December 2014

Static Code Analyzers - JArchitect - Why is it distinctive static code analysis tool for Java?

I hope, you have already read "Preface" of my static code analyzers series.

Regardless you are developer or manager or architect, how meticulous are you about the quality of the software architecture and code you deliver?

In this post, I explained - while there are already free / open-source static code analysis tools available (e.g.  Checkstyle, PMD, FindBugs, CodePro Analytix, SonarQube...), what differentiating features are offered by JArchitect being a commercial tool! How JArchitect is beneficial to all developers, managers and architects! Moreover, how it can facilitate architecture evaluation exercise of existing or legacy java software for refactoring / re-engineering / migration / modernization.

Straight from the horse's mouth

JArchitect manages complex code base and achieves high Code Quality. With JArchitect, software quality can be measured using Code Metrics, visualized using Graphs and Treemaps, and enforced using standard and custom Rules. In a nutshell, improve your Java Code quality with JArchitect 4
  • Customize your own rules through CQLinq
  • Powerful way to combine many Java tools
  • Meaningful reports about your code base

My Personal Feedback

  • When to use and key features?
    • Control Code Quality - Architects can setup JArchitect analysis as part of build and CI process, i.e. integrate with Maven, Gradle, Jenkins, etc. Managers and QAs can keep their eyes on code analysis reports (e.g. sample report) as well as customized trend monitoring views to ensure health of software code quality.
    • CQLinq - I didn't find this kind of awesome feature in any  other static code analysis tool. This enables developers and architects to write queries on java code dynamically (e.g. JArchitect can answer the queries like - what are top 5 complex methods?, is the code layered correctly?, which method has been refactored in last release?). If you know SQL, you can easily learn CQLinq. Otherwise don't worry, even you can use GUI and rich code search facility of JArchitect to form such CQLinq queries quickly. I have become a fan of CQLinq feature.
    • Explore existing architecture - The generated diagrams by JArchitect are immensely interactive. It is so easy to drill down the diagrams by few clicks or highlight areas of interest in the diagrams by changing CQLinq (e.g. highlight top 10 methods by cyclomatic complexity in matric view diagram; drill down dependency graphs or DSM to analyze layered code, high cohesion and low coupling, dependency cycles...).
    • Compare builds and code difference - Let JArchitect tell you that what was changed compare to previous analysis or between two code analysis. For example - methods added or changed, packages added or changed, added or removed third party libraries...
    • The above-mentioned features are extremely useful for activities such as code review, impact analysis for refactoring, etc. Refer more features of JArchitect.
  • Initial learning curve and ease-of-use?
    • It is easy to setup and get started. Depending on experience level, you should be able to adopt  it (e.g. interpret code analysis report/diagrams; play with its CQLinq to query java code, etc.) in less than a week by referring to documentation. I found that JArchitect  GUI is highly neat and interactive.
  • Setup requirements?
    • Download JArchitect compressed installation for supported OS (i.e. Windows, Linux, Mac), unzip it, put license file in root folder of JArchitect and just run the startup file (e.g. VisualJArchitect.exe for Windows). That's it. For further detail, refer system requirements.
  • Cost (Free or Commercial)?
    • Free fully 14-day trial is available, then need to purchase. Refer pricing.
    • Open source licenses are available free to non-commercial open source software development projects.
  • Limitations/ Challenges?
    • JArchitect does not have IDE plugin (e.g. Eclipse/Intellij). Alternatively, it provides the easy way of associating IDE workspace / project (Eclipse, NetBeans and Intellij) in standalone JArchitect GUI tool  for the code analysis and as a source files editor tool. I could accustom myself with this approach easily, but some developers may find it challenging to use two tools (IDE + JArchitect) simultaneously during development.
    • Code coverage analysis is not inherent while executing code analysis in JArchitect. That means, we need to firstly execute cobertura separately on project codebase and then import its resulting xml file into the JArchitect. This approach is not favorable from usability point of view. I would say that code coverage should be default integrated part of the code analysis process of JArchitect (may be with a configuration option of  enable or disable code coverage).

Practical Shot

For JArchitect practical demo, I used Spring Petclinicsample application. Let's assume, you need to deal with this existing unknown codebase for requirements such as assess architecture for migration or modernization, review code quality, impact analysis for refactoring, etc. Following are some highlights of being efficient by using JArchitect...

Note: To enlarge below screenshot images --- Right click the image - Open in New Window - Zoom it.

  • Perform code analysis in JArchitect - First of all, create new project in JArchitect and just associate appropriate folders of your java pplication codebase. You may customize report format too. Finally, run the analysis. The best part of the tool is that source files and byte code are not mandatory for the analysis, rather it supports inputs such as application build files (jar, war, ear), eclipse workspace, IDE projects (Intellij, NetBeans, Eclipse), Maven (pom.xml), etc. For more detail, refer getting started and analysis input.

  • Code quality status and accustom with CQLinq - The red circle (bottom-right side) tells that some critical rules are violated. Let's see the dashboard. Firstly review what rules are violated in "Queries and Rules Explorer" (below dashboard). On top of providing default rule groups, the tool gives you complete control to  customize existing or add new rules based on the project need in "Queries and Rules Explorer". Next explore associated code path for each type of rule in "Queries and Rules Edit" section (left side). Here, even you can update CQLinq query and see the updated result almost immediately. Even you can integrate custom plugin (i.e. other static code analysis tools) in JArchitect to use CQLinq on those. For more detail, refer CQLinq syntax and violating code rules. On a separate note, let me make you aware that you need to configure your choice of editor tool in JArchitect for navigating to java class source from JArchitect, because JArchitect is not an IDE.

  • Dependency analysis - Now understand code structure patterns of application using dependency graphs and DSM (dependency structure matrix). These diagrams offer to explore the codebase in interactive way and are highly useful to review design of application or to perform the impact analysis for code refactoring.

  • Code visualization metrics views - Another interactive diagram, which offers to highlight some areas of code for selected metric parameters. This is one of the distinctive feature of JArchitect. For example, it is so easy to see what are top 10 methods in petclinic application code by "Cyclomatic Complexity (CC)". Even you can hover to see more information of given rectangle (e.g. invoke method in below screenshot) or right click it to navigate to other related things (e.g. open source code in IDE, view on dependency matrix, etc.)… For more detail, refer visualizing code metrics with treemap and code metrics definitions.

  • Track code differences between two build analysis - With JArchitect, it is so easy to focus what things were changed in recent build. Just compare latest build analysis with the previous one, and with just few clicks realize the differences in the codebase. Firstly, I took few months old code from github and performed code analysis in JArchitect (refer older build on 21 Dec). Next, I took recent code from github and performed code analysis again (refer new build on 28 Dec). Then, I did build comparison between older and newer builds. Finally, I could see many code differences by just few clicks. For more detail, refer advance code difference in JArchitect.

My Final Thoughts
  • I endorse JArchitect for being a promising tool for Java architects and developers --- because it can greatly improve efficiency in terms of delivering high quality software components in less time. 
  • Should you try JArchitect? --- If you have an opportunity, I strongly suggest to try 14-day JArchitect trial. Certainly, you will be able to experience superior approach to work on java projects using its some unique features.
  • Should you buy JArchitect? --- Well, this is highly subjective to individual project need and budget. If project has longer lifespan goals and is evolving continuously, then you must consider static code analysis tool to control code quality (preferably as part of Continuous Integration). You can evaluate JArchitect and available open source static analysis tools (e.g. Checkstyle, PMD, FindBugs, CodePro Analytix, SonarQube, etc.) for your targeted criteria, and you can either procure JArchitect or go with open source static code analysis tools. According to my experience with various static code analysis tools, JArchitect offers excellent GUI and unique features like CQLinq, Metrics views, etc. Even on larger codebase, it performs code analysis very fast compare to few other tools I have tried. The tool is very  much stable, because it has never hung (I tried in Windows OS) or thrown weird errors while using it. Obviously, it has to offer special things being a commercial tool.  
  • In a nutshell, JArchitect is an distinctive static analysis tool for Java. Moreover, it also supports each language using the JVM and generating the byte code. So JArchitect can be also useful, if application is developed using polyglot programming* i.e. multiple JVM based languages like Java, Groovy, Clojure, Scala, etc. (* I have not tried it yet on other than Java language).

Disclaimer
I don't aim to exploit code of any open source project or sample application, while I share my evaluation feedback of given tool on selected publicly available code. Also I am not biased to particular free or commercial tools, rather my objective is about sharing my own experience on set of tools.

Also Refer

Sunday 16 November 2014

Core Spring - Learning made easy by sample code snippet

Spring already provides many getting started guides.  Also you would find unlimited blogs, tutorials and ebooks related to Spring framework and projects on internet. Yet I thought to add one more post on Core Spring to the list... :-)

Anyway, to cut a long story short, this is just to let people know that I had made my learning code snippets (along with some notes) of Core Spring on GitHub publically available. It can be useful to you, if you wish to learn key concepts of Core Spring quickly by referring to readily available code snippets, get your hands dirty by altering the code snippet to explore further, refresh it for interview purpose, etc.

Learning-Spring Repository URL@ https://github.com/tirthalpatel/Learning-Spring. Clone or download it to your local machine from the Github and refer README of gs-spring-core for project setup. Below screenshot highlights what you would get in this project.


When I say "Spring Core", it refers to the foundation of Spring Framework as highlighted with red color boundary in below diagram.


Also you can refer my another post on "Executive Overview of Spring IO" to get a bird's-eye view of Spring IO platform and projects.

Also Refer

Saturday 18 October 2014

How Java Developers can get started MongoDB?

About MongoDB (from wikipedia) - In case you don't know what it is, then MongoDB (from "humongous") is a free and open-source cross-platform document-oriented database software. Classified as a NoSQL database, MongoDB avoids the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making the integration of data in certain types of applications easier and faster.  It provides high performance, high availability, and easy scalability.

From java developers outlook - If MongoDB is deliberated to persist some or all data in java based application architecture, then java developers need to write java code in data access layer of application to perform CRUD and other operations with MongoDB backend using Java MongoDB Driver API or may be Spring Data MongoDB (just imagine this something like writing JDBC code to exchange data between JavaEE app and RDBMS). --- On a separate note, are you aware about the term polyglot persistence describing hybrid approach to persistence by using different data storage technologies to handle varying data persistence needs!

M101J Course: MongoDB for Java Developers

Speaking of MongoDB, recently I got opportunity to attend "M101J: MONGODB FOR JAVA DEVELOPERS" course which is a free 7 weeks online course and expects attendees to spend 6-8 hours per week as per the designed course agenda. The course delivers everything java developers need to know for getting started with building a MongoDB-based java application, which includes basic MongoDB installation, JSON, schema design, crud operations, indexing, aggregation framework, application engineering  and working with MongoDB java language drivers. The data interaction between Java app and MongoDB is practically demonstrated by building a java based blogging platform, backed by MongoDB. Moreover, one will receive a certificate of M101J course completion at the end, if achieves a 65% or above on graded material.

As a matter of fact, the quality of M101J is elegant and specially designed for java developers to get started with MongoDB. If you wish to learn MongoDB or don't have exposure of any of NoSQL database, then I highly endorse to register and attend this course.

Self-paced Getting Started with MongoDB

In case you can't manage to accomplish the M101J course, then you can get started with MongoDB as below.

Firstly I suggest to go through MongoDB@TutorialsPoint course to get fair understanding of MongoDB. Don't just read, but also try practically as you progress.

Once you become familiar with MongoDB, then I suggest to refer the sample java code snippet used in the M101J course. For this, you can setup M101J java project and explore code as below.

  1. Download / Clone "MongoDB-ForJavaApp/M101J" project to your local machine from GitHub. 
  1. Import "M101J" project in Eclipse. Fix build path errors, such as JRE configuration. This is maven based project, so it would download dependent jar files from internet.
  1. Ensure MongoD process is running.
  2. Go to "com.tengen.helloworld" package in "src/main/java" folder of the project. As per "README.md" file, create "hello" collection and insert data. Now see code of "HelloWorldMongoDBStyle.java" and run it; which should connect to "course" db in MongoDB, get data from "course" collection and finally print on console. The other hello world programs in this folder are to demo basic usage of freemarker (templating engine) and spark (micro web framework which allows to setup routes for mapping urls and having embedded Jetty) frameworks, which are used to build frontend templates and controller components of blogging app tutorial. For example - just run "HelloWorldMongoDBSparkFreemarkerStyle.java" program and access "http://localhost:8082" url in the browser, so it would fetch data from MongoDB and show on browser page.
  3. Go to "com.tengen.crud" package in "src/main/java" folder of the project to explore java code for Mongo crud operations.
  4. Finally explore sample blogging application.
    • How to run it?
      • Ensure MongoDB instance "mongodb://localhost" is up and running, otherwise you may need to change default configuration is in BlogController.java.
      • Run BlogController.java as java application or using maven command. This would run it on HTTP 8082 port using Spark framework.
      • Now you should be able to access it in browser using this URL "http://localhost:8082/" and can play with the blogging application functionality.

Also Refer

Saturday 13 September 2014

Excellent resources to expedite your Software Architecture Skills

When I started my career as a "Trainee Developer", I was fascinated about just java coding, coding and coding... Then I learned fundamentals and principles of OOP Design and few more programming languages... As I grown my experience in software development and design; I started to get opportunities to grasp architecture of legacy systems, create architecture for proposed applications, envision high level architecture for proposals, analyze architecture and NFRs… And yeah, building architectural proficiency looks like a long journey!

In this post, I am publishing list of my favorite online resources which helping me during the journey of building my software architectural know-how. 

On a separate note,


I am greatly thankful to below mentioned assets and also endorse them for building proficiency in software architecture.

Microsoft Application Architecture Guide

Even though it is for Mocrosoft Application Architecture; the explained fundamentals, guidelines and practices of software architecture and design  is also applicable for Java Platform based Application Architecture. I simply love it! Also Architecture 101: Skyscrapr has interesting articles covering architectural perspective.




Software Architecture in Practice by Len Bass, Paul C. Clements, Rick Kazman

One would find "SoftwareArchitecture in Practice, Third Edition" to be a valuable resource for getting up to speed on the state of the art; when need to design, develop, or manage large software systems (or plan to do so). From this book, one would learn how to envision, create and analyze architectures using provided case studies and some of SEI methods explained in the book. 

One needs to purchase this book, however its second edition is available online.




Software Architecture Documentation Case Studies by SEI Wiki

The known architecture description styles are  ISO/IEC 42010 (an international standard for architecture descriptions of systems and software) / 4+1 Architectural View Model / Views and Beyond: The SEI Approach to ArchitectureDocumentation.

But for newbies to software architecture documentation, the case studies on SEI Wiki is great place to start containing the sample architecture documentation of the "Adventure Builder" and the "Java Pet Store" applications.


On a separate note,
  • One would need to understand UML, when it comes to Architecture documentation. If you don't know UML, then see http://www.uml-diagrams.org/


97 Things Every Software Architect Should Know

Great compilation of things which every software architect should know, and also published as a book by Oreilly.




Architectural Posts

Apart from systematic approach of building architectural skills, one should develop habit of exploring architectural experiences shared by intelligentsia. There are many resources for reading architectural posts, but my favorite are highscalability.com and infoq.com.



Frameworks for Enterprise Architecture

Apart from software architecture, when it comes to enterprise architecture, mainly I refer TOGAF framework documentation.




Disclaimer:
Undoubtedly there are unlimited resources for learning and building Software Architecture know-how. So I don't claim the above-mentioned are the best, but I am saying that those are my favorite and I trust recommending those to others.


Finally if you know any better available online resource for enhancing software architecture skills, then please share in comments.

Saturday 16 August 2014

Executive View of Spring IO

Pivotal released the first version of their new Spring IO Platform 1.0 in June 2014, which is indeed in line with original Spring's aim: bring simplicity to Java development.

Before moving to executive highlights of Spring IO platform, one should know some formerly vs. current key points about Spring.
Formerly
Now
Referred as "Spring Framework and related project"
Highlighted as "Spring IO Platform = Spring IO Foundation + Spring Execution"
Spring framework founders -> Created SpringSource -> Purchased by VMWare -> In April 2013 VMware, and its parent company EMC Corporation created a joint venture called Pivotal
Sponsored and led by Pivotal

A bird's-eye view of Spring IO Platform and Projects

Following mind mapping diagram represents high level view of Spring IO, which brings together the Spring family of projects into a cohesive and versioned foundational platform for modern applications. On top of this foundation it also provides domain-specific execution environments for a variety of enterprise workloads.

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


References


Saturday 26 July 2014

J2SE 5.0 - Sample code snippet for getting started with new features

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

I know Java 8 is already released with remarkable functional programming and many more new features and enhancements. But sometimes I meet candidates claiming Java experience while taking interviews, but not having even fundamental knowledge of J2SE 5.0 (Java 1.5) features! So I thought to collate my Java 1.5 knowledge upgrade notes along with sample code snippet and publish this post for public reference.

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

Executive view of major features introduced in JDK 5.0 --- For more detail, please refer Oracle documentation of New Features and Enhancements in J2SE 5.0.


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

Please note: Purposefully I have referred different terminologies here like J2SE 1.5 / JDK 5.0 / Java 5. To know the exact naming of different Java releases, please refer my New to Java - Getting Started Guide post.

Sunday 13 July 2014

Java power tools series - Diagramming and Reverse Engineering Tools

I hope, you have already read "Preface" of my java power tools series. This post summarizes some of tools for drawing manual diagrams as well as generating diagrams from existing java codebase.

This post would benefit you, if your answer is "No" for below questions
  • UML diagrams are widely used for software architecture and design documentation. Are you aware about UML tools, which offer forward engineering, reverse engineering or roundtrip engineering?
    • Forward engineering = First design using UML diagrams and then generate code from diagrams.
    • Reverse engineering = Generating diagram from code by using static and/or runtime approach.
    • Roundtrip engineering =  Forward + Reverse engineering. UML diagram and Java code are constantly maintained in sync.
  • There is a need to maintain large and complex legacy systems of the enterprise, but system’s documentation is missing or outdated. Beside that you have insufficient knowledge of functionality, architecture and code. In such situation do you use range of tools for visually explore the code or  doing impact analysis?
  • You are not able to understand code sequence flow for the given functional use case of application. Do you know how tools can help to explore code of critical use cases by generating sequence diagrams on the fly? Well, runtime reverse engineering tools can expedite you to perform impact analysis of unknown code, and reduce the bug fix and release cycle time of applications.

My Favorite Tools

Following are some of my favorite tools, which evidently supported me while working on tasks like software architecture and design documentation, impact analysis during maintenance phase, java legacy systems assessment, etc. So I though to summarize those in this post along with few demo diagrams generated for Spring Petclinic application using different tools.

Diagramming Tools

Microsoft Visio - Though commercial, it is my most favorite tool to draw software architecture and design diagrams manually. Also you can empower it further by adding stencils like UML stencils, AWS stencils

Alternatively sometimes I use free online web interfaces like,
  • http://cacoo.com/ - to create a variety of diagrams such as site maps, wire frames, UML and network charts
  • http://www.gliffy.com/ - to create professional-quality flowcharts, diagrams, floor plans, technical drawings, and more

Static Reverse Engineering Tools

This means, such tools would allow you to generate diagrams from the source code without running your application.

ObjectAid (Free for class diagram / Commercial for sequence diagrams)
  • It is a lightweight code visualization tool for the Eclipse IDE. The great features is that, it can show Java source code and libraries in live UML class and sequence diagrams that automatically update as code changes.
  • My personal feedback: Easy to use. I found it highly useful to maintain critical class and sequence diagrams of software system up-to-date as the code changes.

Architexa (Individual Edition is Free for 3 users for a year / Purchase Commercial Edition)
  • One can use it by only installing Architexa plugin in Eclipse IDE.
  • Features - Generate diagrams from code, Understand and document code from diagrams, Share and collaborate visually.
  • Supported diagrams - Layered diagram, class diagram, sequence diagram.
  • My personal feedback: Easy to use. Initially it takes few minutes to build indexes based on the size of the project source code, but then offers to generate excellent diagrams from the java code and specifically I love the unique layered diagrams it can generate.

ModelGoon (Free)
  • Eclipse plugin to generate package, class, interaction and sequence diagrams from existing java source code
  • My personal feedback: Doesn't generate beautiful diagrams, but may be helpful to generate simple diagrams for some portion of java code.

Runtime Reverse Engineering Tools

Such tools demand your application to run, so first of all you need to setup runtime environment of the application. Then run a functional use case scenario and record corresponding trace using options (e.g. start and stop recording) given in the tool. That would generate sequence or class or package diagram for the given call trace, which can expedite developer to analyze application code of that functional use case scenario from generated diagram in just few minutes. All in all, such tool are extremely helpful when developers need to discover and document unknown codebase for the given functional use case scenarios.
  • Features - (1) Flow allows you to visualise the dynamic dependencies between packages, types and methods. (2) Flow provides a view of method call progression of all threads for better understanding of the execution paths. Flow records the entire execution so that it can be replayed forward but also back in time, and as many times as needed.
  • My personal feedback: It's indeed easy-to-getting-started and generates nice package/class/method level visual diagrams. The tool has remarkable ability to enable us recording the execution of code flow for the given use case, and then it can be replayed and visualized through a web interface. Be aware, the tool is free at this stage and it is likely that free version will be always offered in future (as per FAQ). However, you never know. So I suggest check its license, before using it.

Maintainj (7 days Evaluation, then Commercial)
  • Maintainj claims - Generate interactive sequence diagram and captures basic context information from call trace by running a use case, which helps to reduce the bug fix and release cycle time of applications; and document code in minutes.
  • Three step process - (1) Instrument code (2) Generate trace files (3) View diagrams (you need Eclipse IDE to install Maintainj plugin for analysis of generated sequence and class diagrams)
  • Supports - (1) JRE 1.4, 1.5, 1.6 and 1.7. (2) Swing, Applets, JUnit (3) Most of widely used J2EE application servers and Databases
  • My personal feedback: Personally I found it quite useful for runtime reverse engineering. But you must be aware that, it has performance penalty to increase server startup time. So should only use in development/qa environment, but not in production.

  • Both are Free Eclipse plugins and has runtime reverse engineering ability to generate sequence diagrams from java source code
  • My personal feedback: Based on my personal experience, I am skeptical about stability of both compare to Maintainj. Also Maintainj has more advance features compare to both.
    • Eclipse Diver - The last release is in Sep-2012, so it doesn't look active anymore. Also there is major stability issue open for Windows 7 for runtime sequence diagrams generation and analysis, which is mentioned as not going to be fixed in near future. Still one may try it in Linux or other than Windows 7 OS. 
    • Eclipse JIVE - When I tried it for one of J2EE application, it has taken more than 10 minutes time to start server and then also eclipse was getting hang sometimes. I tried with Eclipse Kepler only, and did not check with another Eclipse version!  

Forward and Roundtrip Engineering Tools

Modelio (Free) / ModelioSoftJava Solution (Commercial)

Miscellaneous Tools

Dr. Garbage Tools (Free Eclipse Plugin)
  • Source code visualizer, specifically can be useful to review and analyze complex conditional logic flow within particular method of java class.

Below are miscellaneous tools, which I consider sometimes for generating diagrams from java code to represent internal and external dependencies of software components.





Final Thoughts

  • Use applicable tools to generate diagrams from java code & accelerate productivity to understand/analyze the code.
  • Keep software architecture and design documents up-to-date by adoption of appropriate tools.

Updates History

  • 28/Dec/2014 - Added JArchitect in Miscellaneous tools section
  • 19/Jun/2016 - Added Flow tool (as per comment of Yiquan Zhou) in runtime reverse engineering tools section.

Disclaimer

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


If you know or have experienced any other reverse engineering tools suitable for Java projects analysis, please share the name of such tool along with your personal feedback in the comment.