Thread: C/C++ Vs Java

  1. #1
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66

    C/C++ Vs Java

    have any of you spent time with java ? if so, what are your thoughts on spending time on it. thumbs up or down ?
    i am sure it has its strengths and weeknesses like all other languages, but after reading magazines and web articles, i want to see what our trusty C Board has to say.

    thank you in advance..

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    I like Java, it's a much smaller and easier to learn langauge than C++. It's easier to use Java to do non-low level tasks, but they will typically run slower and consume more memory due to the JVM needed to run them.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310

    Thumbs up

    I'm currently learning Java and I find it very similar to C++. It is SO much easier to utilize graphics but I am still a bit partial to C++.

    //napKIN

    ---------->>All hail John Carmack<<---------

  4. #4
    Originally posted by napkin111
    I'm currently learning Java and I find it very similar to C++. It is SO much easier to utilize graphics but I am still a bit partial to C++.

    //napKIN

    ---------->>All hail John Carmack<<---------
    It might be easy to USE graphics, but then again, it's easier in QBasic than either one of these.
    -Save the whales. Collect the whole set.

  5. #5
    Registered User tgm's Avatar
    Join Date
    Jun 2002
    Posts
    150
    I use it at work. Almost everything we do is in Java.
    I give it a thumbs up.

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Java is easy to use, but a lot slower than C++. If speed is critical, don't use it .
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    CIS and business major
    Join Date
    Aug 2002
    Posts
    287

    Re: C/C++ Vs Java

    Originally posted by Spectrum48k
    have any of you spent time with java ? if so, what are your thoughts on spending time on it. thumbs up or down ?
    i am sure it has its strengths and weeknesses like all other languages, but after reading magazines and web articles, i want to see what our trusty C Board has to say.

    thank you in advance..

    I'm not a programming guru, and I don't know very much about java. But java is completely a oop based programming language, making it very slow. Since c++ has oop and top-down programming functionality, makes it quicker and more powerful than java.

    When sun invented java, they wanted to make an easy to learn, yet powerful language. But most of us know that it's very difficult to make a language both easy to learn, and powerful.

    Java doesn't have pointers, and pointers is what seperates c/c++ from other programming languages.

    The business world is already moving towards c#, which is similar to java, but has a lot of features that c++ has as well.

    So, java is likely to become obsolete before c++ is. And Sun's lawsuit of Microsoft for stealing their Java (and renaming j++) has only made M.S. that much more determined to drain java as a language.

    Also, if you know c++, it's would be very easy to learn java, but not the other way around.

    But, right now, java programmers seem to make relatively the same amount (in general) as c++ programmers. But I don't think that will be the same 5 years from now.

    Anyways, I say stick to c++, it's going to be around longer, it isn't owned by a company, and any good c++ programmer can teach themselves java within a matter of months (if that).

  8. #8
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    yes i programmed n JAVA as much as have done in C and C++... I would say learn both.. Even though it is not widely used now technologies like JAVA servets, JSP which have a wider use.. though these technologies dont make a difference to the end user.. it make a quite a lot of difference at the service side... And even learn Applets... though they are not used much any more.. you can use them to give a GUI to your servlet programs etc etc.... In the future when you get mmany web enabled devices ranging from your watch to your mobile.. JAVA technology will be used...

    And JVM is slow and not the java program.. the byte code is faster in some cases.. you will see the delay while loading the applet because of the JVM loading...

    And one big big advantage of JAVA is its memory managements.. there are no hasels JAVA automaticcaly takes care of cleaning it... Unlike in C and C++ where dynamically alocated memory has to be cleared by the programmer...



    Well i would say that C++ and JAVA have its own advantages.. and it all depends for what you are using it..... there are many technologies now that are better than JSP and servlets like ASP.net PHP etc etc..... But if you have time learning another language wont kill you....

  9. #9
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Re: Re: C/C++ Vs Java

    Originally posted by Terrance
    Java doesn't have pointers, and pointers is what seperates c/c++ from other programming languages.
    Eh? Everything in Java (except the 'normal' datatypes, like int) are pointers.

  10. #10
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683

    Re: Re: Re: C/C++ Vs Java

    Originally posted by Magos
    Eh? Everything in Java (except the 'normal' datatypes, like int) are pointers.

    well i agree with you..
    But let me clarify.. many people think that JAVA does not have pointers and it is a disadvantage.... JAVA uses pointers internally to work.. But it does not allow he programmer to use pointers(like int *variable) etc etc... And it is in no way a disadvantage... This was done to make java more secure... For example if pointes were allowed.. then i could write an applet which would access your memory and put some harmfull code in there... And your computer can be infected by a virus if you visit a web page with an applet in it... So to avoid those problems pointers access is not given to the programmer... When an applet is run on a machine it is not allowed access to other parts of the memory and the files in the system.. The java applet will run in a secure memory space.. and it cannot access anything outside this.. This is what makes java secure.. So hope everyone understands... And java is not mean to write system level programs.. so pointers are not needed...

  11. #11
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Re: Re: Re: Re: C/C++ Vs Java

    Originally posted by vasanth
    well i agree with you..
    But let me clarify.. many people think that JAVA does not have pointers and it is a disadvantage.... JAVA uses pointers internally to work.. But it does not allow he programmer to use pointers(like int *variable) etc etc... And it is in no way a disadvantage... This was done to make java more secure... For example if pointes were allowed.. then i could write an applet which would access your memory and put some harmfull code in there... And your computer can be infected by a virus if you visit a web page with an applet in it... So to avoid those problems pointers access is not given to the programmer... When an applet is run on a machine it is not allowed access to other parts of the memory and the files in the system.. The java applet will run in a secure memory space.. and it cannot access anything outside this.. This is what makes java secure.. So hope everyone understands... And java is not mean to write system level programs.. so pointers are not needed...
    True! But you could still be allowed to use pointers, but only to point at data (variables) in your own program (pretty much how it works now), not to set the pointer to a specific adress in memory like you can in C.

  12. #12
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Java does not have raw pointers like C or C++. It has something almost as powerful, but many times safer called references (Java refers to them as pointers in one place, the NullPointerException). They are like pointers, except that the dangerous features are removed, namely:

    pointer arithmetic
    random initialisation
    dangling pointers to deleted objects
    mismatched types and unions
    You can't construct references out of thin air, only with new.
    Unlike pointers, references cannot point into the middle of an object.
    References are null or always point to something valid of the type they claim to.
    Pointers always point directly to data. References are usually implemented as handles, not pointers. A handle is a pointer to a pointer. This allows objects to be moved around to compact fragmented RAM without having to find and adjust all the pointers to those objects.
    The safety comes with a cost.
    Every downcast has to be checked to ensure the object truly is of the type your cast claims it to be.
    Nearly every time you put an object into an array, the runtime must check the type to be sure it is compatible with the allocated type of the array, (which is distinct from the declared type of the array reference.)
    Implementations of linked structures typically require extra tiny glue objects that point to the objects linked. With raw pointers, typically you manage to embed these pointers directly into your objects.

    And what you are saying is not a pointer technically...

  13. #13
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >if so, what are your thoughts on spending time on it. thumbs up or down ?
    No language is perfect, I have some issues with Java, but overall it is a well constructed language and simple enough to learn.

    >But java is completely a oop based programming language, making it very slow.
    Eh? I thought it was slow because of the virtual machine and not the object orientation. Just so you know, object orientation doesn't make a language slow. There may be some overhead, but a well made OO language can be comparable in speed to low level systems level languages such as C. It's all in the care you take designing it and the goals you set for yourself. C++ is very fast even using OO, but that speed is obtained with a decrease in portability. Java is amazingly portable thanks to the JVM, but having the middleman slows things down when you use it.

    >Java doesn't have pointers, and pointers is what seperates c/c++ from other programming languages.
    Then this code is illegal in Java?
    Code:
    import java.io.*;
    
    class node
    {
      int item;
      node right;
    	
      public node ( int new_item, node next )
      {
        item = new_item;
        right = next;
      }
    }
    
    class list
    {
      private node head;
    
      public void prepend ( int item )
      {
        if ( head == null )
          head = new node ( item, null );
        else
          head = new node ( item, head );
      }
    	
      public void walk()
      {
        node it = head;
    		
        while ( it != null ) {
          System.out.print ( it.item + "->" );
          it = it.right;
        }
    		
        System.out.print ( "END" );
      }
    }
    
    public class list_test
    {
      public static void main ( String args[] )
      {
        list my_list = new list();
    	
        my_list.prepend ( 1 );
        my_list.prepend ( 2 );
        my_list.prepend ( 3 );
        my_list.prepend ( 4 );
        my_list.prepend ( 5 );
    		
        my_list.walk();
      }
    }
    I suggest you learn both, it never hurts to know several languages and may very well help you in the future.

    -Prelude
    My best code is written with the delete key.

  14. #14
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Originally posted by Prelude
    >if so, what are your thoughts on spending time on it. thumbs up or down ?
    No language is perfect, I have some issues with Java, but overall it is a well constructed language and simple enough to learn.

    >But java is completely a oop based programming language, making it very slow.
    Eh? I thought it was slow because of the virtual machine and not the object orientation. Just so you know, object orientation doesn't make a language slow. There may be some overhead, but a well made OO language can be comparable in speed to low level systems level languages such as C. It's all in the care you take designing it and the goals you set for yourself. C++ is very fast even using OO, but that speed is obtained with a decrease in portability. Java is amazingly portable thanks to the JVM, but having the middleman slows things down when you use it.

    >Java doesn't have pointers, and pointers is what seperates c/c++ from other programming languages.
    Then this code is illegal in Java?
    Code:
    import java.io.*;
    
    class node
    {
      int item;
      node right;
    	
      public node ( int new_item, node next )
      {
        item = new_item;
        right = next;
      }
    }
    
    class list
    {
      private node head;
    
      public void prepend ( int item )
      {
        if ( head == null )
          head = new node ( item, null );
        else
          head = new node ( item, head );
      }
    	
      public void walk()
      {
        node it = head;
    		
        while ( it != null ) {
          System.out.print ( it.item + "->" );
          it = it.right;
        }
    		
        System.out.print ( "END" );
      }
    }
    
    public class list_test
    {
      public static void main ( String args[] )
      {
        list my_list = new list();
    	
        my_list.prepend ( 1 );
        my_list.prepend ( 2 );
        my_list.prepend ( 3 );
        my_list.prepend ( 4 );
        my_list.prepend ( 5 );
    		
        my_list.walk();
      }
    }
    I suggest you learn both, it never hurts to know several languages and may very well help you in the future.

    -Prelude

    i would again insist on this
    Java does not have raw pointers like C or C++. It has something almost as powerful, but many times safer called references .. So technically it isnt pointers..

  15. #15
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >So technically it isnt pointers..
    I'm definitely splitting hairs here, but they are the same thing except references do not allow arbitrary arithmetic and they dereference themselves. So yes, they are slightly restricted pointers, but they are still pointers. The concept of a pointer or a reference is irrelevant. They are both another name for an address, it's just that simple.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Java for real-time applications
    By zacs7 in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 08-26-2008, 06:34 AM
  2. C#, Java, C++
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-05-2004, 02:06 PM
  3. The Java language is being expanded
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 06-11-2004, 09:07 PM
  4. Java woes
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 07-06-2003, 12:37 AM
  5. C or Java as a first language
    By CorJava in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 10-23-2002, 05:12 PM