In this video, we discuss interview questions on Java Data Types. This is part 1 of interview questions on data types.
What are variable types?
Variable types can be any data type that java supports, which includes the eight primitive data types, the name of a class or interface and an array.
Name the eight primitive Java types.
The eight primitive types are byte, char, short, int, long, float, double, and boolean.
What is casting?
There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.
Are arrays primitive data types?
In Java, Arrays are objects.
What are Primitive Literals?
Primitive Literals are the code representation of values of primitive data types. For example 'a' is a char literal, 100 is an int literal, 'false' is a boolean literal and 2345.456 is a double literal.
To what value is a variable of the boolean type automatically initialized?
The default value of the boolean type is false.
What is type conversion in java?
Assigning a value of one type to variable of other type is called type conversion.
Example:
int a =10;
long b=a;
There are two types of conversion in java:
1) Widening conversion
2) Narrowing conversion
Explain about Automatic type conversion in java?
Java automatic type conversion is done if the following conditions are met :
1) When two types are compatible
Ex: int, float
int can be assigned directly to float variable.
2) Destination type is larger than source type.
Ex: int, long
Int can be assigned directly to long. Automatic type conversion takes place if int is assigned to long because long is larger datatype than int. Widening Conversion comes under Automatic type conversion.
Explain about narrowing conversion in java?
When destination type is smaller than source type we use narrowing conversion mechanism in java. Narrowing conversion has to be done manually if destination type is smaller than source type.
To do narrowing conversion we use cast. Cast is nothing but explicit type conversion.
Example:
long a;
byte b;
b=(byte)a;
Note: casting to be done only on valid types otherwise classcastexception will be thrown.
Difference between double and float variables in Java.
In java, float takes 4 bytes in memory while Double takes 8 bytes in memory. Float is single precision floating point decimal number while Double is double precision decimal number.
On this page of the site you can watch the video online 4A. Java Basics for Selenium - Java Data Types - Interview questions - Part 1 with a duration of hours minute second in good quality, which was uploaded by the user subbus tech 03 March 2019, share the link with friends and acquaintances, this video has already been watched 49 times on youtube and it was liked by 1 viewers. Enjoy your viewing!