September 23, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Comparing Object-Oriented Languages

  • December 6, 2007
  • By Matt Weisfeld
  • Send Email »
  • More Articles »
.NET

Microsoft initially responded to the popularity of Java by producing a version of Java called Visual J++. However, Microsoft decided on a more comprehensive response. Using many of the groundbreaking concepts that Java implemented, Microsoft developed a language called C# that became the foundation for the company's .NET platform. As with Java, C# relied heavily on the success and failures of earlier languages.

The .NET development environment includes many of the really good characteristics of several other platforms. .NET incorporates many of concepts introduced by the initial Java release. The .NET platform also builds upon many of the powerful features of the VB6 and Visual C++ environments.

Visual Basic 6 was one of the most popular programming languages. The programming environment for VB6 has had a huge impact on state-of-the-art development environments. VB6 has evolved steadily towards the object-oriented model until it finally joined the list of object-oriented languages with the release of Visual Basic .NET. VB6 was not totally object-oriented; it did not implement inheritance completely.

Comparing the Code

For the remainder of the article, I will (mostly) let the code speak for itself. In future articles, you will explore specific programming structures of various programming languages; however; in the context of this article, my intent is for you to take the following examples and develop a baseline for each of the three languages: Java, C#, and VB .NET.

The three example applications are named as follows:

  • IntSquare: A single class to calculate the square of a number.
  • Person: A single class to set and get the name and address of a person.
  • Shape: A hierarchy of classes that calculates the area of various shapes.

These examples are the first step in creating projects in the various programming languages presented.

At this point, you can inspect the code just to get a feel for the syntax of the various languages. This has been very helpful in my programming classes. Often, classes will focus on a single instructional language to keep the development tool overhead, not to mention the language learning curve, to a minimum. Although you may focus on a single language to reinforce the object-oriented constructs, it really helps to see examples in other languages to augment and reinforce the primary language used in the class.

After you have inspected the code, the next step is to load the various development platforms so that you can compile and execute the code. The development platforms are a topic that you will explore at length in the next article.

For each of these examples, I provide brief comments as to the instructional highlights of the code. In each case, the examples are identical—at least in functionality. The point is to solve the same problem with each of the languages.

The three distinct examples are presented in three sections, IntSquare (Listing 1), Person (Listing 2), and Shape (Listing 3). Within each section, I break the code into three sub-listings, for Java (Listing a), C# .NET (Listing b), and Visual Basic .NET (Listing c).

IntSquare

In the IntSquare example, the focus, as the initial example, is on the syntax required to compile and execute a simple program in the three languages. The point here is simple enough; create a method to calculate the square of a number.

The class has a single attribute and two methods (a public interface and private implementation).

public class IntSquare {

   // private attribute
   private int squareValue;

   // public interface
   public int getSquare (int value) {

      squareValue =calculateSquare(value);

      return squareValue;

   }

   // private implementation
   private int calculateSquare (int value) {
      return value*value;

   }
}

Listing 1a: Java Code for IntSquare Class

public class IntSquare {

   // private attribute
   private int squareValue;

   // public interface
   public int getSquare (int value) {

      squareValue =calculateSquare(value);

      return squareValue;

   }

   // private implementation
   private int calculateSquare (int value) {

      return value*value;

   }
}

Listing 1b: C# Code for IntSquare Class





Page 2 of 5



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel