Saturday, 31 May 2014

New to Java - Getting started guide

Today I thought to write a post for those, who are literally new to Java programming language and wondering how to get started with it!

If you already have expertise in Java and  you had followed unique efficient approach to get started with it, then please share your experience in comments for the benefit of others.

If you refer "Newto Java page on Oracle website", you will find key categories namely Java SE, Java Fx, Java EE and Java ME; as well as "Java SE conceptual diagram on Oracle Java 8 Documentation page" as per below screenshot. Also by this time, you might have heard few names of Java based frameworks like Struts, Spring, Hibernate, jUnit and many more. So you may be skeptical about, what to learn in Java space for getting started or what to prioritize in Java SE itself?


If you see history of Java, JDK 1.0 released in 1996 and recently Java 8 has been released on March 18, 2014. So obviously there are unlimited things to learn in Java SE itself, but the question still remains open that "what can be steps to learn Java?" and in the further post I tried to cover it .



Steps for Getting Started with Java

Don't keep switching your focus, instead learn it systematically as per below steps.

Step-1: Development environment setup

At the time of writing this post I would suggest to setup JDK8 and Eclipse Kepler SR2, but you should always consider latest stable release for the setup.  Eclipse IDE setup is optional, and instead you may use any other IDE or may learn Java even without IDE. But Eclipse is suggested, as it is one of most commonly used IDE.

Step-2: Gets your hands dirty with basic Java programming

Now I would suggest to learn java from tutorials point website or may be other videos like Bucky's Java Tutorials Series. Don't just read, instead you must consider basic hands-on with Java programming as you progress such tutorials. Once you gain some basic confidence, then step-3 is waiting for you to build strong foundation in Java programming language.

Step-3: Build strong foundation on Java programming language features and OOPD

Next attempt should be to learn *all* Java programming language enhancements such as Java 4 (assertion), Java 5 (generics, autoboxing/unboxing, enums, varargs, annotations…), Java 7 (Strings in switch statement, binary literals, try-with-resources statement...) and Java 8 (lambda expressions, improved type inference…). This is viable in few weeks time, because I am not telling to learn *all java libraries/packages APIs*. You may refer Java tutorialsby Jacob Jenkov as a basic level cookbook.

In future I will be writing separate posts to cover java programming features of each major release of Java 4 onwards, but for the time being you may refer sample code on my Learn-Java github repo. For example - it already contains thecodesnippet of new language features in Java 1.5 which is Eclipse project, so you can simply import it in Eclipse and start learning those quickly.

Only learning programming language features are not enough to become great developer, but also you should aim to be efficient in OOPDesign - Fundamentals and Principles.

This step would enable to design and write any simplest to complex custom APIs and algorithms for given requirements,  but next step would leverage your overall application development with numerous ready-to-use java based libraries, frameworks and tools.

Step-4: Explore Java packages, libraries, frameworks and tools on need basis


Sorry you can't stop here. Only Java programming expertise is not sufficient for industrial demands, but also you will need to learn more things as per your project architectural and technical requirements such as,

Disclaimer
My objective of this post is limited to provide general steps for getting started with Java. Though I mentioned some of website urls for the reference, in reality you may find other better resources too. So you should always consider any Java books you already have or other better online resources to follow the above-mentioned logical steps.

Also Refer



If you already have expertise in Java and  you had followed unique efficient approach to get started with it, then please share your experience in comments for the benefit of others.

Saturday, 17 May 2014

Three Flaws in Software Design

In below Google Tech Talk series - "Jeremy Walker" & "Max Kanat-Alexander" discussed the three Flaws of Software Design, from Max’s book Code Simplicity: The Fundamentals of Software.
I enjoyed to attend their 40 minutes of talk and below are notes taken for quick reference, but I would strongly suggest to attend this tech talk series for better understand by examples.

Overall software design can benefit incredibly, if such fundamental flaws are avoided.

  • Sounds like "YAGNI" but it's more.
  • It's not about whether you're going to need it in the future.
    • It's about good design.
    • Maybe the only way to do good design is to need the code. (Software solves real problems)
  • Problem
    • Bit rot
    • Will need to be redesigned
    • Trying to handle "every possible thing"
    • Not really saving you time
    • Adding complexity
  • Can be whole classes or functions that you don't need, but sometimes just lines of code you don't need.
  • RULE
    • Don't write code until you actually need it, and remove any code that isn't being used.
    • During code review, check that do you really need this code now for given requirement?
    • Avoid… avoid… avoid… DEAD CODE.
    • Don't assume requirements and write unnecessary code. Ask lots of questions to clarify requirements and write simpler code.
Flaw 2:Not Making the Code Easy to Change (12 minutes video)
  • Also called Rigid design. Two ways to accomplish this,
    • Design in too many assumptions about the future
    • Writing code without enough design
  • Too many assumptions
    • For futures with waterfall model - Essentially a failure to understand that requirements will change.
    • Code can be done in small ways too - For example (i) using magic numbers instead of constants (ii) if you don't need to support international users in current requirements, then you may just consider adding support of it in design as a future requirement but don't implement across the whole framework.
  • Code without enough design (Spaghetti)
    • May be even say to some degree - the more you assume things won't change, the more your code becomes spaghetti.
    • Spaghetti is hard to change because of - Duplication, Complexity, Safety, Could possibly also inversely define spaghetti by these traits
  • RULE
    • Don't assume too much for future requirements. Code should be designed based on what you know now (based on factual requirements), not on what you think will happen in the future!
    • The quality level of your design should be proportional to the length of future time in which your system will continue to help people.
Flaw 3:Being Too Generic (10 minutes video)
  • Often called over-engineering.
  • You cannot accommodate every future requirement now.
  • Too much effort for too little value.
  • Developers do this all the time by trying to be "good" when they don't need to be:
    • Catching exceptions that don't need to be caught
    • Expecting input that you never get
    • Handling situations you're never in (like multi-threading)
    • Injecting dependencies when there's only one choice
    • "One day we might need to…"
  • RULE
    • Be only as generic as you know you need to be right now. Never duplicate code. Have a stable and simple design.

Also Refer

Sunday, 11 May 2014

Java power tools series - Tips to boost Java Developer Productivity

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

Well, first of all let me clarify that I am not going to discuss metaphysical tips here like,

This post is aimed to encourage java developers for adopting some of productivity booster tools (primarily related to hot swapping and code generation) while coding. When I say java developer, I mean to say software programmer working on Java, J2EE and also related frameworks such as Spring, Hibernate...

Someone may say promptly that there are already many IDEs (e.g. Eclipse, NetBeans...) available to increase developer productivity. Although developers are using IDEs for java web or enterprise applications development, they may be getting frustrated because of known issues like,

Problem: Developer productivity loss due to  java app compile, build and redeploy process

The considerable amount of time wasted in traditional build and redeploy process to see/test the changes against any code modifications. Even if you fix just typo in java or properties files, it demands redeployment and keeps you waiting for few seconds/minutes to test changes. TheJava EE Container Redeploy and Restart Report – measuring Turnaround Time survey found that java developers spend an average of 10.5 minutes per hour of coding on redeploying their app to see changes. And, the time wasted doesn’t include build time or the time taken for developers to  focus into the flow again after waiting X minutes for the redeploy to finish. Well, below tips can help you to mitigate this.

Recommendation: Enjoy java coding by using JVM HotSwap / class reloading tools such as JRebel, Hotswap Agent, DCE VM, Spring-loaded, Fakereplace

Click here to watch oneminute JRebel video to see how enjoyable coding becomes when you don’t have to restart while making changes to class structures, resource files and framework configuration files. Do further googling to get setup instructions for each of these tools.

The main purpose of such tools is to avoid traditional java development methodology --- change -> restart and wait -> check. So developers can do java code changes and check those immediately without the need of app redeploy or JVM  bouncing process. That means, developers can focus more on writing code.

At this stage JRebel is the most mature and supports broad ecosystem (most of known containers, IDEs and java frameworks ) among aforementioned tools. But it is commercial and bit expensive. You are lucky, if your company can purchase it to increase your productivity. Below screenshot depicts that how it works in Eclipse IDE!

If your company cannot buy JRebel for you, then don't be sad. You can try open source and free Hotswap Agent project which is similar to JRebel, but main differences are:
  • JRebel is currently more mature and contains more plugins.
  • JRebel offers good reporting like time saved using it.
  • JRebel is neither open source nor free.
  • JRebel modifies bytecode of all classes on reload.

Other freely available hotswap projects are  DCE VM, Spring-loaded and Fakereplace; which can also help you to test your code changes instantly whilst a JVM is running.

If you never experienced one of the above mentioned tools, then I would strongly recommend you to evaluate for your project environment. You should aim to adopt at least one of these to increase development efficiency.

Problem: Getting tired of writing the same java code or xml configuration, over and over again

Repeatedly writing same java code or xml configuration is tedious, but it is inevitable sometimes because the technology demands. For example - hibernate mapping xml files, web services code for given WSDL...  Do you know that there are many tools available to take the burden of repetitive development tasks off your shoulders by automating them?

Recommendation: Use code generation tools as applicable to your project architecture. Some of those are,
Sometimes you may not leverage code generation tools fully, but certainly those can save you from writing some amount of manual code or configuration. Sometimes you may need to do some manual changes, once you get automatically generated code from tools. Still the code generation tools are helpful to developers for reducing some amount of drudgery.

Final Thoughts
  • We should not constantly spend our time complaining about problem we may having; instead focus our time toward correcting the problem. Always remember time is value.
  • I am not saying that, we should use all of the mentioned tools such as JRebel, Hotswap Agent, DCE VM, Spring-loaded and various Code Generation Tools. But we should certainly invest some time to evaluate such productivity booster tools, which are most suitable to our project environment setup.
  • If selected tools are used wisely during the development, those can improve developers productivity tremendously.
  • If you use Eclipse IDE, you can consider installing additional plugins to boost your productivity.


If you know or have experienced any other productivity booster tool which can assist java developers in their chores to increase coding efficiency, please add the name of such tool along with your experience of it in the comment.

Updates History

  • 14/Feb/2014 - Added my another blog post url reference in "Final Thoughts" section, which refers to few productivity related plugins for Eclipse IDE

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