Updates

Java - Interview Questions and Answers on Data Types

Published On: 3/24/2023
Author: Admin
Share Now

What is meant by primitive type?

Data types packaged with core programming language are called as primitive data types.

What are wrapper classes ?

They are wrappers to primitive data types. They allow us to access primitives as objects.

What are the Wrapper classes available for primitive types ?

boolean - java.lang.Boolean
byte - java.lang.Byte
char - java.lang.Character
double - java.lang.Double
float - java.lang.Float
int - java.lang.Integer
long - java.lang.Long
short - java.lang.Short
void - java.lang.Void

Explain Boolean data type in Java!

Boolean data type is primitive type which comes bundled with core programming language. Boolean data type can have only true or false value.

Example:
int num1=10;
int num2=20;

boolean b1=true;
boolean b2=false;

if(num1 {
System.out.println(b1);
}
Else
{
System.out.println(b2);
}

Difference between long.Class and Long.TYPE ?

They both represent the long primitive type. They are exactly the same.

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

What is default or implicitly assigned value for Boolean data type in Java?

“False” is default value assigned to Boolean data type.

What is default or implicitly assigned value for byte data type in Java?

“0” is default value assigned to byte data type.

What is default or implicitly assigned value for short data type in Java?

“0” is default value assigned to Short data type.

What is default or implicitly assigned value for int data type in Java?

“0” is default value assigned to Int data type.

What is default or implicitly assigned value for long data type in Java?

“0L” is default value assigned to long data type.

What is default or implicitly assigned value for char data type in Java?

“/u0000” is default value assigned to char data type.

What is default or implicitly assigned value for float data type in Java?

“0.0f” is default value assigned to float data type.

What is default or implicitly assigned value for double data type in Java?

“0.0d” is default value assigned to double data type.

What is the advantage of using arrays over variables?

Arrays provide a structure wherein multiple values can be accessed using single reference and index. This helps in iterating over the values using loops.

What are the disadvantages of using arrays ?

Arrays are of fixed size and have to reserve memory prior to use. Hence if we don't know size in advance arrays are not recommended to use.

Arrays can store only homogeneous elements.

Arrays store its values in contentious memory location. Not suitable if the content is too large and needs to be distributed in memory

There is no underlying data structure for arrays and no ready made method support for arrays, for every requirment we need to code explicitly

Advantage of Collection classes over Arrays ?

Collections are re-sizable in nature. We can increase or decrease the size as per recruitment.Collections can hold both homogeneous and heterogeneous data's.Every collection follows some standard data structures.

Collection provides many useful built in methods for traversing,sorting and search

What are the Disadvantages of using Collection Classes over Arrays ?

Collections can only hold objects, It can't hold primitive data types.Collections have performance overheads as they deal with objects and offer dynamic memory expansion. This dynamic expansion could be a bigger overhead if the collection class needs consecutive memory location like Vectors.

Collections doesn't allow modification while traversal as it may lead to concurrent Modification Exception.

What is the difference between Data Type and Data Structure ?

Data type: a set of values together with operations on that type

Data structure: a physical implementation of a data type

Is it correct to say that Interfaces are abstract data types ?

No.

Data Type holds data whereas Interface doesn't hold anything. Interface is a contract about how to communicate with the underlying Class.

Do you see Class as a Data Type or Data Structure ?

Class can be better seen as Data Type. This could be implemented as a Data Structure too in some cases.

One thing worth understanding here is that Data type and Data structure are conceptual things. Class could be implementation of either of these.

#java #javaprogramming #interviewQuestions #preparation #pragramming

Practice Tests Available

Currently no practice papers available for above exam. We are working on it and tests will be available soon.

Advertisement

Subjects (Free Online Tests)

Your Comment:
Name :
Comment :
(0) Comments:

 Full Length Mock Tests
 Answers with Explanation**
 Timer Based Exams
 Instant Result and assesment
 Detailed analasys of Result