Category Archives: Programming

Completely removing packages in Debian Linux

I recently had to find out if a particular package was properly installed in my Debian Linux OS as something was broken. I used the following command to do that.

dpkg --get-selections | grep -v deinstall | grep oracle

This basically lists out all the packages which contain the text ‘oracle’ in them. Once I find out the exact package name I can actually decide to remove all packages containing them.

sudo apt-get purge oracle*
sudo apt-get autoremove oracle*

Detecting Java Processes listening on local ports

We can use the jps command that is part of JDK to find out which Java processes are running in the current user’s session. We can further find out which network ports have been opened by a particular java process.

Use the follwing command to list all java processes:
jps -l

If you want more details about a process you can execute the following command:
jps -v | findstr <process id>

The following variant of netstat command lists all the listening as well as established socket connection in a system:
netstat -ano

This command can be further used to find out what sockets are opened by a specific process
netstat -ano | findstr <process id>

Subversion Branch and Trunk Sync – Hands On

Subversion has got concept of branches and trunk. Usually the accepted approach is to keep the trunk stable and do all unstable work on the branch. I am going to document how you can create a branch from a workspace using the trunk of a subversion repository. Further I will show how to pull changes done on the branch back into the trunk and vice-versa.

Please replace the localhost:8443 with your subversion URL, the /svn/cjpcs_repo/trunk with your trunk folder and the /svn/cjpc_repo/branches/temp/abhinav with your intended branch folder.

First we create a branch from a workspace checked out to trunk. In this snippet we are creating a shallow copy of the trunk into a branch.
svn copy https://localhost:8443/svn/cjpc_repo/trunk https://localhost:8443/svn/cjpc_repo/branches/temp/abhinav -m "Created a personal branch for abhinav"

In order to start using the branch we need to checkout the branch into a workspace. In this snippet are checking out the branch into the current folder.
svn checkout https://localhost:8443/svn/cjpc_repo/branches/temp/abhinav .

Now you can make some changes on the branch workspace and commit it. Now we need to merge the changes done on branch into the trunk. So go to the trunk workspace and execute the following command. The first command updates the trunk. The second command pulls in all the changes from the branch into the current workspace. If the merge causes some conflicts you need to resolve it manually.
svn update
svn merge https://localhost:8443/svn/cjpc_repo/branches/temp/abhinav

Now commit the merged changes into the trunk. The first command commits the merges done into the trunk and the second command basically confirms the merge.
svn commit -m "Merging changes from the branch"
svn log

That’s it. Your trunk is updated with the changes done on the branch. The same approach can be applied for updating the branch with all the changes on the trunk. The following short snippet summarizes the commands you should execute in your branch workspace to achieve a sync with trunk. If there are conflicts in the merge you need to resolve that manually.
svn update
svn merge https://localhost:8443/svn/cjpc_repo/trunk
svn commit -m "Merging changes from the trunk"

Creating console based applications in Java

Writing a console based app might sound strange to some Java programmers but for some specific purposes writing a console based application is a necessity. For example let’s say I have write an application which needs to be monitored via SSH. In that either we have to come up with some elaborate command line arguments or special purpose log files. However another approach is write the application and give it a text based GUI which is accessible via textual console like putty, konsole, xterm, gnome-terminal etc. The closes thing that comes to mind is ncurses coming from the C world. We have something similar for Java also available and based on some reports I feel that they are stable enough to be used in any production environment which have need for a light weight, low bandwidth textual client.

  1. Lanterna – 100% Java solution. Very interesting.
  2. Blacken – Not a curses library an has it’s own renderer. The API is however curses-like.
  3. Java Curses Library – It’s built upon the Unix curses windowing system.
  4. Charva – A reliable tool that allows rapid building of UI using OOP approach. Existing UI programmers will definitely like it. It however uses JNI.

 

Production helper utility for Java team

I have been thinking about going through some of these tools to get more productive in deploying / delivering Java based web apps to the team:

Drop Jar is a helpful tool to share jar files.

Drop Wizard is a helpful tool for delivering production read jar files.

Spring Boot allows developers to create web apps easily using convention over configuration.

Shade Plugin allows a Maven based build to overcome duplicate / incompatible versions of libraries. If you have been bitten by incompatible log files you know what I mean.

Reactive programming

Reactive Programming seems to be the rage nowadays (as observed in blogs and newsletter). Out of curiosity I looked it up and was impressed with what it is capable of. Turns out that this is a declarative approach which allow code to react to changes in referenced values.

Let’s understand it from the perspective of a spread sheet. Lets say cell A1 has the formula “=B1+C1”. Now typically we expect that if we change the value in B1 or C1 then the value of cell A1 will be updated automatically.

Keeping this example in mind now lets see how  this can work in programming world. Lets say we have an expression that says A = B + C. When this expression is executed in our code then the value of A is updated whenever this expression is ‘executed’. Once this is done the value of B can be changed or the value of C can be changed without reflecting on the value of A. To enforce a ripple effect back to A like we observed for cell A1 in spreadsheet we have to devise elaborate observers / listeners on the values of B and C to update A whenever the value of B or C change. In a real life production environment this simple expression can be replaced with more complex algorithm or data flow and you have a situation which can quickly get out of hand and might be difficult if not impossible to debug.

In reactive programming we react to changes. So in the above situation the value of variable A will be updated as and when the value of B or C changes.

This concept has been well explained in a dzone article.

Eclipse Maven – Download Sources and JavaDoc

Eclipse Maven integration has improved quite a bit and I find it somewhat comparable to the excellent Maven integration provided by Netbeans. I recently required to debug third party jars and I needed their sources for this purpose and as a general practice I always download the javadoc for any third party library I use. This is easily done in Eclipse using the following approach.

Do it per project

Eclipse Maven Context Menu for Project

Eclipse Maven Context Menu for Project

Do it for all projects

Eclipse Maven Properties Dialog

Eclipse Maven Properties Dialog

Problem found with GWT installation on Chrome

Problem found with GWT installation on Chrome

The idea with GWT is that you need to install a Google Web Tool Kit Plugin on Chrome to realistically debug GWT application in your browser. On Firefox browser the plugin is already outdated and probably discarded so Firefox is no longer an option. However on Chrome we still have a plugin and it should work ideally. However my efforts to debug my GWT apps hit a road bump when I encountered the following error when starting chrome.
At the time of starting chrome:
In the Extensions view:

At the moment I just re-dragged the GWT plugin into chrome and resumed my work but I have a haunch that this is not the end of the problem and it will come back to haunt me. I did some search on the internet and I found the following link where people have discussed this problem. The most potent solution which I have not tried yet is listed here for future reference.
Link #1:
https://code.google.com/p/google-web-toolkit/issues/detail?id=7569
Quick fix that might help:
1. Right click on the chrome icon>Properties>Shortcut
2. Add in target: –enable-easy-off-store-extension-install
3. Open chrome and navitage to extensions ( chrome://chrome/extensions/ )
4. Drag and drop on it the plugin (should be in your download folder if you tried to install it before and didn’t succeed)
Link #2:
http://stackoverflow.com/questions/11901915/installing-gwt-plugin-in-chrome
I think the easiest way to install the plugin is, to load the google chrome Browser with the flag –enable-easy-off-store-extension-install With this flag you disable this “feature”.
Link #3:
http://techie-buzz.com/browsers/chrome-blocking-extension-apps-scripts-chrome-web-store.html

Finally Solution:
I finally gave up after trying all the above approaches and none of them actually worked. I hit the following link:
https://www.google.com/chrome/browser/?platform=win&extra=devchannel
I downloaded the latest devchannel version of Chrome and re-installed the GWT Developer Plugin. This seems to have fixed the problem, however I am not really sure how this has affected my chrome installation’s stability but atleast GWT Dev Plugin works and it’s good enough for now.