Top Advanced Java Interview Questions and Answers

    11 Votes

41) Can you explain about strictfp keyword in Java ?

If we want floating point values to be consistent across platforms, then we need to use "strictfp" as per IEEE 754 standard. When a program runs on multiple platforms, precision of floating point differ which in turn given different results. strictfp helps to enforce the precision across all platforms. For example

Class Level - public strictfp class StrictFpModifierExample{}
Method Level - public strictfp void example() {}

42) Can you explain about String pool ?

String Pool is a pool of strings stored in Java heap memory. String objects can be created either by new operator or by specifying the values in double quotes. 

Case 1 : When a new string is created using double quotes, JVM searches string pool for the string with the same value. if it finds a string which matches the values, it will return the reference of the string. Else it will create a new string in the pool and returns that reference.

String s1 = "Cat"; 
String s2 = "Cat";
if(s1 == s2) System.out.println("equal"); //Prints equal.

Case 2 : When new operator is used to create a string, String class will be forced to create a new String object. To put the newly created string into the pool or assign it to another string, use intern(). 

String n1 = new String("ABCD"); 
String n2 = new String("ABCD");
if(n1 == n2) System.out.println("equal"); //No output.

43) Differences between String, StringBuffer and StringBuilder in Java ?

Immutable Mutable mutable
String operations such as append would be less efficient String operations such as append would be more efficient, String operations such as append would be more efficient
- synchronized Not synchronized.
- versions 1.4 or below you’ll have to use StringBuffer. StringBuilder was introduced in Java 1.5

44) What are the advantage of using unicode characters ?

  • Much larger number of characters or group of characters
  • Contains some non western European characters
  • Supported by all modern technologies
  • Enhance integration opportunities
  • Easy conversion from legacy code pages

45) Can you explain about literals in Java ?

Literals are used to represent a fixed value in source code. Literals don't require computation. For Example, we will have a look at using literals to assign a value to an int variable.

int Days = 7;

46) Is it possible to override an overloaded method in Java ?

Yes. We can override an overloaded method if that method in not a static or final.

47) What is the maximum size of an int ?

-(2 power 31) to (2 power 31-1) or -2,147,483,648 to 2,147,483,647

48) Can you explain about autoboxing and unboxing in Java ?

When primitive data types are automatically converted into it's  wrapper type, it is called boxing. The opposite operation of converting wrapper class objects to it's primitive type is known as unboxing.

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1); //autoboxing - primitive to object
int number = list.get(0); // unboxing

49) How to change the heap size of a JVM ?

The old generation's default heap size can be overridden by using the -Xms and -Xmx switches to specify the initial and maximum sizes respectively:

Format - java -Xms <initial size> -Xmx <maximum size> program
Example - java -Xms64m -Xmx128m Myprogram
Page 5 of 6

Popular Videos


How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?
Let us know

Related Articles

Java OOPS Interview Questions and Answers
Java Interview Questions
Java Collections Interview Questions and Answers
Java Thread Interview Questions and Answers