Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Data types in java
1.
2.
3. Data types specify the different sizes and
values that can be stored in the variable.
There are two types of data types in Java:
Primitive data types: The primitive data types
include boolean, char, byte, short, int, long,
float and double.
Non-primitive data types: The non-primitive
data types include Classes, Interfaces,
and Arrays.
4. In Java language, primitive data types are the building
blocks of data manipulation. These are the most
basic data types available in Java language.
There are 8 types of primitive data types:
boolean data type
byte data type
char data type
short data type
int data type
long data type
float data type
double data type
5.
6. Non-primitive, or reference data types, are the more
sophisticated members of the data type family. They don't store
the value, but store a reference to that value.
A class is a set of plans for a given object. There are thousands
of tree objects, but the parent set of plans would belong in the
tree class. Variables can exist inside the tree class, such as
height or tree type. These are reference variables.
An array is a single object that contains multiple values of the
same type. We could have declared our integer for part Numbers
as an array to hold a given number of part Numbers in a single
object.
An interface is like a dashboard or control panel for a class. It
has the buttons, but the function is elsewhere. We won't go into
detail on implementing interfaces since the focus is on the
interface as a non-primitive, or reference, data type.
7. The process of converting the value of one data type
(int, float, double, etc.) to another data type is known
as typecasting.
Implicit type casting means conversion of data types
without losing its original meaning. This type of
typecasting is essential when you want to change
data types without changing the significance of the
values stored inside the variable.
In implicit type conversion, the data type is converted
automatically. There are some scenarios in which we
may have to force type conversion. Suppose we have
a variable div that stores the division of two operands
which are declared as an int data type. This type of
conversion is called explicit type casting.
8. Converting one primitive data type into another is known
as type casting (type conversion) in Java. You can cast the
primitive data types in two ways namely, Widening and,
Narrowing.
Widening − Converting a lower data type to a higher data
type is known as widening. In this case the
casting/conversion is done automatically therefore, it is
known as implicit type casting. In this case both data types
should be compatible with each other.
Narrowing − Converting a higher data type to a lower data
type is known as narrowing. In this case the
casting/conversion is not done automatically, you need to
convert explicitly using the cast operator “( )” explicitly.
Therefore, it is known as explicit type casting. In this case
both data types need not be compatible with each other.
9. Autoboxing: Converting a primitive value into an object of the
corresponding wrapper class is called autoboxing. For example,
converting int to Integer class.
Autoboxing: Converting a primitive value into an object of the
corresponding wrapper class is called autoboxing. For example,
converting int to Integer class.
Eg. Integer i = new Integer(10);
// unboxing the Object
int i1 = i;
System.out.println("Value of i: " + i);
System.out.println("Value of i1: " + i1);
//Autoboxing of char
Character g = 'a';
// Auto-unboxing of Character
char ch = g;
System.out.println("Value of ch: " + ch);
System.out.println("Value of g: " + g);