Home arrow Java & J2EE arrow Completing the Syntactic Comparison of Java and C/C++

Completing the Syntactic Comparison of Java and C/C++

This is the second half of the two-part series on the syntactic comparison of Java and C/C++. Before we begin, I’d like to encourage you to read its first part if by any chance you’ve missed it. It is called “Syntactic Comparison of Java and C/C++” and it’s published right here. You shouldn’t miss it because grasping the basics is crucial.

TABLE OF CONTENTS:
  1. Completing the Syntactic Comparison of Java and C/C++
  2. Classes continued
  3. Other Distinctions
  4. Conclusion
By: Barzan "Tony" Antal
Rating: starstarstarstarstar / 6
November 28, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In the first part I showed you the main differences as far as data types, classes, and some additional important details on the semantics of those two languages. Now we’re going to discuss more thoroughly the topics of classes, command line arguments, unconditional transfers of control (goto, labels, break, continue), and so forth.

Moreover, before finishing this article I’ll point out the features that are present in C/C++ but missing from Java and vice versa. Furthermore, you might be expecting some kind of conclusion or final words at the end. I definitely won’t conclude that one is better than the other but I’m determined to give you my personal opinions regarding these two languages.

Now the time has come for us to begin. Ready, Steady, Go!

Classes

I’ve mentioned in my previous article that a class is one of the most important concepts in Java. That’s because everything must take part of a class. This wasn’t fashionable with C/C++. Even though classes have critical importance in C/C++ too, they aren’t necessary. In Java they are required and everything happens around them.

Should you desire to create global functions and use global variables, you are going to encapsulate everything inside a class. You do this by creating static methods and static data that ultimately are placed inside a class. Of course, encapsulation into multiple classes is possible too. Additionally, it is worth mentioning that there is a huge family of classes that has a so-called superclass (ancestor), the Object class.

Java also has a long list of access modifiers that can be implemented to classes, constructors, methods, etc. Each of these has their very own rules according to which they can be implemented. For example, out of the following 3 modifiers only one should be used when declaring a method: private, public, protected; or methods that have modified as abstract or native should have no body.

A final note on access modifiers is that they do not interfere with inheritance by prevention. On the other hand, they do affect which parts you can or cannot see within a subclass. Speaking of inheritance, another significant difference is that multiple inheritances aren’t allowed in Java. But there’s a so-called interface structure that is not a class but can inherit from a base class (superclass).

However, there is a workaround by implementing multiple interfaces. An interface is a class that contains nothing but abstract methods. Hence, their body must be defined in the inherited classes.



 
 
>>> More Java & J2EE Articles          >>> More By Barzan "Tony" Antal
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: