By: Laurie Weaver
Member Columnist
Have you been trying to work with Information Technology, but your initiatives and patience grind to a screeching halt? Do the terms they use sound like so much gobbledygook? Do you ever get the sneaking feeling that IT professionals just may, in fact, have come from Mars? If so, you've probably run headlong into some common "GeekSpeak" roadblocks. The aim of this ongoing column is to help forms professionals and technology professionals overcome roadblocks by gaining mutual understanding, vocabulary, and context. So if you need help with specifics, or if you'd just like to know more about a techie topic, email or post any and all questions to Ask Ms. GeekSpeak. This month's topic: Java vs. JavaScript.
Dear Ms. GeekSpeak, Are Java and JavaScript the same thing?
Glad you asked that! Even though their names sound similar and they share some similar qualities, Java and JavaScript are actually different programming languages.
To better understand the key differences, you’ll need to understand these four GeekSpeak terms: call, client, compiled, and interpreted. Read the following sentence, then we’ll go back to define the terms.
Java is a programming language that needs to be compiled prior to being called by the client, and JavaScript is a coding language that is interpreted by the client.
Call:
Programmers use the term call to mean signaling a program or part of a program to start. For example, the action of clicking on a “submit” button on a website may call the associated “submit data” program on the server.
Client:
When programmers say client in this context, we are referring to the browser software that’s used to display web content. The browser is the client of our code.
Compiled:
Compiled code is first written as text by the programmer. At this point, it is “human readable.” But before the code is usable as a software application, it must be run through an additional piece of software that translates the “human readable” code into “machine readable,” (i.e., code the computer can understand). This translation process is called compiling.
Compiled Java code is known as an applet. Applets reside on servers and do their work there. Information may be sent to them from the web page, and they may return information as part of the code that displays on the web page, but they are independent programs. Our aforementioned “submit data” program could be an applet.
Interpreted:
Interpreted code isn’t compiled into “machine readable” code. It doesn’t have to reside outside of the HTML of the web page. The programmer can write HTML and JavaScript into the same text file. The browser software “interprets” the JavaScript commands and performs the required actions.
Here’s an example using HTML, JavaScript, and Java. HTML means HyperText Markup Language and is the code used to display content in web pages.
First, we’ll look at the example from the coder/programmer perspective, then from the user’s perspective.
Coder/Programmer
1) We code a simple form with fields and a button to add users’ first and last names to a database. The entry fields and submit button are coded in HTML.
<FORM action="MySubmitApplet" method="Post">
<P>
<LABEL for="firstname">First name: </LABEL>
<INPUT type="text" id="firstname"><BR>
<LABEL for="lastname">Last name: </LABEL>
<INPUT type="text" id="lastname"><BR>
<INPUT type="submit" value="Submit name">
</P>
</FORM>
2) We have previously written and compiled a Java applet called MySubmitApplet that resides on our server. Its function is to add the submitted user name to our database and return the entire name as a value called “userName” to the response webpage.
3) We also have an HTML coded response page. In this page we have added a snippet of JavaScript that will dynamically display the user’s name. This page is displayed after the server’s submit routine has run.
script type="text/javascript">
name=userName
document.write('Thank you '+name+ ' !');
</script>
User
I’ll take on the role of user now to continue our example from that perspective.
1) I navigate online to our HTML page.
2) I see by the field labels to enter my first and last name into separate fields. I do so and click “Submit name.”
3) The text value “Laurie” is sent to the applet on the server as the value of firstname. The text value “Weaver” is sent to the applet on the server as the value of lastname. Our hypothetical MySubmitApplet applet does its job and puts my first and last names into their corresponding tables of the database. Then the applet calls the response HTML page and returns to that page the value of firstname and lastname in a variable placeholder called userName.
4) I, the user, see “Thank you Laurie Weaver!”
OOPs, am I losing your attention?
Sorry, that’s my little joke, because both Java and JavaScript are Object Oriented Programming languages. But that is a topic for another day. If you’d like to know more about Java, JavaScript, HTML, OOPs, or any other “geeky” word or topic, post here, or email Ask Ms. GeekSpeak.


Posted by: |