JavaScript (1)

Source: Internet
Author: User
The Internet era has created a new way of work and life. Its interconnectivity, openness, and information sharing model breaks the barriers of traditional information dissemination methods, it brings us new opportunities. With the advent of the computer and information age, the progress of human society is accelerating. Every day, new things happen, and every day is a miracle. With the rapid development of Internet technology, all walks of life are joining the Internet industry. In terms of management and business, Internet can bring infinite vitality. Through the Internet, you can achieve regional, collective, and even individual connections to achieve a "unified harmony ". So how to add your or your company's information resources to the WWW Server is a matter of increasing concern to users. Hyper-chain technology (Hypertext and hyper-media technology) is the simplest and fastest way to achieve this goal. The supporting environment for specific implementation of this method is the HTML hypertext mark language. You can use them to create the required web pages.
By combining Hyper Text and Hyper Media Technology with the link function of hyper link, various information groups are woven into a network structure (Web) to form a network document ), implement "Roaming" on the Internet ". You can retrieve multimedia information such as text, tables, sounds, images, and animations through the description of HTML symbols.
However, this hyperchain technology has some drawbacks, that is, it can only provide a static information resource and lacks dynamic client-to-server interaction. Although CGI (Common Gateway Interface) Universal gateway interface can be used to achieve certain interactions, the programming of this method is complicated, so the development of Internet technology is blocked for a period of time. The emergence of JavaScript has brought a glimmer of life to Internet users. It can be said that the emergence of JavaScript is the demand of the times, and JavaScript is created in today's information age.
The emergence of JavaScript enables the relationship between information and users not only to display and browse, but to implement a real-time, dynamic, and interchangeable expression. In this way, CGI-Based Static HTML pages are replaced by web pages that provide dynamic real-time information and respond to customer operations. JavaScript scripts are the languages that meet this requirement. It is very popular among many users. It is an excellent one among many scripting languages, and its combination with WWW effectively realizes the blueprint of network computing and network computer. The Java family will dominate the internet. Therefore, it is of increasing interest to grasp the Javascript scripting language programming methods as soon as possible.

1. What is JavaScript?
Javascript is a scripting language based on object and event-driven with secure performance. It is used with HTML hypertext markup language, Java scripting language (Java smallProgram) Link multiple objects in a web page to interact with Web customers. This allows you to develop client applications. It is implemented through embedding or calling in a standard HTML language. Its appearance makes up for the defects of the HTML language. It is a compromise between Java and HTML and has the following basic features:

Scripting Language
Javascript is a scripting language that uses small program segments for programming. Like other scripting languages, JavaScript is also an explanatory language that provides an easy development process.
Its basic structure is similar to C, C ++, VB, and Delphi. But unlike these languages, it needs to be compiled first, but is interpreted row by row during the program running. It is combined with HTML tags to facilitate user operations.

Object-based language
Javascript is an object-based language and can be viewed as an object-oriented language. This means that it can use the created objects. Therefore, many functions can come from the interaction between methods of objects and scripts in the script environment.

Simplicity
The simplicity of JavaScript is mainly reflected in: first, it is a simple and compact design based on the Basic Java statements and control flow, which is a very good transition for learning Java. Second, its variable type is weak, and strict data types are not used.

Security
Javascript is a security language. It does not allow access to a local hard disk, nor store data on the server. It does not allow modification or deletion of network documents, information Browsing or dynamic interaction can only be achieved through a browser. This effectively prevents data loss.

Dynamic
Javascript is dynamic and can respond directly to user or customer input without passing through web service programs. Its response to users is event-driven. An event-driven action is an action generated by an operation on the home page. It is called an event ). For example, pressing the mouse, moving the window, and selecting a menu can all be regarded as events. When an event occurs, it may cause the corresponding event response.

Cross-platform
Javascript depends on the browser itself and has nothing to do with the operating environment. It can be correctly executed by browsers that can run the computer of the browser and support JavaScript. Thus realizing the dream of "writing once and going all over the world.

In fact, the most outstanding thing about Javascript is that it can do a lot of things with a very small program. There is no need for a high-performance computer. The software only needs a word processing software and a browser. Without a web server channel, you can do everything through your computer.
In summary, JavaScript is a new description language that can be merged into HTML files. The javascript language can respond to user requirement events (such as form input), instead of transmitting data back and forth over the network. Therefore, when a user inputs a data item, it can be directly processed by client applications without being transferred to the server for processing.
JavaScript and Java are very similar, but they are not the same! Java is a program language that is much more complex than JavaScript, while Javascript is quite easy to understand. Javascript creators can focus less on program skills, so many Java features are not supported in Java Script.

Ii. Differences between JavaScript and Java
Although Javascript is closely related to Java, it is two different products developed by two companies. Java is a new-generation object-oriented programming language released by sun, which is especially suitable for Internet application development. Javascript is a product of Netscape, and its purpose is to expand the Netscape Navigator function, developed an object-and event-driven explanatory language that can be embedded into web pages, its predecessor is live script, and Java's predecessor is the oak language. The similarities and differences between the two languages are compared as follows:

Object-based and object-oriented
Java is a real object-oriented language. Even a simple program must be designed.
Javascript is a scripting language that can be used to create complex software that is unrelated to the network and interacts with users. It is based on object and event driver.Programming Language. Therefore, it provides a wide range of internal objects for designers.

Interpretation and compilation
The two languages are executed in different ways in their browsers. JavaSource codeBefore being passed to the client for execution, it must be compiled. Therefore, the client must have a simulator or interpreter on the corresponding platform. It can be compiled independently of a specific platform through the compiler or interpreter.Code.
Javascript is an interpreted programming language. Its source code does not need to be compiled before it is sent to the client for execution. Instead, it sends the character code in the text format to the client for interpretation and execution by the browser.

Strong variables and weak Variables
The variables used by the two languages are different.
Java uses a strongly typed variable check, that is, all variables must be declared before compilation. For example:
Integer X;
String y;
X = 1234;
X = 4321;
X = 1234 indicates an integer, and y = 4321 indicates a string.
The variable declaration in Javascript uses its weak type. That is, variables do not need to be declared before use, but the interpreter checks their data types at runtime, such:
X = 1234;
Y = "4321 ";
The former indicates that X is its numeric variable, while the latter indicates that Y is a numeric variable.

Different Code formats
Java is an HTML-independent format. It must be loaded by referencing external media in HTML, and its code is saved as byte code in an independent document.
JavaScript code is a text character format that can be directly embedded into HTML documents and loaded dynamically. Compiling HTML documents is as convenient as editing text files.

Different embedding Methods
In HTML documents, the two programming languages have different identities. Javascript uses <SCRIPT>... </SCRIPT>, while Java uses <APPLET>... </APPLET>.

Static Association and Dynamic Association
Java uses static concatenation, that is, Java object reference must be carried out during compilation, so that the compiler can implement forced type check.
Javascript uses dynamic concatenation, that is, JavaScript Object Reference is checked at runtime. If it is not compiled, the object reference check cannot be implemented.

Iii. Javascript running environment
Java Runtime Environment
Software environment:
Windows 95/98 or Windows NT.
Netscape Navigator x.0 or Internet Explorer x.0.
The character editor used to edit HTML documents (WS, WPS, notepad, WordPad, etc.) or HTML document editor.
Hardware configuration:
First, you must have the basic hardware configuration environment for running Windows 95/98 or Windows NT. Recommended:
The basic memory is 32 MB.
The CRT only needs 256 less color, and the resolution is above 640x133.
The CPU usage is less than 233.
Mouse and other external settings (as needed ).

4. Compile the first JavaScript Program
The following is an example to compile the first JavaScript program. It shows how JavaScript scripts are embedded in HTML documents.
Test1.html document:

<HTML>
<Head>
<Script language = "JavaScript">
// JavaScript appears here.
Alert ("This is the first JavaScript example! ");
Alert ("welcome to the Javascript world! ");
Alert ("we will learn JavaScript knowledge together in the future! ");
</SCRIPT>
</Head>
</Html>

The result of running e5.0 on the internet is shown in Figure 1-1.

Figure 1-1 running result

Note: test.html is an HTML document whose identification format is standard HTML;
Like the HTML identification language, JavaScript code is a text that can be viewed by word processing software. It appears in the HTML-related area of the description page.
JavaScript code is described by <script language = "JavaScript">... </SCRIPT>. JavaScript scripts can be added between the identifiers <script language = "JavaScript">... </SCRIPT>.
Alert () is a javascript window object method. Its function is to pop up a string with an OK dialog box and display.
Pass <! --... // --> MARK Description: if you do not know the JavaScript code browser, all the marks in it will be ignored. If you know it, the result will be executed. Using annotations is a good programming habit, which allows others to understand your language.
Javascript ends with the </SCRIPT> label.

from the instance analysis above, we can see that writing a javascript program is indeed very easy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.