Pages

Scala On Intellj Idea

Birt Made Report Easy

Here is the complete guide to build report in Eclipse using Birt plugin.

Birt or Business Intelligence and Reporting tool is a tool that can build report without writing toooo many java codes. If you are using ireport you know what I'm talking about :) (crystal report.. no point :D)

Main draw back in Ireport is we have to write too many codes to build simple report that can integrate to java application. But in Birt no need to write codes just drag n drop.

Birt is a Eclipse Plugin (Only to Eclipse) that you can download. So in this article we demonstrate how to build some sample report with ease of drag n drop :)

Here we go...
Step 1

  • Download Eclipse (http://www.eclipse.org/)
    • You can download eclipse for report users (Comes with Birt Plugin)
  • If you already have eclipse just install the birt plugin
    • Help --> Install New Software --> Click Add
    • Give name as Birt and give location as http://download.eclipse.org/birt/update-site/3.7-interim/
    • Click Ok 
    • Select All packages (tic) and accept the license agreement (whether we like it or not :P ).
    • It will take some time to download all the packages and after the download restart the eclipse.

Step 2
  • Before make project adjust your perspective to Report Design
  • To do that Window --> Show View --> Other
  • Select Report tab and select all the fields


Step 3
  • Now its the time to create new project
  • File --> New --> Other --> Business Intelligence and Reporting Tool --> Report Project
  • Give a Name for the Project and click finish.

Step 4
  • Now the Project is created. But we have to create a report.
  • To do that File --> New --> Other --> Business Intelligence and Reporting Tool --> Report
  • Give a name for report and and click Next.
  • In here you can choose the report template. (If you have one you can use it. but before you have to register the report template. will talk about this later)
  • I choose Blank Report and click Finish.





Step 5
  • Now report is ok. But we need to display data. 
  • Click Palette in Left Hand side (this is the place that all controls have) and drag n drop Table component to report design.
  • Give number of rows and columns and click Ok.
  • Now you can see the table  in report view (layout you are currently in)



Step 6
  • So the basic designing part is done. but data?? (give me 5 min)
  • Click on the Data Explorer (right hand sof Palatte) --> right click and select new data source
  • In here we can configure the database. For this demo we configure in built database that comes up with Birt. (Classic Model) (Others will talk later)
  •  Select Classic Models --> Next --> Finish.

Step 7
  • Right click data set --> new data set --> Next 
  • In the query window you can see the databases available. 
  • Select CLASSICMODELS expand it.
  • In the query text area you can write the SQL query.
  • In here we select customer name, customer first name and customer phone (You can do this by double clicking the table values in Available items)
  • After click Ok you can see the window edit data set (if you have any query issue it will show some error window)




Step 8
  • Click Preview tab (in layout are) and you can see the output of data.
  • Run --> View Report --> In web browser --> you can see the report in web browser.
  • Can give more advance function like export to doc, pdf, ppt and many more.






Here is some basic things about Birt report. But Birt is more than that. You can write javascript to get more functionality. We will talk about this later. That means the Advance Birt :) 





Complete Guide To Deploy Java Web Application in Amazon Ec2 using Eclipse

Hi readers,
Today I'm going to show you how to deploy simple java web application in amazon ec2 using Eclipse IDE.
Before we begin we need some required things,

k, lets start, here we go....

Step 1
  • First you have to install the AWS toolkit for eclipse plugin. Simply go to Help--> Eclipse Market Place --> Search Amazon
  • You will get the AWS toolkit for eclipse .
  • Click Install
  • It will show the corresponding packages and after agree the license will install it. Just a simple procedure.

Step 2
  • Windows --> Preferences --> select AWS Toolkit and Fill the fields according to your amazon ec2 account 
  • Give your name to Account Name (Not Necessary), but give exact value to Access Key ID and Secret Access Key according to your amazon acc.
  • In the optional configuration (Expand it) give account id (exact value) to that field.

Step 3
  • Windows --> Show view --> Other --> Select AWS toolkit view (Select all views) --> OK
  • Now you can see the perspective view of aws.

Step 4
  • Now the configuration part is over.
  • Lets create a Amazon ec2 server. To do that File --> New --> Other --> Server --> server  --> select amazon ec2 or amazon elastic server tomcat version 6 (you can either choose tomcat version 7)
  • Fill the fields and Finish. (Hope you have some basic understand about eclipse)


Step 5
  • Now create a Dynamic Web project. File --> New --> Other -> Web --> Dynamic Web Project
  • Give whatever name you like.
  • Choose AWS Ec2 or Elastic runtime as a target runtime. 
  • Click Finish


Step 6
  • Now create a servlet and Finish
  • Change the doGet() in servlet (Only for demo. This is where your code goesssss)


Step 7
  • Right click Servlet --> Run as --> Run On server --> Select the server you above create and Finish.

Step 8
  • Eclipse will automatically open the web page that you created. (Or in server tab right click the server and select amazon web service --> running)

Thats it.....

Just a simple procedure but you can expand this in your war... its up to you.


Top 10 GIT command

  • How to setup git ?
    • Both linux and windows distribution are available.
    • For linux use 'yum intall git-core' 
    • More info for both : http://help.github.com/linux-set-up-git/ 
    • can integrate into your favorite IDE. ex: Eclipse, Intellij IDEA , NetBeans 
  • Top 10 Commands
    • git init
      • To create repository (Use this command inside directory)
    • git add --all
      • To add all new files to repo
    • git commit -m "Initial commit"
      • Commit files
    • git clone
      • Copy repo from remote location.
    • git push
      • Push files to remote repository
    • git pull
      • Get update from latest project
    • git diff
      • Show the difference between current file content and latest repo file content.
    • git status
      • Diff between your local repo and your working directory
    • git rm <file-name>
      • Remove file from local repo
    • git mv
      • Move file to another location

Linux Then and Now

Linux.... one of the most growing o/s in today... most of the people using this because you can gain lot of advantages over windows... So here I found some good picture about Linux then and now stats..

Powering Java Web with Filters

First things First.. What is a Filter ? Filters are Java components that we can use to process request before they sent to servlet or process response before they sent to client. So the poor servlet doesn't know about these things.

So actually why we are using this ? What is that much of important in filters ? Here is the answer..
Suppose you want to enhance your web app by tracking the users that goes to particular servlet. So the typical answer is change the code in servlet and add necessarily things to fulfill the requirement. This is not a good choice. Because editing the servlet source code can effect on the other areas in your app. So the one and only choice is to use Filters.
In this article you will learn some basic things about filters and specially how to use filters.

Filters can be chained together, to run one after the other and its in-dependable. Filters don't know what filter before run or after.
Our Deployment Descriptor(web.xml) control the order that filters run.

Filter's Life Cycle
Every Filter Must implement 3 methods.
1. init()

  • Can do any set-up task before the filter called.
2. doFilter()

  • This method is called every time the container determines that the filter should be applied to the current request.
  • It takes 3 args.--> ServletRequest, ServletResponse, FilterChain
  • This is the method that implements all of your logic that you want to do in filter.
3. destroy()
  • Container decide to remove the filter it calls the destroy(). 
  • Can do any clean-up

Configure Filters in Deployment Descriptor(web.xml)
When we config filters in web.xml we usually do 3 things.

1.Filter Declare


<filter>
<filter-name>name of the filter</filter-name>
<filter-class>class that contain filter login (ex: implement Filter interface)</filter-class>
<init-param>
  <param-name>para name</param-name>
  <param-value>para value</param-value>
</init-param>
</filter>


  • <filter-name> and <filter-class> are mandatory
2. Map Filter to URL 

<filter-mapping>

  <filter-name>name of the filter</filter-name>

  <url-pattern>/*</url-pattern>
</filter-mapping>

3.Map to Servlet Name
<filter-mapping>
 <filter-name>name of the filter</filter-name>
 <servlet-name>name of the servlet map name</servlet-name>
</filter-mapping>



  • If the request coming from forward, include , request dispatch or error you can use this.
  • <dispatcher>FORWARD</dispatcher> or ... inside 2 nd option.
Here is some basic things about request filter. On next post I will talk about response filters and some basic example of this implementation.  KIT :)





Introduction to Scala

Scala scala scala .... one of the most popular JVM based language. So here I found some great presentation about scala which gives some basic idea. :)

Interview with Martin Odesky (Creator of scala)


War Between Developers, Designers and Project Managers

Here I found some interest article about developers, designers and Project Managers. Actually its a picture that tells more about an article.(picture says a thousand words than a single one word article). Here you go :D


Hope you got what it tells :D

Interview with Scala's Martin Odersky

This is an Interview with the developer of scala, Martin Odersky. (Hope you know what is scala :P)
Ref : scala-wiki   scala-lang

Interviewer : There are lots of languages coming to the JVM (JRuby, Fantom, Clojure, Gosu, and so forth). How is Scala different and how will it escape being a niche language?


Martin Odersky(MO) : How will Scala compare to the other languages? First, there's a big divide between statically typed (which typically goes along with a fast runtime) and dynamic typed (which typically goes along with being a little slower). Scala is one of the few statically typed languages on the JVM. The other big one, of course, is Java. It's true that there are some other statically typed languages coming out and we'll have to see what kind of traction they get. Scala, however, was the first statically typed alternative. The other big thing for Scala is that it combines the OO model of Java with functional programming. And it's the only language to do so. The other functional language on the JVM is Clojure, but Clojure sheds the OO model.


I : Sheds it completely, yes.


MO : And Scala doesn't do that. We think that the biggest gains are in the combination of the OO model and the functional model. That's what we firmly believe is the future.


I : Do you expect then that the Scala model will mostly consist of the hybrid model or is part of the effort to encourage people to adopt a mostly functional programming model?


MO : I would contest that it's a hybrid model. I think it's really a fusion. It's not a mixture of two things; a new kind of program, which are both objects and functions. The one thing that you tend to give up more and more is objects with mutable state. That's sort of the old, classical kind of object model, which you can still do in Scala. But it's true that the trend moves more and more away from that to the purely functional. Once you do that, there's no mixture at all between the two models.


I : On the Scala website, you list the qualities of code associated with increasing expertise in Scala. It seems to get more functional as one becomes more expert.


MO : Of course, that's true: Because at these levels of expertise, we took as a baseline somebody coming from Java, so with imperative code and mutability — "that's what I know." It's true that to become functional, for an individual to get deeper into Scala, most people would start off with the more imperative side and then progress towards the more functional side. Imperative and object oriented are two different things.


I : Are there niches where you're seeing Scala being strongly adopted? Like Erlang with telephone switches: Are there areas that are a particularly good fit?


MO : There are two market segments where Scala is leading relative to the others and one is Internet companies; in particular, Internet companies that need to scale rapidly. Examples are Twitter, LinkedIn, Foursquare, and many others. The other big market is in finance. They are more discreet; I can't talk about much. But there are some very high profile projects. For example, at UBS, it's approved for general production usage there. There are many other projects in risk analysis, contract modeling, etc.


I : Is the scalability you're referring to due to the built-in actor syntax?


MO : The actor syntax is actually not built in. It's a consequence of the fact that Scala has very high abstractions for syntax. It's a pure library. So, it's actually not built in.


I : OK, so...


MO : It's actually much more than that. Scala is built on a very fast runtime, the JVM. Being functional, Scala sheds a lot of the liabilities of imperative code, which becomes very, very serious as you go parallel. If you want to go parallel, either implictly with the parallel collections or explicitly with actors, anything that has state change becomes an increasing liability for reliability and sometimes even performance. So essentially, it's the functional genes of Scala, coupled with the fast runtime that makes it a very good contender.


I : It seems that any functional language running on the JVM could probably attain the same kind of scalability you're referring to. Would you disagree with that?


MO : I would disagree with that. Because if you look at the actual code out there, like the collections that have become parallel in Scala 2.9 and will be distributed in one of the next iterations or the actors, they are really extremely expressive and they make essential use of the object-oriented features in Scala. Without those object-oriented features, we could not have built these sophisticated ways to express parallelism.


I : Talking about the syntax of the language, when I look at Scala code, I feel like I'm reading backwards. The return value is at the end of the declaration, and the types are declared after the variable names. Was that an intentional design to move away from Java and C-like syntax? Why did you choose to invert the positioning?


MO : We're not the first to do that. There are many other languages that do that: Pascal, Modula, Ada, and lately, Go. There's a whole language family that does it the Scala way. It's true, though, that the dominant languages — C/C++/Java — put the type first. I think that was a very good decision at the time C was created — actually, C got it from Algol 68, as far as I know — to put the type first. In the early days, the types were very short keywords likeint, or long, or float. Essentially, for the price of one, you got two things: the start of a new definition, and what's the type of the thing.

Nowadays, things have changed a lot. First, a lot of our types have become a lot bigger. We have a type, which is a hash map of strings to a list of booleans [holding out his hands wide apart], and then comes the thing you define at the very end. The type of the thing you define should be the important thing. The second thing is that, quite often, this type (whether long or not) can be inferred, which means it goes away completely. A lot of Scala code is that way.

I : Yes

MO : Then you have to invert things. When the type is gone, you have to put something in its place. So, we decided to do a very regular syntax, which says that we always have a keyword first, which says what kind of definition we define: Is it a method? a mutable value? Is it a variable? Then comes the name, then comes the type. So that's why we went that way.

I : So, it wasn't just a personal preference.

MO : Oh, no, no.

I : What about the use of capital letters on the primitive types? Why is Int not just int? I'm curious because there are several other languages based on the JVM that don't pass through…

MO : On the first iterations of Scala, we did write lower-case int. At some point, it stopped looking right and we converted to the initial upper case. It's mainly in Scala that the primitive types are actually not primitives. They're object types, so it didn't seem to make sense to give them the syntax of other types. We wanted to emphasize that they're types like any other object.

I : I'd like to go over some of the common complaints about Scala and get your feedback about them. The first thing that I see complaints about is the lack of binary compability between releases. Is that problem going away or, if it's going to continue, tell me why.

MO : We are working hard to address that problem right now. The problem with binary compatibility is mainly due to the fact that Scala permits libraries to evolve much better than Java. Essentially, the fundamental problem is that, with Java interfaces, you will never be able to add anything to the interface because you don't have control over who implemented it. When you change the Java interface, you have to rewrite all the implementations. Scala makes it much better and more flexible because you can add methods to a trait — the analogue of an interface — and you don't need to rewrite the clients because essentially the whole thing will continue to work. But you have to recompile the implementations of the interface. As a consequence, people in the Scala community take much more liberty in doing that because the barrier is not very high.

I : So what are you doing to remedy it?

MO : We are working on a tool-based solution because we don't want to restrict the community from using this feature. The tool is based on binary class file rewriting. The compiler would do that automatically by going from an old version of the class to a new one, rewriting [the necessary parts.] And we plan to make that available as part of the TypeSafe stack.

I : So, really, this binary compatibility problem is one of recompiling code that's been extended from previous versions?

MO : Yes.

I : Scala uses a lot of characters with special meanings like Perl does and like Ruby is getting rid of. Do you see them as a problem you're going to get rid of or will they be part of the syntax going forward?

MO : That is all in the libraries because Scala does not really have operators. But as the libraries have evolved, there's been a strong consensus that we should be very careful with these things. There have been some very good usages for these characters and I believe, over time, people will get used to them. But certainly over time, we do not want to get further into that.

I : In a recent post, David Pollak of the Lift framework complains that the multiparadigm design of Scala doesn't encourage a specific kind of style. And so there are people using Scala as syntactic sugar for Java, other people doing functional programming. Because of this, it's hard to know if you're using the right idioms and to read other people's code. How do you solve that when you have a language that's specifically designed to be multi-paradigm?

MO : I think David raises a very good point there. On the other hand, in that same blog post, he says that Haskell and other languages like that will have problems because they're too opinionated. So, whether you're opinionated or not, you lose [Laughing]. What we are going to do is a style-checking tool. I got some feedback the other day from someone who wants not only a style checker, but to know "where are we in the codebase? Are we functional, are we imperative? At what level of the Scala usage are we?" We can answer that with tooling, so we plan to integrate that in one of the next releases of the IDE. We'll include things you can customize and that give feedback for organizations that want to use Scala a certain way.

I : So, enforcing a kind of Scala style.

MO : Yes. And we have a coding standard. It's important that we disseminate that as well. So we plan to have tools that are opinionated that tell you, "you should write this code this way."

I : Will that coding standard be available soon?

MO : There is a Scala coding standard. That's our point of departure. I agree with almost everything in there.

I : Another complaint is the slow compilation and interpreter.

MO : There are two factors in that. The first is start-up cost. Currently, the Scala REPL and the compiler take 3 or 4 seconds to come up. That's too long. We have recently cut that by more than half. It's not released yet, but we take this problem very seriously and we will get it done. There are some solutions now, such as the fsc compiler (Fast Scala Compiler), which essentially stays resident in memory.

I : Is that part of the general distribution?

MO : Yes. We're also working on throughput to make big builds faster. It's hard. Inherently, we can't be as fast in terms of number of lines compiled as Java because typically Scala programs are a lot more compact than Java programs.

I :  Let's talk about tooling. It seems as though the Eclipse, IntelliJ, and NetBeans plugins are pretty much the top three IDEs out there. Are you going to be working on tooling?

MO : We've already put more than 1.5 person years into the new Eclipse IDE, which is currently in beta. I personally switched to the Eclipse plugin after 20 years of emacs. Certainly before then, I tried the plugin; but for the complex projects I do, it didn't live up to what I needed. Now, I would now never go back to emacs.

I : I think that most people, once they leave emacs, do so permanently.

MO : Yes. But there will be some people who will not be happy with you for saying that.

I : You just launched a new company, TypeSafe. What are you planning to do with it?

MO : We see a lot of demand for Scala and for highly parallel middleware on top of Scala from enterprises. This has convinced us that these things need reliable, long-term commercial support. So, we got together with the people behind the Akka framework, which is the most widely used parallel computation framework on top of Java, and we formed Typesafe to provide the developer tools, which will be open source and free, and the Akka/Scala stack, which is also open source. We'll provide support around these things.

I : So, you'll be doing training, services, and tool development. Is that right?

MO : Tool development, training, and lots of support. We want to do subscription-based support, similar to the Red Hat model — it's no accident that people we work with [are] at Greylock (the venture capital firm behind TypeSafe. — Ed.). The lead investor is also on the board of Red Hat.

I : I was just going to ask you if you're VC-backed. So does this mean you'll be leaving your teaching position?

MO : I took a leave from the EPFL in Switzerland to form the company. But I'll be back teaching in the fall if all goes well.

I : Is there a .NET version of Scala planned?

MO : Yes. We announced it in July. We have a project, which is actually funded by Microsoft, to build a .NET version of Scala. And we have the first bootstrap version of the compiler compiling itself on .NET. There is still work to do, especially on Visual Studio integration.

I : How about a compiler to native code. Is that on your radar?

MO : Well, that's interesting, I was attending a talk on this that I left to come meet with you. They're compiling to LLVM. It's being done by a company in association with the University of New Mexico. We'll have to see how that goes. The problem is one of resourcing. We can't do all the back ends at the same time.

I : Understood.

MO : One of the things coming up is Scala for JavaScript.

I : Very cool. So, what's going to be new in the next release?

MO : The next release will be v. 2.10, because v. 3.0, by our numbering scheme, would be backwards-incompatible and we don't want to do that at the present time. We'll have better support for dynamic languages, better reflection, and generally, we want to go into better support for parallelism. And also, we'll be working very hard on the next release of the Akka framework.

I : Any idea of when that release will come out?

MO : We just released v. 2.9 and we generally have a year between point releases. So, in a year, but some of the features might appear in a minor release, such as v. 2.9.1.

I : I noticed to my disappointment that the most recent release of Scala has four digits. You're going corporate!

MO :  [Laughing] That was a hot fix. We shipped v. 2.9 with some problems that we discovered the day after we shipped and we had to do a quick fix.

I : Well, good luck with all these projects. We'll be watching fromDr. Dobb's to see how these multiple endeavors work out.

What's new in Java 7 ?

Everyone is now searching what's hot in java 7(including me :D). What are the new features that added to java 7. When I'm searching I found a good slide presentation that visualize what are the new things that added to java 7 . It was an amazing :D . Check this presentation and you can see why most of people in love with java.






credit goes to : http://blog.eisele.net/2011/07/introducing-java-7-moving-forward-7711.html

Vaadin , Clojure with MongoDB

In this article I'll show how to connect vaadin clojure app with mongoDB. Assume you have a basic knowledge about vaadin , clojure and mongo.

MongoDB Part 1

To connect clojure and mongo we need to use some driver like mysql connector/J use to connect mysql and java. For clojure and mongo we use karras driver.
More info about karras : https://github.com/wilkes/karras/
You can try the example in there : https://github.com/wilkes/karras/blob/master/example/collection_example.clj

In my example I'll show the usage of this.

In here I create a simple text box and a submit button. When a user enter something to textbox and click Submit button that entered data store in as a clo-vaadin collection in test database in mongoDB.

Bellow I mention the git repo that you can find the source code.
https://github.com/rajithd/clojure-vaadin-appV1

MongoDB - A Document-Oriented database (Part 1)

Introduction
MongoDB is a powerful, flexible and salable data store. It have some features such as secondary indexes, range queries, sorting as well as built in support for MapReduce-style aggregation.
MongoDB is a document oriented database, not a relational one.
Document oriented database have more features than relational databases. The basic idea is to replace the concept of a 'row' with more flexible model 'document'.  Also mongodb is schema free database, No joins and lot easier to handle data.


  • Document is basic unit of data in MongoDB, like row in a relational database.
  • Collection is like a table in relational database.
  • MongoDB comes with a simple but most powerful Javascript shell .
  • Every documet has a special key called "_id".

Setup MongoDB
  • Download the appropriate version : http://www.mongodb.org/downloads
    • Windows version
      • Extract downloaded zip file. (Ex: C:\my_mongo_dir)
      • Go to bin directory and start the mongodb server by double clicking  the mongod.exe (Before that create data/db folder inside the C:\ drive) 
      • After that start the mongo shell by double clicking the mongo.exe (It will start a shell and you can type commands)
    • Linux Version
      • Extract downloaded tar file.
      • Create /data/db in root path.
      • ./mongod to start the mongo server.
      • ./mongo to start the mongo shell.

In the next part I'll show some basic commands such as creating, remove and update documents and collections in mongoDB.

Top 7 Programmers bad habits

1. The All code is crap, except mine, attitude.
I have bad news for you buddy, all code is crap. No matter how much effort you put on it, there is always a majority of programmers who are going to think that your code sucks and that they could have done it 10 times better. I have already covered this topic in previous posts, you can find more information of what exactly I mean when I say that all the code is crap here and here.

How to fix it : Don’t criticise others people code, it could be yours the one in the spotlight, try to make objective and professional observations instead, but don’t judge. Be humble and try to learn from everyone around you, hopefully then your code won’t be so bad.

2. The “I fix that in a second” catastrophe.
Taking shortcuts is very tempting, everyone has done it. There are actually situations where they are necessary, but in overall, they are dangerous, very dangerous and should be avoided. A shortcut which goes wrong may save you a few hours, but may cause months of pain.

How to fix it : Don’t trust yourself when carrying delicate activities. Ask someone else to review what you are doing. Make sure that if you are about to take a shortcut, you make very clear to the stakeholders what the reasons and the risks are. Try to get a manager to sign off every time you are about to take a shortcut.

3. The “That will only take a second” misconception.
Being Barcelona my hometown, I am very proud of the Sagrada Familia Cathedral, which is very well know for its beautiness, and also for the time is estimated it will take to complete, (in construction since 1882), but that’s probably because they didn’t ask a programmer to estimate, otherwise the estimate would probably have been somewhere around 2 weeks.

How to fix it : For starters, is important to understand that accurate estimations in software development for non trivial solutions are impossible, we can only guess. Also remember that is very likely that you will find so many things which you didn’t foresee when you start developing that is worth multiplying the estimate to cover for those, I usually go with 1.5 or 2.

4. The ego spiral

Many programmers discussions look more like rooster fights than human discussions. This usually happens in design and architectural meetings. It is actually quite easy to detect this ego spirals, you just have to substitute most of what the contenders are saying with COC! COC! COCOCOOCCC! COOC!

How to fix it: Leave your ego at home. Big egos are one of the biggest non technical issues for any programmer. Keep in mind some basic considerations when making decisions.

5. “It wasn’t me!”

In my opinion, other bad habit from most programmers is the lack of accountability. We always have an excuse… It’s like if we were saying that under normal conditions we would never make a mistake, which honestly is quite hard to believe.

How to fix it: No need to cry, or to perform seppuku, (aka harakiri), when we make a mistake. Having a healthy attitude where we can you just say something like: “yeah, sorry, now we need to do this to fix this issue, my fault” is a very professional attitude, and it will help you to build a reputation and to be better considered by your colleagues.

6. The demotivated genius.
Repetitive and simple tasks are not the best motivators, but they need to be done, programmers tend to get demotivated and very unproductive when they need to complete them.

How to fix it: Discipline. Unfortunately, there isn’t any other remedy I can think of.

7. The premature programmer.

If programming was sex, there would be a lot of unsatisfied computers. You can just not go in, do things halfway through and then fall sleep. One of the concepts that I find most programmers struggling with is the concept of “Done”. Remember that done means: tested (and not only unit tested), documented, committed, merged…

How to fix it: This one is tricky, the complexity of non apparent necessary tasks to fully complete some functionality is quite high and usually requires discipline and training. Probably the two easiest ways to help a programmer understand if some code is done are peer reviews and demos.

Original Source : http://www.makinggoodsoftware.com/2011/05/23/top-7-programmers-bad-habits/

Apache Shiro is not just another security framework...

Complete Guide to Write Vaadin application in Clojure

In this article I'm going to show you how to write a simple vaadin application in clojure. Before start you need some tools. All of the tools are free downloadable.

Assume you have some basic knowledge about vaadin and clojure.

It is not necessary to use IDE(Intellij IDEA, Eclipse, Netbeans) to write the clojure code. You can use a emacs or vi editor to write the code. But using an IDE can obtain lot of advantages. 

If you'r using an IDE install the corresponding clojure plugin. 

So now if you have all the tools we can start the coding.

First step is the project creation.
  • lein new example 
Using the above command you can create the project and the following files are created.
  • project.clj
  • README
  • src
    • example/core.clj
  • test
    • example/test/core.clj
In order to develop vaadin web application we need the web.xml file. To generate the web.xml file
  • lein war
Now the above command will create the web.xml file inside the src directory.

It's all about project creation. Now you need to edit the files to create the vaadin app.

2nd Step

Edit the project.clj file

(defproject example "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]
[com.vaadin/vaadin "6.6.0"]
[javax.servlet/servlet-api "2.5"]]

:dev-dependencies [[uk.org.alienscience/leiningen-war "0.0.1"]]
:aot[example.vapp example.vaadin-servlet]
:war {:name "example.war"}
)


In order to compile the project you need the above dependencies.

3rd Step


Delete the core.clj file and create a file called vapp.clj

(ns example.vapp
(:gen-class
:extends com.vaadin.Application
:name example.VApp
:init cjinit)
(:import (com.vaadin.ui Embedded ))
(:import (com.vaadin.terminal ThemeResource ExternalResource Sizeable))
(:import (com.vaadin.ui Alignment))
)

(defn -cjinit []
[[] (ref {})])

(defn -init [this]
(println "Starting vaadin application")
(let [window (com.vaadin.ui.Window. "sample clojure vaadin application")]
(.setMainWindow this window)
(.setTheme window "runo")
(let [grid (com.vaadin.ui.GridLayout. 3 3)]
(.setSpacing grid true)
(.setWidth grid "600px")
(.setHeight grid "600px")
(.addComponent window grid)
(let [nav_panel (com.vaadin.ui.Panel. "Sample Panel")]
(.setWidth nav_panel (Sizeable/SIZE_UNDEFINED) 0)
(let [form (com.vaadin.ui.FormLayout. )]
(.setMargin form true)
(let [link1 (com.vaadin.ui.Link. "Link 1" (ExternalResource. "http://www.google.com" )) ]
(.addComponent form link1 )
)
(let [link2 (com.vaadin.ui.Link. "Link 2" (ExternalResource. "http://www.google.com" )) ]
(.addComponent form link2 )
)
(.setContent nav_panel form)
)
(.addComponent grid nav_panel 1 2)
)
)
)
)




Now create the vaadin_servlet.clj in src/example directory.

(ns example.vaadin-servlet
(:gen-class
:extends com.vaadin.terminal.gwt.server.AbstractApplicationServlet
:name example.VaadinServlet))

(defn ^Class -getApplicationClass [this]
example.VApp)

(defn ^example.VApp -getNewApplication [this request]
(example.VApp.))


Now Edit the web.xml file as follows.


<web-app>
  <!-- Servlet class taken from first :aot namespace -->
  <servlet>
     <servlet-name>example</servlet-name>
     <servlet-class>example.VaadinServlet</servlet-class>
  </servlet>
  <!-- Servlet is mapped to / by default  -->
  <servlet-mapping>
     <servlet-name>example</servlet-name>
     <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>


Now compile the project using following command.

  • lein compile
It will download all the dependencies and compile the code.
If there is any error it gives some exceptions.

4th Step
To build the war file use the below command.
  • lein uberwar
It will create the war file that you given in the project.clj.

Copy the war file into tomcat and the start the server. 
  • localhost:8080/example 
You can see the menu button.

Reference : http://clojure.org/
                : http://vaadin.com/home

How To Run Vaadin Applications in Intellij IDEA [Video]

How To Run Vaadin Applications in Intellij IDEA

In this article I'm going to show you how to run vaadin applications with Intellij IDEA. Vaadin provide some plugins for Eclipse and Netbeans. But for Intellij IDEA there are no plugins yet. But to deploy vaadin app is easier than other two IDEs.

Here are the steps that you want to follow.

1. First Create a New Project , File --> New Project --> Create Project From Scratch --> Give sample_vaadin as application name and select Java module click Next --> Next.
Now Select Web Application as Technology and click Finish.



2. Now create a lib folder in web/WEB-INF/lib and copy the vaadin jar file into the folder. You can get the latest vaadin jar file http://vaadin.com/home . Now the Project hierarchy looks like this.




3.After that File --> Project Structure --> Artifacts . In below you can see some error and click Fix button. That will add vaadin jar file to your exploded war. Now Click OK.



4. To deploy your application you need a web server. So in here I use tomcat 7. To config it,
Run --> Edit Configuration --> Click + sign -->Select Tomcat --> localhost .
Give vaadin as Name and Select tomcat as Application Server (If the server is not there Click configure and goto the tomcat path it will automatically recognize it)



5. Now create some hello world programme according to vaadin book and click the Run button to deploy it.

java.lang Package

In this tutorial I'll show you the main classes and methods in java.lang package.

Here are the main classes in java.lang package.

  • classses
    • Boolean
    • Byte
    • Character
    • Character.Subset
    • Character.UnicodeBlock
    • Class<T>
    • ClassLoader
    • Compiler
    • Double
    • Enum<E extends Enum<E>>
    • Float
    • InheritableThreadLocal<T>
    • Integer
    • Long
    • Math
    • Number
    • Object
    • Package
    • Process
    • ProcessBuilder
    • Runtime
    • RuntimePermission
    • SecurityManager
    • Short
    • StackTraceElement
    • StrictMath
    • String
    • StringBuffer
    • StringBuilder
    • System
    • Thread
    • ThreadGroup
    • ThreadLocal<T>
    • Throwable
    • Void
  • Interfaces
    • Appendable
    • CharSequence
    • Cloneable
    • Comparable<T>
    • Iteratable<T>
    • Readable
    • Runnable
    • Thread.UncaughtExceptionHandler

First we take a look at the most important class Object class. Object class has several methods. Some methods are very useful. Here are the methods in Object class.
  • protected Object clone()
  • boolean equals(Object obj)
  • protected void finalize()
  • Class<?> getClass()
  • int hashCode()
  • void notify()
  • void notifyAll()
  • String toString()
  • void wait()
  • void wait(long timeout)
  • void wait(long timeout, int nanos)
Now We take a look at some examples of these methods.

  • protected void finalize() throws Throwable
    • Called by garbage collector. (System.gc)
    • We can override this method to cleanup some resources
    • Not invoked more than once by a virtual machine for given object.

Apache Click





 Apache Click is a Web application framework for Java language and built top of Java Servlet API. Its free and open source project under Apache foundation.

In the new version of Apache Click (version 2.3.0) it add some new features like AJAX support, Page Actions and stateful controls.  Using Apache click we can build a web applications without using JSPs and MCV architecture.

Apache click use HTML templates an POJO for develop applications. It also include some unit testing features.

Ref : Apache Click Home
       : Getting Started with apache click
       : Examples

Protect Your application with Apache Shiro



Apache Shiro is a Java security framework that performs four kind of operations such as authentication, authorization, cryptography and session management. Can use in any kind of web applications or mobile applications. It provide a security API for perform the above tasks.

Advantages of Apache Shiro

  • Easy to use
              Using and Implementing is very easy.
  • Comprehensive
            There is no other security framework can compare to Apache shiro. It provide wide range of security aspects.
  • Flexible
           Can work in any application like Web or EJB.
  • Pluggable
           Can integrate with many other framework like Apache camel, Spring , Vaadin , Grails.
      

Shiro was 5 years old and previously know as Jsecurity project. There were no other alternatives for java security but the Java Authentication and Authorization Service (JAAS). But in JAAS also have some issues with cryptographic. Java cryptographic architecture was hard to understand and it did not use as usual. But in Apache Shiro it gives flexible security for Java developers add security there applications.

Furtherer References : Apache Shiro Home Page  

MySQL Storage Engines

MySql database is the world's most popular open source database because of its fast performance, high reliability and ease of use.
In this article I'm going to show you, what are the Storage engines available in mysql and how to use them.

What is a Storage Engine
Data in mysql stored in variety of different techniques.Each of this techniques have different mechanism, indexing facility, locking levels. By choosing most appropriate technique can gain additional speed and functionalities to manipulate data.

This flexibility to choose how your data is stored and indexed is a major reason why MySql is so popular than the other database system. Other database systems support only a single type of database storage.


Available Engines

Can determine the list of engines using

mysql>show engines

it will show the list of available engines.


Using and Engine

Specify the engine type when creating the table.

CREATE TABLE DEMO (ID int,title char(20)) ENGINE=INNODB

Altering the existing table

ALTER TABLE demo ENGINE = MyISAM

Differentiating the Engines


To compare the storage engines we need to know some core functionalities.

  • Field and Data Types
          All Engines supports common data types (integer,real,character) but not all engines support other data types such as BLOB (binary large object) or Text.

  • Locking
         How access and update to information are controlled. When object in the database is locked for updating, other process cannot modify the data until the update has complete.

There are 3 types of levels. Table locking is the most commonly level and it locks the entire table during and update. Ex : MyISAM 
Page level locking lock data according to the page of information that is being uploaded.
Row level locking provide the concurrency. Only individual rows within a table are blocks. That means many applications can update different rows with in same table. InnoDB supports row level locking.

  • Indexing
        Increase the performance when searching and recovering data from database.  Some storage engines not support but some are support.

  • Transaction
       Provide data reliability during update or insert information. For example transferring information from one account to another we use transaction to ensure both debit from account and credit to the other account completed successfully. If the process is failed cancel the transaction and the changes will lost.  

MySQL Storage Engines

MyISAM
  • Default engine
  • Use table level locking
  • lacks of transaction capabilities.
  • Large number of data writes(insert/update) can cause problems
  • Design for read data.
  • 64 index per table
InnoDB
  • Support all functionalities of MyISAM and add transaction function
  • Support transactions
  • Can work with very large datasets.
  • Some data types cannot stored
Memory (Heap)
  • Store data in memory
  • If the mysql server shutdown data will lost
  • Not good for long term use
  • Fast performance
Merge
  • Allow to combine tables into one table
  • Can only merge MyISAM tables
  • Table locking level
  • No transaction support
CSV
  • Store data form of CSV(Command Seperated values) file.
  • Not recommend to store large data.
  • Portable but no indexing
  • Easiest method for data exchange
BLACKHOLE
  • Not store any data. Can do insert and update but not store any data
  • Can create indexes
Berkeley DB
  • Hash based storage mechanism
  • Data accessing is very fast(quickest)
  • Support transaction
  • Use page locking
  • Data recovery is a problem
  • 31 index per table

Here is the brief summary of mysql storage engines. Choose a better storage engine to get much performance. 

Backup and Restore Mysql Database using mysqldump Command

mysqldump is a effective tool to backup and restore mysql databases. Using mysqldump command we can backup one or many databases or tables.

You have to use command prompt[Windows users] or kernel[Linux users,MacOS] to backup databases.

Backup Mysql Database

  • Backup a single database
mysqldump -u root -p[root_mysql_password] [database_name] > [path_to_save_with_sql_extension]

ex:
mysqldump -u root -p123 test > D:/backups/test_backup.sql


  • Backup Multiple databases
mysqldump -u root -p[root_mysql_password] --databases [database_name] [database_name] .. > [path_to_save_with_sql_extension]

ex:
suppose we have two databases called test and tutorial
mysqldump -u root -p123 --databases test tutorial > D:/backups/test_tutorial.sql


  • Backup all the databases

mysqldump -u root -p[root_mysql_password] -all-databases > [path_to_save_with_sql_extension]

  • Backup a specific table 
Suppose we have a demo table in test database.

mysqldump -u root -p123 test demo \ > D:/backups/demotables.sql

Restore Mysql Database

To restore mysql database use following command.

mysql -u root -p[root_mysql_password] [database_name] < D:/backups/test.sql

These can be useful for backup and restore mysql databases.

Running Google App Engine in Eclipse

In this article I'm going to show you how to develop and deploy a small Java app engine application on Google App Engine using Eclipse IDE.

STEP 1
First you have to install Eclipse IDE for that . Its free so anyone can download. Here is the link.
Eclipse IDE

STEP 2
Now install Java SDK. Here is the link..
Java SDK

STEP 3
Now install the Google Eclipse App Engine plugin.
Ref Link : http://code.google.com/eclipse/docs/install-from-zip.html

STEP 4
Install the Google web toolkit plugin.
Ref Link : http://code.google.com/webtoolkit/gettingstarted.html


  • There is easiest way to follow Step 3 and 4. Click Help --> Eclipse Market Place 
  • Type Google App Engine
  • install the plugin

STEP 5
Create Web Application.

File --> New --> Web application or Simply click the g icon (blue background).


  • Enter the Project Name  as GuestBook and Package name as guestbook.
  • Make sure Google Web Toolkit checkbox and Google App Engine check box is selected.
  • Click Finish.

STEP 6
Now it will create the project structure like this.



There are some files that Eclipse automatically created.
  • src/GuestBookServlet.java
  • war/WEB-INF/web.xml
  • war/WEB-INF/appengine-web.xml 
STEP 7
After that debug your app like this. Click Run ---> Debug as ---> Web Application 
now it will create a server 8888 port so you can access it by browsing http://localhost:8888/

STEP 8
To deploy your app to Google App Engine right click the app select Google --> Deploy to App Engine




Before deploy get application ID from http://code.google.com/appengine/ .

Those are the major steps that you want to follow to create and deploy Java App Engine application to Google App Engine.