• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff


Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the meaning of robustness in java?
Saloon Keeper
Posts: 14488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Robustness means something doesn't break easily.

Robust methods are methods that don't allow you to pass invalid arguments, and they don't let the outside world affect them once they are running. Useful tools to achieve this are parameter checking, defensive copying, file locking and synchronizing, among others.

This method demonstrates defensive copying, and parameter checking. Before it does anything, it copies the collection of things to a new list. This makes sure that while the method is running, no other thread can come in and change the collection of things we're working on. Another thread can still edit the individual objects in the list, but you can mitigate this problem by making sure that the objects immutable.

After the argument has been copied, it is checked to see if it is valid to work on, and won't break the program at some later stage, or even worse, do harmful stuff like passing wrong bank account numbers or passwords. In this example, a loop checks that the things in the list aren't null, and that they are valid in some way.

Finally, when the method is certain that everything is okay, it can start working on the input. Depending on what the method does, you can first check the entire input before doing anything at all, or you can check input as you need it. It's important that you check all input before you do anything, if the input in related to each other. The example method assumes that the things in the list are not related to each other, so it processes each thing immediately after it's checked it.

Robust classes are classes that don't allow other classes to use them in a way they weren't intended for. They are built from other classes that are also robust, or if they use classes or methods that aren't, they don't expose them to the outside world directly. They make sure that their internal state is never corrupted, and if it is (because of some exceptional situation they can't recover from) they become unusable. State checking is an important aspect. Making a class immutable makes them as robust as possible.

Sometimes robustness comes at a price. It may be too expensive to check everything before you use it. Here's where assumptions come into play. You don't have to check data as long as you may assume that they will be in a valid state. When can you make assumptions? Classes may assume that private members are always valid, unless the outside world is allowed to have a reference to their values. This is why you should often perform defensive copying in constructors and setters before you assign a value to private members, and defensive copying in getters before you return the private member.

Private methods don't have to check parameters. They can only be called by methods that belong to the same class, so they may assume that arguments passed to them are always valid.
Posts: 17264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Robust - sturdy in construction; strong, health, vigorous.

When referring to code, robustness usually means it is relatively free of bugs, has good design, good structure, good organization, is able to handle exceptional conditions gracefully, is able to handle different kinds of inputs gracefully.
Screaming fools! It's nothing more than a tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic