Sunday, September 29, 2013

The OpenTech confrence

Hi All,
In the last few month I swarmed with work and I didn't have enough time to explore the benefits of new dynamic languages. In the small time that I have I understood that it need to be explore more deeply.
More than that there are other very important fields that rise dramatically over the past few years:
Web technologies HTML5 & javascript that also part of the dynamic languages
The Cloud - A big changing in the way we develop and maintain software
Mobile - A big changing in the way we consume software.
Therefore, we decided in SELA to create a conference for these changes, so the software developers in Israel will be able to catch up with all the new technologies in these areas
here is the link to the conference: http://www.sela.co.il/s/opentech/index.html
Enjoy.
 

Sunday, June 16, 2013

Making order in the new programming languages – Part 1

Recently, we are witnessing to a large number of programming languages that gain popularity in the software industry.  Many of them are known as interpreter languages or also known as script languages. One of the reasons for these blossoms is now you can compile many of these languages to java byte code and run it on the JVM so the differences in the performance become very minor. So now java is not only a language it is .more like an echo-system. 
Today, there are more than 100 programming languages that run on the JVM! and the real questions is how do I know in which one to use and why, or I just need to stick with java
Well, the answer for that is depend on your requirement, each language has its own philosophy if your requirement and the way you like to write code is suitable to the language it means that you should use it. Java is a very object oriented language that encourage the programmer to write in object oriented paradigm. If you like to write object oriented (like I do) and you have a big project that include a lot of maintenance I think java is the language for you, for example java support strict typing and encourage you to write class for any type of object. Java supports interfaces and not multiple inheritance, encourage the developer to set properly the inheritance tree.  Most of the other languages do not try to compete java in that area, however, some of the languages has some features that better in java for that purpose.
Since i'm still not an expert with all these languages, i may find myself wrong about it and maybe i will find languages that has the same philosophy, I will be happy to discuss it.
However, sometimes you have other requirements and maybe for some applications object oriented programming can be cumbersome and awkward. for example, did you try to write swap function in java that swap the value of two numbers, you will find out there is no good way of doing it. Therefore, in the next few posts I will try to label the different programming languages and try to see when you need to work with what. So you use the most suitable programming language to your needs.

Saturday, June 8, 2013

How to choose good framework

The java eco system is full of exciting frameworks most of them are open source, many of them provide the same purpose as others. Many time during the development of your project you consider using one of these frameworks, personally I believe using external frameworks is a great idea. It is best advised to focus on your business logic instead of reinventing the wheel. But how do I know which framework to choose?
In this post I will define some criteria that I think are the most important criteria for choosing a framework, some criteria are controversial but I think there are very important arguments in the decision.

1. Good framework, is framework with big community - this is very important mainly in open source frameworks. Since open source frameworks grown by their community. Usually the community is other engineers that work in places like you are. And if many engineers think it's a good framework and invest time of using it (on the way debug it) and maybe even develop it. It is probably a good framework. If you want to know the size of the community looks for the number of Q&A in stack overflow or number of posts, training solution for this project.

2. Who behind this project, who developed it? Who is the company behind it, if it is top level project of apache you can sleep well at night. If it is one of the big companies like red hat or HP. it is also something safe. Stay away from academic frameworks that more suitable for theoretical issues.

3. Good Framework is well documented framework. Some developers thinks that open source framework should not be well documented since the owner of the project would like to earn money from training.
Well, I believe if we have big community the training will not be the problem.

4. The framework should mature enough - it was already debugged and has many successful case studies around the world. You have enough developers that work with it and usually in this case the code is already optimized for better performance.

5. The framework is easy to use - there is no complicated API, the framework focus in one major thing and not try to resolve everything. When you read the code of the example is very understandable and you can easily integrate it in your program,

So you can see, that in small reading and paying attention to this issues you can determine if you have good quality framework or something that it is not good idea to work with.
I hope it will also help you in choosing your framework


Friday, May 24, 2013

Linux distributions


Linux is one of the leading open source projects in the world, but what is Linux, we have many "Linuxes" - red hat, blue cat, ubuntu, suse so what does it means that all of them are Linux. well, Linux is a standard there are set of rules that if you wish to be Linux you have to satisfy, these rules are in two different standards - POSIX and GNU, POSIX talk about rules for the core of the operating system mainly the kernel and stands for portable operating system interface and GNU stands for gnu not Unix specify applications that complete the Unix standard. Every distribution has to implement these standards so it can be called Linux.
One of the rules is the license of Linux that should be open source and free to download. And usually each Linux distribution builds from a Linux program. The distributers download the code and then add and modify the code for a new Linux, this new version usually called Linux distribution.
I would like to present some of the popular distribution of Linux:

Ubuntu: Ubuntu is distributions that focus on the user and try to provide him easy interface for his work, many feature like plug & play and easy installation are provided in ubuntu. 
Today many users that wish to work at home with Linux work with Ubuntu and it became real (small) competitor for windows.

Red Hat: The biggest distribution for enterprise Linux, the main advantage of the red hat distribution is application called RPM that allow you to update software automatically and in very easy way. the red hat is of course free of charge but if you wish you can be connected to the red hat servers and update your Linux automatically for money. this is highly important feature for enterprise companies who has large number of servers and need to maintain them constantly and be up to date as soon as possible due to critical systems that run on these Linux servers.

Suse: also well known large distributer of Linux, developed by novel and consider to be very reliable and effective Linux distribution. One of the major advantages of Suse Linux is the interoperability with Windows and Microsoft technology so working in this hybrid environment becomes much easy.

Blue cat: this Linux distribution is used for embedded and real-time system it allows you to configure your kernel and customize it to be suitable for embedded systems, remove the mouse and keyboard from the kernel. 

Monday, May 20, 2013

Preform background operation with swing worker

Hi,
I think that one of the suffering things in UI is making a progress bar, you need to update it constantly while the operation is invoked by another thread and calculate the progress of the task.
From java 6.0 we have a new utility that help us with that called SwingWorker.
SwingWorker is an abstract class that you can extend and the abstract method called doInBackground  that allow it to preform background operations. SwingWorker also can update the progress bar with the process method and by firing events for changes in the progress bar.
Let's see an example
In our example, we would like to send mails in the background for large number of users that defined in the Swing application. once the submit button is press the application will send the content of the mail to all the users, let's see the code of the application:

public class Application extends JFrame {
 
  // The UI Components
  private JProgressBar progressBar;
  private JTextArea mails;
  private JTextArea message;
  private JButton sendMails;
  private JLabel status;
 
  public Application(){
   setSize(600, 600);
   message = new JTextArea();
   JPanel rightPanel = new TextAreaPanel(new JLabel("message"), message);
   add(rightPanel, BorderLayout.EAST);
   mails = new JTextArea();
   JPanel leftPanel = new TextAreaPanel(new JLabel("mails"), mails);
   sendMails = new JButton("send it!");
   add(leftPanel, BorderLayout.WEST);
   add(sendMails, BorderLayout.NORTH);
   progressBar = new JProgressBar();
   progressBar.setStringPainted(true);
   add(progressBar, BorderLayout.SOUTH);
   sendMails.addActionListener(new ActionListener() {
  
  @Override
  public void actionPerformed(ActionEvent e) {
   String addresses = mails.getText();
   String[] add = addresses.split("\n");
   SendMailsWorker worker = new SendMailsWorker(message.getText(), add);
   // A property listener used to update the progress bar
      PropertyChangeListener listener = 
                                 new PropertyChangeListener(){
        public void propertyChange(PropertyChangeEvent event) {
          if ("progress".equals(event.getPropertyName())) {
            progressBar.setValue( (Integer)event.getNewValue() );
          }
        }
      };
      worker.addPropertyChangeListener(listener);
   worker.execute();
   
  }
 });
  }
  
 
  // The main method
  public static void main(String[] args){
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        Application app = new Application();
        app.setDefaultCloseOperation(EXIT_ON_CLOSE);
        app.pack();
        app.setVisible(true);
      }
    });
    System.out.println("finish main");
  }
}

// and another class for handling the panel is
public class TextAreaPanel extends JPanel{

 public TextAreaPanel(JLabel label, JTextArea text) {
  text.setPreferredSize(new Dimension(120, 120));
  add(label, BorderLayout.WEST);
  add(text, BorderLayout.CENTER);
 }
}

The action of sending the mail should be in the background, therefore, we should create a swing worker that handle the task, let's see it
public class SendMailsWorker extends SwingWorker {

 private final String message;
 private final String[] addresses;

 public SendMailsWorker(String mes, String[] mails) {
  message = mes;
  addresses = mails;
 }

 @Override
 protected Integer doInBackground() throws Exception {
  int matches = 0;
  for (int i = 0, size = addresses.length; i < size; i++) {
   // Update the status: the keep an eye on thing
   publish("send mail to: " + addresses[i]);
   matches += sendMail(message, addresses[i]);
   setProgress((i + 1) * 100 / size);
  }
  return matches;
 }

 private int sendMail(String message2, String string) {
  // sending the mail
  try {
   Thread.sleep(10000);
  } catch (InterruptedException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return 1;
 }

 @Override
 protected void process(List chunks) {
  for (String message : chunks) {
   System.out.println(message);
  }
 }
 
 @Override
 protected void done() {
  System.out.println("finish sending mails");
  super.done();
 }
}
as you can see from the code, the operation of sending the mail is done by the SendMailWorker that extend SwingWorker. the method doInBackground preform the operation and set the progress so than you can write to the console or to any other place the progress of the writing. I think SwingWorker is very nice utility that simplify the ability to preform background operations.

Sunday, May 12, 2013

What is my problem with Microsoft technology

As an architect that working in the software industry almost 15 years I came across many technologies some are great and some of them are not so great...
In this post i would like to refer to technologies that came from specific vendor - Microsoft.
As you probably can see from my blog name i'm a java person and i don't have a lot of experience in Microsoft technology. I did some projects that related to .NET and Microsoft but i'm not expert.
Generally, i can say that .NET is pretty good framework, some of the things i like some are not but I think this framework contribute a lot to the software industry.
However, The Microsoft technology has one big flow, it refuses to collaborate with many other technologies that exist in the world. for example, last week i lectured about ALM and architecture and one of the listeners ask me if TFS (the Microsoft ALM tool) can work with subversion. The ALM guy that run the user group ask her why she would like to use subversion you can use Microsoft tools instead. this is of course a Microsoft user group...
The philosophy of we will provide you anything that you need and you can't use any other technology is annoying. I personally believe that each framework, tool or language are means to do my job better and every one of them should be used differently according to the circumstances.
If you are eating steak you should do it with fork and knife and not with spoon. it doesn't mean the spoon is redundant t just means that it doesn't feet for me right now.
No company not matter how big it is can't provide solutions to all the use cases in the world, therefore, good technology is a technology that can integrate easily with other technologies.
More than that, Microsoft prove that when it is important for them they can do it better than anyone else, you can see it in the integration inside Microsoft technology and also in there cloud solution, azure.
So i hope Azure is a good start in this direction and hopefully Microsoft technology will be more open for integration with other technologies in the near future.  

Tuesday, May 7, 2013

My lecture about SOLR in the SDP

Hi,
Yesterday i was lecturing about SOLR in the SDP, it's the larget confrence of sela with international speakers about many technology mainly in Microsoft technology - www.seladeveloperpractice.com 
The presentation of Solr can be found here.
Enjoy :-)


Wednesday, May 1, 2013

cloud & ALM

I wrote nice presentation about the changes of the cloud and the implications about ALM and architecture.
You can find the presentation here:

enjoy!

Thursday, April 25, 2013

The NoSql mini revolution

Hi all,
the latest trend in the software industry is the big data and noSQL movement.
since today many applications provide services to a lot of clients and have problem in scaling more and more software vendor considering giving off the sql transactions and choose NoSQL DB.
But i think lately due to this revolution we have another small revolution that provide good back wind for the NoSQL movement - using NoSQL DB just becouse it's easier.
Using SQL DB is something that we use to it but it's not simple. you have to write SQL queries, optimize them and use data structure that very diffrent from your program.
SQL queries are not predictable, i had SQL queries that in some cases took 15min and some cases the all night. now you need to open the execution plan and start understanding how the database server is working.
So sometimes it's very easy to use NoSQL DB usually a document DB that provide you easy working API and simple work if you don't need complicated stuff. and you use it not for sharding just for convnience.
I think it's very refreshing and really contribute a lot for the big data revolution.

Saturday, April 20, 2013

What is the best language programming

I think programmers fight on this questions like football fans cheers there group.
more than this often languages that consider to be the best language like cobol after few years consider to be very problematic languages. i believe also that many good languages are not consider good since they don't have good PR. in this post i will try to tell my opinion about what is the best programming languages and write my criteria on it. as you will see, well you probably already guessing is not a world of black and white and the answers are not so deterministic, however, i think i can spread some light on this issue.
First is important to say that programming language is a tool and like any tool it depends on the task that you need to preform, not all the applications are the same so the language should be feet to the task that you need to preform. of course, that rich frameworks and strong community are also a good criteria for good language. there are some languages that very good in specific thing, for example, perl is very good in text processing. logic languages like prolog good in artificial intelligence and so on.
also when you talk about good languages the question is good in what?
C & C++ good in performance and optimization
VB consider to be good in rapid application development, but notice that languages that belong to the .NET framework limit you to windows so of course they have some advantage working on windows.
But i think the most important thing in programming language is a language that help the programmer not to write bad code. for example, C++ put all the responsibility on the programmer. I think it's not good, good code is a code that prevent the user who use it to make mistakes and guide him to write good separate code.
The disadvantage for this issue is that sometimes you need to write more code since this is the right way to do it. I think java is a great example for such language and this is why i think java is very good programming language. let me provide an example: in java we don't have pointer to function, if you wish to send pointer to function you need to create interface with one method, implement in a class and than this object will be the function itself. java do it since in java everything is an object. this is why java is a pure object oriented language. but sometimes it requires more work even for simple cases. this is why the JCP try to add more functional attributes to java. however, all the functional languages has very unclear syntax and i think we should be very careful on this issue.
so what is the best language, well if you wish to write big server enterprise applications on cross platform probably java is your answer. in places that you wish to avoid the overhead of java you may use other languages and integrate them in java. but i think the architectures of java keep there minds helping the programmers working in the right way.

Saturday, April 6, 2013

The cloud and JEE

Here is a nice presentation that i wrote about the new cloud agenda and what are the plans in the JEE area about this issue: https://www.dropbox.com/s/au9tltnopmhhyds/Cloud%20%26%20JEE.pptx?goback=%2Egin_4829427_false_im*5preapp_cs*5connections

Thursday, March 21, 2013

Taking JSF to a test drive

Hi,
usually I am not a web guy, my work is focused on the business logic and infrastructures. but from time to time i find myself developing some web applications since it's a very important part in any application. long time ago i usually used to work with struts but today struts is not so popular and i usually pick spring MVC for this issue. but when one of my customers wish to know more about JSF i decided to pick up the glove and take JSF 2.1 to a test drive. when i had my devlopments in struts i thought what should be better struts or JSF, in that point JSF was not mature enough but now when JSF 2.1 is already in the air i thought about giving it another chance. well JSF did make a long way since than.

Today JSF is satisfy web framework that give you everything that you need in the server side, including:
1. Full MVC framewok that simplify the nevigation and create seperation in the model, view & control.
2. cross platform rich web UI component that provide better look & feel to the application.
3. AJAX library that enable you to preform AJAX calls

so i decided to take a ride on the JSF see if the rumers are true...
well, i build some basic app and i did have some troubles but basically it looks good.
Well, the idea here is that you have new HTML tags that can be used inside the JSP page and you can inject a code to the JSP if you register the class as a component in the JSF.
this is very diffrent from struts and spring MVC since the HTML looks very diffrent.
i think that front end developers that work with HTML & javascript can find this framework a real treat since it is very much web oriented and the HTML really talks to you. However, server guys like me can find a hard time to optimize it and get full control on behind the scene of this framework.
So probably it will not be my choise as a framework but i can understand why some programmers will love it.

Wednesday, March 13, 2013

java interoperability



Hi, I would like to thank to all the participants that listen to my lecture about interoperability between java and other languages inside the JVM process. In the following link you can download the lecture presentation as well as the code of the presentation.

https://www.dropbox.com/s/hh0ys4gvbehvj0l/script.zip


Friday, March 8, 2013

Java memory leaks

Last week i visited one of my customers that had a memory problem.
His application's memory keep rising no matter how much memory they allocate for it.
Each time OutOfMemory Error has accrued the RnD advice the support to increase the memory size.
However, after few days the old OutOfMemory error happened again.
I told the RnD manager that his application suffer from memory leaks, just like C++ it's also a bug.
The RnD manager told me: "we are working in java with GC it's impossible to have memory leaks" well, in java we also may have memory leaks but it is very diffrent from C++.

In java the application will suffer from memory leaks in the following example:

 public static void main(String[] args) {
  Observable ds = new Observable();
  Main m = new Main();
  ds.addObserver(m);
  // do some work...
  // when finish work with main forget removing m from observer

 }
so in this case even if m was removed from other data structure it's still in the heap of the program. The problem is even worse when you are working with application server since you need to understand how beans released from the memory. Such bugs are difficult to detect since you don't know which object is leaked and you have to deeply understand your program in order to clean all your code. However, most of the professional profilers provide you tools to handle memory leaks and you can use them to clean your code. In addition, there are some tools in the java language and some good best practices to avoid memory leaks. so after 1 day of workshop training that i provide for this customer there are no more questions about memory leaks and the guys start working and removed most of the memory leaks from their application. Now it's work better and the customer stop complaining about the endurance of the application.

Saturday, March 2, 2013

Why using solr search engine instead of searching in DB

Next week at the 6.3 i will lecture about solr in windows azure user group here.
 and i thought it will be nice to explain why i think it's better to use search engine like solr instead of using database search capabilities or implement your own search by iterate your data structure and looking for matches. before i start counting the reasons let me say that i think solr is good but any search capabilities based on lucene framework the bible of the text search is also good enough. notice that some databases use lucene framework for there search so if you are using these capabilities maybe you don't need solr after all. So let me count some major advantages for working with solr (and lucene) 1. Performance 2. Ranking 3. Flexibility 4. Clustering & Cloud support 5. Solr is free open source Let me provide more details about each advantage
 Performance
Solr is fast, i mean very fast. millions of documents can return result in few milliseconds! this is the whole idea of indexed search engine you spend some time in indexing each string in inverted file and you get really fast search. and search must be ultra fast otherwise nobody will use it.
  Ranking
Search is not about finding is about ranking! the most important thing is search is to provide the most relevant results at the top of the search result. needless to say that the most relevant results has to return first so solr stored the data in a way that most relevant results the boosted documents will have the fastest access. Flexibility
Let's say your user type with typo or write something in singular and the word exist in plural or even write word that just sounds the same of the word. if you don't have lucene as a search framework it is almost impossible to get such results. but in solr you can add plugins for different languages that will support such cases.
Clustering  Cloud support
Today when many applications are SAAS and implements multi tenancy and sometimes you need to search on billions of documents having a tool that allow you to split your work for hundreds of nodes and allow you to work in cores for each customer you have your own core is not trivial. more than that ranking is calculated due to other documents in the system so such capabilities is very hard to implement.
 Solr is free open source
And all of this for free in easy to use interface with the ability to add your own code with very large and quality community that will help you provide enterprise search for your application.

Monday, February 18, 2013

Project coin and operator overloading

Today there a lot of programming languages running on the JVM. one of the arguments of the advocates of these languages is that java is old language that require you to write a lot of code while you can simplify and shorten your code if you will use language like scala. This is the reason why in java 7 there is a new project - coin project that wish to simplify the syntax of java. in java 7 the following features were added: 1. using string and enums for switch statement 2. enable adding more than one exception in the catch clause. 3. the diamond operator in generics (removing generics in the constructor) 4. ability to call exotic names of methods that exist in other JVM languages - i will refer to it soon. and one still in thinking process: 5. adding notation to access collection - this one i would like to discuss. Collections are widely used in java and array is pretty much old fusion, however, it is very nice that you can write array[i]. It can be very nice if you can do it to collections as well.
for (int i = 0; i < list.size();i++){
   list[i] = something(i);
}

first, i'm not sure it is such a bright idea since it discourage users to use iterator, but there is something appealing in this idea. so if you wish to create a solution for it, you can go in two ways: collections that provide us index should implement an interface, the list interface - so array should implement list too? and the operator [] will be overloaded only on the list interface. this solution is not generic solution and you can ask yourself why this interface should get operator overloading and other java objects not. or finally we will have operator overloading in java and the integration with languages like scala will be much simpler. it can be nice if you will be able to write the following code:

if (newDate > oldDate){
doSomething();
}

this is really can be nice... and it will also resolve number 4 that i said that i will refer to it later. now you don't need exotic names for functions that support operator overloading. however, operator overloading has problem in java since in java we have only two types of variables: primitive & references. and operators refers to variable and not for objects, let examine the following code:
if (person1 == person2){
   doSomething();
}

the == operator refer to the reference and not to the object. so now if you wish to overload the == operator you can't check if the references point on the same object! so it is a problem to implement operator overloading in java. so you can add syntax sugar in the coin project but it is not feet to a common standard. and one more thing what happened if the object itself is null, what happened in the operator invocation. so i guess, full operator oveloading is not simple in java. but i really be happy to see more thoughts about this idea.

Thursday, February 14, 2013

will we abandon mobile applications

Today most of the java applications has web UI interface and not rich client application. It is almost a curse to develop a rich client application that run on the client side. In one of the projects that i did in a very big enterprise company i herd one of the managers says: I do not wont to install anything on the user machine, only anti virus and OS. No doubt, web UI has a lot of advantages and today with HTML5 you can get rich client application look & feel in your web browser. so it looks very reasonable to abandon rich client technologies like swing and use web development instead. and with tools like GWT it looks very easy to work in web development and you don't have to work with java script if you don't like it. However, today we are facing a very big revolution, the mobile revolution we are replacing our computers and laptops with mobile phones and tablets. But in this world we would like to install applications on our device! even if we write it in java script we wrap it in installation, why? there are probably a lot of answers: 1. very easy to install 2. can use the app store / Google play for earn money and promotions 3. better user experience 4. better performance 5. more capabilities from the device hardware (GPS,jyro...) let me answer it one by one: 1. install on desktop is also quite easy 2. This is an advantage but i ask myself is it a silver bullet? 3. also in desktop 4. also in desktop 5. many applications that don't need extra from the hardware still used as applications. more than that i suspect that the factors that made us abandon rich client and focus on web still exist in mobile slow the computer viruses security and many more... so do you think one day we will stop using applications and return to the web again?

Wednesday, February 6, 2013

Thanks god for ARM in java 7

One of the most disturbing thing that was exist in java was closing resources such files. first, you need to remember to close the file and put it finally since there is a chance that you will suffer from exception, but in the finally you have to protect yourself from getting null since the exception can happened in the creation of the stream or the channel. so the code should look like this:
      FileInputStream FileReader= null;
      FileOutputStream FileWriter = null;
      try {

        FileReader= new FileInputStream("in.txt");
        FileWriter = new FileOutputStream("out.txt");
        int var;
        while (var = FileReader.read()) != -1)
          FileWriter .write(var);
      } finally {
        if (FileReader!= null)
          FileReader.close();
        if (FileWriter != null)
          FileWriter .close();
      }

In addition, the close method throw exception as well so you need to handle it as well. This is very tricky code and very easy to make mistakes. no wonder spring provides useful templates for this issue. But from java 7 with automatic resource management we don't have to take care of it anymore. from java 7 you can write the same code like this:
try (
FileInputStream FileReader= new FileInputStream("in.txt");
FileOutputStream FileWriter = new FileOutputStream("out.txt")
) {
      int var;
      while((var= FileReader.read()) != -1 )
            FileWriter .write();
  }
since OutputStream and InputStream implements the interface closeable with the method close, the close method will be called automatically if the object was created since the code is in try brackets. so now java take care the close of the file. I believe it will save a lot of time and many bugs mainly for novice programmers.

Wednesday, January 30, 2013

What else missing in java NIO

Java NIO2 in java 7 add important features to the NIO framework:
Finally we have good framework that handle files: http://docs.oracle.com/javase/tutorial/essential/io/fileio.html
and improvment of asynchronus chammels: http://www.ibm.com/developerworks/java/library/j-nio2-1/index.html

The reason that now the File framework is usefull is that in java NIO you are not have to support all the types of operating systems but only modern standard kind of desktop server OS. (today with the mobile revolution we can have all kind of OS not always with the same I/O features as windows and linux).
so we finally can copy files and handling directories and all kind of nice features.

Since we are no longer obligated to exotic OS i think it's about time to add interprocess communication in java NIO. so two processes in the same computer will be able to communicate without sockets.

why it is so important? today when we are going to the cloud and computer networks is very easy why spend time and add inter process communication? well i think it's important from the following reasons:
1. don't catch port for inter-process communication - let's say i have a multi process application on the same server - since java has GC sometimes for preformance issue you wish to seperate the application to several processes but still it can run on the same server. in this case if i can avoid catching port is for the best, becouse many time you need to handle issue like port is already taken by another application.

Second, we can add support of share memory that can be very useful in java applications. i know today you can use terracotta for that issue but it's much more complicated (you need teracotta server) here you get your service from the OS and it really simplify your application.

Third, security point of view, socket is a security risk if you can avoid it you reduce the security risk in your application. In addition, it can simplify integration with other languages like .NET since if we will get share memory with other languages communication can be easier.

public static void main(String[] args) throws IOException {
  Descriptor d = Descriptor.create("message");
  ProcessChannel proc = ProcessChannel.open(d);
  ByteBuffer buf = ByteBuffer.allocate(48);
  buf.clear();
  proc.receive(buf);
  ShareMemory s = ShareMemory.create(Descriptor.create("memory"),1000);
  OutputStream o = s.createOutputStream();
  ObjectOutputStream obj = new ObjectOutputStream(o);
  obj.writeObject(new Temp());
 }
So i really hope so java NIO will include such feature, what do you think?

Thursday, January 24, 2013

Back to SELA and intersting issue

Hi all,
It's a long time since i posted something in my blog.
 but now after coming back to SELA i decided to renew my blog and make it much better.
I really wish to make my blog a place where programmers can find deep answers and understand better the all issue of programming.

When I browsing the internet looking for good topic to my blog I found the following question in stack overflow: http://stackoverflow.com/questions/2489701/value-object-getter?rq=1

First it looks like non important issue, however, I think this question is much more important than it looks like , I saw a lot of developers using such utilities methods or choosing the second approach and adding more methods. this issue is important since it touches the core of object oriented programming. both of the options are not good object oriented design.
the first approach creates utility methods that are not really belong to any type and it's really a procedural programming.
The second approach let's the amount of money deal also with the interpretation of the amount to specific type of coins.
The issue become more serious if you wish to support different types of coins (euro, yen, yuan...)
than you can see that both of the approaches are not so good.
Here is my object oriented solution for this issue, the UML should look like this:


1. Create abstract parent class called money with amount and factor, each type of coin will be a subclass of class money and only money will have methods of equals, hashCode and compareTo.
each subclass can implement the toString method for coin presentation. than you can write factory for it to create the right coin that also read the appropriate factor of the coin.
Now let's look how the code should look like:
public abstract class Money implement Comparable{
private int amount;
private int factor;

public Money(int a, int f){
   amount = a;
   factor = f;
}

public boolean equals(Money m){
 return (amount * factor == m.amount * m.factor);
}

public int hashCode(){
  return amount * factor;
}

public int CompareTo(Money m){
    return amount * factor - m.amount * m.factor
}

public int getMoney(){
   return amount;
}

public int getCurrency(){
  return factor;
}

}

public class Cent extends Money{

public Cent(int amount){
  super(amount, 1);
}


public String toString(){
  return Integer.toString(amount) + "C";
}

}

public class Dollar extends Money{

    public Dollar (int amount){
        // here you can also calculate the currency 
        super(amount,100);
    }

    public String toString(){
      return Integer.toString(amount) + "$"; 
    }
}