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
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.
|