C++ |
Java |
assignment operator=
|
cannot be user-defined for a class and performs assignment of a
reference to the instance of the class (see also reference types) |
basic_ string
|
String and StringBuffer
|
bool |
boolean |
char |
byte |
const variables/data members |
final variables/fields |
copy constructor |
no default; one implements the interface Cloneable by
the method Object clone(), which can be an abstract (in C++ notion:
virtual) method |
data members |
fields, so-called instance variables (a term borrowed from
Smalltalk) |
delete |
does not exist; all unreferenced memory is garbage
collected |
derived classes |
subclasses; the keyword extends replaces C++'s
colon. |
destructors ~Class
|
protected void finalize(); note, however, that these are
used for freeing resources other than memory and are therefore rarely
needed |
exceptions, try, catch, throw,
std:exception
|
same concept; Java adds a keyword throws that is used to
declare the exceptions a method throws; the hierarchy of exceptions is rooted in
java.lang.Exception; a finally block is introduced to contain
all common clean-up code. |
extern "C" functions |
native methods |
functions |
do not exist; static methods (``class methods'') are
used |
#include |
does not exist; the paths to the files are known and can be made
know in the CLASSPATH environment variable |
input/output: istream& operator», ostream&
operator«
|
System.in and System.out are the streams; Java
has number formatting tools in java. lang. Number and java. text.
Format. NumberFormat
|
main(int argc, char* argv[]) |
public static void main(String [] args) within a
public class |
member functions |
methods |
multiple inheritance |
does not exist; however, interfaces provide a weak form of
multiple inheritance. |
namespaces |
packages |
namespace
Namespace{ ...}
|
packagePackage; which must appear as the
first line in the file |
nested (member, inner) classes |
Java 1.1 has static (``top-level'') and non-static
(``member'') inner classes, as well as local classes and anonymous classes.
Member classes can refer to the members of the outer class and to
OuterClass.this; they cannot have the name of an outer class and
cannot declare static members. |
new Class(...)
|
new Class(...), which returns a
reference to the created object |
NULL (the 0 pointer value) and the type
void*
|
null in Java is a keyword and represents an
uninitialized reference |
overloaded operators |
do not exist; however, methods can be overloaded. This may be a
major shortcoming of Java, as one cannot revise old Java code by redefining the
operators used (cf. MITMatlab) |
passing arguments to base class constructor |
place the statement super(...); as the first
statement in the subclass's constructor |
public, private, protected
modifiers |
similar as in C++; visibility of classes and nested classes can
be also restricted; there are no friends, but within the same package protected
members are visible |
purely virtual member functions |
abstract methods; the enclosing class must also be
declared abstract
|
reference types Type&
|
all Java types except scalar primitive types are reference types;
note that the method void swap(T a,
Tb) { T t; t = a; a = b; b =
t;} does nothing to its arguments. |
scope resolution, operator ::
|
does not exist; methods must be defined inside the class
declaration. If a base class field is to be explicitly referred, one uses
typecasting:
((Baseclass)Variable).Member; a
direct base class member can be referred to by super.Member;
typecasting has no effect on methods (see virtual member
functions). |
static data members |
static fields, so-called class variables; they
are accessed by Class.Field rather than the C++
Variable.Member; they can be initialized by
=...; within the class definition and need not be declared
outside like C++ static data members. |
static member functions |
static methods, so-called class methods; they are
defined within the class declaration, unlike in C++. |
this |
this, which is a reference to the object and has the
type of the class, not a pointer; note that the call this(...); as the
first statement in a constructor invokes a constructor call for the matching
argument types. |
traits |
marker interfaces |
type_ id
|
instanceof; this is an operator returning a
boolean, not a ``type_ info'' as in
C++. |
using namespace Package;
|
import Package.*;
|
virtual member functions |
in Java, all methods use dynamic method lookup and therefore are
be default virtual. There is no way to explicity call an overridden base class
method, but overwriting can be prevented by declaring a method
final. |
wchar_ t
|
char |
wide character stream wostream
|
PrintWriter replaces PrintStream that cannot
hold unicode; the constructor of PrintStream has been deprecated in
Java 1.1, but System.out is not. |
Java concepts missing in C++ |
abstract windows toolkit AWT |
standard library for building a GUI |
concatenation of strings by + operator |
|
documentation comments |
can be processed (e.g., by javadoc) for automatic online
documentation |
final methods |
those cannot be overridden by a subclass |
interfaces |
are used to denote abstract classes without any method of their
own. They can have static final fields. One class can implement several
interfaces, but it must implement the abstract methods of each
interface. |
reflection |
allows the inspection of a class (which arguments does which
member take? etc.); this is critical for plug-and-play design, such as a Java
bean |
right shift operator with zero extension
>>>
|
|
serialization |
C++ requires the programmer to implement object serialization
member functions |
sockets |
|
threads |
|
C++ concepts missing in Java |
const member functions |
do not exist; final methods cannot be overridden by
subclasses |
friend classes, functions |
do not exist; however, protected members are visible
within the same package |
goto |
is a reserved work in Java, but is not supported by the language;
however break and continue statements can give a statement
label |
multiple inheritance |
virtual base classes seem unachievable by using
interfaces |
new(Pointer)
Type(...);
Pointer->~ Type();
|
this is C++'s explicit memory allocation mechanism. In Java, all
memory is managed by the VM and garbage collection is automatic. Thus, in C++, a
garbage collector can be implemented, while in Java a memory manager
cannot.¶ |
pointer types Type*
|
do not exist; actually, since Java has only reference types, all
variables are some kind of pointers and the = operator behaves like a
pointer assignment |
pointer to function, member |
not a serious restriction, as one may encapsulate a function in a
function object |
standard template library STL |
java.util.Vector provides an expandable vector. Java 1.2
provides Collections, which are essentially C++ STL
containers, but many of the members are renamed. Note that List is a
scrollable list in the AWT. There are third-party vendor container packages: See
http://reality.sgi.com/ austern_mti/java/index.html,
http://www.objectspace.
com/developers/jgl/downloads/index.html§ |
templates |
there is a the GJ compiler http://www.cs.bell-labs. com/~wadler/pizza/gj/.§
C++'s template expansion mechanism is a full-fledged programming language and
has been used for compiler optimization task (e.g., in the Blitz++ matrix
library) |
typedef |
asside as a shorthand, typedefs can be encapsulated in a
class scope to provide a generic type; they function as assignments in template
meta-programming. |
¶Laurent Bernardin points out that this isn't exactly
true: place all objects on arrays/lists for reuse |
§These references were provided by Thierry Gautier |
相关推荐
这本书《C++ for Java Programmers》是为具有一定经验的Java程序员所写,目的是让他们利用现有的面向对象编程知识,快速掌握标准C++的所有重要方面。书中强调了C++与Java之间的差异,并着重介绍了C++的底层C风格细节...
《C++ for Java程序员》是针对已有Java编程基础的学习者,想要深入了解或过渡到C++编程的一份资源。这份压缩包文件包含了一系列的教程、笔记和可能的实践项目,旨在帮助Java开发者理解C++的独特特性和语法差异,以便...
In C++11 for Programmers , the Deitels bring their proven Live Code approach to teaching today’s powerful new version of the C++ language. Like all Deitel Developer titles, they teach the best way ...
### C++11 for Programmers #### 概述 《C++11 for Programmers》是一本由Deitel & Associates, Inc.出版的书籍,作者是Paul Deitel和Harvey Deitel。本书作为Deitel® Developer Series系列的一部分,旨在帮助...
c++教育大师Paul J. Deitel09年最新力作,对c++的阐述巨细靡遗又深入浅出,并包括很多最新的软件工程、UML、编程工具包括Visual Studio的使用。目前网上只有CHM版,字体过小看起来很不方便,我费了很大功夫把它转为...
Written for programmers with a background in another high-level language, C++20 for Programmers applies the Deitel signature live-code approach to teaching Modern C++ and explores the C++20 language ...
Written for programmers with a background in high-level language programming, this book applies the Deitel signature live-code approach to teaching programming and explores the Java language and Java ...
《Java for Programmers 2nd Edition》是一本专为程序员设计的Java编程指南,其提供的“範例程式”旨在帮助读者深入理解Java编程语言的核心概念和技术。这些例子是学习和掌握Java编程的关键,通过实际代码的运行和...
Very useful book for anyone who wants to learn C++, not just for java programmers. The book has less than 300 pages, so it save you lots of time than reading a traditional C++ book that's usually ...
《Java for Programmers 2nd Edition》是一本针对已有编程经验的开发者编写的Java语言教程。这本书出版于2012年,旨在帮助程序员深入理解Java语言的核心概念、语法和应用,提升他们的编程技能。书中的内容不仅涵盖了...
C++ for Programmers: Deitel Developer Series by Paul Deitel, Harvey Deitel release type: eBook (.chm) release size: 4.80 MB Publisher: Prentice Hall PTR Pub Date: February 2, 2009 Print ...
Java 9 for Programmers (Deitel Developer Series) by Paul Deitel English | 16 May 2017 | ASIN: B071S84XCK | 1120 Pages | AZW3 | 83.11 MB The professional programmer’s Deitel® guide to Java® 9 and ...
《TCP/IP Sockets in Java 实践程序员指南》这本书专注于Java平台上的网络编程,特别是TCP/IP套接字的应用。TCP/IP是互联网通信的基础,而Java中的套接字(Sockets)接口为开发者提供了实现网络通信的工具。这本书...
In C++11 for Programmers , the Deitels bring their proven Live Code approach to teaching today’s powerful new version of the C++ language. Like all Deitel Developer titles, they teach the best way ...
《Java SE8 for Programmers》是关于Java标准版(Standard Edition)第8版的程序员指南书籍,是Deitel开发者系列的第三版。这本书面向那些希望通过Java SE8版本进行软件开发的专业程序员。Java SE8是Java编程语言的...
Extending C++ with .NET Features In a very similar way, C++/CLI is layered on top of C++. C++/CLI provides a high degree of source code compatibility with C++. As a consequence, the following code is ...
C++ for Lazy Programmers - Will Briggs
C++ 11 for Programmers(2nd) 英文epub 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除