Swapping Values of Two Integer Variables

The simplest way to swap the values of two variables is to have a third variable that can temporarily hold the value of one variable while the other is being copied. This is very easy code, but a small problem is that we have to allocate extra memory. In these days of gigabytes of data, that is not a huge concern. But still it is useful to know a technique where you can achieve that.

So here are a couple of ways to do that I saw in a few places. I don’t have the name of the original author, I am assuming that it became common knowledge early. The first method uses addition, but if you have large values, then there is the chance of arithmetic overflow based on the result. The second method uses bitwise operations that avoid the “over-flaw” (sorry!)

public class Swap extends Object
{
    public static void main(String args[])
    {
        int a = 123;
        int b = 345;
        System.out.println(a + " : " + b);

        //Swapping using temporary variable : straight-forward method
        int temp = a;
        a = b;
        b = temp;
        System.out.println(a + " : " + b);

        //Swapping using arithmetic operations : saves memory
        a = a + b;  //You can use a += b;
        b = a - b;
        a = a - b;  //You can use a -= b;
        System.out.println(a + " : " + b);

        //Swapping using bitwise operations : avoids arithmetic overflow
        a = a ^ b;  //You can use a ^= b;
        b = a ^ b;  //You can use b ^= a;
        a = a ^ b;  //You can use a ^= b;
        System.out.println(a + " : " + b);
    }
}

Implementation of Kruskal’s algorithm in Java

I will be posting some code from time to time. Some of these posts are from way back. I could probably rewrite them if I wanted to and perhaps in a different language, but there are bigger fish to fry. But maybe someone may find this useful.

So this is the Kruskal’s algorithm which finds a minimum spanning tree for a connected weighted graph. The program below uses a hard-coded example. You may want to write a unit test or something, changing it to match your problem by changing the edges in the graph. The Kruskal class contains the main method. The Edge class represents an edge (!). The KruskalEdges class contains the edges determined by the Kruskal algorithm.

The meat of the algorithm is in the InsertEdge method of KruskalEdges class. Let us assume that the edge to be inserted has 2 vertices, namely A and B. We maintain a vector that contains groups of vertices. We first check if either A or B exists in any group

  • If neither A nor B exists in any group, we create a new group containing both the vertices.
  • If one of the vertices exists in a group and the other does not, we add the vertex that does not exist to the group of the other vertex.
  • If both vertices exist in different groups, we merge the two groups into one.

All of the above scenarios mean that the edge is a valid Kruskal edge. So we will add the edge to the Kruskal edges.

However one final scenario remains where both vertices exist in the same group (note the missing empty else statement). In that case, we will not consider the edge as a valid Kruskal edge.

import java.util.TreeSet;
import java.util.Vector;
import java.util.HashSet;

class Edge implements Comparable<Edge>
{
    String vertexA, vertexB;
    int weight;

    public Edge(String vertexA, String vertexB, int weight)
    {
        this.vertexA = vertexA;
        this.vertexB = vertexB;
        this.weight = weight;
    }
    public String getVertexA()
    {
        return vertexA;
    }
    public String getVertexB()
    {
        return vertexB;
    }
    public int getWeight()
    {
        return weight;
    }
    @Override
    public String toString()
    {
        return "(" + vertexA + ", " + vertexB + ") : Weight = " + weight;
    }
    public int compareTo(Edge edge)
    {
        //== is not compared so that duplicate values are not eliminated.
        return (this.weight < edge.weight) ? -1: 1;
    }
}
class KruskalEdges
{
    Vector<HashSet<String>> vertexGroups = new Vector<HashSet<String>>();
    TreeSet<Edge> kruskalEdges = new TreeSet<Edge>();

    public TreeSet<Edge> getEdges()
    {
        return kruskalEdges;
    }
    HashSet<String> getVertexGroup(String vertex)
    {
        for (HashSet<String> vertexGroup : vertexGroups) {
            if (vertexGroup.contains(vertex)) {
                return vertexGroup;
            }
        }
        return null;
    }
    public void insertEdge(Edge edge)
    {
        String vertexA = edge.getVertexA();
        String vertexB = edge.getVertexB();

        HashSet<String> vertexGroupA = getVertexGroup(vertexA);
        HashSet<String> vertexGroupB = getVertexGroup(vertexB);

        if (vertexGroupA == null) {
            kruskalEdges.add(edge);
            if (vertexGroupB == null) {
                HashSet<String> htNewVertexGroup = new HashSet<String>();
                htNewVertexGroup.add(vertexA);
                htNewVertexGroup.add(vertexB);
                vertexGroups.add(htNewVertexGroup);
            }
            else {
                vertexGroupB.add(vertexA);           
            }
        }
        else {
            if (vertexGroupB == null) {
                vertexGroupA.add(vertexB);
                kruskalEdges.add(edge);
            }
            else if (vertexGroupA != vertexGroupB) {
                vertexGroupA.addAll(vertexGroupB);
                vertexGroups.remove(vertexGroupB);
                kruskalEdges.add(edge);
            }
        }
    }
}

public class Kruskal
{
    public static void main(String[] args)
    {
        //TreeSet is used to sort the edges before passing to the algorithm
        TreeSet<Edge> edges = new TreeSet<Edge>();

        //Sample problem - replace these values with your problem set
        edges.add(new Edge("0", "1", 2));
        edges.add(new Edge("0", "3", 1));
        edges.add(new Edge("1", "2", 3));
        edges.add(new Edge("2", "3", 5));
        edges.add(new Edge("2", "4", 7));
        edges.add(new Edge("3", "4", 6));
        edges.add(new Edge("4", "5", 4));

        System.out.println("Graph");
        KruskalEdges vv = new KruskalEdges();

        for (Edge edge : edges) {
            System.out.println(edge);
            vv.insertEdge(edge);
        }

        System.out.println("Kruskal algorithm");
        int total = 0;
        for (Edge edge : vv.getEdges()) {
            System.out.println(edge);
            total += edge.getWeight();
        }
        System.out.println("Total weight is " + total);
    }
}

Search Engine Monopolies

(Written in January 2004)

I recently read an article about Google adding another billion pages to its search engine. It is yet another development in the battle for supremacy between search engines. Increasingly, browsing trends indicate that most people have started using search engines as their starting point to other web sites. As electronic commerce increases, companies that invest more into improving their visibility in search results show greater increase in website visits and ultimately revenue through sales. The current search engine market leader Google and the currently-trailing Yahoo! and Microsoft search engines are trying to corner the market for search engines.

At one time, Yahoo was the premier search engine and search directory, but Google slowly captured the search engine market with its highly effective search engine. Finally, Yahoo abandoned its search engine and licensed Google, which propelled Google’s fortunes upwards. During the same period, Microsoft bundled MSN Search with its Windows operating system. By default, all website searches in Windows went to MSN Search, increasing its visibility to Internet users.

When the Internet was relatively small, web searches were not considered very important. However, as websites proliferated and grew larger, Internet users could not manage the information overload. They looked towards search engines as their tool to mine and discover what they needed. Studies show that a considerable number of users visit a website by clicking its link in search results. Companies have started investing in sponsored ads in search engines and also finding ways to increase their ratings in search results. This has produced millions of dollars in revenue for the search engines. However, revenue for a search engine is directly tied to the effectiveness of the search engine and the extent of its coverage of web pages.

Back to the article I read: At first glance, this might seem like a positive development for consumers, since Google search could become better with greater reach. However, the end result of the leadership battle for online search engines could result in a virtual monopoly for Google. What this means for Internet users is that they are increasingly dependent on Google’s ability and judgment in rating websites. For example, if a person relies on Google news for his or her view into the world, his/her vision starts getting colored by the results that Google returns.

Google has sponsored ads, which are paid ads that are displayed when a person searches for a particular keyword. This gives such businesses a huge advantage and forces other businesses to buy ads. Since space is limited, the best bidder wins. While in the past mom-and-pop businesses had huge successes on the web, they will face greater challenges by changes in Internet usage pattern and sponsored ads.

There does not seem to be an easy way to prevent a monopoly on the search engine market. A search engine’s only benefit is its effective search results. Unlike other businesses, cost is not a factor. If a search engine produces results that help people achieve what they want, it will attract visitors. However, sponsored ads could be prevented from appearing from all searches to help non-advertising businesses.

The fact that Yahoo and Microsoft have decided to launch their own search engine efforts does present an alternative to users. Although search engines are not Microsoft’s primary market at least for now, it might continue to pose an alternative to Google for the foreseeable future. However instead of striving to be a Google-clone, it should work on better and different features for users.

Digital Distress

Aldous Huxley once said, “Technological progress has merely provided us with more efficient means for going backwards.”

Technology is supposed to make your life easier. That was the plan. I find that technology is increasingly creating more work and making us more stupid.

Last month, a few friends and I went to visit Quebec. In the good old days, when we had an analog camera, we would buy 3–4 rolls of film and be very conservative in taking shots. Find the best spot. Get the lighting right. Stand straight. Say cheese. Snap!

Now equipped with a digital camera and gigabytes of card space, nobody has any patience any more. Every 5 steps you take a photo. It does not matter what it is. It may be a great scenic location, or a mundane statue. It may be a beautiful rose or an ugly duck thinking you are its father. No more rolls to burn. So keep on snapping!

If there are 2 people, first you take the photo of Person A. Then you take the photo of Person B. And then give to a stranger to take both of them. Oh yes, I forgot. Now you can see how the photos look like before they are developed. Zoom to see if there were any blemishes. And if so, repeat the process again.

And so, literally you take hundreds of photos on one trip. I would not even call it a “trip”. More like a modeling engagement except that your photos never get published.

I am sorry. Did I just say those photos never get published? I was thinking about the old days when your photos go into a carefully stored photo album and only looked at by a handful of people.

I forgot about social networks like Facebook and Orkut. Nowadays, you have to be extra careful when you pose for a photo, because anyone with a camera, essentially anyone, can post your unflattering moments online for everyone to view. My looks are not that flattering anyway, but I have my pride too.

I also look at our inclination to keep hoarding these bits and bytes. Every year, each one of us adds thousands of photos and videos. And our friends do the same. To actually look at them would take hours, maybe even weeks.

I recently read an article where a person boasted that he had 20,000 hours of bootlegged music and video. Very nice! The problem is that it would take the person two and a half years to listen to that music if they did it 7 days a week, 24 hours a day.

While technology is making it easier for us to do various activities, it makes it also easier for us to do too much of them. For examples, airports are among the most dangerous places in the world not because of terrorists, but because you never know when someone using a Blackberry is just going to crash into you.

Blogging made it easy for every person to publish their sorry diary, but today it gets even better. You have micro-blogging with Twitter where you can write all day long about “What are you doing?” and follow hundreds or thousands of other people doing the same.

The lesson we can derive from this is that technology has subjugated us. We no longer have any free will. We all need to need to take a deep breath (go ahead) and look at how we are utilizing technology. And become its master once again.

Becoming a Better Developer

(Written in 2008 for “IT Glimpse 2008″, a magazine published by the School of Computer Science, M.G. University, Kottayam, Kerala)

In Hollywood action movies, there is usually one actor who plays a computer hacker. Although each movie has its own plot and there are different actors, the role of the computer hacker is almost the same. It is usually a male in his early 20’s who lacks any grooming or discipline, doesn’t know anything else apart from computers and usually knows how to hack into a system by guessing passwords in less than three tries.

This is a stupid caricature that is incredibly far from the reality of what good programmers actually are. Many people, influenced by this popular image, think that to be a computer programmer, you have to be born extra brilliant and have skills that ordinary human beings don’t possess. They also think that computer programmers have no social skills or life, and have to sacrifice the good things in life.

The truth is that becoming a better software developer is very similar to becoming better at any other activity such as becoming a better electrician, or plumber, or cook. You can become better at programming because it is a learned skill, that improves with more learning and more experience.

For example, no one is born knowing how to cook. It has to be learnt. Also, most people, even good cooks, don’t learn to cook until they are several years old. In the same manner, no one is born a programmer. You don’t have to start programming (or even how to use a computer) when you are young. You could be a late starter and still become a very good programmer.

In fact, because there are so many rapid developments in programming, past knowledge can quickly become obsolete. So the advantage of having more years of experience is less when compared to other jobs. For example, languages like Cold Fusion and databases like FoxPro, which were very popular just a few years ago, are now in rapid decline. New frameworks like .NET and Ruby on Rails are catching on in a big way.

Programming is a skill that you can learn yourself, even if you have never learnt it at school or college. All you need is a computer and a programming book or Internet access. Today, across the globe, there are many self-taught school-age programmers who go way beyond what they are taught at school.

But that doesn’t mean that a college education is useless. On the contrary, a formal computer program and degree is invaluable on many levels. Foremost (and this is an obvious point), it provides you with the necessary credentials to apply for software jobs. Most companies will not hire someone who does not have a computer science degree and many will not even consider those without a good academic record.

You also learn the necessary fundamentals to apply your knowledge to different computer science problems. One of the drawbacks of being self-taught is that you only learn “how” to code something. Only in college will you learn the “why”. You will use the lessons learned in a course like “Computer Algorithms” in solving computing problems years later.

A formal degree is usually your first introduction to like-minded friends, who are also interested in learning software development. You will find that many of these friendships last a lifetime unlike those friendships formed in school, because the career path of your college classmates will be similar to yours. They will work in similar projects in similar companies.

As you progress through your career, you will add more such friends, both whom you meet in person and others whom you meet online and know only through a virtual relationship. This community of software friends is one of your most important assets. Through them, you will learn tried-and-tested solutions, latest industry trends, and tips and tricks that will help in your continuous improvement.

The reason I call this a community is that these friends and acquaintances are not a bunch of contacts in your Address Book, but instead form a group that derives its happiness from sharing ideas and information. To participate in this community, all you need is a thirst for knowledge, a curious mind and, most importantly, the ability to leave your ego and complexes behind.

One of the great revolutions in recent years has been the explosion of Web 2.0 websites which has dramatically increased the amount of information available for any topic. Just a few years back, if you wanted to learn a programming language, you would have to rely on either a book or somebody to teach me. Today, not only the number of books and websites has increased, but you can simply go to YouTube and actually see videos of programming examples. You have access to high-quality classroom material, such as the audio and PDF slides of MIT (Massachusetts Institute of Technology) lectures. You no longer have an excuse for not learning.

We have left out the most important aspect of learning, which is practice. It is simply not enough to read, listen or talk. It is important to do. Going back to our initial example of cooking, you will never know how to cook a dish until you actually spend time cutting vegetables, adding spices and using the stove. Until then, everything is in your head. You have to practice so that it becomes a reality.

To become a great programmer, you must spend time in the front of the computer, trying out different techniques and examples. Take real projects or classroom problems and try to find solutions for them. One of the best ways to learn is to attempt a project for a subject that appeals to you. For example, you could do a project to keep track of your friends’ birthdays or addresses.

Ultimately, learning is about your personal inclination. It boils down to one single question: Do you like solving problems? Because that is what software development is about — It is an entire career of taking on and clearing challenges. If you like doing that, then you will also enjoy the rest of the learning activities that will make you better at them.

Building a Great Software Product

(This article appeared in “IT Glimpse 2001″, a magazine published by the School of Computer Science, M.G. University, Kottayam, Kerala.)

How does one make a great software product?

Don’t you wish you had the answer? Me too. A lot of people would kill to know the right answer to that one. Try asking this seemingly simple question to ten of your friends. You will be very amused at the variety of answers you get. The truth is that at best, one can only (and this article claims to do no more) get insights into causes of success and failure.

Defining Success

Before proceeding, lets stand back and define our yardstick for “greatness” of a software product. How is “success” measured?

If you ask this question. a designer would opt for a well-built, modular architecture. A programmer would point out new technologies, challenges overcome and low-level hacks. The quality team would talk about “Six Sigma” initiatives or some such confusing jargon.

This article submits that user acceptance is what makes a great software product. Great design, clean coding and overcoming technological barriers are all very good and usually would be present in such a product. But by themselves, they would mean nothing if the software application was not used by anyone.

Maybe this is too simplistic, but the success of a software product is

  • Getting users to understand that they need the software
  • Getting users to try the software
  • Getting users to buy the software

Sustained success is

  • Getting existing users to keep buying newer versions of the software
  • Getting more and more users to buy the software
  • Keeping users happy

Sometimes success is highly relative. Going by the previous definition and taking a practical example, the Windows OS would be a qualified success. There are quite a few users who are dissatisfied with it, but keep buying it because they say they don’t have a choice, given Microsoft’s monopoly.

Examine the facts and you will see that there are always choices. Users buy Windows because it keeps them relatively happy by avoiding the issues (cost / user-friendliness / availability of applications) arising from using other operating systems like Unix, MacOS, etc.

In real life, there is no free lunch. People don’t “just build” software products. They build it for getting something back. Usually this “something” means money, directly as revenues or indirectly as increased efficiency. Even if there is no profit motive involved, software is built so that people use it.

Getting users to understand that they need the software

Users try out a product only if they see a need for the product. Custom-built software applications fit this bill because requirements are pre-determined. The story is a little different for software products and services.

Market research on needs can help in discovering niche or even mass markets. “Killer apps” such as e-mail and instant messaging come to mind. Products must be built with an audience and a need to cater to. Otherwise, the software would end up nothing more than an interesting programming exercise.

Sometimes, new products are built to capture a market by displacing existing products. To do this, the new product must have something new to offer, such as extending existing functionality with better features at lower cost. Microsoft is particularly notorious for muscling into existing markets by buying out leading products or using a marketing blitz for its new product in that area.

To put a Machiavellian aspect to this issue, companies come up with useless products or features and create demand by sustained marketing hype. Its is not just children and teenagers, but even adults who can be susceptible to such tactics. Companies sometimes corner markets by patenting technology or creating monopolies through acquisitions and mergers. Such measures, while despicable, are becoming more of a reality than one would like to admit.

Getting users to try the software

At this stage, there is a user with a need and there is a product which meets the need. To get the user to try the software is the next struggle. Some users go to the buying stage directly. This is, of course, a welcome scenario, but something that cannot be depended upon.

Shareware was one of the great ideas in the Internet age that encouraged users to try out products with minimal fuss. Over the years, traditional marketing strategies such as sales pitches, ad campaigns, promotions, etc. have been supplemented with web marketing using Flash demos and email ads.

Getting users to buy the software

There is an old worn-out adage — “First impression, best impression”. If the user can get through the first few minutes of using a software and getting it to do the right thing, the battle is half won.

Here, an intuitive user interface is very important. The user must be able to find the commands that he/she is looking for very easily. The usability of a user interface assumes predominance over considerations such as attractiveness and originality.

Let’s take the vi editor in Unix. As a powerful text editing application, it has few equals. Yet people would rather use the lowly Notepad on Windows, because it makes them so much more productive in a shorter time.

The next point is so obvious: The software must be right. One can never overstate the importance of quality assurance. Nothing bugs users more than seeing the software application die on them. (Pun intended)

One of the more common programmer nightmares is a demonstration to an important customer crashing when his/her module is being shown.

Cost can be a major factor in purchase decisions. But if we take a look around, we see that costly Microsoft Office outsells the free Star Office. I guess this is what business folks mean when they talk about “Total Cost of Ownership”, i.e., the price tag of a product is less important than the costs or reduction of costs involved in using it in the long term.

Existing applications, setup and personnel inertia can be a major factor (rather obstacle) in product acceptance. Inter-operability with or easier migration from current systems would increase the chances of success.

Getting existing users to keep buying newer versions of the software

You might spend months designing the most complete application for solving a particular problem, using teams of analysts and designers. But let a user use the completed product for half an hour and ask him/her, “How did you like it?” 99% of the time, you can be sure that any answer will start with “Its great, but…” along with a list of new features wanted desperately.

The point is — no software is ever complete. There is no “The End” banner and dramatic music after the successful release of the product. More work begins at this step, namely, finding out how users are using the software and what more they want from it.

People use some products in weird ways. For example, a developer I know uses Allaire HomeSite for generating imagemap code and uses different editors for different sections of the rest of the server page.

Successful products inspire imitations. If an imitation includes the additional features that users are looking for, it may very well displace the original. Hence, the original product needs new versions to come out at regular intervals. Work should start on those versions immediately after the first release and not after product sales lose steam.

In large corporations, buyers are automatically locked into the software they purchase, because of the huge investment involved, particularly with regard to infrastructure and training. For less expensive products, there is no guarantee that the current user will not abandon the current application and go with a product from another vendor.

Lets take a parallel from the drug business. The product should be good that buyers are “hooked” on it and they want more and better stuff. But while the drug mafia can ensure their exclusive presence in a locality, software vendors do not have that luxury. The market leader should be alert and miss no opportunities.

Getting more and more users to buy the software

Keeping users happy

In case you are losing sleep over it, the occurrence of the two headings above is intentional. By a happy coincidence, the best way of getting more users of the product is to keep the existing ones happy and getting them to spread the “truth” (God forbid you be in the Trojan Horse creation business).

Users buy a product for a particular need. If the software helps them do it, they are satisfied. If it doesn’t, they don’t want it. Nor will others with similar needs. Once this essential criteria of meeting needs is satisfied and the product keeps improving through each release, a strong word-of-mouth reputation starts building up.

It goes without saying that the product has to be marketed properly, regardless of its technical perfection. For those operating on a shoe-string budget, reading about some of the low-cost innovative Internet strategies might be a good idea.

Nothing succeeds like success (cliché!). The more copies of the product that are sold, the more users that want to try it at least once, which increases the possibility of more sales. Hence the importance of striking the bull’s-eye at the very outset.

Conclusion

How to make a great software product? Well, we are back to where we began.

We see dud releases from huge corporations investing billions of dollars in marketing research. We see stunningly successful products (Linux, Winamp) from students writing software as a hobby. Through every story of triumph or disaster in software development, one lesson stands out — “The customer is everything”.

Build software for users. Learn about user needs, build software and market it for those needs. Keep finding out how you can improve upon what you have built.

Imagine that you are the customer and start. You can’t go wrong.

Java — The Platform

(This article appeared in “IT Glimpse 2000″, a magazine published by the School of Computer Science, M.G. University, Kottayam, Kerala. Current technology advancements have made some of the statements below obsolete.)

One of the most common mistakes that people make about Java is to regard it as just another programming language and then get involved in futile arguments over whether it is better than C or C++ or other languages. They miss the whole point.

Java provides many more benefits than simply a new programming language. It is a complete platform for development and deployment of software solutions ranging from hand-held products to enterprise-wide applications. The actual language specification provides a base for addressing real-life concerns like performance, security and cost.

Java is general-purpose. Although initially marketed as a Web technology and used for creating jazzy Web applets, Java is now being used in a wide variety of other applications. Java Servlets and JSP are being used in place of CGI and ASP. Enterprise Java Beans are being used to build n-tier applications. Java is being used for network programming, game programming, database programming — what not!

One of the most touted benefits of Java is “write-once run-anywhere”, an old programmer mirage. A developer can create his product, implement all the business needs, round it off with an intuitive user interface and never worry about which software or hardware platform it is going to run on. The days of painstakingly re-writing code, especially GUI frameworks, is over. Barring minor areas, a Java program will run the same on any platform that has a Java Runtime Environment.

The portability of Java frees the developer and end-user from the tyranny of being tied down to a specific vendor or product. One can change the platform on which the program is running to a cheaper, better or more convenient one. Makes better sense. Makes better markets and products too as software makers have to get involved in actually bettering their products instead of the old scenario of “once-a-customer, always-a-customer” where a change for the customer was prohibitively expensive.

The development time for Java is considerably less than other languages. One factor is the well-thought-out design of the language itself. Compilation and run-time checks allow a lot of bugs to be trapped early enough. The language prevents a lot of errors by various means such as array bounds checking, type checking and exception handling. The object-oriented nature forces the programmer to invest more in the design process, leading to a smoother coding and testing phase.

One of the great advantages of using an object-oriented language is the ability to reuse components. The JavaBeans API specification provides a framework for defining reusable, embeddable, modular software components. More importantly, they can be visually manipulated in a builder tool, even if they don´t have a visual representation. This has created a whole industry of GUI development tools for Java.

With JavaBeans, one can create complex objects to function as a collection of co-operating intelligent beans. A Java program can dynamically extend or change its behaviour by loading or replacing different objects at runtime from resources in its accessible network path. Thus Java has changed programs from monolithic entities to interacting collections of intelligent software components.

The amazing array of reusable classes that Sun provides the developer for implementing various features adds to the ease of development. Java 1.2 at the last count had around 1500 classes in more than 50 packages. In addition, one can purchase objects from different software vendors or download free Java classes from the Net. The bottom line reads thus: High quality at inexpensive development costs.

RMI (Remote Method Invocation) allows Java objects on one machine to invoke methods on other machines. Unlike socket programming, this ensures type safety of the communicated values and also enables event and exception handling. The Java IDL (Interface Definition Language) specifies the way in which Java objects acquire the capability to communicate in a broader environment that includes programs written in other languages.

Java has been designed with networking in mind. From a programmer perspective, Java makes it easy to work with resources across the network, be it a LAN or the Internet. In fact, interaction with different resources such as system accessories, local and remote files hardly changes as far as coding is concerned. From simple file access to socket programming to communicating using different protocols, Java is right there at the top.

Java applets have spawned a new line of thinking in the business world. Everywhere businesses are moving from a client-server paradigm to a Web-centric online world. Users are asking, “Why do I have to pay for something I seldom or never use? Why should I have to perform an upgrade every so often? Give me something basic to work with and I will pay for the extra software fittings when I need them.” This is something that the dynamic nature of Java programs is very comfortable with and adept in handling.

Java Servlets and JSP, at the other end of the pipe as applets, are the hottest technology in town today. Offering the same functionality as CGI with additional advantages such as robustness, security, speed and all the other advantages of Java technology, they are virtually taking over the market for server-side programming.

Security has always been a major concern of software clients. This goes way beyond stopping freak hacker attacks. It involves maintaining confidential information, maybe involving complex encryption. It needs safe, secure electronic communication with authentication, policy-based access control and non-repudiation. These are all areas where Java is good and we are seeing such real systems being built with Java.

Database programming has been made child’s play by Java. Through allowing different mechanisms of access through its various classes with easy-to-use methods, the programmer can concentrate on the high-level functionality instead of the petty details of coding. For hard-core developers, the latest version of JDBC (Java Database Connectivity) offers pooled database connections, scrollable resultsets, batch updates and even storing Java objects in databases.

Multi-threading allows programmers to build applications that more accurately reflect the way the world works. Although users and developers alike have long known the advantages of multi-threaded programs, creation of such programs had long been a big pain with languages providing little or no support. Programmers usually ended up making and using specialised libraries. Sun has incorporated threads into the language, building into them some of the same safeguards as “heavy-weight” threads with little of the overhead.

Java really shines when it comes to programming for other natural languages and cultures. While the initial design of Java had features that supported internationalisation such as support for Unicode, more enhancements to the platform have come to prevent the programmer in falling for the trap of coding to a particular region. These improvements have been made throughout the platform such as database programming.

When it comes to GUI systems, even programs written in languages with a compile-everywhere tag are rewritten at heavy expense for different platforms. With its powerful AWT and Swing classes, Java has eliminated all that drudgery without sacrificing the ability to build sophisticated user interfaces. Swing also allows a developer to either maintain a consistent platform-independent look or acquire the look-and-feel of the underlying operating system.

Swing also provides several accessibility features to visually impaired end-users, such as the ability to work with screen readers, screen magnifiers and speech recognition systems. Through its support for windowing systems, drag-and-drop data transfer capabilities and 2D and 3D graphics, Java programs can be made very user-friendly. After all, users more readily identify themselves with metaphorical symbols and actions than cryptic command-line statements.

For more elegant applications, Sun has included several application services for use by Java Foundation Classes. These include keyboard navigation, multi-threaded event queue, undo capability, bounded range model, custom cursors, graphics debugging, screen repaint batching and event target manager. And that´s not all – Java now offers splendid sound and graphics support for its applications.

One limitation of Java programs is their speed when compared to natively compiled programs. This situation has been improved by Just-in-Time technology that compiles Java byte code on the fly into native code, thus increasing efficiency multi-fold. Direct compilation of programs into executables for different platforms is also possible. Improved performance is also expected through techniques such as memory compression, faster memory allocation and garbage collection, monitor speedups and native library JNI port. JNI (Java Native Interface) allows a Java application to link to platform-specific code written in other languages.

Several metaphors come to the mind like “Java is a vast ocean” or “You have only seen the tip of the Java iceberg”, but I guess you get the idea. Important things like JNDI, JTA, JMA, JavaDoc, Java Help and JAR have hardly found a mention. But that is not even the idea. What is important to know is that if you want to do something, just pull out that Java reference book you will be buying after reading this article. What you want will be there somewhere in it.

The range and power of Java is simply amazing. It provides a complete environment for building software solutions, down to the last wire. For the developer, Java makes it easy to build, maintain and extend. For the software maker, this means faster development, less costs and more profit. For the end user, it means a robust, secure and supported product. In short,

Java is it.

The Oasis

(Written sometime in 1995, this essay appeared in Scintilla, a manuscript magazine by our class, Third year BSc Physics students)

The story of man started unfolding some million years ago when a lazy, nonchalant world unconsciously perceived a new species going about its instinctive business of existence. The rest of the creation must have felt that they were witnessing one of nature’s practical jokes. Indeed, compared to other wild animals, man was
something of a freak. Tail-less, hairless, wingless, fin-less; without any appreciable speed, strength or defence mechanism, the biped was graciously ignored by the ruling classes of the jungle.

It was rather fortunate for man that animals had no astrologers or prophets to predict the unchallenged supremacy in the future of this then seemingly negligible organism. They had no inkling whatsoever of the priceless treasure that man jealously guarded in the top storey of his anatomy. The mass of tiny grey cells, which constituted the brain, was to cement man’s path to becoming the undisputed crown of the blue planet.

No animal possesses the complicated thought processes that man enjoys. It is governed by its blind emotions and impulses and therefore wallows in the peaceful luxury of simplicity. With unhesitating, uncompromising fidelity, it mechanically obeys the plain, matter-of-fact messages put out by its mental production line. Its nervous system is in fact, a total slave to its constitution and environment.

Let us consider a hungry tiger and a human with proportionate appetite. The tiger, coming upon a deer caught in a prickly bush, licks its lips, spits on its paws and gets down to work. When all the tissues of the deer have been respectfully digested, it goes off in search of more prey. The man in a similar situation repeats this operation with the exception that he begins thinking in terms of artificially recreating the circumstances, in which the deer got entrapped, thus avoiding needless wandering for sustenance.

It was this remarkable ability of logical analysis, deduction and application that helped man survive in a harsh world. His superior intellect and reasoning ability worsted the beasts that still believed in the suzerainty of might. In their ignorance, they might not have known it, but the heady days of mastery and domination by mere brute strength were over.

While intelligence was mankind’s greatest asset, one must not forget the importance of the unique physical structure of the Homo sapiens. The significance of his perfectly developed sense organs, faultless photomechanical co-ordination, dextrous hands with opposing thumbs and bipedal locomotion in man’s struggle can never, ever be overstated.

Man was a crack shot at everything he attempted to do. His obstinate nature could never accept defeat or halfway balances. His determination, perseverance and hard work opened the gates to the exploration of greater frontiers. All through the ages, by destroying myths and discovering hitherto unknown truths, by inventing new and better tools and machines, man was slowly, but surely grinding away the mist that enveloped the laws of nature.

This quality of scientific temperament in man has been the driving factor behind the relentless march of civilisation and the rapid development of science and technology. But one may ask, what exactly is meant by scientific temperament or scientific spirit?

This technical term can be interpreted in different ways, but we could call it the consistent, unfaltering search for truth; truth in the complete sense of the word. It means the unravelling of the mysteries of the universe or simply, leaving no question, however frivolous, unanswered. It is the insatiable urge to appreciate and understand the various aspects and facets of nature. It is learning how to live hand-in-hand with the environment.

Somewhere along his tiresome journey through history, however, man has lost the true spirit of science and the results lie before us like an open book.

Although scientific and technical knowledge has produced awesome achievements in the fields of industry, agriculture, medicine, and in raising the standard of living of the average human being, this very knowledge has proven exceptionally successful in bringing man to the brink of extinction. In the meantime, it has been systematically destroying thousands of varieties of flora and fauna.

Seemingly oblivious of the threat to his own existence, man has for the fulfilment of his selfish ends declared war on the biosphere, somewhat like the proverbial lunatic hacking at the branch on which he is sitting. Can we call man’s mental short-sightedness towards the long-term consequences of his actions advancement?

Mankind has achieved astonishing progress in virtually every arena of life, yet the world is plagued with unhappiness, violence, war and ever-increasing human decadence. Billions live in unimaginable squalor and poverty, lacking even the basic necessities of life. So what have we really achieved — progress or retardation?

Apart from creating new problems, how far has science gone to solve the existing ones? One may even question the very validity of science which promises to take humans to the outer reaches of space, yet is incapable of ensuring three square meals a day on the mother planet.

These are admittedly cynical questions, but there is no doubt on their relevance in our critical times. As we prepare to step into the third millennium, the moment has come for direct confrontation and grappling with these irksome and uneasy queries.

It goes without saying that science has been made the scapegoat for all the ills of mankind while the real causes go unnoticed. Science is just a tool like the elaborate contraptions it has invented. A knife, for example, is an indispensable part of any first-aid kit, yet it is a must for every thug on the street. The fault is not in the knife, but in the manner of its handling. Similarly, misuse of scientific developments can bring unthinkable misery and irreversible ruin in their wake.

The real culprit is man himself, and all the dimensions of his character are splendidly reflected in the working of the artificial world that he has managed to create. The mental prowess, about which we had been talking with such great gusto, has been corrupted with man’s unrestrained desire for short-lived glory and comfort at any cost, and thus ironically it has transgressed even the permissible boundaries of stupidity. Let us not elaborate on the ridiculous story of man’s vanities and failures.

Our final destination is the nub of this discussion, namely, where does man go from here? What will he do to save himself from the present day predicament? One can only cross one’s fingers and pray for the best.

But one thing is absolutely certain. If man continues travelling as he is, with his back to the future, he can without any great effort wipe himself out of existence. Let us hope that man wakes up from his complacent slumber and conquer the oasis of real peace and prosperity which has been the ever-elusive mirage for thousands of generations, the ones wilted away in the barren desert of insecurity and destruction. Let us fervently hope that we don’t join their ranks.