Most of the developers previously have experience
with an object-oriented programming language such as C++. While you
make the changeover to Java, you will come upon lots of differences, in
spite of some deep similarities.
In this article, we will discuss
the major differences that C++ programmers should know. These
components or differences will also be logically analyzed in this
article.
As a C++ programmer, you must the fundamental idea of
object-oriented programming, and the syntax of Java undoubtedly appears
familiar to you. This fact is logically strong since Java was derived
from C++. Still, there are a storming number of differences between C++
and Java.
Such differences are planned to be major improvements,
and if you recognize the differences you'll see why Java is such a
helpful programming language and its advantages over other programming
languages.
This article will make clear the important features that differentiate Java from C++.
Speed: The
biggest potential stumbling block is speed: interpreted Java runs in
the range of 20 times slower than C. Nothing forecloses the Java
language from being compiled and there are just-in-time compilers
coming out at this writing that offer important speed-ups. It is not
implausible that full native compilers will appear for the more
accepted platforms, but without those there are classes of issues that
will be unsolvable with Java because of the speed issue.
Comments: Java has both kinds of comments like C++ does.Â
Class:
Everything must be in a class. There is no global function or global
data. If you require the equivalent of globals, make static technique
and static data within a class. There are virtually no structs or
enumerations or unions, only classes.
Functionality: All
method definitions are defined in the body of the class. Therefore, in
C++ it would appear like all the functions are inlined, but they're not
(inlines are noted afterward).
Class definitions: Class
definitions are roughly the same form in Java as in C++, but there's no
closing semicolon. Basically there are no class declarations of the
form class foo, only class definitions.
class aType {
void aMethod( ) { /* method body */ }
}
Scope resolution:
There's no scope resolution operator :: in Java. Java utilizes the dot
for everything, but can get missing with it since you can describe
elements only within a class. Still the method definitions must always
happen within a class, so there is no requirement for scope resolution
there either. A single place where you'll observe the difference is in
the calling of static methods: you say ClassName.methodName( );.
Besides this, package names are recognized using the dot, and to carry
out a kind of C++ #include you use the import keyword. For example:
import java.awt.*;. (#include does not straight map to import, but it
has a related feel to it.
Primitive Type: Java, like C++,
has primitive types for efficient access. In Java, there are char,
boolean, byte, short, int, long, float, and double. The entire
primitive types have specified sizes that are machine autonomous for
portability. (This must have drive on performance, varying with the
hardware.) Type-checking and type requirements are much strict in Java.
For example:
- Conditional expressions can be only boolean, not integral.
- The result of an expression like X + Y must be used; you can't just say "X + Y" for the side effect.
Characters:
The char type uses the international 16-bit Unicode character set, so
it can automatically represent most national characters, ), as told by
your C++ Tutor.
Strings:
Static quoted strings are automatically converted into String objects.
There is no autonomous static character array string similar to there
is in C and C++.
Right Shift: Java adds the triple right
shift >>> to act as a "logical" right shift by inserting
zeroes at the top end; the >> inserts the sign bit as it shifts
(an "arithmetic" shift).