Search code examples
javamisra

Is There a Java Equivalent to MISRA C?


In some languages, there are rules/best practices/etc. that promote software safety, ensure expected runtime behavior, etc. Two that come to mind are MISRA for C/C++, and the Ravenscar profile for Ada. There is typically a warm fuzzy feeling about your code if it is stamped as following these standards. Is there any such standard for Java?


Solution

  • I don't think there is something like the MISRA C/C++ best practices for Java, and I think it is also less necessary with a language like Java because it doesn't have as many corners of undefined or unspecified behaviour like C and C++ have. Features such as the lack of explicit pointers in Java and the fact that the bounds of array indices are always checked by the runtime make Java a safer language than C or C++.

    There is a common coding standard that most Java developers seem to follow: Code Conventions for the Java Programming Language, but that is more a style guide than a best practices guide.

    There are a few good and well-known static code analysis tools for Java: FindBugs and PMD for example, which will check your code for possibly dangerous constructions or bad practices.

    If you want to learn about the potential pitfalls in Java, then two books are highly recommended: Effective Java and Java Puzzlers.

    Additional, similar resources include: