• No se han encontrado resultados

JavaScript is a client side, interpreted, object oriented, high level scripting language, while Java is a client side, compiled, object oriented, high level language. Now after that mouthful, here's what it means.

Client side

Programs are passed to the computer that the browser is on, and that computer runs them. The alternative is server side, where the program is run on the server and only the results are passed to the computer that the browser is on. Examples of this would be PHP, Perl, ASP, JSP etc. Currently the most popular client-side scripting language is JavaScript

Interpreted

118

The program is passed as source code with all the programming language visible. It is then converted into machine code as it is being used. Compiled languages are converted into machine code first then passed around, so you never get to see the original programming language. Java is actually dual half compiled, meaning it is half compiled (to 'byte code') before it is passed, then executed in a virtual machine which converts it to fully compiled code just before use, in order to execute it on the computer's processor. Interpreted languages are generally less fussy about syntax and if you have made mistakes in a part they never use, the mistake usually will not cause you any problems.

Scripting

This is a little harder to define. Scripting languages are often used for performing repetitive tasks. Although they may be complete programming languages, they do not usually go into the depths of complex programs, such as thread and memory management. They may use another program to do the work and simply tell it what to do. They often do not create their own user interfaces, and instead will rely on the other programs to create an interface for them. This is quite accurate for JavaScript.

We do not have to tell the browser exactly what to put on the screen for every pixel (though there is a relatively new API known as canvas that makes this possible if needed), we just tell it that we want it to change the document, and it does it. The browser will also take care of the memory management and thread management, leaving JavaScript free to get on with the things it wants to do.

High level

Written in words that are as close to English as possible. The contrast would be with assembly code, where each command can be directly translated into machine code.

What is Object Oriented Programming?

An Object Oriented Programming is a set of tools and methods that enable software

Engineers to build reliable, user friendly, maintainable, well documented, reusable software systems that fulfils the requirements of its users. It is claimed that object-orientation provides software developers with new mind tools to use in solving a wide variety of problems.

Object-orientation provides a new view of computation. A software system is seen as a community of objects that cooperate with each other by passing messages in solving a problem.

Not all programming languages can be ‘‘object oriented’’. Yet claims have been made to the effect that APL, Ada, Clu, C++, LOOPS, and Smalltalk are object oriented programming languages

An object-oriented programming language provides support for the following object oriented concepts:

• Objects and Classes

• Inheritance

119

• Polymorphism and Dynamic binding

What Is an Object?

An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. This lesson explains how state and behavior are represented within an object, introduces the concept of data encapsulation, and explains the benefits of designing your software in this manner.

What Is a Class?

A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how a simple class can cleanly model state and behavior.

What Is an Inheritance?

Inheritance provides a powerful and natural mechanism for organizing and structuring your software. This section explains how classes inherit state and behavior from their super classes, and explains how to derive one class from another using the simple syntax provided by the Java programming language.

What is polymorphism?

In object-oriented programming, polymorphism (from the Greek meaning "having multiple forms") is the characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form. There are several different kinds of polymorphism.

What is Dynamic Binding

The property of object-oriented programming languages where the code executed to perform a given operation is determined at run time from the class of the operand(s). There may be several different classes of objects which can receive a given message. An

expression may denote an object which may have more than one possible class and that class can only be determined at run time. New classes may be created that can receive a particular message, without changing (or recompiling) the code which sends the message. A class may be created that can receive any set of existing messages.

Java and JavaScript

Never confuse JavaScript with Java. Java is an application development language developed by SUN Microsystems and has no links with J avaScript. JavaScript was created long before

120

java was developed. JavaScript is many times denoted as Java Script.

Table 1. JavaScript compared to Java

JavaScript Java

Interpreted (not compiled) by client Compiled byte codes down loaded from server, executed on client

Object-based. No distinction between types of objects. Inheritance is through the prototype mechanism and

properties and methods can be added to any object dynamically.

Object-oriented. Objects are divided into classes and instances with all inheritance through the class hierarchy. Classes and instances cannot have properties or methods added dynamically.

Code integrated with, and embedded in, HTML

Applets distinct from HTML (accessed from HTML pages).

Variable data types not declared (loose typing).

Variable data types must be declared (strong typing).

Dynamic binding. Object references checked at runtime

Static binding. Object references must exist at compile-time

Cannot automatically write to hard disk. Cannot automatically write to hard disk (in Java Applets).

Documento similar