Java
  Home arrow Java arrow Page 2 - Syntactic Comparison of Java and C/C++
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
JAVA

Syntactic Comparison of Java and C/C++
By: Barzan "Tony" Antal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 11
    2007-11-21


    Table of Contents:
  • Syntactic Comparison of Java and C/C++
  • Data Types
  • Pointers
  • Summing Up

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Syntactic Comparison of Java and C/C++ - Data Types
    ( Page 2 of 4 )


    Before we move on to the actual syntactic comparison of these two languages, I must confess that due to the overwhelming reputation of ANSI C and C++ being fairly accepted as one of the most widely spread programming languages, I’m going to approach this comparison from a C-centric point of view. That is, I assume that most of my readers have a basic understanding of C and not necessarily Java.

    As a result, I will sort of introduce the Java programming language while comparing it simultaneously with C/C++ and pointing out the differences and similarities in their syntax.

    First, check out the next table of primitive data types that are present in Java.


    Primitive Data Type

    Description

    byte

    Signed integer on 8 bits.

    short

    Signed integer on 16 bits.

    int

    Signed integer on 32 bits.

    long

    Signed integer on 64 bits.

    float

    Floating-point on 32 bits.

    double

    Floating-points on 64 bits.

    char

    Unicode character on 16 bits.

    boolean

    True or False.


    The first two differences that one might notice right away while skimming through the above table are the lack of ‘unsigned’ data types and the presence of the ‘boolean’ type per se. All of the primitive data types that are present in Java are signed. And the boolean type isn’t possible by default with C/C++; however, a few of the latest C++ compilers added this data type.

    The rest of the data types look quite similar to those used by C/C++ but there is a significant difference in their “inner mechanism.” In Java the sizes of these data types is clearly specified and exact. This was incorporated to maintain a high level of portability for the Java programming language.

    Because most of today’s machines are still running on 32 bits, Java developers had taken this into consideration. Consequently, an integer is stored on 32 bits while a long is on 64 bits. This differs from C/C++ where 16/32 bits and 32/64 bits are possible for these two, respectively. C/C++ mostly focuses on maintaining a relative comparison of the data types (a long data type is longer or equal to an int) while Java specifies their sizes exactly.

    Now that we’re speaking about data types, what about conversions? The actual conversion procedure is done with a casting procedure in Java. However, Java isn’t doing any kind of automatic casting. The programmer must explicitly use casting like so: “IntVar=(int)OtherVar” (without quotation marks). In C/C++ if the conversion isn’t pointed out explicitly the compiler does it anyway; this could turn into the cause of multiple problems depending on the particular scenario.

    The conditional and negation operators are working on a ‘boolean’ basis in Java. Due to this and the aforementioned non-automatic conversions, it is really important to realize that conditions like “a && b” won’t result into “a!=0 && b!=0” like they do in C/C++.

    It is also worthwhile to point out that overloading operators is forbidden in Java. This was considered to be the root of certain problems and therefore wasn’t implemented. Nevertheless, I know that many C/C++ coders get frustrated at first. It’s a feature that certainly helps but we should be fine without it.



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

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek