8.4 PROGRAMMING VS. SCRIPTING

JavaScript and Java-
JavaScript and java are both Object-Oriented Programming languages, but JavaScript is an object-oriented scripting language. They are completely different programming languages with a small number of similarities. JavaScript is mainly used in Web pages. Almost all Java expression syntax and naming conventions are followed by JavaScript. This is the main reason for calling it JavaScript. Unlike Java, JavaScript does not bother about the methods, variables and classes at all. Java is much more complex than JavaScript. Let us compare Java and JavaScript in detail.

• In Java, the source code is first converted into an intermediate code, known as the byte code. This byte code is non-readable by humans and is independent of any machine. Afterwards, this byte code is interpreted by the interpreter (Java Virtual Machine). Since JavaScript is a scripting language, it is only interpreted. So, making any modification in a Java program are more difficult than making the changes in a JavaScript program.
• Java needs the Java Development Kit. JavaScript mainly requires a text editor.
• Java is a strongly typed language instead JavaScript is a loosely typed language.
• In a Web environment, Java is a back-end language whereas JavaScript is a front-end language.
• JavaScript is considered as a part of HTML file, so it is visible in the source file. Java applets are not a part of HTML file so they are not visible in the source file.
• Java is very complex to learn due to its rules and restrictions whereas JavaScript is very easy to learn, as compared to Java.
• The User Interface of JavaScript is developed in HTML and is very easy to understand, whereas the User Interface of Java is developed in AWT or Swing, which is very complex to understand.
• The client-side is more secured in Java compared to JavaScript.
• In Java and JavaScript, routines are known as the methods and functions respectively.
• Java supports Polymorphism, but JavaScript does not support Polymorphism.
• Java uses the classes and objects to make its code reusable easily, but this service is not available in JavaScript.

JavaScript can be implemented using JavaScript statements that are placed within the <script>... </script> HTML tags in a web page. The <script> tags may be placed anywhere in your web page, but it is a recommended to keep it within <head> tags. The <script> tag alerts the browser program to start interpreting all the text between these tags as a script.
The syntax of our JavaScript should be -
<script> JavaScript code </script>

The script tag contains two attributes:
• Type: This attribute value should be set to “text/JavaScript”.
• Language: This attribute specifies the scripting language we are using. Here it is JavaScript. 
So now our JavaScript syntax is:
<script language= “JavaScript” type= “text/JavaScript”>
  JavaScript code;
</script>
Example:
Let us take a sample example to print “Hello World”. 
we call a function document.write which writes a string into our HTML document.
<html>
<body>
<script language= “JavaScript” type= “text/JavaScript”>
document.write (“Hello World!”);
</script>
</body>
</html>
This code will produce the following result:
Hello World!

Programming Vs. Scripting-
Basically, all scripting languages are programming languages. The theoretical difference between the two is that scripting languages do not require the compilation step and are rather interpreted. For example, normally, a C program needs to be compiled before running whereas normally, a scripting language like JavaScript or PHP need not be compiled.
Generally, compiled programs run faster than interpreted programs because they are first converted native machine code. Also, compilers read and analyze the code only once, and report the errors collectively that the code might have, but the interpreter will read and analyze the code statements each time it meets them and halts at that very instance if there is some error.
Scripting languages are languages that are not compiled, more like interpreted at run-time. It's like a file containing instructions for a computer to follow to carry out a task. Examples of scripting languages are JavaScript, VB script, Perl, python, php, shell script, etc. 
A scripting language generally sits behind some programming language. JavaScript is extremely fast to load since most of the web browser comes with already installed components.

Licensed under the Creative Commons Attribution Share Alike License 4.0

Made with eXeLearning (New Window)