0% found this document useful (0 votes)
135 views23 pages

Data Types Used in JAVA Vs C++

The document compares data types in Java and C++. [1] In C++, data types are categorized into built-in, derived, and user-defined types, while Java categorizes them as primitive and non-primitive. [2] The main primitive types in Java include boolean, char, integer, and floating-point types, while C++ distinguishes between integral and floating-point built-in types. [3] The sizes of char types differ between the two languages, and Java arrays are aware of their size while C++ arrays are not.

Uploaded by

Phadtare Tejas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views23 pages

Data Types Used in JAVA Vs C++

The document compares data types in Java and C++. [1] In C++, data types are categorized into built-in, derived, and user-defined types, while Java categorizes them as primitive and non-primitive. [2] The main primitive types in Java include boolean, char, integer, and floating-point types, while C++ distinguishes between integral and floating-point built-in types. [3] The sizes of char types differ between the two languages, and Java arrays are aware of their size while C++ arrays are not.

Uploaded by

Phadtare Tejas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Vishwakarma Institute of Technology

SUBJECT-OOP

DATA TYPES USED IN JAVA VS C++


33 Vishwajeet Pawar 12011287
BY: PRA_B3_group1
34 Tejas Phadtare 12010300
35 Vinayak 12010375
Phulambrikar
36 Rohan Pisal 12011214 GUIDE: RAJASHREE
37 Sanmit Pise 12010604 AKOLKAR MAM
CONTENT
Introduction
Block Diagrams
Data types in C++
Data types in JAVA
Difference between data types in C++ Vs Java
References
INTRODUCTION
Datatypes Definition :
 Data types define the type of data a variable can hold,
for example an integer variable can hold integer data, a
character type variable can hold character data and it can
also of the type string or an object of a custom class.
Syntax : data type_variable name;
Example : int a = 10; or char c = ‘a’; or float f = 1.02;
DATA TYPES IN C++ ARE CATEGORISED IN THE
FOLLOWING GROUPS
Data types in java are categorised in the following groups
1.BUILT-IN DATA TYPE:
1.Built-in Data types

Integral Character Float Double Void

Keyword int char float double void

Memory 4 bytes 1 byte 4 byte 8 byte 4 byte


space

- -
21474836 -128 to 127 -3.4e38 to 1.7e308 to 214748364
Range 48 to or 0 to 255 +3.4e38 8 to
+1.7e308 214748364
21474836
47 7
2.User defined Datatype:
1) Structure: It allows to combine the data items of different kinds.

Keyword : struct
Syntax :
Struct [structure tag]
{
Member definition;
Member definition;
….. Member definition;
} [one or more structure variables];
2.User defined Datatype:
2) Union: In this datatype all the members share the same memory
location. We can define a union with many members, but
only one member can contain a value at any given time
Syntax :
Union [union tag]
{
Member definition;
Member definition;
…. Member definition;
} [one or more union variables];
2.User defined Datatype:
3) Class: It is the building block of C++. It holds its own data members and
member functions, which can be accessed and used by creating an instance of
that class.

Keyword : class
Syntax :
Class ClassName
{
Access specifier: //can be private, public
or protected
Data members; //Variables to be used
Member Functions{} //Methods to access
data members
};
2.User defined Datatype:
4) Enumeration: It is mainly used to assign names to integral
constants, the names make a program easy to read and maintain.

Keyword : enum
Syntax:
enum enum_name {const1, const2, const3,..., const-n};

Example-
Enum State { Working =1 , Failed =0};
3.Derived Datatype :
1) Function: A function is a block of code that is defined to perform a
specific well-defined task. A function is generally defined to save the
user from writing the same lines of code again and again for the
same input. main() is a default function that is defined in every
program of C++.

Syntax :
FunctionType FunctionName(parameters)
3.Derived Datatype :
2) Array: An array is a collection of items stored at continuous
memory locations. The idea of array is to represent many instances
in one variable.

Syntax :
DataType ArrayName[size_of_array];
3.Derived Datatype :
3) Pointer: It is the special variable used to store the address of
another variable. They enable programs to simulate call-by-reference
as well as to create and manipulate dynamic data structures.

Syntax :
datatype *var_name;
DATA TYPES IN JAVA

A] Primitive data types:

1. Boolean Type –
2. Numeric Type – A. Character Value –
B. Integral Value –
1. Integer
2. Floating-Point
1. Integer types : 1. Byte
2. Short
3. Int
4. Long

2. Floating-Point : 1. Float
2. Double
Data type Byte Short Int Long

Memory space 1 byte 2 byte 4 byte 8 byte

Range -128 to 127 32768 to 32767 -2147483648 -


to 922337203685
2147483647 4775808 to
922337203685
4775807

Syntax byte byteVar; short shortVar; int intVar; long longVar;


Data type Float Double Boleean Char

Memory space 4 byte 8 byte 1 bit 2 byte

Range Fractional no.(s) upto Fractional no.(s) upto True or False Stores single
6 decimals 15 decimals characters

Syntax float floatVar double boolean


doubleVar; booleanVar; char charVar;
B]Non-primitive data types :
1) Strings :
Syntax - <String_Type> <string_variable> = “<sequence_of_string>”;
Ex - char ch={“java”};
2) Array : 
Syntax - dataType []arr;
Ex- int arr[]={33,3,4,5}; 

3) Object :
Syntax - className object = new className();
Example - Bicycle sportsBicycle = new Bicycle();
4) Class :  
1. Modifiers
2. Class name
3. Superclass(if any)
4. Interfaces(if any)
5. Body 
DIFFERENCE
C++ Data type JAVA Data type

1.It is classified into 3 types: Built-in, Derived and 1.It is classified into 2 types: Primitive and Non-
User defined data type. Primitive data type.

2. Here Integral and Floating are built-in data types. 2. Here Integral and Floating are primitive data types.

3. Size of char is 1 byte. 3. Size of char is 2 byte.

4.Here array is not aware of its size. 4.Java array is aware of its size.

5.C/C++ Strings are terminated with null character. 5.Java Strings are not terminated with the null
character.

6. These data types cannot be changed with Wrapper 6. These data types can be interchanged with
classes. Wrapper classes.
REFERENCES

 
 https://www.geeksforgeeks.org/data-types-in-java/
  https://www.w3schools.com/java/java_data_types.asp
 https://www.geeksforgeeks.org/c-data-types/
 https://appdividend.com/2019/06/28/c-data-types-tutorial-data-types-in-c-example/
 https://www.javatpoint.com/array-in-java
THANK YOU!!!

You might also like