Facade Design Pattern

Façade Pattern

It is used to hide the complexities of system behind a simple interface. Generally with time, the simple system grows to complex systems having a number of different APIs and objects to interact with. It happens especially if we are following the design patterns. Due to this increased complexities, it becomes very difficult for client to remember the exact flow of API and the right way to use it. Façade comes here and provides a simple interface to user, thus hides the complete complexity behind it. 

Example

  • One way to access database is to use the raw API of JDBC which may not be very convenient for every user or user may need to repeat same code again and again to access the database. Other alternative is to create a ‘Data Access Object’ which can hide the complexities of JDBC API and can provide a simple and convenient interfaced to user for most of the required operations. So we can define a SQL Data Access Manager which can provide methods like execute query, get table names etc. Here SQL Data Access Manager is working as façade.
  • Any session bean on server most of the time works as façade.
  • An Object Manager on server which allows the user to save any object and fire the relevant events in a single call.

What is the Use of Ant Build Tool

Ant is a build tool and is used in build process of softwares.

Now the question is that what is a build process? Build process is used to build the software, which comprises a list of tasks items  required to deploy the software application and make it runnable. A few task items are as:

  • Creating the basic structure for project, which is required for deployment. The structure may vary from project to project or depending upon the type of application
  • Taking the latest checkout of the project files from any source code version system
  • Copying the required set of files to the desired directories. This may include filtering of the files which are not required in deployment, but are required only for development. 
  • Compiling the source code to generate output runnable files
  • Copying the required non-source code files to output folders
  • Generating the documentation by using various tools like Java Doc or PHP Documenter. 
  • Running the test cases on the compiled source code
  • Package the output in required format, like jar, war, ear etc
  • Copy the packaged output to the target directory, like in application directory of web servers
  • Generate the schema in database
  • Run scripts for entering sample data in database
  • Starting/Restarting the server
  • And so on

How to file the Income Tax Return

Disclaimer: This information is only for knowledge purpose and may not be correct at all places. So after initial understanding from this article, it is good to refer to authenticated sources like Income Tax Department web site (http://www.incometaxindia.gov.in/) for various rules and procedures.

It is the time to file the income tax return again and we again need someone who can help us in filing the return. Here we are discussing that we can do it ourselves, if we have all the documents available with us for the income and deductions and if the sources of income are not very discrete and complex, like it can be in case of business income. Filing return is not that complex now. To file the return, we just need to understand the flow of filing the return. Once you understand it, it would be much simpler. So let us start to make some understanding of the process.

At first we need to remember the due date of filing the return. It is 31st July of every year. It is recommended that we should not wait till last week to file the return. There can be various unpredicted road blocks on the way, like you forgot to collect any document required for return, or the online sites are down due to heavy traffic and so on. So it is always good to be early.

Next is to collect all the information for your income and deductions. For income, you need to be aware about all heads of income which are defined by IT act. Here is the list of all income heads and the documents required for these

Wings of Fire - Agni ki Udan

'Agni ki Udan' is the autobiography of Dr. Avul Pakir Jainulabdeen Abdul Kalam. This is a wonderful book for the professionals who want to read some literature to have a direction in their profession, and in the life that how to utilize their knowledge and skills for social good and the country and for the Organization for which they are working. He is among one of few great scientist who have devoted their whole life for the progress of science and technology in country. Dr Kalam has shared their experience in this book which may not be able to describe his complete personality, however gives us a brief about him

  • As an innocent boy in the streets of 'Rameshwaram Ji', who has lived a simple life with his religious and simple family, 
  • As a student in college who came from a small town and left his home first time for studies; and then left an everlasting impression on many teachers with his sincerity, 
  • As an graduate engineer who had a dream job in mind however landed at some different job and still made a enourmous contribution everywhere with his passion, dedication and commitment to the work, 
  • As a true follower of Gurus like Dr Vikram Sarabhai, Dr Satish Dhawan, Dr Brahm Prakash, who has followed his seniors with utmost faith and respect and hence manage to change the future of country with their guidance and his efforts, 
  • As an amazing scientist who learnt from each experience and used all of his amazing intellectual power for his country without ever thinking for earning money outside the India, 
  • As a true and caring leader during PLSV and Indian Missile programme who has motivated a big big group of people across the institutions to work like a team with a single and defined mission in mind, 
  • And moreover as a good human being whose only mission was to do good for his country and even now is contributing to welfare of society in whatever mean he can do. 

How to Configure PHP Project in Eclipse for Debug Mode

Eclipse is very important tool for any developer, all due to the vast library of open source and freely available plug-ins which provides almost every required facility for development environment.

Now if we are using Eclipse, then ‘debug’ mode in Eclipse is a very useful tool to debug the code. Putting prints in the code and tracking the print-outs on the server console is very tedious job. So here we are explaining; how we can configure Eclipse and PHP web server to enable debugging of PHP applications in Eclipse using XDebug (http://www.xdebug.org/docs/).

As PHP code runs on web server, so that means, debugging can be performed only on server. So we put the debugging information in PHP code file using eclipse in IDE, however we need to install XDebug on web server for actual debugging. XDebug will sit on the server, and will generate the required debugging information like variable dump, stack traces etc and put all of this information for public use on a specific port of the server. Now any application can access this debug information by sending request to server on this port.

Eclipse works on same concept for showing debugging information for PHP application. It connects to the web server on given port, and fetches the debug information to show in a user friendly way with its UI. So to configure the debug mode in Eclipse, we need to configure XDebug on web server and also need to configure the eclipse for XDebug properties. Configuration steps are as following:

Data access by Client Pull or by Server Push

This is a design consideration between client - server interaction, i.e. whether client should call the server and pull the data from the server as and when required. Or the server should push the data to the client whenever there is some new data for the client.

Out of these two approaches, the first approach i.e. Client Pull is the most common approach where client opens a connection with the server (using any client/server protocol) and ask the server for the data. Here client pull the required data from the server as and when required.

Second approach is, where the server keep track of all its clients. Whenever server find any data which should be sent to the client, it pushes the data to the client. In this approach, there should be some provision using which server can interact to the client, like client should have some server socket open with it or client request should be hold on server for pending response for a long time. Now server keep track of all its clients. If we are working with server socket at the client, then it should be opened for all the time, so that server can connect to it anytime for pushing the data to client.

Sometime we find a need where server need to update the client for any latest data, like share trading software or weather information software. Here server keep getting updated data from multiple sources and now same data should be updated to all client terminals of the server. Now above mentioned both approaches can be used here as mentioned below:

Simplifying the Locking Mechanism in Threads

synchronized(lockObject)
{
    // do the job
}

This is one of the ways to acquire a lock on an object and then do the work in a code block with exclusive rights. Synchronization is already explained with another blog 'Mystery of Synchronized Keyword'. 

Here the question is that why we take the lock on an Object, not on current thread. Answer is fairly simple. Whenever you want to secure the admission to any premises, you never apply a lock on yourselves but you will put a lock on some other object, like on door. So the thread is the 'actor' (you) who want to perform some work in a code block (premises). Here the thread want a exclusive access on a code block where it want to work. Now procedure to have exclusive access is to have a lock for code block, so that only the current thread can have access rights to it. Here thread needs any object (door), like lockObject in above example, to have lock on the code block. 

Further we need to understand that how thread get lock using an object. To understand the story under the hood, consider that every Object is having a state within it which shows that whether any thread has lock on this object or not. Whenever any thread request the lock on any object, object checks whether its lock property is already set or not. If not, it set its property for current thread otherwise it refuse to give the lock, ask the current thread to wait till previous thread release the lock and put the thread in queue. Once the previous thread release the lock, and hence unset the property, Object picks the next thread from queue and set the lock property for it. As soon as thread get the object property set for it, it get the rights to enter in code block and to execute it.

Another example is like more than one painters are painting an house. Now painting of one room needs that only one painter works in it at a time for good output. Like first one painter should apply the putty on the wall, then the next one should apply the primer and paint and so on. To ensure that everyone follow this, painter decide to lock the door of the room whenever anyone enter inside for the work. So as soon as putty man enters the room, he locks the door from inside. When other come for the work, they find the door locked and hence wait for their turn. As soon as, first man finishes his work, he opens the door and the next painter waiting in the queue gets the access to room. 

Runtime environment of Java ensure all of this processing i.e. it puts the current thread to wait state till it gets access on current object lock property and put it back to execution after getting the property set for it. 


Mystery of Synchronized Keyword

'Synchronized' keyword is used to ensure that only one thread access a code block or a method at a time. It is very important keyword in multi-threaded programming. In multi-threaded programming, multiple threads work on the same code blocks simultaneously. But there can be some code blocks which manipulate shared data. So if multiple threads executes the same code and try to manipulate the same data, it can results in inconsistent result. For example:

public class TestSynchronized {

private int i;

// suppose param value is 5
public void testMethod( int param)
{
    // thread update i to 5
    // simultaneously other thread enters the block and update i to 10 before first thread would be able to            
    // execute next statement
    i = i + param;

    // result is expected to be 25
    // but result comes to 50, as second thread updates i to 10 before first thread executes the multiple
    //statement

    int result = i*5;

    System.println.out("thread[" + Thread.currentThread + "] result[" + result  + "]");
    i = 0;
}

}

How to Stop a Thread

There is no direct method to stop a thread. Earlier there used to be methods like Thread.stop(), however now these are deprecated. So how can we stop a thread if there is no 'stop' method?

To understand the answer, we first need to understand the thread and its working. For understanding the thread, please refer to other post 'What is Thread'. So one thread performs a assigned work at a time and its life is over once this work is done. Like if we take example quoted in 'What is Thread' post, then a painting work assigned to a sub-contractor is the life of relation with him. As soon as, he will complete his painting work, the sub-contracting relation will end. 

So the right way to stop a thread is to complete its work, or to make it understand that its work is over and it has to exit. For example, Painting contractor can ask the sub-contractor painter while assigning the job that please work till you finish painting in this service or till I call you to come out of this room. So the sub-contractor will start painting and will automatically exit from the relation as soon as it will finish the painting. Alternatively Painting Contractor can call him in-between and so the sub-contractor will keep on checking that whether the contractor is calling him or not. If not, he will continue with his work till its completion. If yes, he will leave the work and exit the room. 

What is Thread

A thread is a fork of a computer program in two or more concurrently running tasks. Let us try to understand it with example, 
  • Process: It is generally a single program in computer. Like, You need to get your house painted. So you hire a painting contractor and make a contract for painting your house. Now this painting contractor will get the house painted. So we can equate it with a process which, once start, will paint the home. Suppose you also want to change the flooring of your home, then you will hire some other contractor for this work. This will be another process which will do the flooring work. 
  • Threads: Now if the painting contractor paint the whole house himself single handedly, it will take him many days. But he as well as you want to get your work done ASAP. The solution is that contractor uses multiple sub-contractor under his control and use them to paint the house. These sub-contractors work simultaneously on different portion of the tasks. These sub-contractors can share the resources, i.e. will be using the resources from same pool. Now as multiple sub-contractors are working in parallel on multiple tasks, it will speed up the whole process and whole house will be painted in much lesser time. So these multiple sub-contractors are like threads in main process (painting contract).