Java
  Home arrow Java arrow Page 2 - Completing the Syntactic Comparison of...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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? 
JAVA

Completing the Syntactic Comparison of Java and C/C++
By: Barzan "Tony" Antal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2007-11-28

    Table of Contents:
  • Completing the Syntactic Comparison of Java and C/C++
  • Classes continued
  • Other Distinctions
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    Completing the Syntactic Comparison of Java and C/C++ - Classes continued


    (Page 2 of 4 )

    In Java to set the relationship between a parent and child class you need to use the extends keyword. Likewise, the keyword this works the same as it does in C/C++; it stands for referring to the method itself. Additionally, Java has super that is used when you want to refer to a method that’s within a parent class.

    Now let’s talk about constructors and destructors. A constructor is a method that basically defines the way an/more object(s) should be created. These do not return any kinds of values. Each class in Java can contain one or more constructors. We all know that in C/C++ destructors were used to free up the memory that was allocated to a particular object. However, this isn’t the way Java works. Destructors aren’t required.

    In Java there’s a new addition called garbage collection. What this collector does is quite simple to understand. On a very frequent basis it verifies all of the references in all objects; due to this, it classifies each of them as either live or dead. References that do not exist (cannot be reached) are rapidly freed up from the memory.

    As a result, destructors aren’t necessary anymore. Garbage collector (GC) does it more efficiently than any coder could explicitly do it in C/C++. It won’t free up live objects by mistake, nor will it forget to perform the task of freeing memory and thus leave dead objects further clogging up the memory. Once you get the hang of Java you’ll realize that GC is great!

    Nevertheless, nobody prevents you from explicitly freeing up the objects. There’s a method called finalize() that indeed finalizes an object. Each class can contain the finalize method because it’s defined within the Object superclass, therefore every class inherits it. Calling finalize is akin to freeing up the object before it gets collected by the GC (read as: freed up automatically).

    More Java Articles
    More By Barzan "Tony" Antal


       · Finally, here's the second segment of this series. Thanks for following this JAVA...
     

       

    JAVA ARTICLES

    - 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...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway