Introducing the .NET Framework and JScript .NET

The .NET Framework is a unified, object-oriented set of services, libraries, and programming languages, which developers can take advantage of to build robust, networked applications and services. The .NET Framework architecture, shown in Figure 1, is made up of four main components:

  • Common Language Runtime - includes the Common Type System
  • .NET Class Library
  • Unifying components (ASP.NET and Windows Forms)
  • Visual Studio .NET

Basics of the Common Language Runtime

The one sentence definition of the Common Language Runtime is: the Common Language Runtime provides managed execution services to applications that target the .NET Framework. The definition introduces two new concepts: "managed execution services" and "applications that target the .NET Framework".

Figure 1 - Architecture of the .NET Platform

If you write script code within an HTML page you're already familiar with working in an environment that provides "execution services" - for example, consider the code in Listing 1.

Listing 1 - A simple HTML Page with Script

<html>
<head>
<title>JScript .NET Series: Article 1, Listing 1</title>
<script language=javascript>
function person(theName,theAddress)
{
  this.name = theName;
  this.email = theAddress;
}

function createPerson ()
{
  return new person("Essam Ahmed","essam@designs2solutions.com");
}

function demo()
{
  var essamAhmed;
  srcObject.innerText=person;
  srcPerson.innerText=createPerson;
  essamAhmed=createPerson();
  theResult.value=essamAhmed.name + " " + essamAhmed.email;
}
</script>
</head>  
<body onload="demo()">

  <!-- code removed for brevity -->

</body>
</html>

The listing is a simple HTML page that contains some JavaScript code. The person function isnt a true function in the sense that it doesnt do anything useful - it takes two parameters and copies them to itself using the this object. When the code in the createPerson function executes, Internet Explorer creates an instance of a person object and dynamically adds two new attributes to it (name and email). The code in the demo function uses the name and email attributes of the new person object to populate the input box that's on the page - the result of opening the page is shown in Figure 2.

Figure 2 - Using IE to open the demo page

As you review the sample code, you'll notice that the code isn't at all concerned about tasks like managing memory or handling data type conversions. The scripting engine, the entity that's part of Internet Explorer and executes the code in the sample, handles the details of managing memory and ensuring that the data the code uses is of the correct type. The result of the scripting engine's work is that it simplifies the code developers need to write to get their applications working. Another aspect of the code in Listing 1 is that it clearly assumes that a particular type of application or system will consume or execute it - Internet Explorer is the consumer of the code in this example.

The .NET Common Language Runtime is similar to the scripting engine in Internet Explorer, except that it works for all programming languages that target the .NET Platform (there are about 25 programming languages that are either currently available or under development that target the .NET Platform). Like the scripting engine in Internet Explorer, the Common Language Runtime provides memory and thread management services to applications, but goes beyond that to provide additional benefits like configuration management, error handling, component lifetime management, and security services. As a result of the Common Language Runtime, applications are easier to write, manage, and deploy.

Introduction to the Common Type System

A component of the Common Language Runtime is the Common Type System (CTS). The CTS is a common set of data types that are available to all .NET-programming languages, enabling applications to easily interoperate and exchange data regardless of what programming language they're implemented in. For example, a JScript .NET program can easily use and pass data to another application written in Visual Basic .NET, Visual C# .NET, or any other .NET-programming language. In fact, .NET programming languages transparently map their internal data types, such as JScript's Number type, to their equivalent CTS types without any involvement from the developer—making cross-language interoperability a breeze! Examples of CTS data types include String, Int32, and UInt64.

Basics of the .NET Class Library

The .NET Class Library is a collection of hundreds of classes and objects that can be used from any .NET programming language. The .NET Class Library models the services that the .NET Framework and underlying operating system provide, establishing an easy to understand and consistent approach to taking advantage of system services regardless of what programming language you use. Some examples of the tasks you can perform using the .NET Class Library include: creating applications with a graphical interface, processing files, working with XML, debugging, working with security sub-systems, and more.

The .NET Class Library is divided into namespaces, as shown in Figure 3, making it easier to work with (a namespace is a logical grouping of related classes). For example, ADO.NET classes and objects - the updated version of ADO (ActiveX Data Objects) - resides in the System.Data namespace.

Figure 3 - Organization of the .NET Class Library

Unifying Components

The unifying components of the .NET Framework bring the other key elements of the .NET Framework together based on two distinct applications models:

  • ASP.NET
  • Windows Forms.

ASP.NET provides a Web-based application model in the form of components and controls that make it easy to build Web applications and Web Services. ASP.NET exposes a common set of controls to developers including buttons, text boxes, and other controls. Unlike their equivalent simple HTML controls, which developers must manage on their own using ASP or client-side code, ASP.NET controls manage their state and have advanced rendering capabilities. ASP.NET controls reside on the server and enable developers to work with them without regard to where the controls get rendered (delivered) - making developing Web-based applications much easier. ASP.NET controls render themselves based on the capabilities of the browser that's accessing an ASP.NET page. For example, text field along with a button and some code to ensure that the text field is filled in can be rendered as plain HTML or Dynamic HTML (DHTML - HTML combined with client scripts) depending on the capabilities of the client's browser thereby eliminating a whole class of problems associated with browser incompatibilities.

Windows Forms provide a rich user experience by exposing a common set of controls to all .NET programming languages making it easy to build "traditional" windows applications (applications that, in large part, execute on a user's system and have a graphical interface). For example, JavaScript and JScript developers traditionally rely on browsers like Internet Explorer to provide user interface capabilities for their applications. The Windows Scripting Host provides a simple command-line based interface and some message boxes, and is far from providing complete graphical application support. Through Windows Forms, JavaScript and JScript developers can easily create a Windows application - complete with menus and other common controls.

Visual Studio .NET

Visual Studio .NET fulfills the promise of a unified development environment for .NET programming languages. Visual Studio .NET combines the best of Visual Basic, Visual C++, and Visual InterDev development environments and adds some great new features. Tools like the Visual Basic forms editor, Visual Modeler, an XML editor, a To Do list, and a new dynamic help system are available for all supported languages (like Visual C# .NET, Visual Basic .NET, and Visual C++ .NET).

Introducing JScript .NET

JScript .NET is the single most significant upgrade to JScript since it was first introduced in 1996 in Internet Explorer 3.0. JScript .NET is a flexible, powerful programming that you can use to create everything from simple scripts to full-blown Windows or Web-based applications. JScript .NET preserves your investment in JScript by maintaining 100% backwards compatibility with existing JScript code.

JScript .NET is fully object-oriented programming language, offering support for classes, inheritance, polymorphism, function overloading, and many other modern features. JScript .NET maintains its easy to use nature by allowing you to take advantage of new language features as you become familiar with them. For example, even though JScript .NET supports typed variables, you're still free to not even declare variables before using them. JScript .NET is the only other standardized language currently available on the .NET Platform (C++ is the other standardized language) - standardization is your assurance of on-going multi-vendor support for JScript .NET.

The following listing demonstrates some of JScript .NET's new features:

// create a new package (namespace)
package jsnetSample {

  // declare a new class
  class jsnetClass 
  {
    // static member variable - a variable that can exist without a class
    public static var staticString : String;

    // Note the staticString declaration above - it is a String variable 
  
    // Sample member function - takes a string argument and return an int
    // The declaration of the function's parameter type is similar to
    // declaring a variable...
    public function methodOne(param1 : String) : int {
    
      // declare a variable and initialize it
      var i : int = 5;
      // call a .NET Class Library method to send output to the console
      Console.WriteLine("Hello {0}\n",param1);
      return i;
    }

    // overload methodOne for to take int parameter and 
    // return a String (reverse of original method)...
    public function methodA(param1 : int) : String {
      //...
      return "this is a string"; 
    }

    // delcare a private member function
    // Private member functions are accessible only by the
    // class that declares the function...
    private function privateMethod() {
      //...
    }
    // Static initializer - initialies static variables even
    // without an instance of the class avaialble at runtime...
    static {
      sampleString = "This is a static initializer"; 
    }
  } // end of the class
} // end of the package

The listing demonstrates the following features:

  • The package statement to create a new namespace
  • The class statement
  • Typed and static variables
  • Member functions
  • Function overloading
  • Working with the .NET Class Library

Summary

This article introduced you to the .NET Platform, which is made up of four key components including the Common Language Runtime, ASP.NET and Visual Studio .NET. This article also introduced you to JScript .NET and demonstrated some of its new features using some sample code. The next installment of this series discusses all of JScript .NET's new features.


About the Author

Essam Ahmed is a senior developer with a large multinational corporation where he specializes in developing server-centric Web applications. He has contributed to articles, sample appliations, and book reviews here on CodeGuru.com as well as on Developer.com. Not only is he a frequent speaker at developer conferences, he is also the author of JScript .NET Programming.

# # #



Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds