Part 2: Java Interview Questions And Answers!

If you to know about Java interview questions then this blog is for you. Join the Java training institutes in Pune and make a successful career in this field.


1) What is the right data type for representing a price in Java?

If memory is not to be considered and performance is of no importance then the right data type to represent a price in Java is BigDecimal or else double with predefined precision is the right choice.

2) How would you convert bytes to String?

You can use the Strong constructor for accepting byte[] for converting bytes to String. The platform’s default character encoding will be used and it is important to be mindful of the right character encoding which may not be sure all the time.

3) Can an int value be cast into a byte variable? What is possible if the value of int is greater than byte?

Yes, it is feasible but in Java int is 32 bit long while byte is 8 bit long in Java. If you can cast an int to byte higher, 24 bits are gone and a byte can only have a value between 128 to 128.

4) Which class consists of methods: Object or Clonable?

The market interface also is known as Java.lang. Cloneable and it does not have any method. In the object class, the clone method is well defined. Make a note that clone() is a native method and it is applied in C or C++ or any other programming language.

5) Does Java contain thread-safe operation?

In Java ++ is not thread-safe as it contains lots of commands like reading a value, implicating it and then restoring it into memory. It can be overlapped between multiple threads.

6) Can a double value be stored in a long variable without casting?

No it is not possible for storing a double value within a long variable without casting as the range of a double is big and it means you need to typecast.

7) Which one will have more memory: int or integer?

For storing metadata overhead about the object, integer object will take memory. An int is primitive as it takes less space.

8) The reason behind immutable String in Java?

In Java, String is immutable because the Java designer thought that String will be used mostly and made it immutable. There are few optimization easy sharing in it and the same String object between various clients.

9)  Can we use String in the switch case?

From the 7th version of Java, it is possible. It can be used even in switch case but it is just syntactic sugar with internal string hash code used for switching.

Join the Best Java training in Pune and make a successful career in this field.

YOU CAN ALSO READ:  Part 1: Java Interview Questions And Answers!

Posted in IT

One thought on “Part 2: Java Interview Questions And Answers!”

  1. Hey
    Thank you for sharing such a interesting blog about “Part 2: Java Interview Questions And Answers! ”
    Very useful blog
    Keep sharing
    Keep up the good work!

Leave a Reply

Your email address will not be published. Required fields are marked *