advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Articles : JavaBoutique's Introduction to Java : Q and A :

Java versus JavaScript

Q

Can you compare/contrast java vs javascript?
I don't know which to tackle first.
I'd like to use it for both web-based and non web stuff.

A

Java is essentially a plug-in that was integrated into the browsers almost as soon as it was released. Java is a programming language that can be used by anyone to code add-on features which can be executed within the browser.

Browsers include Java Virtual Machines to interpret the Java code downloaded from web servers. In fact, the browser became a sort of worldwide desktop upon which application developers could distribute their own full-featured applications with high performance scalable widgets such as trees, grids, tables, image buttons, etc...

Java was originally developed at Sun Microsystems in 1991 to provide a platform-independent programming language and operating system for consumer electronics (TV sets, toasters and VCRs).

In syntax and execution, Java is a lot like a simplified version of C++. ("simplified" should be read in the previous sentence as "an improved"). It is a highly robust, distributed, high performance, object-oriented, multi-threaded language with all of the usual features. As such, it builds upon years of C++ development, taking the good and dispensing with the bad.

As it so happened however, Java did not make it into the consumer electronics market. Instead it wound up in our web browsers.

Java seemed to be a perfect fit for the web. The language itself was extremely small (as it was built to go inside toasters and alarm clocks with tiny amounts of memory). Thus it could quickly be transferred over the web.

Further, Java was platform independent. That is, any computer with a Java Virtual Machine can run a Java program. Programs can be written anywhere and be run anywhere. This is crucial because if a language can not run on any machine, it cannot be used on the web that must service every machine, language, and environment imaginable.

Platform independence works because Java is an interpreted rather than a compiled language. Unlike C or C++ code, when Java is compiled, it is not compiled into platform specific machine code, but into platform-independent byte code. This byte code is distributed over the web and interpreted by a virtual machine (typically built right into a web browser these days) on whichever platform it is being run.

Thus, as a programmer, you need only concern yourself with the generic Java programming language and compile your applications into bytecode on whatever system you are using. You can then be assured that your bytecode will be executed correctly whether your clients are using Macs, Pcs, Unix boxes or anything else.

What's more, Java is a full-featured programming language complete with a complete collection of user interface widgets in its AWT library, networking capabilities, database connectivity, internationalization features, and much, much more.

Though Java was sadly reduced to tickers and bouncing balls for the first few years of its life, now many high quality production applications have been completed and are running happily with java served through web pages.

NOTE: To a certain degree, I also like to think of client-side Active-X components as plug-ins. Active-X technology allows web browsers on Microsoft systems to leverage the vast resource of Windows. Like Java applets, Active-X components can be instantiated within the context of the web browser itself making it appear that the web browser is providing the functionality when in fact the Active-X component is simply piggy-backing off the browser.

Since any COM object in Windows can be an Active-X control, almost every Windows resource can thus be embedded in the browser window. Controls can be as simple as a custom stock ticker or as complex as an application like Microsoft Excel.

Of course, beware that Active-X is a Microsoft-specific technology so it may not ever work on Netscape or on Macintosh.

Exposing the Browser API with Client-side Scripting...

As you might imagine, adding all these add-on features to the web browsers began to cause problems. Specifically, distributing functionality in the form of Active-X controls, plug-ins, or Java applets could mean unacceptable download times for users. In some cases, users would be willing to wait. Specifically, if the applications they required demanded the rich texture provided by plug-in technologies, users would accommodate download times.

However, in other cases, users wanted a less complex solution. Granted, the solution should be more complex than HTML forms, but not necessarily as complex as Java.

Enter JavaScript.

Netscape 2.0 introduced JavaScript (initially LiveScript), a distant cousin of the Java language, as a means for achieving some special effects in the web browser without actually having to resort to a plug-in technology.

NOTE: Soon after the release of JavaScript by Netscape, Microsoft released their own semi-compatible version called JScript in Internet Explorer 3.0. JScript, however eventually lost much of its appeal after Microsoft released VBScript, which leveraged the Visual Basic programming language to do the same thing as JavaScript. VBScript would fast become Microsoft's preferred Web Language however because most developers like to keep their applications cross-browser compatible. VBScript has receded to a large degree onto the server side for ASP, which we will talk about later. Most client-side development is done in JavaScript.

Actually, to tell you the truth, JavaScript is a bit of a misnomer (or a marketing ploy) because though JavaScript is indeed a scripting language (browsers include a JavaScript interpreter), it actually is very different from Java. Whereas Java is a self-contained programming language capable of full featured application development on its own, JavaScript is built as a programming glue that developers can use to tie together other technologies (HTML or the browser itself) within the scope of the web browser. That is, you would rarely say that you had finished work on a JavaScript application, but you might say that you had added some JavaScript functionality to your web page.

JavaScript is not so much about adding new functionality as it is about tweaking existing functionality to make it seem more cool.

The most important thing to understand about JavaScript is that it exposed much of the browser API to developers. Specifically, the browser and many of the widgets inside the browser could be talked to, listened to and controlled.

Developers quickly began to use JavaScript for such purposes as

  • animation
  • accessing the bookmarks and history
  • event handling (like mouse over effects such as when a graphical image button lights up when the mouse crosses over it)
  • form field validation (such as when you make sure the user has entered in data for all the required fields before you let them submit the HTML form to a web server)
  • and the spawning of event dialogs and new windows.

What was nice was that JavaScript was written for the common person and required little programming background to master. Web designers could add a great deal more functionality and bells and whistles to their existing HTML pages without needing to resort to server-side programming like CGI.

JavaScript has gone through several iterations of versioning and though there are still compatibility problems between IE and Netscape, the standard features of the language have been nailed down pretty well.


Selena Sol contributes to the JavaBoutique's Introduction to Java. Selena curently works for Barclays Capital in London, one of the leading global investment banks in Europe and has worked as a software developer for the National Center for Human Genome research, Microline Software, Neuron Data, and Electric Eye in Singapore. Selena is perhaps best-known for creating the Public Domain Web Script Archive (Extropia) and writing several books on Web Programming (Perl, CGI, Java).
Email: selena@extropia.com

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs