11.07.2015 Views

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

256 JavaScriptIn 2006 Sun Microsystems announced that it wouldmake Java’s source code freely available (see open source).In part this may be an attempt to maintain Java’s positionamong programmers, some <strong>of</strong> whom have shifted theirattention from Java to Micros<strong>of</strong>t’s own <strong>of</strong>fshoot <strong>of</strong> C++ (seec#). However, Java’s greatest challenge seems to be in theWeb programming area, where it faces increasing competitionfrom more agile languages (see, for example, Ruby) aswell as a variety <strong>of</strong> scripting languages that may be easier tolearn <strong>and</strong> quicker to use for many applications.Further ReadingArnold, Ken, James Golsing, <strong>and</strong> David Holmes. The Java ProgrammingLanguage. 4th ed. Upper Saddle River, N.J.: PrenticeHall, 2005.Burd, Barry. Beginning Programming with Java for Dummies. 2nd ed.Hoboken, NJ: Wiley, 2005.Gosling, James. “Is Java Getting Better with Age?” [interview].Cnet News. Available online. URL: http://news.com.com/2008-7345_3-6022062.html. Accessed April 10, 2007.Krill, Paul. “Java Facing Pressure from Dynamic Languages.” Info-World, March 25, 2006. Available online. URL: http://www.infoworld.com/article/06/03/25/76803_HNjavapressure_1.html. Accessed April 10, 2007.McGovern, James, et al. Java Web Services Architecture. San Francisco:Morgan Kaufmann, 2003.Schildt, Herbert. Swing: A Beginner’s Guide. New York: McGraw-Hill, 2007.JavaScriptJavaScript is one <strong>of</strong> several popular languages that canenable Web pages to interact with users more quickly <strong>and</strong>efficiently (see vbscript, php, <strong>and</strong> scripting languages).The language first appeared in the mid-1990s’ Netscape 2browser under the name LiveScript. Technically, JavaScriptis the Sun Microsystems trademark for its implementation<strong>of</strong> a st<strong>and</strong>ard called ECMAScript. Despite the name, Java-Script is not directly related to the Java programming language.In its early years JavaScript was perhaps a victim <strong>of</strong> itsown success. Having a relatively easy-to-use scripting languageprovided an easier way to add features such as 3Dbuttons <strong>and</strong> pop-up windows to formerly humdrum Webforms. However, as with an earlier generation’s fondnessfor multiple fonts, early JavaScript programmers were <strong>of</strong>tenprone to add unnecessary <strong>and</strong> confusing clutter to Webpages. Besides sometimes annoying users, early JavaScriptalso suffered from significant differences in how it wasimplemented by the major browsers. As a result, Netscapeusers were sometimes stymied by JavaScript written forMicros<strong>of</strong>t Internet Explorer, <strong>and</strong> vice versa. Finally, browserflaws have sometimes allowed JavaScript to be used to compromisesecurity such as by installing malware-infested“browser helpers.” As a result, many security experts beganto recommend that users disable JavaScript execution intheir browsers.Using JavaScriptJavaScript syntax <strong>and</strong> language constructs are similar tothose <strong>of</strong> C, with the addition <strong>of</strong> basic object-oriented features(see object-oriented programming). The languageitself has no capabilities for manipulating the environment(such as input/output). Instead, JavaScript calls upon an“engine” written for each host environment (normally aWeb browser). The engine implements features designed tocontrol how a Web page interacts with the user, such as thedisplay <strong>of</strong> windows <strong>and</strong> controls such as menus, buttons, ortoolbars. JavaScript can also be used to validate a Web formin the browser before it is submitted to the server. In general,“browser side” JavaScript processing reduces the loadon Web servers while allowing pages to respond quickly,such as by changing graphics as the user’s mouse pointerpasses over parts <strong>of</strong> the page.The principal interface between JavaScript <strong>and</strong> HTMLpages is the Document Object Model (see html <strong>and</strong> documentobject model). A World Wide Web Consortium (W3C)st<strong>and</strong>ard defines the DOM functions, <strong>and</strong> most browsers nowconsistently support Levels 1 <strong>and</strong> 2 <strong>of</strong> these st<strong>and</strong>ards. However,there are many Web users who cannot run st<strong>and</strong>ardJavaScript, such as users with visual disabilities (see disabledpersons <strong>and</strong> computing), users <strong>of</strong> some mobile browsers(such as for PDAs or smart phones), or users who have simplydisabled JavaScript for security reasons. Therefore, whenJavaScript is used for essential page functions (such as formprocessing), the developer should provide an alternative wayfor the user to perform the relevant task. (In the case <strong>of</strong> disabledusers, this may be a legal requirement.)Traditionally, JavaScript code has been embeddeddirectly in the containing HTML page, using tags like thefollowing:JavaScript Examplevar Name = prompt (“Enter yourname”,“”);alert(Name);When a JavaScript-enabled browser encounters thiscode, a text box will prompt the user for a name, which isstored in the variable Name <strong>and</strong> then displayed in an alertbox.In modern Web design to XHTML st<strong>and</strong>ards, however,just as formatting information is kept in a separate document(see cascading style sheets) JavaScript code is alsomaintained in a separate file <strong>and</strong> simply linked to withinthe HTML page:JavaScript can do much more than just display informationor process forms. JavaScript can access a variety

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!