Contents - Cultural View
Contents - Cultural View Contents - Cultural View
Comparison of Java and C++ 84 Source code can be written to be platform independent (can be compiled for Windows, BSD, Linux, Mac OS X, Solaris etc. without needing modification) and written to take advantage of platform specific features. Is typically compiled into native machine code. Is compiled into byte code for the JVM. Is dependent on the Java platform but the source code is typically written not to be dependent on operating system specific features. C++ is a powerful language designed for system programming. The Java language was designed to be simple and easy to learn with a powerful cross-platform library. The Java standard library is considerably large for a standard library. However, Java does not always provide full access to the features and performance of the platform that the software runs on. The C++ standard libraries are simple and robust providing containers and associative arrays. [2] Language features Syntax • Java syntax has a context-free grammar which can be parsed by a simple LALR parser. Parsing C++ is somewhat more complicated; for example, Foo(3); is a sequence of comparisons if Foo is a variable, but it creates an object if Foo is the name of a class template. • C++ allows namespace level constants, variables, and functions. All such Java declarations must be inside a class or interface. • In C++ declarations, a class name declares an object of that class as a value (a.k.a. value semantics). There is no way to do this in Java. Objects are not values in Java. In Java declarations, a class name declares a reference to an object of that class (a.k.a. reference semantics). The equivalent way to do this in C++ is to use "*" to declare a pointer. • In C++, the operator "." takes an object as the left operand and accesses a member of the object. Since objects cannot be values in Java, and all objects are accessed through references, this cannot be done in Java. In Java, the "." operator takes a reference to an object as the left operand and access a member of that object. The equivalent operator in C++ is "->". e="7.71"> { // Declares class Foo ; // Member variable : x(0) { // Constructor for Foo, // initializes x ar(int i) { // Member function bar() eturn 3*i + x; e="7.71"> C++ Java es a to be a Foo object value, lized using the default constructor wanted to use another constructor, uld declare it as "Foo a(args);" class Foo { // Defines class Foo public int x = 0; // Member variable, // with initializer public Foo() { // Constructor for Foo } public int bar(int i) {// Member method bar() return 3*i + x; } } Foo a; // declares a to be a reference to a Foo object a = new Foo(); // initializes using the default constructor // If you wanted to use another constructor, // you would declare it as "Foo a = new Foo(args);
Comparison of Java and C++ 85 e="7.71"> ; the contents of a to a new Foo object b; ative syntax is "Foo b(a)" Foo b = a.clone(); // copies the values of all members // of this instance if, and only if, // Foo implements a public method called // clone() which returns a new copy of the object e="7.71">a.x = 5; // modifies the object a a.x = 5; // modifies the object e="7.71"> .x es c to be a pointer to a ject (initially ned; could point anywhere) e="7.71"> oo(); c to reference a new Foo object e="7.71"> c; d to reference the same object as c e="7.71"> es the object referenced by c e="7.71"> // invokes Foo::bar() for a ; // invokes Foo::bar() for *c e="7.71"> ->x
- Page 37 and 38: Java applet 33 there are frequently
- Page 39 and 40: Java applet 35 } } g.drawString("He
- Page 41 and 42: Java applet 37 The 2002 Sun - Micro
- Page 43 and 44: Java applet 39 [18] W3.org (http:/
- Page 45 and 46: Associació d'Usuaris de Java de Ca
- Page 47 and 48: Associació d'Usuaris de Java de Ca
- Page 49 and 50: Associació d'Usuaris de Java de Ca
- Page 51 and 52: Associació d'Usuaris de Java de Ca
- Page 53 and 54: Bean Scripting Framework 49 Bean Sc
- Page 55 and 56: CJAN 51 Ostensibly, CJAN.org failed
- Page 57 and 58: Chainsaw (log file viewer) 53 Chain
- Page 59 and 60: clone (Java method) 55 Alternatives
- Page 61 and 62: clone (Java method) 57 } } abstract
- Page 63 and 64: Comparison of Java and C Sharp 59 A
- Page 65 and 66: Comparison of Java and C Sharp 61 R
- Page 67 and 68: Comparison of Java and C Sharp 63 T
- Page 69 and 70: Comparison of Java and C Sharp 65 f
- Page 71 and 72: e="6.73"> = 42; = null; Comparison
- Page 73 and 74: Comparison of Java and C Sharp 69 L
- Page 75 and 76: Comparison of Java and C Sharp 71 I
- Page 77 and 78: Comparison of Java and C Sharp 73 t
- Page 79 and 80: Comparison of Java and C Sharp 75 N
- Page 81 and 82: Comparison of Java and C Sharp 77 L
- Page 83 and 84: Comparison of Java and C Sharp 79 T
- Page 85 and 86: Comparison of Java and C Sharp 81 C
- Page 87: Comparison of Java and C++ 83 C++ J
- Page 91 and 92: Comparison of Java and C++ 87 the c
- Page 93 and 94: Comparison of Java and C++ 89 • D
- Page 95 and 96: Comparison of Java and C++ 91 Sever
- Page 97 and 98: Comparison of the Java and .NET pla
- Page 99 and 100: Comparison of the Java and .NET pla
- Page 101 and 102: Comparison of the Java and .NET pla
- Page 103 and 104: Comparison of the Java and .NET pla
- Page 105 and 106: Constant interface 101 } public sta
- Page 107 and 108: Java 4K Game Programming Contest 10
- Page 109 and 110: Java 4K Game Programming Contest 10
- Page 111 and 112: CookXml 107 Creators, setters, adde
- Page 113 and 114: Cougaar 109 Cougaar Cougaar is a Ja
- Page 115 and 116: Devoxx 111 Related links • Devoxx
- Page 117 and 118: Elastic Path 113 References [1] htt
- Page 119 and 120: Electronic Disturbance Theater 115
- Page 121 and 122: Event dispatching thread 117 • Sw
- Page 123 and 124: Facelets 119 The above code can be
- Page 125 and 126: final (Java) 121 } Sphere(double x,
- Page 127 and 128: FormEngine 123 FormEngine Developer
- Page 129 and 130: Generics in Java 125 Motivation for
- Page 131 and 132: Generics in Java 127 Pair grade440
- Page 133 and 134: G-java 129 G-java G-java 2.x was a
- Page 135 and 136: GlassFish Metro 131 Features Metro
- Page 137 and 138: James Gosling 133 Contributions He
Comparison of Java and C++ 84<br />
Source code can be written to be platform independent (can be<br />
compiled for Windows, BSD, Linux, Mac OS X, Solaris etc. without<br />
needing modification) and written to take advantage of platform<br />
specific features. Is typically compiled into native machine code.<br />
Is compiled into byte code for the JVM. Is dependent on the Java platform<br />
but the source code is typically written not to be dependent on operating<br />
system specific features.<br />
C++ is a powerful language designed for system programming. The Java language was designed to be simple and<br />
easy to learn with a powerful cross-platform library. The Java standard library is considerably large for a standard<br />
library. However, Java does not always provide full access to the features and performance of the platform that the<br />
software runs on. The C++ standard libraries are simple and robust providing containers and associative arrays. [2]<br />
Language features<br />
Syntax<br />
• Java syntax has a context-free grammar which can be parsed by a simple LALR parser. Parsing C++ is somewhat<br />
more complicated; for example, Foo(3); is a sequence of comparisons if Foo is a variable, but it creates an<br />
object if Foo is the name of a class template.<br />
• C++ allows namespace level constants, variables, and functions. All such Java declarations must be inside a class<br />
or interface.<br />
• In C++ declarations, a class name declares an object of that class as a value (a.k.a. value semantics). There is no<br />
way to do this in Java. Objects are not values in Java. In Java declarations, a class name declares a reference to an<br />
object of that class (a.k.a. reference semantics). The equivalent way to do this in C++ is to use "*" to declare a<br />
pointer.<br />
• In C++, the operator "." takes an object as the left operand and accesses a member of the object. Since objects<br />
cannot be values in Java, and all objects are accessed through references, this cannot be done in Java. In Java, the<br />
"." operator takes a reference to an object as the left operand and access a member of that object. The equivalent<br />
operator in C++ is "->".<br />
e="7.71"><br />
{ // Declares class Foo<br />
; // Member variable<br />
: x(0) { // Constructor for Foo,<br />
// initializes x<br />
ar(int i) { // Member function bar()<br />
eturn 3*i + x;<br />
e="7.71"><br />
C++ Java<br />
es a to be a Foo object value,<br />
lized using the default constructor<br />
wanted to use another constructor,<br />
uld declare it as "Foo a(args);" <br />
<br />
class Foo { // Defines class Foo<br />
public int x = 0; // Member variable,<br />
// with initializer<br />
public Foo() { // Constructor for Foo<br />
}<br />
public int bar(int i) {// Member method bar()<br />
return 3*i + x;<br />
}<br />
}<br />
<br />
Foo a;<br />
// declares a to be a reference to a Foo object<br />
a = new Foo();<br />
// initializes using the default constructor<br />
// If you wanted to use another constructor,<br />
// you would declare it as "Foo a = new Foo(args);