Page 73 - DCAP202_Fundamentals of Web Programming
P. 73

Fundamentals of Web Programming




                    Notes          6.3.1 Java and JavaScript

                                   JavaScript is not the same as Java. Although the names are much alike, JavaScript is primarily a
                                   scripting language for use within HTML pages, while Java is a real programming language that
                                   does quite different things from JavaScript. In addition Java is much  harder to  learn. It  was
                                   developed by Sun for use in pretty much anything that needs some computing power.

                                   JavaScript was developed by Brendan Eich, then working at Netscape, as a client side scripting
                                   language (even though there’s no fundamental reason  why it can’t be  used in a server side
                                   environment).

                                   Originally the language was called Live Script, but when it was about to be released Java had
                                   become immensely popular (and slightly hypey). At the last possible moment Netscape changed
                                   the name of its scripting language to “JavaScript”. This was done purely for marketing reasons.
                                   Worse, Eich was ordered to “make it look like Java”. This has given rise to the idea that JavaScript
                                   is a “dumbed-down” version of Java. Unfortunately there’s not the slightest shred of truth in this
                                   story.




                                     Notes  Java and JavaScript both descend from C and C++, but the languages (or rather,
                                     their ancestors) have  gone in  quite different directions. You can see  them as  distantly
                                     related cousins. Both are object oriented (though this is less important in JavaScript than in
                                     many other languages) and they share some syntax, but the differences are more important
                                     than the similarities.




                                      Task  Analyse various applications of javascript.

                                   6.3.2 What can JavaScript do?

                                      JavaScript gives HTML designers a programming tool: HTML authors are normally not
                                       programmers, but JavaScript is a scripting language with a very simple syntax! Almost
                                       anyone can put small “snippets” of code into their HTML pages.

                                      JavaScript can put dynamic text into an HTML page:  A JavaScript statement like this:
                                       document. write (“<h1>” + name + “</h1>”) can write a variable text into an HTML page.

                                      JavaScript can react to events: A JavaScript can be set to execute when something happens,
                                       like when a page has finished loading or when a user clicks on an HTML element.
                                      JavaScript can read and  write HTML elements: A JavaScript can read and change the
                                       content of an HTML element.
                                      JavaScript can be used to validate data: A JavaScript can be used to validate form data
                                       before it is submitted to a server. This saves the server from extra processing.

                                      JavaScript can be used to detect the visitor’s browser: A JavaScript can be used to detect the
                                       visitor’s browser, and - depending on the browser - load another page specifically designed
                                       for that browser.
                                      JavaScript can be used to create cookies: A JavaScript can be used to store and retrieve
                                       information on the visitor’s computer.







          66                                LOVELY PROFESSIONAL UNIVERSITY
   68   69   70   71   72   73   74   75   76   77   78