Interview Questions and Answers for 'Cla' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   next 30
 Q41. Explain Autoboxing ?Core Java
Ans. Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java5   autoboxing   wrapper classes     Asked in 2 Companies      basic        frequent


Very frequently asked. Usually difference between String,StringBuffer and StringBuilder is asked in different variations.
  Q42. Difference between StringBuffer and StringBuilder ?Core Java
Ans. StringBuffer is synchronized whereas StringBuilder is not.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   string   stringbuffer   string class   stringbuilder   synchronized   basic interview question   infosys technologies     Asked in 17 Companies      basic        frequent

Try 1 Question(s) Test


 Q43. When do you get ClassCastException?

or

What is ClassCastException ?
Ans. As we only downcast class in the hierarchy, The ClassCastException is thrown to indicate that code has attempted to cast an object to a subclass of which it is not an instance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   class casting   classcastexception   exception   error     Asked in 4 Companies      intermediate        frequent

Try 2 Question(s) Test


 Q44. Difference Between this() and super() ?Core Java
Ans. 1.this is a reference to the current object in which this keyword is used whereas super is a reference used to access members specific to the parent Class.

2.this is primarily used for accessing member variables if local variables have same name, for constructor chaining and for passing itself to some method whereas super is primarily used to initialize base class members within derived class constructor.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   class   objects   inheritence   constructor   this   super   this vs super     Asked in 1 Companies

Try 1 Question(s) Test


 Q45. Difference between the jsp scriptlet tag and jsp declaration tag?Java EE
Ans. The jsp scriptlet tag can only declare variables not methods whereas jsp declaration tag can declare variables as well as methods.

The declaration of scriptlet tag is placed inside the _jspService() method whereas The declaration of jsp declaration tag is placed outside the _jspService() method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     j2ee   jsp   scriptlet tag   declaraation tag   web application


 Q46. What are the Disadvantages of using Collection Classes over Arrays ?Core Java
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.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   collections classes   disadvantages of collections over arrays   collections vs arrays


 Q47. In which cases , moving methods to utility class could be useful ?Core Java
Ans. It could be worthy to move a method to util class if the method needs to be shared, doesn't require polymorphic behavior and need not be overridden in special cases.

Don't belong to one group through is-a relationship ( You can share through parent class method )

Don't implement a specific interface ( java 8 default methods )

Doesn't involve complex computing as you will be loosing the benefit of object state with just static method.

Doesn't require polymorphic behavior as static methods don't participate in runtime polymorphism.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     utility classes   util classes   static methods   application design        rare


 Q48. If an Abstract class has only abstract methods, What's the difference between such a class and an interface ?Core Java
Ans. Such a class still can have member elements which can be inherited and hence facilitate code reuse. Moreover Abstract class can have non final static elements whereas interfaces are only allowed to have static final elements.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     abstract class   interfaces     Asked in 2 Companies      Basic


 Q49. Can we overload method as following ?

void method(int... x){};
void method(int[] x){};
Core Java
Ans. No. Because java internally treats var args as arrays and hence both method declarations will generate the same byte code and hence would result in ambiguity while determining call binding.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     var args  methods  functions   method declaration  scjp  ocjp


 Q50. What is the use of Object class ?Core Java
Ans. 1. Default definition for some of the methods , like equals, hashcode etc that gets carried to all objects even if you don't define anything. But that default definition is kind of like assigning 0 to integer, it just provide a safe state , nothing much for comparison.

2. Places where you have no idea about what object you may receive and just want to perform out of 8 basic methods of object class, something like printing their string representation ( defined by their toString method ), or equality ( using their equals method )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     object class


 Q51. Differences between class not found exception and noclassdef found error ?Core Java
Ans. ClassNotFoundException is an exception that occurs when we try to load a class at run time using Class.forName() or loadClass() methods and mentioned classes are not found in the classpath.

NoClassDefFoundError is an error that occurs when a particular class is present at compile time, but was missing at run time.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exception handling  ClassNotFoundException  NoClassDefFoundError     Asked in 1 Companies


 Q52. Which access specifier can be used with Class ?Core Java
Ans. For top level class we can only use "public" and "default". We can use private with inner class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   class   access specifier   inner classes      basic        frequent


 Q53. How to display and set the Class path in Unix ?
Ans. To display the current CLASSPATH variable, use these commands in UNIX (Bourne shell):

% echo $CLASSPATH

To delete the current contents of the CLASSPATH variable,

In UNIX: % unset CLASSPATH; export CLASSPATH

To set the CLASSPATH variable,

In UNIX: % CLASSPATH=/home/george/java/classes; export CLASSPATH

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     unix   unix commands   classpath


Very Frequently asked.Favorite question in Walk in drive for many Indian service companies.
 Q54. What is a Final Class ?
Ans. A Class that cannot be sub classed.

  Sample Code for final class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   final   final class   java keyword   basic interview question     Asked in 3 Companies      basic        frequent


 Q55. Difference between boolean and Boolean ?Core Java
Ans. boolean is a primitive type whereas Boolean is a class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   wrapper classes   boolean vs Boolean      basic        rare


 Q56. What are Wrapper Classes ? What are Primitive Wrapper Classes ?
Core Java
Ans. A wrapper class is any class which "wraps" or "encapsulates" the functionality of another class or component. A Wrapper Class that wraps or encapsulates the primitive data type is called Primitive Wrapper Class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   wrapper classes   primitive wrapper classes


 Q57. What Design pattern Wrapper Classes implement ?Design
Ans. Adapter.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   wrapper classes   adapter design pattern   design pattern


 Q58. What is a class loader ? What are the different class loaders used by JVM ?Core Java
Ans. Part of JVM which is used to load classes and interfaces.

Bootstrap , Extension and System are the class loaders used by JVM.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   class loaders  classloaders   jvm   java memory management   advanced     Asked in 3 Companies


 Q59. Difference between nested and inner classes ?
Ans. Inner class is a type of nested class.

Inner classes are non static nested classes i.e the one that are associated with the instance of outer class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   static   nested classes   inner classes   nested vs inner class      basic        frequent

Try 1 Question(s) Test


 Q60. What is a nested interface ?
Ans. Any interface declared inside a class or an interface. It is static by default.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   nested classes


 Q61. What are the design considerations while making a choice between using interface and abstract class ?Core Java
Ans. Keep it as a Abstract Class if its a "Is a" Relationsship and should do subset/all of the functionality. Keep it as Interface if its a "Should Do" relationship.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   abstract classes   interfaces   advanced     Asked in 3 Companies


  Q62. what is the difference between collections class vs collections interface ?Core Java
Ans. Collections class is a utility class having static methods for doing operations on objects of classes which implement the Collection interface. For example, Collections has methods for finding the max element in a Collection.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   collections class   collection interface   basic interview question     Asked in 6 Companies      basic        frequent

Try 1 Question(s) Test


 Q63. How are classes loaded by JVM ?Core Java
Ans. Class loaders are hierarchical. The very first class is specially loaded with the help of static main() method declared in your class. All the subsequently loaded classes are loaded by the classes, which are already loaded and running.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   jvm   memory management   class loaders  classloaders     Asked in 1 Companies


 Q64. Difference between static vs. dynamic class loading?Core Java
Ans. static loading - Classes are statically loaded with Java new operator.

dynamic class loading - Dynamic loading is a technique for programmatically invoking the functions of a class loader at run time.

Class.forName (Test className);

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   jvm   memory management   class loaders  classloaders   static class loading   static loading   dynamic class loading   dynamic loading     Asked in 2 Companies      expert        frequent


  Q65. Advantage of Collection classes over Arrays ?Core Java
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.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   collections classes   advantages of collections over arrays   collections vs arrays   basic interview question     Asked in 6 Companies      basic        frequent


  Q66. Write a method to check if input String is Palindrome?Core Java
Ans. private static boolean isPalindrome(String str) {

if (str == null)
return false;

StringBuilder strBuilder = new StringBuilder(str);

strBuilder.reverse();

return strBuilder.toString().equals(str);

}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   string   stringbuilder   stringbuilder   string class   code   palindrome     Asked in 38 Companies      Basic        frequent


 Q67. Write a method that will remove given character from the String?Core Java
Ans.
private static String removeChar(String str, char c) {    
if (str == null)
return null;

return str.replaceAll(Character.toString(c), "");
}


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   string   string class   code   write code


 Q68. Why String is popular HashMap key in Java?Core Java
Ans. Since String is immutable, its hashcode is cached at the time of creation and it doesnt need to be calculated again. This makes it a great candidate for key in a Map and its processing is fast than other HashMap key objects. This is why String is mostly used Object as HashMap keys.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   string class   string   immutable  immutability   hashmap   immutable  immutability   hashcode   hash code   advanced     Asked in 2 Companies      expert        frequent


 Q69. What does String intern() method do?Core Java
Ans. intern() method keeps the string in an internal cache that is usually not garbage collected.

Moreover provide reference for scp object for corresponding string object present in heap memory.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   string class   string   intern method   garbage collection   advanced     Asked in 2 Companies      expert


 Q70. How substring() method of String class create memory leaks?Core Java
Ans. substring method would build a new String object keeping a reference to the whole char array, to avoid copying it. Hence you can inadvertently keep a reference to a very big character array with just a one character string.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   string class   string   substring   memory leaks   jvm   memory management   advanced   architecture   technical architect   technical lead      expert


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: