Ask Experts Questions for FREE Help !
Ask
    mani_jeddah's Avatar
    mani_jeddah Posts: 75, Reputation: -1
    Junior Member
     
    #1

    Jan 15, 2008, 10:09 AM
    Similarity by the way Cpp and java?
    Hey

    Am student of computer science
    This semester we have covered object oriented programming in C++
    In upcoming semester we will do it in java "oop in java"

    So I want to ask about the similarities by the way c++ n java and diffrences wheather in concepts or scope

    Kindly I want technical ans not flying on air!
    slapshot_oi's Avatar
    slapshot_oi Posts: 1,537, Reputation: 589
    Ultra Member
     
    #2

    Feb 20, 2008, 10:32 PM
    I'm one semester ahead of you, I'm taking the OO course in Java now, I took C++ last semester. This is what I've learned in the three weeks of school I've had this semester.
    ______________________________________
    C++
    ______________________________________
    Call by Value language - Just like C.

    Pointers and References - Yup, they still exist in C++, however, the C++ convention is to use references--aliases for objects, not a holder of an address--instead of pointers. They are safer to use. Only use pointers when you need to.

    User defined operator overloading - This can get hairy, + can mean -, up can mean down, you can really get lost if you're not careful.
    _______________________________________
    Java
    _______________________________________
    Dynamic allocation - All objects in Java are instantiated with the "new" keyword and stored in the dynamically allocated heap area in memory, rarely will Java ever use the run-time stack. Remember malloc() in C? Yeah, what a piece of crap.

    No pointers or references - Yes, no more pointers. This is a safety feature of Java so that programmers won't crash their programs and get the dreaded "Segmentation Fault". It makes programming easy but less powerful and slower.

    Object Oriented - You will learn that C++ is not entirely object oriented. A true OO programming language has no primitive types (no int, char, long, etc.), Java is not truly OO in nature either, but it is closer than C++. Java has "wrapper classes", they are classes built around the primitive types to give them OO properties, like inheritance.

    Call by value language alteration - In OO programming, it's good practice to pass objects to functions as references rather than making a copy of an object, this is simply because objects can be huge. In Java, you do not have to specifically send objects to methods (member functions as you would know them in C++) as references, Java does this automatically. This characteristic would make Java a Call by Reference language, however, Java does send a copy of an argument to a method if the argument is a primitive type, hence it is still Call by Value.

    Garbage collection - No destructors, worrying about unfreed memory or dangling pointers, Java will do it for you. This was such a pain in the when dealing with C.

    Everything must be a class - In C++, you'd write your main function as a separate C++ file and that would be it, making half your program OO. In Java, your main function has to be part of a class. Because of this, the main function has to be declared as "static" so it will be stored in the global and static data area of memory and will remain there throughout the remainder of the program. In C++, main was the first to be put in the run-time stack. This is probably th most confusing concept in Java, and yet no one bothers to explain well. Please pay close attention to this and your transition will go much more smoothly.

    On a personal note, I like both languages, and I know you will too. I like C++ more because the programmer has more freedom and with that comes more responsibility, but I like Java more because it's easy to write GUIs and has excellent documentation. Java is easy to learn, but no way in hell would I recommend learning an OO programming language without learning a language as bare-bones as C.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Java [ 3 Answers ]

Please will you help me with these questions... where can I find a great site that will help me answer these... 1/ Who developed Java and when? 2/ What are some unique features of Java? 3/ Is java used for websites or stand alone programs? 4/ What does it mean when I say java is an "object...

Java [ 4 Answers ]

We can not instantiate an abstract class. But we can write a constructor in abstract class. If we are not able to create an object, then how and why is it possible to create a constructor in an abstract class?

Java Is used for [ 2 Answers ]

When I rest my pointer over a link, it diplays information about that link Is that Java at work? Why are there different Jav versions? Is Java compiled like C or interpeted like Basic? Is this contained in Internet Explorer? Thank You very much

By using vc++ or java? [ 1 Answers ]

Hi, I want to make image processing application.which programming language I should use? Either vc++ or java or anything else? Please guide me early.


View more questions Search