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.

 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