Java Interview Questions With Answers – Part 4

[1][2][3][4] – Here’s part 3 of some Java Interview Questions. The level of questions is suitable for beginners as well advanced core Java programmers. This part covers Java Arrays and Datatypes in Java.

Java-Arrays-Interview-Questions

The series includes more than 200 questions, so stay tuned for more.

Q41. What is the range of a short type?

A41. –32,768 to 32,767

Q42. What is the range of a byte type?

A42. -128 to -127

Q43. Floating-point numbers can be represented in which two notations?

A43. Floating-point numbers is represented in the following two notations: Standard Notation and Scientific Notation

Q44. Explain standard notation for floating point numbers?

A44.  Standard notation for floating point numbers has a whole number followed by a decimal point, which is then followed by a fractional component. For example, 5.0, 2.34285, etc.

Q45. Explain scientific notation for floating point numbers?

A45. Scientific notation uses standard-notation floating-point number followed by a suffix.
In this notation, exponent can be seen that is indicated by an E or e. The exponent is then followed by a decimal number. This number can be positive or negative.

For example,  1.175494E-38

Q46. Define a variable in Java and give an example of how it is declared and initialized?

A46. Variable is the basic unit of storage.
For example, int z = 5;
Here, z is variable name
z initialized to value 5

Q47. How to initialize a variable dynamically in Java?

A47. double var1 = 3.0, var2 = 4.0;
double result = Math.sqrt(var1 *var1 + var2 * var2);

Q48. In what conditions, Java automatically performs type conversions (Automatic Conversion)?

A48. Here are the two conditions,

  • The two types should be compatible with each other.
  • Destination data type should be larger than the source type.

For example, int data type is larger than byte

Q49. Java Automatic conversion is also called ____________ conversion?

A49.  It is also called Narrowing Conversion.

Q50. In Java, how do you cast incompatible types and why it is needed?

A50. If the destination data type is smaller than the source type, then use cast. For example, int data type (destination) is smaller than double (source), so conversion of double to int would need cast,

int z = 50;
double y = 110.130;
z = (int) y;

  Q51. What is the role of new operator in the following code snippet that shows one-dimensional Java arrays?

            int rank_points[];

rank_points = new int[5];

A51.  In the above array, new operator allocates memory.

Q52. All arrays in Java are dynamically allocated? True or false?

A52. True

Q53. How will you initialize the elements for the array given in Q51.?

A53.      rank_points[0] = 500
rank_points[1] = 400
rank_points[2] = 300
rank_points[3] = 200
rank_points[4] = 100

Q54. How the array given above can be initialized without using new operator?

A54.  int rank_points[] = { 500, 400, 300, 200, 100 };

Q55. Declare a multi-dimensional array in Java?

A55. int prod [][]= new int[2][3];

Q56. Are both the declarations of one-dimensional arrays in Java same?

         1.)   int rank_points[] = new int[5];

         2.)   int [] rank_level = new int[5];

A56. Yes, both are same. The second way i.e. int [] rank_points = new int[5]; is another way of declaring one-dimensional array in Java.

Q57. What are multi-dimensional arrays?

A57. Multi-dimensional arrays are arrays that has more than one dimension i.e. arrays of arrays.

Q58. Are both the declarations of two-dimensional arrays in Java same?

         1.)   int prod [][]= new int[2][3];

         2.)   int [][] dept = new int[2][3];

A58. Yes, both are same. The second way i.e. int [][] dept = new int[2][3]; is another way of declaring two-dimensional array array in Java.

Q59.  Java supports Pointers? True or False?

A59. True

Q60. Is this a disadvantage of Java that it does not allow Pointers?

A60. It’s not a disadvantage, since Java is designed in a way that it does not need the support of pointers.

[1][2][3][4]

Comments

comments

thegenericwhiz@gmail.com'

GW Editorial Staff

Editorial Staff at Generic Whiz.

4 thoughts on “Java Interview Questions With Answers – Part 4

Leave a Reply

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