Sunday, March 5, 2023

Spring Boot Annotations

Spring Boot Annotations is a form of metadata that provides data about a program. In other words, annotations are used to provide supplemental information about a program. It is not a part of the application that we develop. It does not have a direct effect on the operation of the code they annotate. It does not change the action of the compiled program.


@Required: It applies to the bean setter method. It indicates that the annotated bean must be populated at configuration time with the required property, else it throws an exception BeanInitilizationException.

@Autowired: Spring provides annotation-based auto-wiring by providing @Autowired annotation. It is used to autowire spring bean on setter methods, instance variable, and constructor. When we use @Autowired annotation, the spring container auto-wires the bean by matching data-type.

@Configuration: It is a class-level annotation. The class annotated with @Configuration used by Spring Containers as a source of bean definitions.

@ComponentScan: It is used when we want to scan a package for beans. It is used with the annotation @Configuration. We can also specify the base packages to scan for Spring Components.

@Bean: It is a method-level annotation. It is an alternative of XML <bean> tag. It tells the method to produce a bean to be managed by Spring Container.

@Component: It is a class-level annotation. It is used to mark a Java class as a bean. A Java class annotated with @Component is found during the classpath. The Spring Framework pick it up and configure it in the application context as a Spring Bean.

@Controller: The @Controller is a class-level annotation. It is a specialization of @Component. It marks a class as a web request handler. It is often used to serve web pages. By default, it returns a string that indicates which route to redirect. It is mostly used with @RequestMapping annotation.

@Service: It is also used at class level. It tells the Spring that class contains the business logic.

@Repository: It is a class-level annotation. The repository is a DAOs (Data Access Object) that access the database directly. The repository does all the operations related to the database.

@EnableAutoConfiguration: It auto-configures the bean that is present in the classpath and configures it to run the methods. The use of this annotation is reduced in Spring Boot 1.2.0 release because developers provided an alternative of the annotation, i.e. @SpringBootApplication.

@SpringBootApplication: It is a combination of three annotations @EnableAutoConfiguration, @ComponentScan, and @Configuration.

Saturday, July 5, 2014

Why people migrate from Flex to HTML 5 ? - Important Reasons

The web application landscape has shifted rapidly in the past year.  Due to Adobe’s changing view of the Flash Platform, many companies who have relied on technologies like Flex are looking to migrate to HTML 5.  This transition can be tricky both for an organization as well as its developers.  Here are five steps that should be some of the first an organization takes in this process:
1. Choose a Client-Side MVC Architecture
Many developers will quickly become overwhelmed when examining the options for HTML 5 web application frameworks.  With Flex, there was a defined class system, a defined component model, and a similar Model View Controller architecture that most of the micro-architectures implemented.  This is not the case in HTML 5 / JavaScript applications.
Within JavaScript you will find frameworks that differ greatly on each of these points.  For example, Backbone JS is a popular client-side MVC architecture for HTML 5 applications, but it does not dictate how your user interface is rendered.  Some people pair Backbone with a client-side templating solution like Mustache JS while others use manual DOM manipulation and still others generate the interface entirely on the server side.
There are several key points to consider when making this decision for your organization:
  • How documented is the framework?  Can your developers easily pick up new concepts solely from the documentation?
  • Does the framework provide adequate real world examples?  These will be crucial for the internal learning process with your developers.
  • Does the framework provide a level of flexibility for the type of applications that your organization creates?
  • Does the framework allow for you to create testable applications?  Does the framework have a testing story already crafted for its applications?
  • Does the framework provide the level or support needed for your organization?
  • What level of support do you require?  Many frameworks are purely open source with no support options.  Some frameworks (like Sencha Touch / ExtJS) have a level of support available to organizations.
If your company is attempting to decide on an MVC architecture, I would recommend examining Backbone JS, Ember JS, Angular JS, and ExtJS / Sencha Touch.  Choosing a framework that contains both a client side MVC architecture and a mature class system is almost always going to be superior than piecing multiple frameworks together.  Picking a micro-architecture doesn’t have to be a permanent decision, but it will give your developers a place to start.
In addition, your team can augment the framework that you have chosen over time.  For example, At Universal Mind we work with Sencha Touch and ExtJS (in addition to other frameworks).  To facilitate code organization and reuse one of our team members, John Yanarella, crafted DeftJS which adds dependency injection (among other things) to the core framework that powers both Sencha Touch and ExtJS.  In short, you can make a framework into what you want it to be.
2. Select a DOM Manipulation and AJAX Library
A DOM (Document Object Model) manipulation and AJAX library is an essential tool in JavaScript development.  In Flex, developers could leverage effects, transitions, and states as all of them integrated with the component model.  In JavaScript, to make something change visually within an application, a developer will have to modify the DOM to add elements, remove elements, change styling, and so on.  In addition, the way to modify the DOM differs across browsers.  A proven DOM manipulation library will make these tasks much easier and will work consistently across all of the popular browsers.  Most of these libraries will include functionality to handle HTTP requests in a consistent manner across browsers.
In many cases, the DOM manipulation library will not be included with your MVC framework.  Some solutions (like Sencha Touch / ExtJS) aim to provide an all-in-one framework, but that isn’t the norm. 
The most popular DOM manipulation library is jQuery, and it has a vast online community.  This also includes a large library of community plugins, but many of these may not meet the bar of quality that one would expect for an enterprise application.
There are many other DOM manipulation libraries that exist such as Prototype, Dojo, and MooTools (just to name a few).  Determining which one is a best fit for your organization requires an examination of  your developers experiences, desired level of documentation, and proposed use cases.
3. Adopt Code Conventions Quickly
There was a level of consistency across most Flex applications in both MXML and ActionScript.  There were obviously subtle differences from one developer to another, but these differences pale in comparison to the differences that HTML / JavaScript bring to the table.  One of the first steps that any organization must undertake is developing a defined set of HTML / JavaScript code conventions.
This task may seem daunting, so I recommend that your organization initially adopt standards that already exist.  As an example, Douglas Crockford, the Senior JavaScript Architect at Yahoo, has a brief list of JavaScript Code Conventions.  I would recommend starting with something like this and then expanding once your organization has some HTML5 development under its belt.
In addition, tools such as JSLint (also authored by Crockford) can force developers into following many of these best practices and conventions.  JSLint also has integration into many of the popular IDE’s including Aptana and WebStorm.
Organizations that skip this step will find that their code has little coherence between projects, and that it is increasingly difficult for developers to ramp up on a code base created by another team.
4. Develop a Testing Plan
Through its lifetime Flex developed a quality testing story.  Developers could leverage unit testing tools like FlexUnit and also enterprise functional testing tools such as HP’s Quick Test Pro.  Making the switch to HTML5 application requires building a testing plan that is just as rich.  Determining how to integrate your QA team into this process is crucial.
For the first piece of the testing plan, an organization will need to make a decision around testing units of code.  One popular solution is Jasmine, a JavaScript BDD (Behavior Driven Development) testing framework.  If you are looking for a more traditional TDD (Test Driven Development) framework, the jQuery project uses a custom framework called QUnit.  If your team prefers to use something similar to JUnit (which FlexUnit was based on), then I would recommend looking at JSUnit.
Another important area to consider is Code Coverage.  The current options for JavaScript are passable, and I hope that they will mature over time.  Options like JSCoverage can help your organization enforce an expected level of testing in your HTML5 applications. 
The next piece centers on functional testing of HTML5 applications.  This is one area where HTML5 development can exceed Flex.  With Flex development, the only truly powerful testing tool was HP’s Quick Test Pro (because Adobe wrote this integration into the framework).  With web standards development, the integration is a little easier.  Tools like Selenium provide for quality functional testing of your HTML5 applications.
5. Define a Build and Deployment Process
As Flex matured, many organizations adopted build tools such as ANT and Maven.  These tools all had integration with the Flex compiler, and building an optimized Flex application generally only took a few discrete steps.  The process becomes a bit more complicated with HTML5 applications.
As you build your applications, you will need to plan on having a build process that accomplishes the following (or a subset of these items):
  1. Minify all JavaScript code
  2. Combine minified JavaScript into a single file (to reduce the amount of files that have to be loaded)
  3. Compile LESS/SASS CSS code (if your organization chooses to use one of these tools)
  4. Combine CSS code into single file
  5. Validate HTML, JavaScript, and CSS against organization or web standards
  6. Run unit tests
  7. Run functional tests
  8. Execute load tests in a staging environment
This integration will generally be a combination of tools from different locations that all need to be scripted using a tool such as ANT.  You can utilize some of the command line tools to minify your JavaScript and CSS files (such as the YUI Compressor from Yahoo).  Some frameworks like Sencha Touch 2 and ExtJS 4 already have a build tool included that accomplishes these steps.
Developing a repeatable and consistent process to push to production will certainly be key to your organization’s success.
Conclusion
Starting off on the right foot is crucial in this transition.  Empowering your developers with these new technologies requires careful research and planning.  By working your way through these items, you can approach your decision with the required amount of forethought.

Saturday, June 28, 2014

Happy Coding with Junit frameworks ecobertura and Emma




Spring MVC is one of the leading Java Web application frameworks along with Struts. In the next few blogs, I will take an use case and demonstrate how to develop a good quality web application in an enterprise Java world. I will also demonstrate latest capabilities of Spring like Annotation based configurations and its advantages over XML based configurations. Prerequisite for this application is Java 7.x, Tomcat 7.x, Maven 3.x and STS IDE.

The use case I will be talking about is a Bookstore application, where in user register to this application and purchase books. There is also an administration task like creating the book catalog.

Spring MVC application architecture

For this sample application we extensively use the Latest Spring MVC annotation capability. The major advantage with this is we will not be depending on any xml configuration including web.xml. I personally like XML configuration with namespace, because it is readable. The advantage of annotation is, since everything is Java, if we use STS IDE, any typo can be caught at compilation time, and we can write a good quality code and even measure the code coverage. We also used Kickstrap as the css engine for this application. Here is a blog on Integrating Kickstrap with Spring MVC application.

What is code coverage?

Code coverage is a measure of how well you unit tested your code. If you use a good IDE like STS IDE we can install ecobertura using the update site. Once you setup ecobertura, you can start developing your application. When you run your JUnit test in “Cover as” mode, it will show the code coverage of your JUnit tests as below,

eCobertura STS-IDE view

Tuesday, May 21, 2013

Central Dogma of Bio Informatics and Model organisms


The whole process which involves transcription of DNA to mRNA and translation of mRNA to a functional protein is called the Central Dogma of Bio Informatics. This dogma forms the backbone of Bio Informatics and is represented by following stages.

DNA Replication
The DNA contains the genetic blueprint which is maintained and passed on by a process called replication. Replication is carried out by DNA polymerase.

Transcription
DNA codes for the production of messenger RNA (mRNA) during transcription. Transcription is carried out by RNA polymerase. The mRNA (messenger RNA) undergoes splicing and migrates from the nucleus to the cytoplasm.

Translation
Ultimately, this created mRNA finds its way to a ribosome, where it is translated. In prokaryotic cells, which don’t have nucleus and ribosomes the process of transcription and translation may be linked together. In eukaryotic cells, the site of transcription is usually separated from the site of translation (the cytoplasm), thus the mRNA must be transported out of the nucleus into the cytoplasm, where it can be bound by ribosomes. The mRNA is read by the ribosome as triplet codons. Then RNAs (tRNAs) transferred into the ribosome-mRNA complex, matching the codon in the mRNA to the anti-codon in the tRNA, thus adding the correct amino acid in the sequence encoding the gene. Then the amino acids are linked into the growing peptide chain. Finally, protein will be created according to the processes mentioned before.
So eventually it’s clear that the DNA carries information for proteins which perform many functions in different locations of an organism. Proteins in living organisms perform several functions like biological catalysts, Structural proteins etc. The proteins which perform a catalytic function are known as enzymes. Each functional protein has a specific region known as active site which combines with the substrate. The active site has a unique geometric shape that is complementary to the geometric shape of a substrate molecule, similar to the fit of puzzle pieces. This means that proteins specifically react with only one or a very few similar compounds.

Hence an error in the blueprint (DNA) would cause a change in the geometric shape of the active site of the protein. This results in deactivation of the functional protein thus engaging in termination of a reaction or its function and eventually causing a disease condition.

So the Central Dogma of Bioinformatics acts as the backbone for diagnosis of diseases and for drug designing. To perform this much easier and effectively model organisms are used extensively


Model organisms

A model organism is a simplified system that is accessible and easily manipulated. A model organism is an animal, plant or microbe that can be used to study certain biological processes.

They are used to obtain information about other species including humans that are more difficult to study directly which means the situations where human experimentation would be unfeasible or unethical. Regardless of their obvious differences in size and life style, all these model organisms create proteins that perform the same core functions as in humans

When scientists discover that a particular gene is associated with a disease in humans, one of the first things they typically do is find out what that gene does in a model organism such as mouse. Hence the mouse genome is similarly organized to the human genome and large blocks of genes are even arranged in the same order. This often used extensively to establish disease models by imitating the gene defects seen in humans, and these models can be used to test the efficacy of new drugs.

The model organisms and humans share the similar core functional proteins the geometric shape of the active sites is also similar. Thus the potential drugs which have a complementary geometric shape of the disease causing protein can be used on to the model organisms which would result in a similar conclusion if it is used on to humans. For the final confirmation of the drug can be tested on more related species of humans such as chimpanzee and eventually on humans as well.

Many of the drugs in current use were discovered by experiments conducted in animals and humans. However, many drugs are now being designed with the specific disorder in view. Model organisms play a significant role as a resource in the process of drug designing.

Saturday, January 5, 2013


Part-Of-Speech Tagger (POS Tagger) is a piece of software that reads text in some language and assigns parts of speech to each word, such as noun, verb, adjective, etc. It is an extremely powerful and accurate tool. You can use it in any application that deals with natural language text to analyze words/tokens and classify them into categories.
For pre-requisites, follow these simple steps:
  1. Download and install java JDK and JRE on your system from here.
  2. Edit system environment variables by right clicking on My Computer -> Properties -> Advance System Settings ->Environment Variables. Copy the path to the bin directory of your JDK installation to the beginning of your environment variable PATH. For default settings, this will look like this: “C:\Program Files\Java\jdk1.7.0_09\bin;” (without the quotes ofcourse).
  3. Download Eclipse IDE from here depending upon your system configuration. You can pick “Eclipse IDE for Java and DSL Developers” if you are not sure which one to chose.
  4. Download Stanford POS tagger from here.
You’re almost ready to go. Lets setup our work:
  1. Open Eclipse and chose the location of your workspace. This is where all your projects will be stored.
  2. Make a new project and name it anything you want. I’ll go with the name “practise“.
  3. Add a new class to it. You can name it “tagText”.
  4. Go to the directory where your downloaded the Stanford POS tagger, and inside the folder “models”. Copy a .tagger file and its corresponding .props file. I will assume these are: “left3words-wsj-0-18.tagger” and “left3words-wsj-0-18.props”.  In your workspace directory, inside your project folder make a new folder and name it “taggers”. Go to this folder and paste the tagger and props files.
Alright people. Now lets start coding !
Add/write this code to the tagText.java file you created.
01import java.io.IOException;
02import edu.stanford.nlp.tagger.maxent.MaxentTagger;
03 
04public class tagText {
05public static void main(String[] args) throws IOException,
06ClassNotFoundException {
07 
08// Initialize the tagger
09MaxentTagger tagger = new MaxentTagger("taggers/left3words-wsj-0-18.tagger");
10 
11// The sample string
12String sample = "This is a sample text";
13 
14// The tagged string
15String tagged = tagger.tagString(sample);
16 
17//output the tagged sample string onto your console
18System.out.println("Input: " + sample);
19System.out.println("Output: "+ tagged);
20}
21}
We are not done yet. We need to import the Stanford tagger library to eclipse. To do this:
Right click on your project “practise” -> Build Path -> Configure Build Path -> Click on Add External JARs -> Browse to the location of your download directory of the Stanford POS tagger and select the stanford-postagger.jar file -> Click OK.
Import library to Eclipse
That’s it guyz. Run your code and you should have this output:
Loading default properties from trained tagger taggers/left3words-wsj-0-18.tagger
Reading POS tagger model from taggers/left3words-wsj-0-18.tagger … done [2.1 sec].
i/FW can/MD man/VB the/DT controls/NNS of/IN this/DT machine/NN
The output you will get
The “FW”, “MD”, “VB”, etc next to each word are classes. For example, VB stands for Verb. The complete list of classes can be found here.
To play around more with this, you can have lots of English sentences stored in a file, say “input.txt” and we can run the tagger and store all tagged sentences in another file, say “output.txt”.
To accomplish this, add a new class named “tagTextToFile” to your project with the following code:
01import java.io.*;
02import edu.stanford.nlp.tagger.maxent.MaxentTagger;
03 
04public class tagTextToFile {
05 
06 public static void main(String[] args) throws IOException,
07 ClassNotFoundException {
08 
09 String tagged;
10 
11 // Initialize the tagger
12 MaxentTagger tagger = new MaxentTagger("taggers/left3words-wsj-0-18.tagger");
13 
14 // The sample string
15 String sample = "i can man the controls of this machine";
16 
17 //The tagged string
18 tagged = tagger.tagString(sample);
19 
20 //output the tagged sample string onto your console
21 System.out.println(tagged);
22 
23 /* next we will pick up some sentences from a file input.txt and store the output of
24 tagged sentences in another file output.txt. So make a file input.txt and write down
25 some sentences separated by a new line */
26 
27 FileInputStream fstream = new FileInputStream("input.txt");
28 DataInputStream in = new DataInputStream(fstream);
29 BufferedReader br = new BufferedReader(new InputStreamReader(in));
30 
31 //we will now pick up sentences line by line from the file input.txt and store it in the string sample
32 while((sample = br.readLine())!=null)
33 {
34 //tag the string
35 tagged = tagger.tagString(sample);
36 FileWriter q = new FileWriter("output.txt",true);
37 BufferedWriter out =new BufferedWriter(q);
38 //write it to the file output.txt
39 out.write(tagged);
40 out.newLine();
41 out.close();
42 }
43 
44}
45 
46}
References:
  1. http://www.galalaly.me/index.php/2011/05/tagging-text-with-stanford-pos-tagger-in-java-applications/
  2. http://nlp.stanford.edu/software/tagger.shtml