Java
  Home arrow Java arrow Page 2 - Completing the 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

Completing the Syntactic Comparison of Java and C/C++
By: Barzan "Tony" Antal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    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:
      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


    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
     

       

    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