Talk:Comparison of Java and C++: Difference between revisions

Content deleted Content added
Texture (talk | contribs)
m User
Remove merge proposal
 
(221 intermediate revisions by 87 users not shown)
Line 1:
{{Talk header}}
There are some on-line articles comparing Java with C++. Some of them emphasize C++'s advantages, while others highlight Java's. Who's that guy who write "Thinking in Java"? He had a pretty comprehensive one, although it's dated now. [[User:Ed Poor]]
{{Old AfD multi |date=17 December 2021 |result='''keep''' |page=Comparison of Java and C++}}
{{WikiProject banner shell|class=List|1=
{{WikiProject Computing |importance=low}}
{{WikiProject Java |importance=low}}
{{WikiProject C/C++ |importance=low }}
}}
{{User:MiszaBot/config
|archiveheader = {{Talk archive}}
|algo = old(365d)
|maxarchivesize = 100K
|minthreadsleft = 5
|minthreadstoarchive = 1
|counter = 2
|archive = Talk:Comparison of Java and C++/Archive %(counter)d
}}
 
== remove bounds checking ==
 
It is said that "HotSpot can remove bounds checking". But as far as I understand it's only an optimization technique which sometimes remove bound checking but not suppress it totally. [[User:Xavier Combelle|Xavier Combelle]] ([[User talk:Xavier Combelle|talk]]) 17:33, 22 July 2013 (UTC)
How come this page says Java doesn't have GoTos and contradicts the main [[Java programming language|Java]] page which says it does? --[[User:thadk]]
 
== Copyrights and patents ==
Java does not have gotos. The main page is wrong.
 
If we're going to say that "Various aspects of the language are covered by patents and copyrights held by Oracle.", then we need a cite to back it up. [[Oracle_v._Google]] says the opposite, that provided they avoid copying code, Google can implement Java (and all its APIs) even over Oracle's objections. http://www.javaworld.com/jw-10-1997/jw-10-lawsuit.html says "the complaint charges Microsoft with trademark infringement, false advertising, breach of contract, unfair competition, interference with prospective economic advantage, and inducing breach of contract." That long list does not include copyrights or patents. If we're wildly speculating, http://communities.mentor.com/community/cs/archives/cxx-abi-dev/msg01295.html is a list of possible patents over C++ implementations (not really from a reliable source) and if GCC's C++ implementation violates any of them, so almost certainly does GCC's Java implementation, as they share an ABI... and IBM and Microsoft are the corporate names on those patents, not Oracle.--[[User:Prosfilaes|Prosfilaes]] ([[User talk:Prosfilaes|talk]]) 08:24, 27 October 2013 (UTC)
:The main page is correct. Java does have "goto" but it is a reserved word and thus cannot be used. [[User:RedWolf|RedWolf]] 02:31, Apr 12, 2004 (UTC)
:Your last observation is interesting, but irrelevant here. The point is, Oracle may at any time assert it's intellectual rights over various aspects of the Java language. Moreover, the verdict in the Oracle/Google lawsuit does not in any way affect their right to sue even on the very same grounds laid out in that particular lawsuit, and however unlikely, they could still win such a lawsuit. And please note that a large part of that lawsuit was simply an objection to Google duplicating the Java API of all things! Which means, of course, that the types of complaints filed in any future lawsuit are only limited by the creativity of Oracle's legal department. [[User:Sebastiangarth|Sebastian Garth]] ([[User talk:Sebastiangarth|talk]]) 13:45, 27 October 2013 (UTC)
:: The point is, Microsoft may at any time assert its intellectual rights over various aspects of the Java and C++ languages. So might IBM. So might any other huge patent holder. So might any designer of a pre-Java API who wanted to claim that Java's API is a copyright infringement of theirs. Looking at the results of the SCO trial, it's not at all improbable that somewhere BSD-licensed code snuck its way into Oracle's Java implementation sans proper copyright notice. All of this might happen, and all of it is [[WP:CRYSTAL|crystal-balling]].
:: Yes, Oracle could sue on the same grounds. There's very few limitations on what people can sue on. Speculating that they could win such a lawsuit is, again, crystal-balling, and again, Oracle is not unique in having a creative legal department.
:: Going back to the original statement, nobody has ever shown that a language can be covered by copyrights, and [[Oracle v. Google]] said they couldn't, or at least Java wasn't. Neither 6061520 or RE38104, the two patents brought up in the Oracle trial, seem to be about Java as much as ways to implement Java. If we want to make the claim under question, we should speak with specificity and with cites. (And we should avoid saying anything about Oracle's "intellectual rights" over Java. That's not a clear term. We should speak specifically of copyrights, patents or trademarks, each of which has very different extents and limitations.)--[[User:Prosfilaes|Prosfilaes]] ([[User talk:Prosfilaes|talk]]) 17:40, 27 October 2013 (UTC)
:::I do understand your point but I still must disagree here. At any rate, I'm not going to press the issue any further. Perhaps we'll revisit the discussion sometime in the future. For now, at least, we can leave the wording as it is. [[User:Sebastiangarth|Sebastian Garth]] ([[User talk:Sebastiangarth|talk]]) 19:36, 27 October 2013 (UTC)
 
== Multiple Inheritance in Java ==
----
 
Guys/Gals,
''Java constants (the "final" keyword) are only enforced within class scope.''
 
Java does not support multiple inheritance. <---- note that there's a period at the end of that sentence
This statement makes no sense. I think what is meant is that Java has no global scope constants.
 
I call your attention to: http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)
: That's the best I can figure. I have changed it to clarify what I think was meant.
 
Specifically, the fact that that article begins by stating that *implementation* is what is being inherited, NOT TO BE CONFUSED with subtyping:
 
http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)#Inheritance_vs_subtyping
 
Anyone who understands multiple inheritance and its problem(s) would know quite well that Java does not support multiple inheritance, and the creators of Java were very vocal and open about their reasons for excluding multiple inheritance from the Java language spec.
 
[[User:Aquishix|Aquishix]] ([[User talk:Aquishix|talk]]) 12:19, 10 February 2014 (UTC)
 
== Java Generics Inaccuracy ==
 
I believe there is an error in the generics vs. templates comparison section.
 
It says (as of 11/18/2015):
{| class="wikitable"
! '''C++ Templates''' !! '''Java Generics'''
|-
| Templates can be [[Template (programming)#Explicit template specialization|specialized]]—a separate implementation could be provided for a particular template parameter.
|| Generics cannot be specialized.
|}
 
The below program shows an example of specializing a generic method for a specific template parameter. The "myCount" method is specialized for subclasses (inclusive) of Character. Is this not "providing a separate implementation for a particular template parameter"? It seems to precisely match the definition of "Explicit template specialization" given here: [[Template (programming)#Explicit template specialization]]
 
<syntaxhighlight lang="java">
import java.util.*;
 
public class Test {
 
static <T> int myCount (Iterator<T> iterator, T val)
{
int ret = 0;
while (iterator.hasNext()) {
T entry = iterator.next();
if (entry.equals(val)) ++ret;
}
return ret;
}
 
static <T extends Character> int myCount (Iterator<T> iterator, T val)
{
System.out.println("weirdcount");
int ret = 0;
while (iterator.hasNext()) {
T entry = iterator.next();
if (entry.equals(val)) ++ret;
}
return ret*3;
}
 
public static void main (String[] args) {
List<Integer> nums = new ArrayList<>(Arrays.asList(1,2,3,3,3,4,5,2,1));
int count = myCount(nums.iterator(), 3);
System.out.println(count);
 
List<Character> characters =
new ArrayList<>(Arrays.asList('a','b','c','d','e','a','b'));
int count2 = myCount(characters.iterator(), 'a');
System.out.println(count2);
}
}
</syntaxhighlight>
Thanks,
[[User:Vancan1ty|Vancan1ty]] ([[User talk:Vancan1ty|talk]]) 04:35, 19 November 2015 (UTC)
 
== nested/inner classes ==
 
I think the article should also state that C++ nested classes differ from Java inner classes.
C++ nested classes are kinda like a static class in Java and can not access fields in the outer class unless they are static (C++11) [[User:Peter.quiring|Peter.quiring]] ([[User talk:Peter.quiring|talk]]) 22:42, 4 April 2016 (UTC)