Monday, October 8, 2012

Linux at your Destkop

Audience: This is for majority of the Pakistani's and Outside Pals, who just are sick of their pirated attitudes and want to get a kick-start-inside look. 

Been with Linux, using it as my Desktop, from the past 2 years. Fedora's, Ubuntu's. As a developers-desktop, needing to be on top of it, when you desperately need things to work and look clean. Linux, therefore, becomes a part of a day and night system.


'Fedora kde spin', can't argue about it's selfishness, full of themes and colors, at the height of your imagination. Of all the Fedora's and Ubuntu's I have come across, kde, let's you feel at-home.


Installation of Linux, could not be made simpler, download live image, FedoraUbuntu, to the USB, boot, install and you will be able be dual booting. Hardly takes more than five minutes.

  • '/' This will be the root partition of your system. As c: in windows.
  • 'swap' This will be the swap space. 3 GB, more than enough.
  • You can opt to make /home, if you need a lot of seperate space, e.g. I have 15 GB, as /home.  
  • Continuing bootloader will be installed, and there you are, congrats. You now have, Linux.
Linux hardly two or three commands: 
  • 'su --' will give you root access to your system, and there you are, ready to empower your thoughts.
  • Add the software repositories: RPM Fusion Repositories.
  • 'yum update' immediately after installation. This will update all packages to the latest. Restart !
  • Linux A Distribution, try to install packages from repositories...those are tested and jam packed for your release. Development Tools e.g. Net Beans, Eclipse, Gimp (Gnu Image Manipulation Program), NoSql, taking on, web cam softwares, chat clients, whatever you need you will find a software package for it. Google that, OR, 'yum search all package-name'. 'yum install package-name'. e.g. you are looking for web cam software, by default Linux come with interesting ones, but still: Google: Linux WebCam Software, take the official results preferably and most of your needs (Default or Troubled) are already there. Linux apps are usually for all major flavors, Ubuntu, Fedora, Debian. One is there for Ubuntu, will be for Fedora.
  • SELinux: I dont' want anybody to install a keyboard hook in the OS, If any software is messing up outside it's permissions, SELinux comes in it's way. As new developers mess with  installations e.g. when I was new, installed Apache, and while doing WordPress, downloaded, but couldn't copy it in Apache's serving dir, this is owned by root, so what I ended up with, 'su --' i.e. root, and copied. OK. Does it work? Now as WordPress tries to use mail services or other more advanced features, it will cause ownership problems, as you downloaded WordPress as User, not as root, so I changed the ownership of WordPress, to root, using 'chown' command, changing ownership of every file in WordPress, recursively for it to be a web app, Well ... roughly speaking, Apache has a 'host' concept, Make a dir in your home, for which you have all rights and permissions, and host it in Apache. Yes, you will be required to poke at the Apache docs, but this should be brought in the manager's notice that I will need an extra 5 minutes, lay off. Anyway, SELinux together with The Firewall, is very handy, as I think of my system using USB's and Trojans and Worms in the Downloads. How many times I have tried to use pirated Internet Security Suits in Windows. Linux Security was always a major, but, still many ceo's hesitate to make a move. Interesting? I need your input here. What do you say about SELinux.
Microsoft, in very few scenarios, as in Office Products. What if tomorrow you have to come up with a Web Sites Tabular Data into an Excel Sheet, Or, Something like whole web pages being captured into a word document, Ever tried to write such a document :)? Can Open Office or K-Office do that. Any plugin for that?

Wednesday, October 27, 2010

My Development Experience

Went into university in 1998 for my engineering degree, After 2 failed attempts in big names of the country. We were caught up by Professors Fascinating and we started programming in Pascal. Still up till now we follow their lines. They delivered some brief.

Besides programming in the beginning years the students are learning Calculus (Thomas Finny) and Physics. As the time goes by they get involved in Programming Libraries and languages. Young students should be doing Neat Things, at the Right Time. e.g. I wrote an encryption module in my FYP. Security courses are offered in the final years. I was interested in Network Security and went all the way to Ascertia in Lahore, Got selected, but didn't go to live in another city. Go try your luck there. Almost all Good Software Companies need security athletes, whereever. I would strongly urge you to look at a final project from a Security Perspective. Thereof you can find instructions and programming libraries to suit your needs, in any emerging or mature language. Write an Authentication module or an Encrypted File Transfer over the internet, in leading algorithms, like RSA, Rijndeal.

I was an intern in Enabling Technologies there learned the domain of J2EE. Afterwards got myself into a multinational where programmed progressively in Struts/JavaScript/J2EE. Fascinating time there with my colleagues. Learnt lots and lots as the working environment was Great. I was consistently working since five months, without any breaks. Took some time off and the sweet HR Manager started complaining. Couldn't argue with her vicious smiles and caught up a fight. Left.

Planet Beyond took me on and success in development there but had to opt for Freelancing, again due to such management issues, I was living on a Flat the owner was a big jerk, payed him a lot, but it's nice to stay away from such people in the first place, before they start interfering a too much. Started freelancing on  sites like rentacoder. I must say freelancing sites are a whole lot more than one would expect. My manager's in my first Job at Digital Processing Systems are still my best friends. They come over to my place and I am working with them.

I did my university project in Java. Interned in Java/J2ee. 1st, 2nd development position in Java/J2ee and most Freelanced Projects in Java. Made the habit to read about it. Used to watch Google Tech Talks in my spare time and there heard about Bruce Eckel's "Thinking in Java". He writes about Inheritance Vs. Composition, Lists, Polymorphism and many other great aspects of programming. I have read Dietel and Dietel and many other big programming achievements as well but no comparison can be made. Bruce offers skills that are unmatched. As an example read about Inheritance Vs. Composition and Exceptions.

As the time went on, became an Open Source Fanatic. Since the past 3 years, I have used 4 major versions of Linux, quite successfully. Off which I am on Fedora KDE these days. And I dont' have Windows. KDE has been on the cutting edge of User Experience, as a whole, with it's color full themes, and things right on top of each other, as and when required. and it's always great to be different. who needs windows.

I do web development, experienced PHP recently. And fighting with my manager to opt for a Java CMS in replacement of WordPress.

Want to know more about me. Don't hesitate to drop me a line: abbas.babar@gmail.com

Monday, October 25, 2010

The J2EE applications with Simple JSP's and Apache Struts 1.

I did extensive J2EE programming (Jsp's Model 1 Architecture and Model 2 MVC in Struts). This post refers to development earlier in my career, Developers working now, on web applications can always refer to newer frameworks like Spring. This is a showcase and just a Tutorial for developers working on Projects, based on my 7 to 8 months experience.

Applications with simple JSP's:
If it's an application with no MVC, simple jsp's, still there are things which can be done.
  • Commenting e.g. the SQL queries what they are supposed to do.
  • Maintaining the data in session that is needed most often in more places, such as user id's etc. 
  • Following a standard naming convention, for Javascript and Java, e.g. id and name attributes can be same for HTML elements etc. 
  • Trimming fields before they go to the database. 
Applications with Apache Struts 1:
Struts a joy to program, I had background in Jsp's, So moving to Struts was not that tough. Besides I had a background in Java, and the book Mastering Jakarta Struts is a basic, concise introduction to Struts. I remember when I cleaned my code in the last iteration. I was joyed to see the all the crappy code gone, with few Java Classes left.

I was working on an application, where the user goes back and forth the Next Previous buttons you see on screens, then how would you deliver him the data he has submitted already, there you have to maintain it in Session. With struts it's the scope attribute, in struts-config, and the FormBeans get it from there. Complex screens having multiple elements, moving here and there, there I needed advanced struts scripting, e.g. Indexed Properties.

Struts Indexed Properties:
Let's consider an example, You have a form for the user to submit his education, such as.










 



We will use Indexed Properties here. The first attempt to put the RowObject (containing a single html row elements) directly in the FormBean, OR, if the single column is considered a Collection. Not The Struts Way.

Instead the FormBean contains the Collection and RowObjects are seperate Objects. RowObjects are assigned to the Collection in the FormBean through the setter as:
public void setRowObject(int i, RowObject rowObject) in the FormBean.

Here is the FormBean EducationForm.java.
































The RowObject is SingleEducationUnit which is assigned to the Collection through the setter:
public void setSingleEducationUnit(int i, SingleEducationUnit singleEducationUnit) as above, The last method.

Here is the Single RowObject which is SingleEducationUnit.java in our case.
Here is the education.jsp
































We needed the Indexed Properties in several places in our application, and once I got it right it was nice going there on. You can figure out the rest, struts-config.xml, EducationAction.java for example.

Add Row:
The real fun started when we had dynamic rows in the tables which the user can make, there I passed hidden attribute for how many new rows the user created, and then at the server side I extended the array list, with this hidden attribute.

Books: Mastering Jakarta Struts. (Handy book, concise, Good Starting Point)
             Jakarta Struts Live (Good Book, free I think).          

Client End Scripting:
I had to program extensively in Javascript, DHTML, CSS. Dynamically generating all sorts of Screen Elements, Using Calendars etc.

Accessing the Database:
The DAO Layer, we used it for a medium sized J2EE application. My manager wrote it. Using it was good, as we were spared from writing SQL queries. There are Create, Retrieve, Update, Delete Operations for DB tables, (Which is the common CRUD Operations). I have seen the DAO Layer pattern in PHP (Symfony framework), for example. MVC and DAO are everywhere, once you get the concept e.g. I got from Struts, it's same in other frameworks.

Ofcourse there should be validation, for which Validator Framework can be used, Using Calendars, use of Message Resources, but you can figure that out yourself.

Sunday, July 12, 2009

Building Java Project with SCons (This Article is misleading)

Attention Correction: I did recursive walk in the directories to pick up all jars and include in the -classpath option of javac, which is naive. As Mark A. Flacy pointed out: 

"It is not a good idea to traverse a directory structure and pick up a list
of jar files to build your classpath. This works only if you ensure that
all of your classes are unique in all the jars. If you were to have
different versions of the same class in multiple jar files, you would not
know which one would be found first.

It is *always* a good idea to ensure that the order of the jars used to
compile java source matches the order in which you will run the compiled
code for that reason. Otherwise, you get interesting runtime errors."

After Mark emailed the above correction, to me, I deleted this post so it's not misleading. But now I am reposting, as I was getting a lot of hits from SCons site, as: I informed people of this creative work of mine at the SCons mailing list. 

SCons now might have better and enhanced Java Support. See you. 


Here Goes the original: As it was previously:


Audience: This article is not for any other thing, but a regression of SCons and Java only. We had a requirement of building a Java Project in SCons. The java project build was done with Python2.5, later and earlier releases cause problems. So please install version 2.5 of Python, it's almost mandatory.

The Project was quite well generalized. But we have to see if SCons fits the model of Java. I did research on SCons for Java for quite a few days, and it turned out that SCons support for Java is very limited. Here is the corresponding article. JavaStrategy : That explains SCons and Java.

Anyway, We had a requirement and we tried it out.

The javac and classpath option of SCons is just an unfacilitated wrapper of -classpath option of javac.

Problem with -classpath option of javac:
First of all the Java native compilers(javac) didn't support native inclusion of directories and subdirectories of jars in the -classpath. If you have a lib dir, in which there are directories and subdirectories containing jars, you will have to mention the full path of each jar to the -classpath option. So some deep lib dir structure with many jars will be a problem. The project we were working on was, a user is free to make any dir structure in lib.

For example, if we have, lib/apache/struts.jar and lib/com/somecompany/hello.jar
and we do, javac -classpath lib com/somcompany/Hello.java
The jars will not be included in the build process, as we didn't explicitly mentioned full path.

Instead you will have to do
javac -classpath lib/apache/struts.jar;lib/com/somecompany/hello.jar com/somecompany/Hello.java

Underlying javac and -classpath is used. A very good read of setting classpath at sun' site is: Setting the class path. Below is the short conclusion of the article

  • In the classpath, classes in any directory structure are (dir/subdir) are picked up, if you include top dir.
  • For jars, The full path to the jars is required.
  • The current directory and subdirectories for classes are automatically included, but if you have mentioned -classpath explicitely, for either reason, you will have to explicitly do "." to include current directory.
This is just a conclusion in a very short form, Setting the class path is very well written. Take a look for any confusions.

So, what was the conclusion for jars inclusion problem. What I found, is to recursively walk through the lib directory and take full path of each jar, in a loop, appending to the string.

Following is our project. src, lib, bin, and tools dirs.



Here is the attachment link to the Project. project-java-build-run

May be you would download the project, and inspect. There are 3 main files, SConstruct, config.py, run.py

SConstruct would build all classes in src and put the class files in bin, while using lib.
config.py has project structure definitions, as changing a dir name in the project, or such, would need to change just at one place. i.e. in the config.py


config.py:
Has main functions, and the directory structure of the app.
The "walkDirs(path)" function, recursively passes through all the dirs of the given path, and appends the resulting path of each, to a string and returns it. (It's been a year before I did this, I think for a python programmer interpreting this Python function would not be a problem.) This is the key function, as now we have all the jar paths, so we can use SCons and it's "JAVACLASSPATH" to invoke build.

The directory structure is as follows.

  • src: This dir. has all the src files, to build.
  • lib: contains all the lib files, which are included in the classpath at the time of compilation and running.
  • bin: contains, the compiled class files.
  • tools: contains the files for scons-local, and other tools like junit, or testng, etc. which you wish to include in your app.
SConstruct:
SConstruct contains the build code, to invoke build,
$ python tools/scons/scons-local-0.98.4/scons.py buildresource=src/somecompany/HiSCons.java

this will build the HiSCons.java and put the resulting class file in bin/com/somecompany/HiSCons.class.

The classpath consists of all the files in dirs/subdirs of lib, and files in src.

Complete src directory is build, with all classes inside, if you don't specify buildresource parameter or buildresource=src.

run.py:
Calls SConstruct for building the .java file passed as parameter, on successfull build, runs
the java class. Usage: python run.py [--javaargs] filepath. The file should be residing in the src directory. Go ahead and start experimenting let me know and we will fix any bugs.

I repeat, I did it a year and a half ago, so now writing about it and interpreting my own Python code is a bit more demanding, as I am more Java. For a Python programmer it would not be much effort. As then I wrote the code under a lot of attention. May be the lib and jar path problem was a result of over enthusiasm, as we could restrict jars to be placed in lib directory, not in the sub dir of lib. Normally we see jars put straight away in the lib.

Any comments are warmly welcomed, I will try to answer them.

Followers