Syntactic Comparison of Java and C/C++ - Summing Up (Page 4 of 4 )
Now is the perfect time to sum up what we’ve just learned. First of all, Java as a programming language was consciously simplified and the most common sources of trouble were eliminated, either completely or by incorporating specific safer workarounds.
You can add comments the same way in both languages, either the // per line or the /* */ for multiple lines. These are called implementation-comments and they’re derived from C/C++. However, Java has document-comments too. You can delimit these using /** */ tags. Additionally, these can be exported to HTML using javadoc.
Using operators = and == in Java considers only the references. If the coder wants to either copy or test the equality of two objects/arrays s/he should use clone() and equals(), respectively. A null in Java is not akin to 0 per se, it stands for a void reference.
C-like pointers do not exist in Java. They are created as references and de-referenced automatically. Some might argue that Java has some kind of pointers; well it has, but they are not true pointers from a C/C++ point of view — there is no pointer arithmetic at all.
The idea of restrict programmers from directly manipulating addresses of the memory was mostly carried out to enhance the security of the language. Yes, one of the reasons is to provide more of a type-safe coding. But the most important underlying reason is that it gives less control over the system’s resources to programmers. Thus it drastically decreases the opportunities to code malicious programs (e.g., buffer and/or stack overflow, etc.).
The last syntactic difference between Java and C I want to point out before I finish this half of the two-part series is about global data and variables. In Java there are no structs or unions. Everything is part of a class. Static methods behave like globals inside a class.
Until next time, keep coding! Stick around; you won’t want to miss the next part.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |