Monday, July 13, 2015

Design Pattern Interview Questions (Part 1)

Mastering Design patterns is a must for any software engineer. The problem that most of us would face in job interviews is the fact that may be we didn't had the opportunity to implement all these design patterns in a real experience. But there's no excuse no to know the general concept behind everyone. I also recommand this Dzone Refcard in which you can find a quick summary of all design patterns. In the following post we will expose a quick quizz to refresh your memory..


1) What is the difference between Factory and Abstract Factory design patttern?
With the Factory pattern, you produce implementations (Apple, Banana, Cherry, etc.) of a particular interface -- say, IFruit.
With the Abstract Factory pattern, you produce implementations of a particular Factory interface -- e.g., IFruitFactory. Each of those knows how to create different kinds of fruit.

2) What is the difference between State and Strategy Pattern?
State pattern changes the behaviour of an object according to its different inner states.  For example : the Train cannot open the doors only when the train is the STOPPED state.

Strategy pattern gives the possiblity to write many algorithms and use them on the go. Actually a class can implement different behavioral interfaces designed to be "algorithms" or "Strategies".
For example, for sort algorithms.


3) Difference between Proxy and Decorator design Pattern?
The Decorator adds functions to a basic class to enhance it and improve its performance like BufferReader and BufferWriter they enhance Reader and Writer to add the Bufferized ability.
The Proxy mainly deals with the access to the object.


4) Why Composition is better than Inheritance? Give two reasons

- Because it's easier to add more functionality
- Because in most of times we want the inherit just a part of the behavior from the parent class and not the whole of it
- Because most of languages doesn't permit multiple inheritance


5) Difference between aggregation, association and composition in OOP?
In Aggregation we can delete the parent class and keep the children for example we can in the aggregation of Class and Students. We can delete the Class but the student can still exist.

In the composition, there no way we can talk about the children without the parent class. For example The House is composed from a set of Rooms. But there is no meaning of a room without a house !

In Association, both classes are independant from each other. They can exist without each other. 


6) Difference between Template and Strategy design pattern?
Template method pattern: compile-time algorithm selection by subclassing
Strategy pattern: run-time algorithm selection by containment


PS : a great thanks to stackoverflow forums and JavaRevisited Blog in which I found valuable information to collect those questions/answers.

Monday, June 29, 2015

Install Jenkins in ububtu : Quick HowTo

Jenkins.. a very trendy continuous intergation tool. Everybody should give it a try. Specially if you have an ubuntu distribution, it's just the perfect match. All you need to do is to run those command lines step by step :

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - 
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
export JENKINS_HOME=/opt/jenkins
That's it !! and you will have jenkis already running and available on your localhost (http://localhost:8080/).
You can start and stop Jenkins using these command lines :
sudo /etc/init.d/jenkins start
sudo /etc/init.d/jenkins stop

Saturday, April 11, 2015

How to fix org.apache.xmlbeans.XmlException: error: Unexpected character encountered (lex state 3)


I have encountred this error while trying to communicate with a webservice that returns in its XML a url containing a "&" character. While parsing the XML response my web server gives this error : "org.apache.xmlbeans.XmlException: error: Unexpected character encountered (lex state 3)".
The solution is to replace this character by "&" before parsing the XML response.

response = response.replaceAll("&", "& a m p ;"); 
That's all you need to do. It means that the xml document you're parsing isn't perfect.




How to delete control+Q keyword shortcut from ubuntu

There is a very annoying keyword shortcut for those who have used both Azerty and Qwerty keyboards. Actually, it's the ctrl+q shortcut. Some old reflexes come back to me since I used to have a french keyboard and it happens that I want to select all content using ctrl+A but suddenly the whole application shuts down.

In order to delete this shortcut, You need to go to :

System > Preferences > Keyword

Add a new Ctrl+q shorcut to the /bin/false command.
if the keyword preference windows shuts down when you try to add the ctrl+q shortcut, try to add another one. ctrl+j would do.

Then use your console to navigate to :

home/$USER/.gconf/desktop/gnome/keybindings/custom0/%gconf.xml

and edit this xml file with gedit if you want and change the ctrl+j by ctrl+q.

Then you need to reboot to activate those changes.

That's all.


source link.

Tuesday, March 31, 2015

Cannot enable Crtl+space shorcut for Content Assist in Eclipse for Ubuntu

Sometimes, some conflicts in keyboard shorcuts can drive you nuts ! After reading dozens of forum discussions about this subject. I have found the solution in this link.
 
Actually, you need to change the Ibus keyboard shorcut (control+space) so it doesn't "eat up" your magic shorcut on Eclipse.

Now you can go ahead and enjoy your programming !

Saturday, February 18, 2012

How to call Matlab functions from a Java program

Matlab is a very reputed piece of software specially among researchers and graduate students. It allows users to code complicated algorithms thanks to its rich libraries that implement many mathematical functions and statistical models. You may have ever used it to implement some classification processes that deals with heterogeneous data and you have got some interesting results and you wanted to show it to a client. He may not be interested in your statistical model nore in your charts and graphs. He is interested in a beautiful application with an ergonomic user interface with big shiny buttons that allow him to use you piece of program. He is interested in the usability of your program more than the academic process that allowed you to get your result.

So to make this happen, you need to implement a simple prototype that calls your Matlab functions and show resluts in a simple GUI. If you're a Java savvy, or you prefer java to make this happen you need to use the MatlabControl API. It's a simple Java API that allows you to call Matlab functions and execute eval, feval and other commands.


All you need to do is to download the jar file and add it to your classpath and use this code to open a Matlab session.



MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder()

.setHidden(true)
.setUsePreviouslyControlledSession(true)
.build();

MatlabProxyFactory factory = new MatlabProxyFactory(options);

MatlabProxy proxy = factory.getProxy();

After that you need to change your Matlab current path to your Matlab script path using CD command and then you can execute call your function:

proxy.eval("cd C:/Users/MyName/Desktop/MyScriptFolder");
proxy.eval("myFunction('"+param1+"','"+param2+"',intParam)");

If you need other details about variables and parameter you can use the API Walkthrough or check out the API Javadocs.


Monday, January 02, 2012

Writing Java code in blogger posts

I've been looking for a simple way to help me tweak my blog to show Java code.
This is what I've got after some changes in the blog template.

// Comment
public class Testing {
public Testing() {
}

public void Method() {
/* Another Comment
on multiple lines */
int x = 9;
}
}
All you have to do is changing your blog template and add some scripts so you can use the "SyntaxHighlighter" Library.
It works thanks to this post.

Tuesday, September 14, 2010

Web-Desktop Application for Network Monitoring and Alert Management.


Currently, computer networks are the backbone in the remote communication. Now they have become essential for the proper functioning of many domains and applications. Their rapid growth induces increased complexity of administration tasks and fault detection. Any problems or failure may have serious consequences forcing the use a system of monitoring and alert management.

The network monitoring has become therefore a major task not only the ensure the system retention and good functionality but also to have a global view on problems that may occur to prevent their appearance. As the task of the administrator is to ensure the smooth functioning of its network and manage heterogeneous devices, administrators were then forced in the past to work on a machine connected to the network which makes their task more difficult and may risk delaying critical tasks. Thanks to advances in technology and the evolution of the Web, this monitoring task has become more flexible.

In fact, the administrator is now able to monitor its network remotely via a web application that provides network monitoring and is capable of describing its condition and report alerts when this is necessary. Hence, it can remedy problems and resolve them as quickly as possible.

Indeed, this application starts with the automatic detection of network equipment (Routers, firewalls, terminal) which allows to draw the map showing equipment found to give the administrator a clear view on its network. The administrator can also predefine the annoying problems that which he judges to be important to be notified when they occur. Once one of these problems is encountered, an alert will reported to the administrator to inform him about the problem detected, its severity and its location so that he becomes able to correct it immediately.

The main objective of this project is to develop a web application for network monitoring and effective management of alerts. This application should be able to monitor services and network resources (routers, terminals). The following video is a demonstration of the project.