| | |
A few questions about C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Solved Threads: 0
Hey, im Keith and im 15 years old. I like computers alot and im pretty good at making websites, so this year i signed up for computer science. Our teacher is teaching us how to wrote programs using C++ and i love it, but i was wondering, why are they teaching us C++ when Java is alot more powerful and you can do alot more with it? Please correct me if im wrong, im new to the code language world
.
Also, i was wondering if you can make cool graphics programs with C++ or only crappy triangles like we are learning? ( :-| )
. Also, i was wondering if you can make cool graphics programs with C++ or only crappy triangles like we are learning? ( :-| )
Greetings kppowell,
I'm glad you have asked this question. Here is a detailed explanation between the differences of the two languages:
Differences between C++ and Java
Although the Java language is modeled on C++, it has several fundamental differences. It is important to keep in mind (for now) one fact: Java was designed to allow portable applications to be safely downloaded over a network. In its current form, it is not designed to replace C or C++ as a systems programming language. (this will not be true pretty soon).
There are a number of C++ features that Java does not support. Perhaps the single biggest difference between Java and C++ is that Java does not support pointers. In C++, pointer is one of C++ most important language features. It is also one of the most dangerous if used improperly. Pointers don't exist in Java for two reasons. First, pointers are inherently insecure. For example, using a C++ pointer, it is possible to gain access to memory addresses outside a program's code and data. Second, the designer of Java probably think that they were too troublesome. Since pointers don't exist in Java, neither does the -> operator.
Some key points
New features added by Java
Java adds several features that C++ has no equivalent: packages, interfaces, and multithreading. There is no feature in C++ that directly corresponds to a Java package. The closest similarity is a set of library functions that use a common header file. The Java interface is somewhat similar to a C++ abstract class.
Multithreading allows two or more pieces of the same program to execute concurrently. There is no parallel for this in C++. If you need to multithread a C++ program, you will need to do so manually.
Java contains a built-in string type called String. String is somewhat similar to the standard string class type provided by C++. Of course, in C++ string is only available if you include its class declarations in you program. It is not a
built-in type.
While both C++ and Java support a Boolean data type, Java does not implement true and false in the same way as C++. In C++, true is any nonzero value. False is zero. In Java, true and false are predefined literals, and these are the only values boolean expression may have.
C++ supports exception handling that is fairly similar to Java's. However, in C++ there is no requirement that a thrown exception be caught. In Java, most exceptions must be caught.
I could go on, though I believe the difference has become clear. If you would like further information, please feel free to ask.
- Stack Overflow
I'm glad you have asked this question. Here is a detailed explanation between the differences of the two languages:
Differences between C++ and Java
Although the Java language is modeled on C++, it has several fundamental differences. It is important to keep in mind (for now) one fact: Java was designed to allow portable applications to be safely downloaded over a network. In its current form, it is not designed to replace C or C++ as a systems programming language. (this will not be true pretty soon).
There are a number of C++ features that Java does not support. Perhaps the single biggest difference between Java and C++ is that Java does not support pointers. In C++, pointer is one of C++ most important language features. It is also one of the most dangerous if used improperly. Pointers don't exist in Java for two reasons. First, pointers are inherently insecure. For example, using a C++ pointer, it is possible to gain access to memory addresses outside a program's code and data. Second, the designer of Java probably think that they were too troublesome. Since pointers don't exist in Java, neither does the -> operator.
Some key points
- Java does not include structures or unions. These were felt to be redundant since the class encapsulates them.
- Java does not support operator overloading as does C++.
- C++ includes a preprocessor or support the preprocessor directives
but Java does not. - C++ does perform automatic type conversions that result in a loss of precision. Java does not.   For example, a conversion from long integer to integer must be explicitly cast.
- C++ allows default arguments. This means that you may specify a value that a parameter will have when there is no argument corresponding to that parameter when the function is invoked. Java does not allow default argument.
- C++ supports inheritance of multiple superclasses by a subclass which Java does not.
New features added by Java
Java adds several features that C++ has no equivalent: packages, interfaces, and multithreading. There is no feature in C++ that directly corresponds to a Java package. The closest similarity is a set of library functions that use a common header file. The Java interface is somewhat similar to a C++ abstract class.
Multithreading allows two or more pieces of the same program to execute concurrently. There is no parallel for this in C++. If you need to multithread a C++ program, you will need to do so manually.
Java contains a built-in string type called String. String is somewhat similar to the standard string class type provided by C++. Of course, in C++ string is only available if you include its class declarations in you program. It is not a
built-in type.
While both C++ and Java support a Boolean data type, Java does not implement true and false in the same way as C++. In C++, true is any nonzero value. False is zero. In Java, true and false are predefined literals, and these are the only values boolean expression may have.
C++ supports exception handling that is fairly similar to Java's. However, in C++ there is no requirement that a thrown exception be caught. In Java, most exceptions must be caught.
I could go on, though I believe the difference has become clear. If you would like further information, please feel free to ask.
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
Ah,
Glad to be of assistance.
> i dont think it recognized #include <iostream.h>
I've heard this from alot of programmers before. Though there is a difference between <iostream.h> and <iostream>.
Difference between iostream.h and iostream
iostream is somewhat more restrictive than the older iostream.h. One would possibly avoid problems by careful use of namespaces, but it would be a lot smarter to stick with one or the other.
On a futher note, iostream.h is deprecated (it was replaced when the C++ standard came out about 7 years ago)
Technically speaking, iostream.h is not considered depreciated, because it was never part of the official standard in the first place.
You should avoid using the *.h version as much as possible, because some implementations have bugs in their *.h version. Moreover, some of them support non-standard code that is not portable, and fail to support some of the standard code of the STL.
Furthermore, the *.h version puts everything in the global namespace. The extension-less version is more stable and it's more portable. It also places everything in the std namespace.
iostream.h is an old style method of including std C++ headers, and in opposite to iostream you don't have to declare that you're using the std namespace.
It is sometimes recommended to use:
What does using namespace do?
Explained as simply as possible, namespaces allows us to group a set of global classes, objects and/or functions under a name. If you specify using namespace std then you don't have to put std:: throughout your code. The program will know to look in the std library to find the object. Namespace std contains all the classes, objects and functions of the standard C++ library.
Hope this helps,
- Stack Overflow
Glad to be of assistance.
> i dont think it recognized #include <iostream.h>
I've heard this from alot of programmers before. Though there is a difference between <iostream.h> and <iostream>.
Difference between iostream.h and iostream
iostream is somewhat more restrictive than the older iostream.h. One would possibly avoid problems by careful use of namespaces, but it would be a lot smarter to stick with one or the other.
On a futher note, iostream.h is deprecated (it was replaced when the C++ standard came out about 7 years ago)
Technically speaking, iostream.h is not considered depreciated, because it was never part of the official standard in the first place.
You should avoid using the *.h version as much as possible, because some implementations have bugs in their *.h version. Moreover, some of them support non-standard code that is not portable, and fail to support some of the standard code of the STL.
Furthermore, the *.h version puts everything in the global namespace. The extension-less version is more stable and it's more portable. It also places everything in the std namespace.
iostream.h is an old style method of including std C++ headers, and in opposite to iostream you don't have to declare that you're using the std namespace.
It is sometimes recommended to use:
#include <iostream> using namespace std;
What does using namespace do?
Explained as simply as possible, namespaces allows us to group a set of global classes, objects and/or functions under a name. If you specify using namespace std then you don't have to put std:: throughout your code. The program will know to look in the std library to find the object. Namespace std contains all the classes, objects and functions of the standard C++ library.
Hope this helps,
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
>iostream is somewhat more restrictive than the older iostream.h.
If by "more restrictive" you mean the requirement to qualify the std namespace when using a standard name. iostream is vastly more powerful and flexible than iostream.h and is more fully featured.
>iostream.h is deprecated
No, iostream.h is gone. It was completely removed when the language was standardized. Deprecated means that the feature is still supported but may be removed in future revisions.
>It is sometimes recommended to use
Of course a better recommendation would be either explicitly qualifying names that you intend to use with a using declaration:
or with every use:
The using directive is no better than how iostream.h leaves every name in the global namespace.
If by "more restrictive" you mean the requirement to qualify the std namespace when using a standard name. iostream is vastly more powerful and flexible than iostream.h and is more fully featured.
>iostream.h is deprecated
No, iostream.h is gone. It was completely removed when the language was standardized. Deprecated means that the feature is still supported but may be removed in future revisions.
>It is sometimes recommended to use
Of course a better recommendation would be either explicitly qualifying names that you intend to use with a using declaration:
C++ Syntax (Toggle Plain Text)
using std::cout;
C++ Syntax (Toggle Plain Text)
std::cout<<"blah blah"<<std::endl;
![]() |
Similar Threads
- I have a few questions to be patched up can anybody get these to me ? (C++)
- Questions about Forum (Geeks' Lounge)
- Preparing for an interview and need some questions answered (C)
- Wireless Questions (Networking Hardware Configuration)
- Linux printing questions (*nix Hardware Configuration)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
Other Threads in the C++ Forum
- Previous Thread: xml and c++ help
- Next Thread: Question about a program I'm looking
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets







...