Sunday, July 29, 2012

How Interfaces are used internally in Java

Before reading this post, I recommend you to go through the following posts:
Interfaces in Java
Runtime Polymorphism in Java
Abstract Classes in Java : Runtime polymorphism

The interfaces have played a key role in making the architecture of Java robust and uniform. The interfaces are used in many places in Java. They are extensively used in JDBC architecture, Collections framework, Multi-threading etc., We will see in detail how interfaces have become crucial for Java to become robust and maintain the uniformity.

Interfaces used in JDBC:

Interfaces are so well used in architecture of JDBC by Java. I should say Java has got most of the flexibility mainly from interfaces and abstract classes. In fact, what Java has done is defined all the method-names in the interfaces. It did not give any implementation for any of the methods. So, what the  DBMS has to do is just use these method-names and build implementation according to the DBMS implementation. In case of migration from one DBMS to other DBMS literally, only the database driver URL, username, password for connection have to be changed.

Now consider a situation without interfaces in Java. In such cases, each DBMS will have its own set of method-implementations and method-names for specific functionalities in Java. Eventually, the method-names for database processing such as executing SQL stored procedures will differ from one DBMS to other DBMS. Now if we want to just change the DBMS we need to change the entire database processing code instead of just changing the driver URL, username and password.


Interfaces used in Multi-Threading:

Similarly interfaces are critical in view of the multi-threading. We know that a thread can be created by two methods.
1. Extending Thread class.
2. Implementing Runnable interface.

Now the first method can impair you in one way. If you extend Thread class, there is no way that you can extend another class since multiple inheritance is not allowed in Java. Now the second option is always good since we can create a class that implements any number of interfaces.

Interfaces used in Collections framework:

Another place where Java has made use of the interfaces is the Collections framework. The Collection framework is the most basic interface. It contains methods to add, remove, search and iterate over list. These are most general functionalities provided. The List, Set and Queue interfaces extend the Collections interface. These interfaces have their specific functionalities in addition to those provided by the Collection interface.

Related Posts:
Interfaces in Java
Runtime Polymorphism in Java
Abstract Classes in Java : Runtime polymorphism
Java Database Connectivity with MS Access -- Part 1
Java Database Connectivity with MS Access -- Part 2
Java Database Connectivity with MS Access -- Part 3

Saturday, July 28, 2012

Interfaces in Java

Before reading this post, I recommend you to read the following posts.
Runtime polymorphism in Java
Abstract Classes in Java:Runtime polymorphism

An interface is a collection of methods that must be implemented by the implementing class. An interface only tells the class what to do. Thus, the interfaces only have the declaration of member variables and methods. Implementing class defines all the methods declared in the interface. If a class implements an interface and does not implement all the methods then the class must be declared as abstract. Variables in interface automatically become static and final variables of the implementing class. Members of interface are implicitly public. A class cannot narrow the accessibility of an interface.

An object reference of an interface can refer to an object of implementing class. However, only methods that are present in the interface can be called using the object reference of interface.

Now lets put the interface into implementation. We consider the implementation of the Stack data structure. Below is the Stack interface and its implementing class MyStack.


The public class which uses the interface and its implementing class is as follows.




Interface Vs. Abstract Class:
Both interface and abstract class cannot have objects, but can have object references. In case of interface, object reference can reference an object of the implementing class. An object reference of abstract class can reference an object of subclass. However, abstract class can have non-abstract methods and instance variables but interface can have neither of them.

Java allows interfaces to be empty. An empty interface contains no variables and methods. It is used to mark a class to be having certain behavior.

Related Posts:
Abstract Classes in Java:Runtime polymorphism
Runtime polymorphism in Java
How Interfaces are used internally in Java

Sunday, July 22, 2012

Abstract Classes: Runtime Polymorphism



Before reading this post, I recommend you to go through Runtime Polymorphism since this post is an extension of the same.

Consider an organization where an Employee can be a Regular Employee or a Consultant. After all, an employee cannot be just an employee. An employee is under one of these categories. To simulate these types of cases in OOP, we make use of abstract classes in Java.

An abstract method (pure virtual function in C++) doesn’t contain a body. An abstract method must be overridden in subclass. Otherwise, the subclass will become abstract.

A class having one or more abstract functions can be declared as an abstract class. We cannot create an object for an abstract class. However, an object reference for an abstract class can be created. Now you may doubt the use of creating a class without an object. For example, in the above example, an object of the Employee class should not be created since an employee cannot just be an employee. Such types of classes should be defined as abstract classes. Now if we allow the objects to be created for an Employee class, it might lead to extra memory usage and also might defeat the very purpose of runtime polymorphism. But we can create an object reference of Employee and point it to an object of its subclass. This is where runtimepolymorphism again comes into picture. In the previous post, you must have already read the golden rule of Runtime Polymorphism: “An object reference of a super class can always point to an object of a subclass.” Instead of the super class object reference pointing to an object of subclass, we now make the abstract class object reference pointing to an object of a subclass.

The implementation for Employee Class is given below.


The implementation for RegularEmployee class is given below.



The implementation for Consultant class is given below.



You can observe that the abstract method in the superclass is overridden in both the above subclasses. Now we will see how runtime polymorphism can be applied using abstract classes.



A class can be declared as an abstract class even though it doesn’t contain any abstract methods. This can be used in situations where there are no abstract functions to be overridden in the subclasses, but at the same time, the abstract class should not have an object.

An abstract class can contain other non-abstract members such as methods and instance variables.

Related Posts:

Sunday, July 8, 2012

Essence of OOP: Runtime Polymorphism in Java

This post does not give the definitions of Runtime polymorphism or Dynamic method dispatch. Instead, it helps Java beginners (or any OOP Beginner) to use runtime polymorphism. I personally think Inheritance and Runtime polymorphism forms the crust of OOP (not just in Java but in all other OOP Languages also).

The entire dynamic method dispatch is based on the rule that an object reference of the super class can refer to an object of any subclass in the hierarchy. This can be explained with the following example.

Consider there are two classes Person and Faculty. Person class is the super class of Faculty class.

Since superclass and subclass share IS A relationship, every Faculty is a Person. So, whenever Java expects Person, a Faculty can be used. This kind of implicit casting is called upcasting.



Unlike in upcasting, every Person need not be a Faculty. Thus, if we use Person in place of Faculty, explicit casting needs to be done. Therefore, we need to use explicit typecasting in order to perform this operation. This kind of explicit casting is called as downcasting.



In runtime polymorphism, the call to an overridden method is resolved at runtime instead of compile time. It occurs when an overridden method is called using an object reference of superclass. Remember that you can only call methods which are present in the super class.

Now let us extend the previous mentioned example with another subclass to "Person" class: NonTeaching class. Now the class diagram is as follows:

The below class demonstrates the runtime polymorphism for the above class diagram.



As can be seen from the code above, Java calls appropriate method depending on the object pointed to by the object reference. In the first case, the object reference p is pointed to the object of Faculty class. So, the printDetails() from the Faculty class is called. In the second case, p points to object of NonTeaching class. Thus, the printDetails() from the NonTeaching class is called.

Always remember that the dynamic method dispatch is applied only to method that is defined in the super class, overridden in subclass and invoked using an object reference of superclass.

Saturday, July 7, 2012

gdb tutorial

Sometimes when you build a project in C++, it might become necessary that the code needs to be changed/added. In such cases, debugging the entire project becomes really very important because you need to ensure that the program flow is correct and no regression takes place.

In this post, we will debug the case study which we implemented in C++ demonstrating the employee register with the help of vectors. To know about how this case study is implemented, read the following posts:
1. Vector Operations - API
2. Vector Operations - Implementation
3. Vector Operations - Implementation part 2

We will use GNU C debugger in order to debug the case study. To start debugging of the case study, first we need to type the following command:

g++ -g "files.cpp"

which in our case transforms to be:

g++ -g EmployeeRegister.cpp Employee.cpp Display.cpp main.cpp

To start debugging, invoke gdb with the following command:

gdb a.out

To debug the entire case study, we will set a breakpoint in main.cpp from the beginning of main function. If you need to debug only a part of a huge project, you can specify that particular file with line number. The idea of this breakpoint is to run the project till that particular breakpoint and from there on, we can inspect or evaluate what each programming statement is actually doing.

break file.cpp:line_no

which in our case is:

break main.cpp:3

Now we want to start running the code line by line with the following command.

run

To go to the next line for debugging, execute the n command in gdb prompt. When you encounter any function and you want to get inside the function definition, use the s command. This is similar to the Step Into functionality in debugging.

In between when you want to check the value of any variable, use the following command:

p variable_name

To exit the GNU C debugger, use the q or quit command.

Now let us use all the above mentioned gdb commands in the case study.



Related Posts:

Vector Operations - API
Vector Operations - Implementation
Vector Operations - Implementation part 2


Sunday, July 1, 2012

Using Eclipse Database Tools -- Access Database from Eclipse IDE


Know Java?? Used Eclipse?? Bored with Database command interface?? Want to access database from Eclipse?? Then this post is for you...
We can access database from the Eclipse IDE itself whenever you want to check some database tables in the middle of a Java or PHP project. So, life becomes easier when you can do everything related to a project in a single tool.

To configure Database access in Eclipse IDE, first we need to open the Database Development perspective. In the Data Source Explorer, you can add a database connection by right-clicking on Database Connection > New.


The list of all the DBMS will be listed in the next wizard as shown below.


Click on the new Driver definition button as indicated in the below figure.


Specify the Driver type > JAR file > Username, Password and Other Database Server details.




You can Test the connection by clicking on the Test Connection Button available in the below wizard. If ping gets succeeded, then click on Next.

Verify whether all the details are correctly filled in and click on Finish.
 

You can see that the new connection added is listed in the Data Source Emplorer view.

The database development perspective in general has Data Source Emplorer, SQL Results, Execution Plan and Bookmarks Views.

The Schemas, Users and Roles on a connected database management system can be viewed in the same Data Source Explorer view.

The SQL Scrapbook can be used to type in SQL commands in Eclipse. You can execute a command by right-clicking on it and selecting the relevant Execute option. Also you can get suggestions as you type in a SQL command in the SQL scrapbook provided by Eclipse.
You can also use SQL Query Builder which is very similar to that of the SQL Scrapbook.

Saturday, June 30, 2012

Vector Operations in C++ -- Part 3

In the last post, we implemented the searching procedure followed in the Employee Register. Now we will discuss the CRUD operations on the vector with Employee class.

To go to the previous two posts,
Vector Operations in C++ -- Part 1 and
Vector Operations in C++ -- Part 2

For adding an employee, we need to first check if another employee of the same employee ID exists in the vector. If it exists, we should give the relevant message to the user. Since we know that adding or deleting the employees at the ends is done very quickly, we have used the function "push_back" to add the new employee to the end.



For displaying the employee details, we must first check if the vector is empty. If it is empty, we need not traverse through the vector.



For deleting and updating an employee details, we need to check if the employee with the given ID exists. If it does not exist, the relevant message must be displayed.



Till now we have done all the operations required for manipulating or displaying the employee data. But a good user interface which is easily understandable by the user is equally important. Thus, we will have a menu with all the above discussed operations. To take numerical and string input from the user, we use two member functions in the class "EmployeeDisplay". Validation to the complete extent is not done for numerical and string inputs.

Compiling and running the case study:

Compiling:
g++ -o EmployeeRegister main.cpp Display.cpp Employee.cpp EmployeeRegister.cpp
Running the executable:
./EmployeeRegister

Sample Output for an add operation in the following menu is given below.



I have uploaded the entire project at the following link: Vector Operations Case Study. You can download the "Employee Register.zip" from this link.

Vector Operations in C++ -- Part 2

Have some information about vectors and want to implement the vector operations?? You have come to the correct place.
In the last post, we have discussed about the operations in vectors and the functions that can be used in vectors. If you do not know about vectors in C++, then refer this page. In this post, we will see the practical implementation of vectors by using a case study.

We are building an employee register in which an employee has two attributes -- a unique Employee ID and the Employee Name. If you want more attributes such as Date of Birth, Work experience, Designations etc., you can add them. But I thought of keeping it simple. So, I have included only two attributes for an employee. I am not linking this case study to any database programming. But I am sure this case study would be very useful in many of the applications based on CRUD and can be used in applications which include database programming. The following actions are done in this case study:
  1. Add a new employee
  2. Display the existing employees
  3. Delete an employee details
  4. Update an employee details
We will have a total of three classes:
  1. Employee class  -- To define the basic attributes of Employee
  2. EmployeeRegister class  -- To do the vector operations on Employee class
  3. EmployeeDisplay class --  Created for User Interface programming

To ensure data abstraction, the header files are separated from the actual implementation. In the header files, the declarations of the variables, classes and methods will be present, while the implementation is covered in the corresponding CPP source files.

First let us see what Employee class has. The following piece of code is Employee.h which declares the variables and the member functions of Employee class.



The implementation of the Employee class are given below. The getters and setters are defined so as to access the member variables in the Employee class.



The implementation of EmployeeRegister class has the following operations:
  1. Adding, Deleting and Updating an employee.
  2. Displaying the current employee details.
  3. Searching for an element in the vector.
  4. Checking whether the vector for Employee class is empty.
We can check if the vector is empty by using the boolean function "empty()" used in vector STL.



Searching is an important operation and will be used by almost all other functions. Imagine you have large number of employee records and you need to search for a record which is the last in the vector. By using linear search, the search process will consume more time. For binary search to be implemented, we need to have the elements in the vector in an increasing order which is not the case here. They can be any possible order. Thus, due to all these factors, the STL algorithm "find" is used to find the position of an element in the vector. For this function to be used, we need to create another vector of integers "emp_id_records". This vector should have all the employee ID's exactly in the same order as that of the emp_records. So, if we can get the position of an element in one vector, we can the index of the other too. 



Friday, June 29, 2012

Vector Operations in C++ -- Part 1

At the end of this series of posts, you will understand the working of vectors, the functions used in vectors. In addition to this, you will be able to do the basic CRUD operations on the vectors.

Vector is a type of sequence container in C++ and is implemented like a dynamic array. Vectors are very similar to arrays except that the arrays have a constant size while vectors can be extended or contracted as needed. However, the size of vector can also be fixed and resized. Once the storage of a vector is exhausted, it grows automatically in size. The storage space they have been allocated can be either equal or greater than the actual size. The extra amount of storage allocated is not used, but is reserved for the vector to be used in case it grows. Thus, the vector does not have to re-allocate storage on each occasion it grows or a new element is inserted.

Similar to arrays, we can access a given element in a vector easily with the index. The elements of vectors are stored in contiguous memory locations just like in the case of arrays. We can iterate over a vector by using its index or by using iterators used in vectors.

Adding or removing the elements from the vector at the ends is done very well as far as the time complexity is concerned. However, the performance of insertion/deletion at positions other than the ends is worse than that of the other sequence containers in C++ (deques and lists).

Constructors for the vector class are as follows:


Constructor Name Syntax Example Description
Default Constructor vector<T> vector_name; vector<int> a; Creates a vector with no elements
Repetitive sequence Constructor vector<T> vector_name(No. of Elements to be repeated, Value to be assigned); vector<int> b(4,100); Creates a vector of 4 elements with value 100.
Iterator constructor vector<T> vector_name (Beginning of another vector, End of another vector); vector<int> c (a.begin(),a.end()); Creates a vector with elements from vector “a”. Can also create a vector by copying only a part of the vector “a”.
Copy constructor vector<T> vector_name(another_vector); vector<int> d(c); Creates a vector by copying the vector “c” into vector “d”.


Accessing an element in a vector:
An element in a Vector can be accessed in two ways:
1. vector_name[index]     (or)
2. vector_name.at(index)

Iterating over a vector using an iterator:
We can iterate over a vector using a normal for loop with the initialization variable from 0 to the vector's maximum size (vector.size( )). But here is another method to explore all the elements in a vector:

vector<int> vector_name;
vector::iterator it;
for(it=vector_name.begin();it < vector_name.end(); it++)
      cout<<*it;

This piece of code will print all the elements one by one in the vector. Similar to iterator, there is also reverse iterator, which iterates over the vector from right to left.

Functions in Vector:

Function Syntax Description
push_back vector.push_back(element) Inserts the element at the end of the vector
pop_back vector.pop_back() Deletes the last element in the vector and returns the same
erase vector.erase(position) Deletes the element from the vector in the specified position/index
insert vector.insert(element,position) Inserts an element (1st argument) into the position (2nd argument)

In the next post, we will apply this concept of vectors in our case study, which involves the basic CRUD operations.

Sunday, June 5, 2011

UNIX Command History

All the commands typed by the user are stored in a file named ".bash_history" (for bash) in the Home directory of the User. It is a hidden file as its name is preceded by a dot (.) and therefore you can view this  in the File manager only when you hit the Ctrl-H combination. To view this file in "bash" the option -a has to be used with the ls command, i.e., to view this file in the command line interface, the command ls -a has to be used.

This file contains the list of all the commands typed since the system formatting. The operations on the command history such as retrieval or reuse of the commands depends on the contents of this file.

Type history at the command prompt and you will get the last 500 commands used. If you only want to look at the last 10 commands, you could type the command history 10. Commands are remembered so you can reuse them.



You can reuse any command in the history list by typing its number (as shown by the history command), preceded by an exclamation mark (!). If you want a view a file listing of the Documents folder, and ls Documents is command #31 in the list, you could type !31.




Say you’ve just typed a long file-name copy (cp) command, and want to use it again. Typing !cp will find the last line in your history list that begins with cp and reuse it.



Typing two bangs (!!) will cause the last command you typed to be reused. Finally, typing !? and then part of a recently-typed command will cause bash to auto-complete using the nearest match it can find in the history.


Wednesday, May 25, 2011

What went wrong in Natty Narwhal Ubuntu 11.04

It was 29th of April, 2011 and I just completed my exams. I was so excited to try the new release of Ubuntu as I knew that Ubuntu is going to concentrate much on the User Interface part of the Operating System this time. I really thought it would be a success compared to the earlier versions and new users would definitely try it. But after trying it, I was hugely disappointed.

We understand that user interface is important. But it is not a crucial element in an operating System. Many other things such as the performance, the hardware utilization, memory management determine the success of an operating system. In addition to this, it would be a basic thing to provide software without bugs. The earlier versions of Ubuntu also had some issues. But we cannot expect everything to be perfect, especially for an open source software. On the other hand, if the bugs occur every now and then when we use it; it would be irritating for any kind of a user. Remember its not an alpha or a beta release, its the final release.

There are many issues with this release, which are listed below:

  • Not responding state: The users able to control the system under this state is one area where Windows is way ahead of Linux. The Windows Task Manager does a very good job, allowing the user to control the System.
    • We have an applet namely Force Quit that ends any application forcibly. This applet in the previous releases used to be a decent application, which responded quickly and took control of the system immediately, when invoked. However, the new release of Ubuntu has not got any such applet and the system often goes into the not-responding state. 
    • In addition to this, this release does not respond well to the Hot Keys. Even if we use Ctrl-Alt-Backspace, which is used to kill the X server and log out of the system; we are logged out of the system, which does not display the login screen, thus posing problem to most of the beginners. In this scenario, we are left with using the system in command-line through Ctrl-Alt-(F1 to F6). Thus, the not-responding state eventually makes us to use the Power Button for restarting the system, rather than the conventional way of shutting the machine down. 
    • Banshee Music Player is good when compared to Rhythm box Music player regarding the ease of use. It is selected as a default music player this time instead of Rhythm box Music Player. This crashes every now and then irritating us to the maximum. To some extent, Rhythm box Music Player was better and can be used.
  • Customization reduced: One main reason, I use Ubuntu is the customizations in it. However, this release left me with dissatisfaction giving absolutely no customization to the panel.
    • The earlier releases had given control to the user as far as the panel is concerned, through which I was able to add the applets to the panel, which I found to be useful. But now, the panel at the top has got minimum customizations and gives zero control to the user. 
    • The menu bar is another disappointing change made in the interface. The menu bar appears on the top panel according to the active window or the active application. 
    • The Launcher is a new idea and it is good when it comes to look and feel. But a huge deal of it still has to be improved. Many parameters of the Launcher are pre-defined and cannot be changed by the user and the drag and drop option for the launcher is not complete. However, after using it, one makes a statement that literally everything has to be done through the launcher only, allowing minimum customization. 
    • The interface sometimes crashes out, especially in the case of drag and drop. When I tried to move the files from one folder to another by using the drag and drop in the Nautilus File manager, I experienced it to be an absolute prison with the not-responding state again. Interesting point to make a note of is that the previous releases all remained stable with the same kind of mouse drag-and-drop action on the file manager. 
    • The old Compiz settings are far better than the changed ones.
  • Untested Software: I got a feel of using an alpha or beta release when I was using the final release of Natty Narwhal.
    • The mouse and keyboard listeners are not well programmed and have to be looked into once again. Sometimes, the Close, Maximize and Minimize buttons for a window disappear suddenly. We do not know what to do under these circumstances and use the System Monitor to kill that specific application. 
    • The themes sometimes get changed by themselves. These new themes are out of control of user, as they do not get changed the way we want. In such cases, the previous theme is restored only after the system is restarted and there are situations where even  the system restart does not help. 
    • The dialogs or the wizards for the settings in applications especially is cumbersome as the wizard is found to be defective if it is un-maximized. 
    • Under some circumstances, I came across a situation where the items in the panel are not listed. This makes us difficult to control the system, as the menu for any application appears in the panel. 
    • There is another situation where everything was going well with my modem and a bug appeared in the Network Manager applet while trying to connect to the Internet. But the Network Manager applet says it does not identify network devices in-spite of everything being fine with the devices.
This release has got many attractive features as well. The interface has been the focus of the development team this time. But there are some other encouraging features as well.
  • Ubuntu Software Center: With every release, the Ubuntu Software Center is getting better and better. The encouraging feature this time is the reviews and ratings added to the softwares. The reviews put in by various users and their ratings are given.
  • Easy access to items in Launcher: The launcher may not be good at the customization but it certainly gives easy access to the items in the Launcher through the simple shortcuts.
  • Unity Applications Menu Support: This is a welcome development. Unity now lists the installed applications under a section "Installed". Though it looks good, it is not very user friendly yet. There are no categories as we saw in GNOME Shell before and it is not very stable as well. This still requires a lot of work. 
  • Improved Search Options in the Unity: The Search options certainly have been very good compared to the previous versions. The categories such as Frequently used, Installed applications are included which makes it much more easy for the users. However the auto-completion option has not been added yet. With that option, the Search functionality would become a true class application.
  • Improved Window movements: Like in Windows 7, the windows can be thrown to the corners and edges on the environment resulting in maximization, minimization of the windows.
The strategy of the Ubuntu developers must certainly change now. Anything overdone is dangerous. All the operating system concepts must be kept in mind while development and bug-free software is essential in the increase of popularity of a software and Ubuntu is no exception to that. It has been good and sticking to the right areas till Maverick Meerkat. But this time, the interface frequently leads to Force Restarts, which is not a good sign. However, there are many positives that can be made out of this release. What everyone needs is a bug-free software and good user-friendliness; both have to be taken care of. I just think that the next release is going to be a success as the testing will become important this time and will lead to error-free system.

Thursday, February 24, 2011

Firewalls in Ubuntu -- details and configuration

Ubuntu Linux has mainly two strong firewalls, namely:
  1. Netfilter
  2. Firestarter

Netfilter firewall:

Ubuntu has a powerful firewall called netfilter that is part of the central kernel program. The ufw command at the terminal allows us to configure the firewall. However, this command needs you to be root of the system. For this purpose, we add sudo in before the command. For example, to enable the netfilter firewall we type the command as: sudo ufw enable. The manual pages for this firewall can be seen by typing the command: man ufw. 
However, this firewall can be operated in a more user-friendly way, by installing the package named Firewall Configuration. This package supports common tasks such as allowing or blocking pre-configured, common p2p, or individual ports, and many others. Rules can be easily added, removed and edited with the help of this interface. The interface is simple with easy usage and is recommended for beginner users.


We can configure the netfilter firewall by --
  1. Adding allow, deny and limit rules.
  2. Enabling, disabling and reloading the firewall.
  3. Deleting and Inserting rules.
  4. Displaying the information and status of the firewall.

Firestarter firewall:


Another user-friendly Firewall in Ubuntu is Firestarter. On the start-up for the first time, a wizard will be run, for configuring the network states. You can read the manual pages of this firewall by the command: man firestarter. There are three pages/tabs in the Firestarter interface, namely --
  1. Status page giving an overview of the firewall state. 
  2. Events page, where blocked intrusion attempts and the firewall history is shown.
  3. Policy page for altering the behaviour of the firewall.


This firewall can be in one of these three states: Active, Disabled and Locked (Nothing is allowed through the firewall, neither in nor out). The Network section of the status page gives an overview of the network resource usage. In addition, the status page also lists the Active connections, the firewall is tracking every moment. The entries in the Active connections are color coded as: Gray for a terminated connection and black for a currently active connection. However, terminated connections are removed from the list after 10 seconds.
The Events page shows the history of connections blocked by the firewall. The entries in the Events page can be allowed connections from source, port or everyone or can be disabled events from source or port. The Firestarter colour codes the entries as:
  1. Black -- A regular connection.
  2. Red -- A possible attempt to access a non-public service and needs special attention.
  3. Gray -- Harmless connections, mostly broadcast.

The third page, Policy can add, edit or remove rules for the firewall. Two types of rules can be created: Inbound rules, that allow through connections from the network or Internet, and Outbound rules, that can block unauthorised data emissions from your computer, such as those from potential virus infections, or spyware. Inbound rules allow you to filter all incoming connections. When it comes to blocking data emanating from your computer, Firestarter can enact two different modes:
  1. Whitelist: In this mode, network traffic is not allowed out of the computer unless a rule allows it. This is also known as restrictive policy. 
  2. Blacklist: In this mode, which is default, all traffic is allowed out of the computer unless a rule specifically forbids it. This is also known as permission policy.

Monday, February 14, 2011

Java Swing applications -- Telephone and Address Book -- II

Implementation:


The Telephone Book application is now designed and we need to just put the coding for that. We already know which objects in swing package are used as the components in the panels for the application. For example, we have mentioned in the last post about some components such as Drop-down list (JComboBox), Labels for the appropriate components(JLabel), Buttons (JButton), Text-Boxes (JTextBox), Scroll Panes (JScrollPane), Results displayed in Tables (JTable), Confirmation of the results through Dialogs (JDialog) etc.

The Front end is Java Swing while the application has a database connectivity with MS Access database. As mentioned in the previous post, there is only one table in the database. The coding is done in two packages: 
  1. TeleAddress package for Component design and Action listeners &
  2. dao package for accessing database from the MS Access database through JDBC API
In all the classes, the constructors play a key role with initializing the frame window processing purposes. Mouse action listeners are applied to the buttons in the interface that interacts with the user, most of them being applied when the user clicks the mouse.

The confirmation dialogs are present in a separate class, named Dialogs with separate dialogs for contact creation, updating contacts and contact-deletion. The Dialogs class contains the following:
  1. Two Constructors -- one for Deletion and the other for Updation / Addition of contacts
  2. dialog( ) and deldialog( ) functions for processing one of the two constructors.
The TelephoneBook class in TeleAddress package is the main class in the application and binds all the classes together. The TelephoneBook class contains the following:
  1. All the Interface-Components such as Buttons, Drop-down lists, Text-Boxes,Labels,Tables etc. are defined in this class.
  2. 5 Panel functions for adding the components into each panel.
  3. A Constructor having function calls to the Action-listeners.
  4. A function named initComponents( ) for the lay-out of components.
  5. All Action-listeners for all the buttons such as Create, Delete, Update, Refresh, Cancel etc.
The SearchTable class allows the user to view the results in a table in a different Frame window. The Database class consists of all the database-connections, where we use the JDBC-ODBC Bridge Driver for connecting to MS Access. The static methods in this class are used for every database operation being done in the application. The dao package makes use of PreparedStatement and Statement for database query executions. The Database connectivity with MS Access can be done as shown clearly in these posts as part 1, part 2 and part 3. The dao package has the data access objects listed below:
  1. Database class for Database connection.
  2. AddDAO class for insertion of new contact into the database table.
  3. DeleteDAO class for deletion of contact records from the database table.
  4. OtherDAO class to get all the records from the database table
  5. SearchDAO class to facilitate searching upon inputs given in the Search and Delete panels.
  6. UpdateDAO class for updating contact details.
The documentation for the classes of this application have been automatically generated by NetBeans IDE through Javadocs which can be downloaded here.

Installation and Configuring the application:

Pre-requisites:
  1. The system should have Java (JDK and JRE) installed on your system, which can be downloaded from this page.
  2. The system should have Microsoft Office Access DBMS.
Configuring and Installation:
  1. Invoke Control Panel -- Administrative Tools -- Data Sources (ODBC). Go to UserDSN tab and click on Add button.
  2. Select Microsoft Access Driver (*.mdb, *.accdb) and click on Finish button.
  3. Give the Data Source Name as TeleAddressBook and select the Database Select button and give the path of the database file which can be downloaded from here. After selecting the .accdb file, click OK. Any doubts regarding the configuration of DSN (Data Source Name) can be clarified with the tutorial specified previously at this post with screen-shots.
  4. Download the JAR file which can be downloaded here.
  5. After configuring the DSN and downloading the JAR file, double-click on the JAR file to invoke the application. If its not invoked with the double-click then open Command-Prompt and type the one specified as: java -jar "/* Complete Path of the JAR file */"

    Sunday, February 13, 2011

    Java Swing applications -- Telephone and Address Book -- I

    Before starting the design and implementation of Telephone cum Address Book, I recommend you to go through the following post which gives an insight of how a layout should be in Java Swing.
    How to choose a layout in Java Swing

    It is quite common to have a telephone book to note the contact numbers, addresses and other notes of relatives, colleagues, acquaintances and so on. The search operation still has be improved under such circumstances. We need to find the contact quickly in the telephone-contacts book. In addition to that, updation, deletion of contacts is quite cumbersome in such circumstances. I have come up with a typical CRUD (Create, Read, Update, Delete) kind of an application built on Java -- a Java Swing application to be precise, which provides the following:
    1. Create / Add a new contact to the Telephone book
    2. Update the details of a contact
    3. Delete the contact details
    4. Search functionality based on many parameters such as Name, City, Contact Numbers, Address etc.
    5. List the entire list of contacts
    6. Refresh capability for the changes to be applied to the database.

    Advantages over the normal telephone book:

    1. Quick search and display of details
    2. Easy updation and deletion of contacts
    3. Robust contact addition

    User Interface Analysis and Design:

    The entire application is built on tabs, rather than using Menus and sub-menus in the application as most of them do. But to avoid complexity in the application, the results are maintained in tabs (JPanel). The results of the search and listing functionality are displayed in a Scroll Pane (JScrollPane). The items in individual panels are programmed in separate functions to provide easy maintainability. There are 5 panels in the application which are listed below:
    1. Create Panel
    2. Delete Panel
    3. Update Panel
    4. Search Panel
    5. List Panel
    The search results and the listing operations are displayed in a tabular format (JTable), with 7 different contact details. The operations on the table can be made by clicking on that particular cell and deleting the corresponding record. The table is added to the Scroll Pane (JScrollPane) with vertical and horizontal scroll bars as needed.

    The form-elements in the panels such as Create, Update and Search Panels is arranged in Grid Layout. Go through the guidelines to use Grid Layout. All the guidelines listed to use Grid Layout will have to be followed for better look and feel. The text-boxes (JTextArea) and buttons (JButton) are mainly used in all these forms, with the drop-down lists (JComboBox) also being added to the Search and Update Panels for better functionality and ease of use. The screen-shots can be downloaded here.

    Database Analysis and Design:

    This is a simple application with only a few contact-details which allows us to design the entire database using a single table. The main motto of this series of posts is to work with Java Swing and database is the easiest way to access data. So, we make an assumption that a contact has only single Office, Residence and Mobile contact numbers. The Normalization is not needed as per this assumption and a single table prevents the joining of tables. The database table telephone consists of fields listed below:
    1. Contact-Name
    2. Street, Area and City details of the person's residence
    3. Office, Residence and Mobile phone numbers 

    Monday, February 7, 2011

    The Best Instant Messengers in Ubuntu Linux

    As many of us use Instant messengers, we need to select the best of the best on any platform and Linux is not an exception to this. There are as many as 18 Instant messengers for various chat networks in the Ubuntu Software Center. While Windows has Digsby judged as the best and most popular Instant messenger, Ubuntu has three of them that are popular. If Digsby were in Linux also, I would be more than satisfied to use it because of its real time notifications, the look and feel and the features it provides. But unfortunately, Digsby is currently unavailable on Linux and Mac platforms and works only on Windows. But well, there is no need to worry as there are others which fulfill your requirements. I found the following three to be interesting in Ubuntu:
    1. Pidgin
    2. Kopete
    3. Empathy

    Pidgin:

    Pidgin was the most popular IM in Windows (and Linux) before Digsby came into picture. It was the default IM till Ubuntu version 8.10, but from Karmic Koala, Empathy became its default IM. It is an impressive master piece with a lot of features, with as many as 30 useful plugins and support for over 15 different protocol services such as AIM, MSN, Google Talk, Jabber, Yahoo etc. The only disadvantage I found with this IM is the slow start-up though it might not be a problem with the modern hardware configurations.
    Some of the plugins are listed below:
    • Voice and video chat support
    • Message highlighting
    • Enhanced history
    • SSL plugins
    • Topic change notification
    • Spell checker
    • Recent conversations and many more
    As you can see from the above plugin list, this IM has something for every level of user. It suits advanced users, beginners and intermediate users as well. Pidgin is quick at mail notifications, buddy status notifications. I would recommend you this IM if you have not got any on your Linux (not just Ubuntu).


    Kopete:

    Kopete is an instant messaging and chat application with support for a wide variety of services, such as AIM, Yahoo, ICQ, MSN, IRC, and Jabber. This package is part of the KDE 4 networking module. The layout of Kopete is glossy as it is available in KDE desktop environment. One good feature of Kopete is the KDE Wallet, which acts similar to the master password in Web Browsers. The KDE Wallet has passwords, cookies which once lost cannot be recovered. Besides this, the IM provides indexing for faster file search. Unlike Pidgin, it starts quickly with its look and feel being an extra asset. Notifications part is pretty good. It has got an extensive range of plugins including:
    • Video, voice chat support
    • Translator
    • Logging of all messages
    • Statistics
    • Bookmarks
    • Auto replace
    • Message highlighting and so on...

    Empathy:

    The Empathy Instant messenger is now the default IM in Ubuntu Linux. The premier advantage of this IM is the notifications. This supports as many as 20 different protocol services including Google talk, Facebook chat, Yahoo etc. It supports all protocols supported by Pidgin. It has support for voice, video chat, file transfers. Apart from this, it supports logging of messages according to date and it is quick.

    Sunday, February 6, 2011

    Gedit -- The complete Text Editor


    Gedit is the default text-based editor for GNOME desktop. I can say its complete because of its enormous features. Gedit is an open source text based text editor that can be installed in operating systems such as Windows, Linux and Mac (not just Linux). It is powerful for programmers with its wide range of features and plugins, which makes it appealing to any level and type of user. 

    Computer world is changing from time to time and I can say there is a considerable transition in the field of the text editors. In the early days,  many machines were GUI less and the users had to learn vi editor. Well, fewer and fewer machines are GUI less now. However, it is always important and is considered an extra edge to learn the vi editor, which is more often than not, useful to edit configuration files. Gedit gives more productivity than all the other predecessor editors such as vi, emacs etc.


    Syntax Highlighting:

    Gedit provides syntax-highlighting capability with a large number of
    1. Programming languages, 
    2. Hardware programming, 
    3. Scripting languages, 
    4. Markup languages and 
    5. Scientific purposes. (FCL, Octave, GAP, R)

     
    To select the highlighting mode, select View -> Highlighting mode -> Select the mode from the drop down list.

    Gedit Features and Plugins:


    In addition to the highlighting mode, Gedit supports a number of features such as:
    1. Bracket Completion -- Automatically adds closing brackets
    2. Change case  -- Inverts the case in the entire file
    3. Commenting or uncommenting a selected block of code.
    4. Document statistics -- Gives some information about the number of characters, words, lines etc., of the file
    5. Embedded Terminal
    6. Spell checker
    7. Tag list -- Inserts commonly used tags and words into document
    8. Word completion
    9. Sorting a document or selected text
    10. Snippets -- Insert often used pieces of text quickly mostly becoming the templates of documents with a specified highlighting mode
    11. Python console in the bottom pane and thus can run python programs.
    12. Language Support
    However, some of the above plugins will work only if you add the external plugins, which can be installed with the help of Ubuntu Software Center, by typing in the filter text as "gedit-plugins" and click Install.

    Colour Schemes:


    Apart from all these plugins and features, Gedit consists of some Colour Schemes which customise the environment of this text editor. Some of the colour schemes can be downloaded here. These colour schemes can be installed by selecting Edit -> Preferences -> Font and Colors tab and then adding the schemes (.xml files) by clicking on the Add button there under.

    Saturday, February 5, 2011

    10 Beginner Mistakes to be avoided by Linux newbies

    Ever increasingly, Linux is becoming more and more popular. Along the way, there are several common mistakes that users new to Linux tend to make. In fact, from time to time, you can even find some seasoned Linux users making some of these same mistakes. If you can avoid these mistakes, the transition to Linux will be a lot easier.


    1. Installing from outside the official repositories:

    This mistake is generally done by those who have used mostly Windows before. They try to programs and software from outside the official repositories just as  in Windows. Almost all Linux distributions have official repositories and the software packages need to be installed from them. For example, in Ubuntu, install the software from the Ubuntu Software Center. This Center contains a list of all the softwares available officially. If you have installed the software outside the official repositories, there is a little chance to get assistance.


    2. Doing selective updates:

    This undoubtedly will make your system unstable mostly by broken links. It's considered a good practice to install all the updates periodically. To install all the updates, goto System > Administration > Update Manager. Not only this, but delaying these updates would be costly for you. So, it is always suggested to do complete update periodically.


    3. Linux is not Windows:

    There may be a lot of similarities in between Linux and Windows. But, don't expect Linux to be exactly like Windows. The similarities help in making an easy transition towards Linux.


    4. Avoid learning command line:

    The computer world has been changing continuously in the field of user interfaces. Its getting easier and easier for the users to use many operating systems and applications now-a-days. But, the whole process started with the command line user interface. And Linux is an operating system which expects you to learn a bit of command-list. Command line way of doing things is a lot quicker than the GUI. Besides all this, some things can be done only through the command line. So, if you have decided to work with Linux, then learn commands.


    5. Misusing the help forums:

    Even though Linux is free, help for getting started is close at hand, and available from multiple sources. There are help files, user manuals, and even the "man pages" that are easily accessed through either the command line or the other graphical way. For each Linux distribution, there is a separate user forum for getting help regarding all the operating system issues. By searching, you are likely to learn other important things. So, get the most of these user help forums.


    6. Avoid running as root (when needed):

    Running the operating system with root privileges will surely inflict some damage to your system. So, avoid running as root as far as possible.


    7. Avoid relying too much on WINE:

    WINE is a utility to run Windows executable programs on Linux. Find Linux software counterparts and try using that instead of installing all the softwares through WINE.


    8. Ignoring the system messages and errors.



    9. Its not Ctrl-Alt-Delete:

    In Windows, this shortcut gives you the Task Manager. However, Linux restarts when these buttons are toggled. There is an applet named "Force quit" which can be used for force quitting unresponsive programs.


    10. Giving up too early:

    This happens mostly as far as Linux is concerned. Everyone must realise that they are not born knowing Windows. So, put some efforts to learn Linux and you will get rich dividends.

    Sources: PC Linux OS Magazine
    Related Posts Plugin for WordPress, Blogger...