Executing Java Scripts

By: aathishankaran Emailed: 1765 times Printed: 2515 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

JavaScript execution begins after the HTML document loads into the browser, but before the users can interact with the document. The browser reads in all JavaScript statements, as it does HTML statements, and then begins interpreting the JavaScript code. 

If your JavaScript scripts are stored in a separate file, they are also evaluated when the page loads and before any script actions take place.

 All JavaScript statements that are contained within a function block are interpreted, and execution does not occur until the function is called from a JavaScript event. JavaScript statements that are not within a function block are executed after the document loads into the browser. The execution results of the latter will be apparent to the users when they first view the page. The second process which JavaScript executes statements is though function calls. Any statement contained within a function will not be executed until a JavaScript event calls the function. . 

Writing the Script

As in any other programming language, JavaScript statements can be implemented using various methodologies. A function has to be defined in the <HEAD>section and then calling these functions within the HTML body is the best w to take advantage of the object-based JavaScript language. Java script is simple to understand. Although HTML statements are not case-sensitive, JavaScript statements are.

 When beginning to write your code, keep the following items in mind:

v     Code reuse

v     Readability

v     Ease of modification

You can use JavaScript tags in either the body or the head of a document. Placing the <SCRIPT>in the head rather than the body ensures that all statements will be evaluated (and executed, if necessary) before the user interacts with the document. The hazards of putting script statements in the body of the document are varied. Depending on the specific tags and the order of the document, you can never be positive that the user will not interact with the script in the wrong manner or react to the page before the script has fully loaded or executed. If any of these occur, the effect that you want for your page might not be seen. (After all your effort, who wants that?) The practice of defining your JavaScript functions and then calling them from the body will ensure that all the functions are evaluated before the user can begin interaction with the page. 

Running the Script 

As you probably realized, JavaScript scripts are as simple to load as HTML documents. You do not have to explicitly execute any code to run your scripts, because you place your code in the HTML document or call it explicitly in the first script line, your script will run when the page loads. Remember that not all the code will necessarily execute immediately upon loading. Code that is enclosed in a function call is only evaluated when the page loads but does not execute until the function is explicitly called from a JavaScript event. Code that is not enclosed in a function call runs after the page finishes loading but before the user has a chance to interact with the page.


Java Home | All Java Tutorials | Latest Java Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by aathishankaran
Web Security Issues
The Web User's Perspective
Server-side plug-Ins
The best way to avoid security vulnerabilities with new server
JavaScript Security
Window Object
Working with Status Bar Messages
Retrieving a Portion of a String
Referencing Windows
Math Object
Frame Object
Document Object
Closing Windows
Built-in Object in Javascript
Textarea Object

More Tutorials in Java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Java File
Java String
Count number of vowels, consonants and digits in a String in Java
Reverse a number in Java
Student marks calculation program in Java
Handling Fractions in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Multiple Inheritance sample in Java
Java program using Method Overriding
Java program to check if user input is an even number

More Latest News
Most Viewed Articles (in Java )
A Serialization Example in Java
Type Casting in Java
instanceof sample program in Java
Using One-Dimensional Arrays in Java
FilenameFilter - sample program in Java
Method Overriding in Java
indexOf( ) and lastIndexOf( ) in Java
The java Buzzwords
Write to a file in Java - Sample Program
What is Java?
FileReader and FileWriter example program in Java
How to use ArrayList in Java
Extract characters in Java
XML and Java - Parsing XML using Java Tutorial
Character Arrays
Most Emailed Articles (in Java)
Converting a number into its equalant value in words in Java
java.lang.reflect package
Disadvantages of using Native methods in Java
What is UCS? What is ISO 10646?
Generating Your Key Pair example using keytool in Java
Operator Precedence in Java
PushbackReader sample program in Java
concat(), replace(), and trim() Strings in Java
instanceof sample program in Java
Use of - new - in Java
The Benefits of OOP
Increment and Decrement Operator
Characters in java
The continuing Revolution of java
Why java is important to the Internet