UNIVERSITY OF INFORMATION TECHNOLOGY
AND MANAGEMENT IN RZESZÓW, POLAND
Faculty: INFORMATION TECHNOLOGY
Specialty: ADVANCED PROGRAMMING
Differences between C++ and Java
Supervisor: Student:
mgr Aleksandra Czyżowska Marochkancyh Mariia, w60105
Rzeszów 15.11.2020
Content
Differences between C++ and Java___________________________________________________3
Primitive types__________________________________________________________________3
Strings________________________________________________________________________3
Testing and Equality_____________________________________________________________3
main Method (Function) and Other Methods__________________________________________3
Class and Method (Function) Definition______________________________________________3
No Pointer Types in Java__________________________________________________________3
Arrays_________________________________________________________________________3
Portability_____________________________________________________________________3
Hardware______________________________________________________________________4
Other Comparisons______________________________________________________________4
Vocabulary_______________________________________________________________________4
Questions________________________________________________________________________6
Summary_________________________________________________________________________6
Literature________________________________________________________________________7
2
Differences between C++ and Java
Primitive types
Java has most of the same basic primitive types as C and C++ (int, short, long, float, double, and char),
but Java adds the types byte and boolean. The Java type boolean corresponds to the C++ type bool. Java
has no type named long double. Unlike C and C++, in Java the size, in bytes, of a value for some specific
primitive type is fully specified and is not implementation dependent.
Strings
Unlike some versions of C and C++, in Java strings are not special kinds of arrays of characters. Java has
a class String that serves as a predefined type. String is somewhat similar to the class String in recent
versions of C++.
Testing and Equality
Testing objects of a class type for equality can be troublesome in Java. With values of a primitive type,
the == operator tests for equality, as you might expect. However, when you use == to compare two
objects of a class type, the addresses of the objects are compared instead of their data. Java classes often
define a method called equals to test objects for our intuitive idea of equality. You cannot overload the
== operator (or any operator) in Java.
main Method (Function) and Other Methods
Functions are called methods in Java. The main method serves the same purpose in Java as the main
function in C and C++. In Java, the main method heading is always as follows:
public static void main(String[] Parameter_Name)
In Java, all methods are defined inside of a class, as is code of any kind.
Class and Method (Function) Definition
In Java, all methods must be defined in some class. Additionally, a class definition can be fully defined
in one file. Java has no required header, or .h, file, as do C and C++. In particular, all method definitions
are given in their entirety in their class definition. Java does provide for an interface, which is similar in
form to a header file in C and C++ but serves a different purpose.
No Pointer Types in Java
There are no pointer types in Java. Java does have pointers; in fact, all objects are named by means of
pointers. However, the pointers are called references, and they are handled automatically. For example, a
variable of type String will contain a reference (pointer) to a string, but there is no type for a pointer to a
String.
Arrays
Java arrays are very much like C or C++ arrays, but there are some differences, and Java arrays are better
behaved. An array in Java “knows” its range. If a is an array, the instance variable a.length contains an
integer equal to the number of elements that the array can hold. Java ensures that the values of array
indices (subscripts) are valid, and an exception is thrown if your code attempts to use an array index that
is out of range.
Portability
C++ code is not portable. It must be compiled for each platform. Java, however, translates the code
into byte code. This byte code is portable and can be executed on any platform.
3
Hardware
C++ is close to hardware and has many libraries that can manipulate the hardware resources. Because of
its closeness to hardware, C++ is often used for system programming, gaming applications, operating
system, and compilers.
Java is mostly an application development language and is not close to the hardware.
Other Comparisons
Comments in Java and C++ are essentially the same
There are no global variables in Java.
Java has no structures or unions.
Java has no multiple inheritance, but interfaces provide much of the functionality of multiple
inheritance.
You can overload methods(function) named in Java, as you can in C++, but you cannot overload
operators in Java.
Java has no templates, but it does have generics in their place.
Java has no destructors.
Vocabulary
Word Translation to Polish Meaninge
language
Implementation Wdrożenia The process of putting a decision or
plan into effect; execution.
Equality Równość A symbolic expression of the fact that
two quantities are equal; an equation.
String Ciąg Is a sequence of characters, either as a
literal constant or as some kind of
variable.
Class Klasa A data type in object-oriented
programming that consists of a group
of objects.
Object Obiekt A data structure in object-oriented
programming that can contain
functions as well as constants,
variables, and other data structures.
Operator Operator Something and especially a symbol
that denotes or performs a
mathematical or logical operation.
Function Funkcja A computer subroutine, one that
performs a calculation with variables
provided by a program and supplies
the program with a single result.
Pointer Wskaźnik A computer memory address that
contains another address (as of desired
data).
Reference Referencja Constituting a standard for measuring
or constructing.
Arrays Tablice A data structure in which similar
4
elements of data are arranged in a
table.
Indices Indeksy An arrow-shaped piece on a dial or
scale for registering information.
Exception Wyjątek A case to which a rule does not apply.
Attempts Próbowanie To make an effort to do, accomplish,
solve, or effect.
Variable Zmienna Symbol representing a variable.
Structure Struktura Is a group of different data types under
a single name.
Union Unia Is a value that may have any of several
representations or formats within the
same position in memory.
Overload Przeciążenie It means that you are providing a
function (method or operator) with the
same name, but with a different
signature.
Destructor Samolikwidator Is a method which is invoked
mechanically just before the memory
of the object is released.
A comment Komentarz Is a programmer-readable explanation
or annotation in the source code of a
computer program.
Type Typ Is an attribute of data which tells the
compiler or interpreter how the
programmer intends to use the data.
Inheritance Dziedziczenie Is a process of defining a new class
based on an existing class by
extending its common data members
and methods.
Interface Interfejs Is a device or a system that unrelated
entities use to interact.
Platform Platforma Is a group of technologies that are
used as a base upon which other
applications, processes or technologies
are developed.
Byte Bajt The basic unit of information in
computer storage and processing.
Code Kod Is a term used to describe text that is
written using the protocol of a
particular language by a computer
programmer.
Hardware Sprzęt komputerowy Tools, machinery, and other durable
equipment.
Library Biblioteka Is a collection of precompiled routines
that a program can use.
Systems programming Programowanie systemów Involves the development of the
5
individual pieces of software that
allow the entire system to function as a
single unit.
Operating system (OS) System operacyjny Is system software that manages
computer hardware, software
resources, and provides common
services for computer programs.
Compiler Kompilator Is a computer program that translates
computer code written in one
programming language into another
language.
Questions
1) What are the differences between C ++ and Java? List 5 of them.
2) What primitive types are there in Java?
3) Which Java boolean value corresponds to a C ++ value?
4) What class serves as a predefined type in Java?
5) What operator in Java checks for equality?
6) What can't be done with any of the Java operators?
7) Does the main method serves the same purpose in Java as the main function in C and C++? What
the main method heading in Java looks like?
8) What should you know about similar in classes and methods in Java and C ++?
9) Does Java have the required header, like C and C ++?
10) Are there pointer types in Java? What else are pointers in Java called?
11) What does Java ensure for arrays?
12) Is C++ code is portable?
13) Why is C ++ often used because of its closeness to hardware?
14) Are Java and C ++ comments the same?
15) What can not be overloaded in Java and what in C ++?
Summary
Java and C ++ have many similar primitive types (int, short, long, float, double and char), and Java
also has byte and boolean. In Java, there is a String class that serves a predefined type. And this class is a
bit like the String class in the latest versions of C ++. In Java the operator == means equality which it
checks. But when to compare two objects of type class the operator compares addresses of these objects,
instead of their data. Also it is impossible to overload the operator == in Java. Functions in Java are
called methods. All methods in Java are inside a class. And the main heading of methods is : public static
void main(String[] Parameter_Name). In Java, all methods are defined in a class. In Java there is no
header or .h file, as in C ++. Java does not have types of pointers. But in Java objects are called by
pointers. Pointers are called references. Arrays have similarities in both C ++ and Java. In Java, the
values of array index are valid, and this is guaranteed by this programming language. In Java, bytecode
is portable and can be used on any platform, but this is not possible in C ++. C ++ has libraries that
manipulate hardware resources. C ++ is used for operating systems, system programming and games.
And Java is used to develop applications. In Java and C ++ you can overload methods. In Java there are
6
no global variables, structures, templates, multiple inheritance, and destructors. In Java and C ++ the
same comments.
Literature
Java. Ann Introduction to Problem Solving & Programming
Starting Out with C++ from Control Structures Through Objects” 8th Edition, by Tony Gaddis, 2014
https://www.softwaretestinghelp.com/cpp-vs-java/
https://www.educba.com/c-plus-plus-vs-java/