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 :

Defining "robust"

Q

What do you mean when you use the adjective "robust"? (sturdy?)

A

"Java is robust."

Sometimes it is very easy to forget what is a jargon term and what is a "real" term!

Looking at the section in the Introduction to Java Tutorial where you pulled that line, I realize that some of the terms could use explanation... so I will try to do that in this email. Hopefully, my editor will also post this response to the website so that others can benefit from your question!

NOTE: By the way, there is an excellent free online dictionary of computer terms at http://foldoc.doc.ic.ac.uk/foldoc/index.html Editor's note : Also see Webopedia's searchable dictionary.

Java is a robust language. What does "robust" mean in the context of computer languages?

Well, we say that a programming language or an application is robust when it is very resilient to bad user data and the resultant "run-time errors".

Oh no! more jargon....let me take a step back.

Errors. There are two types of errors: Compile-time errors and run-time errors.

A "compile-time" error is the error you will be most familiar with as a programmer. A compile-time error is an error in syntax. Compile-time errors occur when you write a line of code wrong, you forget punctuation, or you make a typo in your program.

Compile-time errors are pretty easy to find because a program will not even run with a compile-time error. There is no program, it just crashes until you go back through the code and find the error you made. Compile-time errors are our friends... they warn us about when we have made a coding mistake.

"Run-time" errors, on the other hand are our worst nightmares.

A run-time error happens when you have written perfectly syntactical code but the user has typed in something so foul that your nice, well-written, happy code crashes and burns.

Consider the textbook case.

You have written a function that accepts to numbers from the user, divides the first by the second, and returns the result. In java, that would look something like

public float divide(int numerator, int denominator) {
     return numerator/denominator;
}

and you would call such a function like

int result = divide(10,5);

Seems reasonable right? Well, what happens if some dummy user says...

int result = divide(10,0);

What is 10/0? Uh oh! Your program will now crash.

There was no way to know at compile time that there was an error. The divide function is syntactically correct. It is only when you put a clean program in the hands of a messy human where things start falling over.

Okay, enough side tracking... let's get back to "robust".

A "robust" language is a language that is resilient to run-time errors. Specifically, a robust programming language has built into it means to handle these exceptional circumstances (called exceptions in Java) intelligently. A program written in a robust language will not fall over and die if the user tries to divide by zero because the language itself is built to handle these weird circumstances. That is, the programmer does not have the responsibility to handle run-time errors because the language does that for her.

Let's look at an example... consider JavaScript which is NOT a robust language.

How would you protect yourself against run-time errors in javaScript?

Well, in JavaScript, you would have to think about all the possible ways that a user could screw up your program in advance and write code to specifically handle those events.

So, for instance, before you sent two user-defined numbers to a divide function, you would need to specifically check that neither are zero.

Believe me, it is a lot of code to write when you start to imagine all the ways a user could input bad data into forms. Dates need to be checked, email addressees, credit card numbers, number-only fields, letter-only fields, two decimal place numbers versus no decimal place numbers... the list goes on and on and on.

And what is worse, you may not cover all your bases... the user may still find a way to break your code that you did not think of.

To be robust, you need to be able to handle all currently known errors as well as all future errors that could crop up.

Now let's consider a robust language like Java. Java has something called a "try-catch block". Try-catch blocks are used whenever there is a possibility that there will be a runtime error and work as a global safety net for present and future possible errors. Also, they provide an easy way for you to notify the user that they need to modify their input without the whole program crashing down.

Consider how it works in Java.....

try {
    public float divide(int numerator, int denominator) {
         return numerator/denominator;
    }
}

catch (DivideByZeroException e) {
        System.out.println("Wooopsy, you cannot divide by zero.");
}

There are lots of run-time exceptions that you can handle and most are much broader than DivideByZeroException.

At any rate, in order to compile a Java program, you are required to catch all errors that can be thrown at run time. Thus, Java forces the developer to handle their errors and that leads to robust programs.

PS: Exception handling will be covered in a few more months in my column at JavaBoutique.


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.

 DevX Skillbuilding from IBM developerWorks
 RIA Run Contest: Build Next-Gen Apps in Microsoft Silverlight 2
 Avaya DevConnect Center
 Intel Go Parallel Portal
 Internet.com eBook Library
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 53
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%.

SaaS Tool Offers Custom Database Development
Microsoft’s Automated Agent: Can We Talk?
Borland Finally Sells CodeGear
Red Hat Heads For The JON 2.0
Out with the Old, in with the New at JavaOne
Trolltech Expands WebKit Footprint
Oracle: Eating its Own Open Source Food
Big Money and Open Source May Not Compute
Open Source Embrace Gives Sun New Fans
NetBeans, OpenSolaris Also in Spotlight at JavaOne

Taming Trees: Building Branching Structures
Clean Up Function Syntax Mess with decltype
Sutter Speaks: The Future of Concurrency
INTEL SCAVENGER HUNT, LENOVO X300 AND APPLE IPOD TOUCH GIVEAWAY (the "Giveaway")
Comparing Multi-Core Processors for Server Virtualization
Intel® Desktop Business Computing Solutions
Intel: What Downturn?
Managing the Evolving Data Center
Implement Drag and Drop in Your Windows Forms Applications
Processing Linked Web Data with XSLT

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



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES