Data Types Used in JAVA Vs C++
Data Types Used in JAVA Vs C++
SUBJECT-OOP
- -
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
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
Range Fractional no.(s) upto Fractional no.(s) upto True or False Stores single
6 decimals 15 decimals characters
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.
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!!!