Help Us Improve. Please let us know if you were asked any of these questions.

More Questions

Java - Interview Questions and Answers on Data Types

Q1.  What are the Wrapper classes available for primitive types ?

Ans. 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

Q2.  Difference between long.Class and Long.TYPE ?

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

Q3.  What are wrapper classes ?

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

Q4.  What is casting?

Ans. 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

Q5.  What are the default or implicitly assigned values for data types in java ?

Ans. boolean ---> false
byte ----> 0
short ----> 0
int -----> 0
long ------> 0l
char -----> /u0000
float ------> 0.0f
double ----> 0.0d
any object reference ----> null

Q6.  What is the advantage of using arrays over variables ?

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

Q7.  What are the disadvantages of using arrays ?

Ans. 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 requriment we need to code explicitly

Q8.  Advantage of Collection classes over Arrays ?

Ans. 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. 

Q9.  What are the Disadvantages of using Collection Classes over Arrays ?

Ans. 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 concurrentModificationException.

Q10. What is the difference between Data Type and Data Structure ?

Ans. 

Data type: a set of values together with operations on that type 
Data structure: a physical implementation of a data type


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

Ans. No.

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

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

Ans. 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. 

 Stay Updated with Java Posts directly to your mailbox.
Enter your email address:

'
Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.