Today most of the mobile applications that used to communicate to some server use REST services. These services are also common practice to use with JavaScript or jQuery. Right now I know 2 ways to create client for REST service in java and in this article I will try to demonstrate both the ways I know hoping that it will help someone in some way.

1. Using Apache HttpClient

The Apache HttpClient library simplifies handling HTTP requests. To use this library you have to download the binaries with dependencies from their website.
Here is the code for HTTP GET method:

2. Using Jersey

Jersey is the reference implementation forJSR-311 specification, the specification of REST support in Java. Jersey contains basically a REST server and a REST client. it provides a library to communicate with the server producing REST services. For http get method:

Architexa is a really useful tool for generating UML diagrams for Java projects in Eclipse. Most UML tools out there give you functionality of generating classes from the diagram you have created. But in Architexa you have a reverse functionality; it generates diagrams from existing code. It helps a team to understand and document collaboratively a large Java code base. Starting from today, Architexa is available for free for individuals to use, and this post talks about my experience using it – how I used it?, which features I used?, and what I think of it?

Why should one use Architexa?

If the answer to any of following is yes for you then you should go for Architexa:

Working with a new project or difficulty in introducing an existing product to a new team member.

Finding it hard to understand the architecture of your code.

Exploring unfamiliar code to determine its dependencies, relationships, interactions, and behavior within a codebase.

Trouble finding a starting point in a large codebase.

Wasting time deciphering complex code or documenting about code.

If your answer to any of the above questions is YES then you must go for Architexa. It will handle all these difficulties for you. Architexa helps you create UML diagrams directly from the code in just a single click. So making UML diagrams is way easier than before. It can create layered-diagrams, class, and sequence diagrams. These diagrams become the base for effective discussions and act as useful documentation for the project. Architexa allows you to add and edit Java Doc from code and other notes right next to the diagram.

My experience with Architexa:

(How I used Architexa?)

As do many other Java developers out there I also use Eclipse as an IDE for Java development and face some of the issues listed above in development due to lack of documentation about the project. I was already using an Eclipse tool/plugin for UML diagrams in Eclipse, but that tool was only very helpful if you are the one who starts the project. If you have been given a project that is already developed and does not have enough documentation to understand its flow and code then that tool doesn’t help me much.

About few days ago I got an email about Architexa, a tool for generating UML diagrams for Java projects in Eclipse. At first it looked like a normal tool of generating UML diagrams and I thought why download and use it as I was already using a tool to do same thing? But then I came to know about its functionality of directly generating UML diagrams from the existing code and this feature forced me to try Architexa once. And as I was expecting this is really a great and helpful tool for understanding the top level architecture of a large project. And as an advantage it provides functionalities of sharing diagrams or exporting diagrams as pictures.

I tried Architexa with one of our currently on-going projects and I would like to share my experience about how I used this tool and what features I liked most. I have written how I installed it and used it. I have listed what features I liked and used and would like to suggest you use those features. I have also written suggestions from my side that I would like to see in the product.

Download and Installation:

Download and installation of Architexa is very easy. One can start this procedure by registering on their site here: http://www.architexa.com/start. This registration is required as when you complete the installation it asks for this registered username and password. After this registration steps complete it will take you to the page where you find information on how to install Architexa on your Eclipse, which is also easy understandable and easy to follow. You also have to follow an email verification process which I guess is a very known and common practice to protect from spam and everybody is familiar with it. We have also installed extended features and the in-house group server to see how they all works together.

Generating my first diagram:

Before generating diagrams you first have to configure Architexa indexing. You can configure it after successful installation and account validation or later in Preferences. After this configuration you are ready to generate diagrams. You will see a Cheat Sheets view of Architexa when you install it, where you find and explanation of steps to get started with the different capabilities of Architexa.

Layered-diagrams:

To generate a layered-diagram, you just have to right click on project and select Open in diagram->Layered diagram. Layered diagram gives a good representation of project packages and dependencies between them. It’s a good diagram to have a quick overview of the project. It is very good in displaying a particular classes’ dependency from a package view, and how packages are dependent on each other. Some features that I used and liked in layered diagrams are:

Size of the module is drawn based on code inside it and they are also placed in layered style such that higher layered modules are dependent on lower layered modules. When you hover on any class or package it shows it’s dependencies by arrows to other class and/or packages. Also those packages are highlighted to get proper focus on it. It helps us to decide which modules will get affected if do change in a module.

Double clicking on packages will show the classes and packages inside it.

You can easily add new packages, classes, general connections, actor, database and/or comments directly from this diagram.

Class and sequence diagrams:

Generating class and sequence diagrams is also easy, right click on some class then click on Open in diagram->Class diagram or Open in diagram->Sequence diagram. When you do this it draws a diagram with only one selected class, no any other classes to make it messy. Now you can add things you need by dragging and dropping classes or by exploring class members/methods and their dependencies. Also it uses icons for classes, members and methods that Eclipse uses, so it becomes easy to understand it.

A sequence diagram is a good representation of call hierarchy of methods or members of a class. By this you can easily see which methods/members are called and used by which other classes. To demonstrate the possible flow of control that a system could take depending on various conditions or tests, Architexa displays loops, iterations, and conditional statements in sequence diagrams.

A class diagram gives information about relationships and dependencies of classes with each other. It gives an overview of which class inherits from which class or what classes subclass it. Some features that I used and liked are in these diagrams are:

You can easily go to the code of particular class or method by just double clicking on it.

You can add new methods and/or members to a class. You can also add method call, inheritance, method override, actor, database, comments in these diagrams.

In sequence you can see differences in a file if 2 or more members of a team are working on same file. It shows difference in the diagram which is in my opinion a very cool feature.

Sequence diagrams are also integrated with the debugger.

Sharing diagrams:

Architexa provides a functionality to share created diagrams to team members. To share diagram you have to create a group on its server. By sharing diagrams your team members can easily access the documents whenever they want to. Creating groups is also easy, I have created a group from the website, but one can also create it from Eclipse. After creating a group you have to save your diagram in it. When you press CTRL + S to save a diagram it will open a dialog with 3 options:

Save diagram on local disk

Save diagram on private server

Save diagram on community server

3rd option is for saving a diagram on their server. When you click on it, you will see Upload to server view. Here you can give it a name and choose a group to share this diagram with.

The other way to share is by email. I have not tried this functionality yet and so am not able to write much about it.

Some suggestions:

In layered-diagram, if I drag and drop packages then sometimes it results in duplicate packages in the same group.

In layered-diagram, sometimes an empty group of packages gets hidden and sometimes it stays visible. Not sure if it’s intended but it doesn’t look consistent to me so would like to see a change in this.

Diagrams also include method calls to Java’s default classes like Map or String. What I think is generally people don’t want to know about these classes and calls to methods of these classes as they can be considered as a part of the implementation and not documentation. It’s a part of how one has done the task. Everything else in this diagram is cool.

Fonts used for class names in layered diagram are quite bigger relative to package names; it will be good if it can become smaller.

If you close Eclipse without saving the diagrams, it doesn’t notify or alerts you about first saving diagrams and then close Eclipse. It should alert if one is closing Eclipse without saving diagrams.

Summary

Architexa is a good tool for UML diagrams in Eclipse for Java development. It is very easy and simple to use. Once a class is in a diagram, it is always kept up to date so no need to refresh diagrams every time you change something. And the graphs are also very readable. If you have a large team in which members keep getting changed or you are the one who is responsible for understanding already written large codes then this is the must-use tool for you. Currently Architexa is only available for Java. Though they also have a prototype for C/C++. If you have used it for a new project from the beginning then it will become very easy to document your project, share the diagrams, code change reviews, and much more.

Architexa also has many other features that I have not used yet. For more information on Architexa visit their website: http://www.architexa.com/

Like this:

This article will explain you “how to draw chat bubble in java swing application?” Chat bubble is same as call-out or thought bubble. Today most of the chat application is showing conversion in this format, so this article will help you to do the same in desktop application made in java swing.

Following class is used to draw first chat bubble: (Arrow at the left side of bubble)

Like this:

Hi, I tried to make android robot in java swing. I found 2 ways of doing this:

Get android robot image, and show it as background in panel.

Draw whole robot shape in java 2d graphics.

Here I will demonstrate the second way. The final output will be like this:

There are mainly five shapes used in this:

A half circle shape for the head.

Round rectangles for hands and legs.

Big rectangle for the body.

Lines for antennas.

Small white circles for eyes.

So here is how you do it in java swing using Graphics2d object. The color used is “r=153, g= 204, b=0”:

g2d.setColor(new Color(153, 204, 0));

1. First for the head, the half circle:

g2d.fillArc(75, 55, 150, 125, 0, 180); // head circle

2. The body, a big rectangle. But as in the icon the bottom of body has round corner so as a hack added a round rectangle just after the body, with slightly overlap for not showing top round corners of second rectangle.

Like this:

Had you ever got thought of creating a circular progress bar in swing? yes, huh. At first it sounds difficult but then when you start building it then you might found that it is very easy if you have already made an clock application. 🙂

Final result would be like this:

We will start by creating a circle animation by use of Timer and overriding paintComponent method of a JPanel:

It was easy, huh. Now the challenging part is to remove inner circular part and make it to view like first image. For that I decide to draw another circle with the same color as background. So here it is:

Add this code to paintComponent method and once again run the program. Now you will see something like in first picture. In above code FRACTION is the width you want for your progress bar. Lesser value of fraction, wider the progress bar. One more difference in 2 fillArc method is in the start angle, in first method it is 90 and in second its 92. This difference will be width of the middle hand.